{"id":4158,"date":"2017-03-18T02:26:52","date_gmt":"2017-03-18T02:26:52","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=4158"},"modified":"2017-03-18T10:28:07","modified_gmt":"2017-03-18T10:28:07","slug":"beyond-good-ol-run-key-part-60","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2017\/03\/18\/beyond-good-ol-run-key-part-60\/","title":{"rendered":"Beyond good ol\u2019 Run key, Part 60"},"content":{"rendered":"<p>Today I&#8217;ll describe a little secret &#8211; a stealthy autostart key that is not very well-known and is very reliable since it is used by&#8230; well&#8230; the Windows Update.<\/p>\n<p>Yup, it&#8217;s a pretty handy one&#8230;<\/p>\n<p>This is the key:<\/p>\n<ul>\n<li>HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Setup\\ServiceStartup<\/li>\n<\/ul>\n<p>It has two interesting properties:<\/p>\n<ul>\n<li>It can be used as a persistence mechanism<\/li>\n<li>It can also mysteriously make files re-appear on the system as the mechanism is used to update files and as such, the entries are being used to copy files during the system start (by the &#8216;svchost.exe -k netsvcs&#8217; process)<\/li>\n<\/ul>\n<p>This is an example entry:<\/p>\n<pre>HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Setup\\ServiceStartup\\malware.dll\r\n\"RegistrationFlags\"=dword:00000001\r\n\"CacheFile\"=\"C:\\\\test\\\\malware.dll\"\r\n\"TargetFile\"=\"C:\\\\WINDOWS\\\\system32\\\\malware.dll\"<\/pre>\n<p>The entry will force the file:<\/p>\n<ul>\n<li>\n<pre>C:\\test\\malware.dll<\/pre>\n<\/li>\n<\/ul>\n<p>to be loaded.<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-4159\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup1-300x130.png\" alt=\"\" width=\"501\" height=\"217\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup1-300x130.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup1-768x333.png 768w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup1-1024x444.png 1024w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup1.png 1429w\" sizes=\"(max-width: 501px) 100vw, 501px\" \/><\/a><\/p>\n<p>It will be also copied to:<\/p>\n<ul>\n<li>\n<pre>C:\\WINDOWS\\system32\\malware.dll<\/pre>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-4160\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup2-300x168.png\" alt=\"\" width=\"500\" height=\"281\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup2-300x168.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup2.png 597w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Note that you can also simply ignore the copying and drop the file anywhere, and just point &#8216;CacheFile&#8217; and &#8216;TargetFile&#8217; to it.<\/p>\n<p>If you look at the first screenshot you will notice the Procmon logs show a reference to the &#8217;20MUIFixUp&#8217; entry.<\/p>\n<p>Interestingly, this entry can be used to just copy files, so adding a reg combo as below:<\/p>\n<pre>HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Setup\\ServiceStartup\\malware.dll\r\n\"20MUIFixUp\"=dword:00000001\r\n\"CacheFile\"=\"C:\\\\test\\\\malware.dll\"\r\n\"TargetFile\"=\"C:\\\\WINDOWS\\\\system32\\\\malware.dll\"<\/pre>\n<p>will create &#8216;C:\\WINDOWS\\system32\\malware.dll&#8217; anytime you boot the system (but the file won&#8217;t be loaded\/executed). The&#8217; 20MUIFixUp&#8217; entry in the Registry will be deleted afterwards (so it needs to be re-created).<\/p>\n<p>Interestingly, the information about the loaded DLLs can be found inside the Windows Update log file:<\/p>\n<ul>\n<li>c:\\WINDOWS\\WindowsUpdate.log<\/li>\n<\/ul>\n<p>Here&#8217;s an excerpt:<\/p>\n<pre>Misc\u00a0\u00a0\u00a0 Registering binary: C:\\WINDOWS\\system32\\regsvr32.exe\u00a0 \/s \"C:\\WINDOWS\\system32\\malware.dll\"\r\nMisc\u00a0\u00a0\u00a0 FATAL: Self registration of C:\\WINDOWS\\system32\\malware.dll failed, error = 0x8024D007\r\nSetup\u00a0\u00a0\u00a0 FATAL: Failed to register C:\\WINDOWS\\system32\\malware.dll: error 0x8024d007\r\nSetup\u00a0\u00a0\u00a0 FATAL: ProcessDelayedCopies failed: 0x8024d007\r\nService\u00a0\u00a0\u00a0 FATAL: Failed to fix up registration at service startup: 0x8024d007<\/pre>\n<p>My test DLL was not prepared correctly (missing exported &#8216;DllInstall&#8217; &#8211; see below), but the DLL still loads.<\/p>\n<p>At least on Windows XP.<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-4161\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup3-300x151.png\" alt=\"\" width=\"300\" height=\"151\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup3-300x151.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2017\/03\/ServiceStartup3.png 366w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Okay, what about newer versions of Windows?<\/p>\n<p>First, let&#8217;s fix my DLL.<\/p>\n<p>To do so, I actually add two exported functions:<\/p>\n<ul>\n<li>DllInstall, and<\/li>\n<li>DllRegisterServer.<\/li>\n<\/ul>\n<p>Why?<\/p>\n<p>Because the &#8216;RegistrationFlags&#8217; parameter can be equal either to &#8216;1&#8217; or &#8216;2&#8217;.<\/p>\n<p>If it is 1, the &#8216;DllInstall&#8217; API will be called. Otherwise, it will be the &#8216;DllRegisterServer&#8217; API.<\/p>\n<p>When these DLLs are loaded and respective functions are called the Windows Update service logs the appropriate information to the &#8216;WindowsUpdate.log&#8217; file &#8211; let&#8217;s have a look at the two examples:<\/p>\n<pre>HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Setup\\ServiceStartup\\malware.dll\r\n\"RegistrationFlags\"=dword:00000001\r\n\"CacheFile\"=\"C:\\\\test\\\\malware.dll\"\r\n\"TargetFile\"=\"C:\\\\test\\\\malware.dll\"<\/pre>\n<p>and<\/p>\n<pre>HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Setup\\ServiceStartup\\malware.dll\r\n\"RegistrationFlags\"=dword:00000002\r\n\"CacheFile\"=\"C:\\\\test\\\\malware.dll\"\r\n\"TargetFile\"=\"C:\\\\test\\\\malware.dll\"<\/pre>\n<p>When Windows Update service is restarted, you will get the following log entries inside the WindowsUpdate.log:<\/p>\n<pre>\"RegistrationFlags\"=dword:00000001\r\nMisc\u00a0\u00a0\u00a0 Registering binary: C:\\Windows\\system32\\regsvr32.exe\u00a0 \/s \"C:\\test\\malware.dll\"\r\nAgent\u00a0\u00a0\u00a0\u00a0\u00a0 * WU client version 7.6.7600.256\r\nAgent\u00a0\u00a0\u00a0\u00a0\u00a0 * Base directory: C:\\Windows\\SoftwareDistribution\r\nAgent\u00a0\u00a0\u00a0\u00a0\u00a0 * Access type: No proxy\r\nAgent\u00a0\u00a0\u00a0\u00a0\u00a0 * Network state: Connected\r\n\r\n\"RegistrationFlags\"=dword:00000002\r\nMisc\u00a0\u00a0\u00a0 Registering binary: C:\\Windows\\system32\\regsvr32.exe\u00a0 \/s \/n \/i \"c:\\test\\malware.dll\"\r\nAgent\u00a0\u00a0\u00a0\u00a0\u00a0 * WU client version 7.6.7600.256\r\nAgent\u00a0\u00a0\u00a0\u00a0\u00a0 * Base directory: C:\\Windows\\SoftwareDistribution\r\nAgent\u00a0\u00a0\u00a0\u00a0\u00a0 * Access type: No proxy\r\nAgent\u00a0\u00a0\u00a0\u00a0\u00a0 * Network state: Connected\r\n<\/pre>\n<p>The trick works like a charm for Windows 7. I don&#8217;t see it working on Windows 10 though, but perhaps it has to be triggered some other way.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I&#8217;ll describe a little secret &#8211; a stealthy autostart key that is not very well-known and is very reliable since it is used by&#8230; well&#8230; the Windows Update. Yup, it&#8217;s a pretty handy one&#8230; This is the key: HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Setup\\ServiceStartup &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2017\/03\/18\/beyond-good-ol-run-key-part-60\/\">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,35,15,19,46,9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4158"}],"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=4158"}],"version-history":[{"count":4,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4158\/revisions"}],"predecessor-version":[{"id":4165,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4158\/revisions\/4165"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=4158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=4158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=4158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}