{"id":9481,"date":"2024-09-21T22:43:06","date_gmt":"2024-09-21T22:43:06","guid":{"rendered":"https:\/\/www.hexacorn.com\/blog\/?p=9481"},"modified":"2024-09-22T15:19:00","modified_gmt":"2024-09-22T15:19:00","slug":"rundll32-goes-to-hell","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2024\/09\/21\/rundll32-goes-to-hell\/","title":{"rendered":"Rundll32 goes to hell&#8230;"},"content":{"rendered":"\n<p>Parsing command line invocations is fun, because it&#8217;s impossible to do it right (all the time).<\/p>\n\n\n\n<p>Imagine a test DLL that exports a function called <em>foobar<\/em>. We place this DLL in <em>c:\\test<\/em> directory and name it like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">test.dll, #666<\/pre>\n\n\n\n<p>We can then use <em>rundll32.exe<\/em> to execute the <em>foobar<\/em> function using the following syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rundll32 \"c:\\test\\test.dll, #666\", foobar<\/pre>\n\n\n\n<p>A different version can use the following name:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">test.dll,abcxyz<\/pre>\n\n\n\n<p>with the invocation:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rundll32 \"test.dll,abcxyz\", foobar<\/pre>\n\n\n\n<p>We do need quotes, because <em>rundll32.exe<\/em> does not accept file names with a &#8216;coma&#8217; in them (for obvious reasons), and the full path is not needed if we are in the same directory, but the gist is that these are all proper DLL file names!:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2024\/09\/rundll_1.png\"><img decoding=\"async\" loading=\"lazy\" width=\"189\" height=\"47\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2024\/09\/rundll_1.png\" alt=\"\" class=\"wp-image-9482\"\/><\/a><\/figure>\n\n\n\n<p>What your sophisticated regexes extracting DLL name and API&#8217;s ordinal number, or API name from this sort of invocations tell you today?<\/p>\n\n\n\n<p>And then here&#8217;s another case for your consideration &#8211; create a test DLL with the following exports:<\/p>\n\n\n\n<ul>\n<li>A<\/li>\n\n\n\n<li>W<\/li>\n\n\n\n<li>AA<\/li>\n\n\n\n<li>AW<\/li>\n\n\n\n<li>WA<\/li>\n\n\n\n<li>WW<\/li>\n<\/ul>\n\n\n\n<p>When you run the following invocations:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">rundll32 c:\\test\\test.dll, A<br>rundll32 c:\\test\\test.dll, W<\/pre>\n\n\n\n<p>&#8211; which of these 6 exported functions will get executed?<\/p>\n\n\n\n<p>I have <a href=\"https:\/\/www.hexacorn.com\/blog\/2019\/09\/28\/rundll32-api-calling\/\">provided<\/a> an answer to this question a few years ago, and here&#8217;s the DebugView output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2024\/09\/rundll_2.png\"><img decoding=\"async\" loading=\"lazy\" width=\"479\" height=\"129\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2024\/09\/rundll_2.png\" alt=\"\" class=\"wp-image-9483\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2024\/09\/rundll_2.png 479w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2024\/09\/rundll_2-300x81.png 300w\" sizes=\"(max-width: 479px) 100vw, 479px\" \/><\/a><\/figure>\n\n\n\n<p>The bottom line is that you can&#8217;t use regexes for parsing command line invocations or make assumptions w\/o running into many corner cases.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Parsing command line invocations is fun, because it&#8217;s impossible to do it right (all the time). Imagine a test DLL that exports a function called foobar. We place this DLL in c:\\test directory and name it like this: test.dll, #666 &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2024\/09\/21\/rundll32-goes-to-hell\/\">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":[13,53],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/9481"}],"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=9481"}],"version-history":[{"count":5,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/9481\/revisions"}],"predecessor-version":[{"id":9491,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/9481\/revisions\/9491"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=9481"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=9481"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=9481"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}