{"id":7817,"date":"2021-05-26T22:49:12","date_gmt":"2021-05-26T22:49:12","guid":{"rendered":"https:\/\/www.hexacorn.com\/blog\/?p=7817"},"modified":"2021-05-26T22:56:54","modified_gmt":"2021-05-26T22:56:54","slug":"a-story-about-procmon-no-not-that-one-its-misbehaving-client","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2021\/05\/26\/a-story-about-procmon-no-not-that-one-its-misbehaving-client\/","title":{"rendered":"A story about Procmon (no, not that one &#8211; its misbehaving client)"},"content":{"rendered":"\n<p>We all love Process Monitor, but what we love even more are its undocumented features. <\/p>\n\n\n\n<p>Checking program&#8217;s accepted command line arguments we can quickly discover that it can be called with an option &#8220;\/client&#8221;. When started like this Process Monitor creates a socket and starts listening on port 23219:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_2.png\"><img decoding=\"async\" loading=\"lazy\" width=\"555\" height=\"45\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_2.png\" alt=\"\" class=\"wp-image-7818\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_2.png 555w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_2-300x24.png 300w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>Now that we found how to make it listen on port the only thing to do is finding how to talk to it. Ater checking the Window Messaging callback procedure I noticed it includes code to handle message WM_COMMAND with wParam equal to 40072. Code like this is typically executed via Menu, or keyboard accelerators. After inspecting GUI and accelerators table in procmon resources I couldn&#8217;t find any way to trigger it. At this stage I have already suspected this is probably a legacy code that has never been removed from the program, so it&#8217;s time to play dirty.<\/p>\n\n\n\n<p>There are many ways to trigger execution of the afrementioned code path &#8211; we could probably add a new shortcut to accelerator table and recompile the .exe using Resource Hacker. We could write a small snippet of code to find PROCMON_WINDOW_CLASS window and then send the message to it. Or, we can be lazy and use an existing tool to do just that. I chose the latter and used <a href=\"https:\/\/github.com\/stefankueng\/sendmessage\">SendMessage64<\/a>:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_0.png\"><img decoding=\"async\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_0.png\" alt=\"\" class=\"wp-image-7819\" width=\"500\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_0.png 602w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_0-300x167.png 300w\" sizes=\"(max-width: 602px) 100vw, 602px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>You must ensure the program is launched with admin privileges otherwise Procmon won&#8217;t be able to receive the window message.<\/p>\n\n\n\n<p>Once we send the message, Procmon will use SHGetSpecialFolderLocation API with CSIDL_NETWORK parameter to allow us to select the computer from our local network:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_1.png\"><img decoding=\"async\" loading=\"lazy\" width=\"320\" height=\"338\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_1.png\" alt=\"\" class=\"wp-image-7820\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_1.png 320w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_1-284x300.png 284w\" sizes=\"(max-width: 320px) 100vw, 320px\" \/><\/a><\/figure><\/div>\n\n\n\n<p>Once we choose the computer, we will &#8230; crash Procmon \ud83d\ude42<\/p>\n\n\n\n<p>This pretty much confirms the hypothesis it&#8217;s a legacy code.<\/p>\n\n\n\n<p>With that, I loaded procmon into xdbg, and made a breakpoint after SHGetSpecialFolderLocation, then checked where the crash happens. It was two hardcoded values &lt;remote system root&gt; and &lt;remote computer name&gt; which (due to lack of GUI) can&#8217;t be initialized with proper values. I initialized them manually in memory and while avoiding crash, managed to connect to the host (which in this case was the same box &#8211; yes, you can run two Procmon instances simultaneously in this setup).<\/p>\n\n\n\n<p>This is where I hit the wall as this time it&#8217;s client Procmon that crashed anyway:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_4.png\"><img decoding=\"async\" loading=\"lazy\" width=\"507\" height=\"245\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_4.png\" alt=\"\" class=\"wp-image-7822\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_4.png 507w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2021\/05\/procmon_4-300x145.png 300w\" sizes=\"(max-width: 507px) 100vw, 507px\" \/><\/a><\/figure>\n\n\n\n<p>I suspect that a) I should not be running two Procmon instances on the system or b) the code is broken and it&#8217;s a miracle we got that far anyway or c) I have no idea \ud83d\ude42<\/p>\n\n\n\n<p>Still, in theory you should be able to connect to the client w\/o crashing it. The only remaining bit is the protocol which may be a bit time-consuming to crack. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>We all love Process Monitor, but what we love even more are its undocumented features. Checking program&#8217;s accepted command line arguments we can quickly discover that it can be called with an option &#8220;\/client&#8221;. When started like this Process Monitor &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2021\/05\/26\/a-story-about-procmon-no-not-that-one-its-misbehaving-client\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[53],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/7817"}],"collection":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/comments?post=7817"}],"version-history":[{"count":5,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/7817\/revisions"}],"predecessor-version":[{"id":7826,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/7817\/revisions\/7826"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=7817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=7817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=7817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}