{"id":5992,"date":"2019-02-23T01:39:31","date_gmt":"2019-02-23T01:39:31","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=5992"},"modified":"2019-02-23T01:49:00","modified_gmt":"2019-02-23T01:49:00","slug":"beyond-good-ol-run-key-part-104","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2019\/02\/23\/beyond-good-ol-run-key-part-104\/","title":{"rendered":"Beyond good ol\u2019 Run key, Part 104"},"content":{"rendered":"\n<p>Today&#8217;s entry is not about new persistence mechanism, but about a few relatively less known mechanisms that are involved in the Windows startup on newer versions of the OS, and are primarily involved during the user log on process.<\/p>\n\n\n\n<p>Newer versions of Windows completely re-engineered the Task Manager application. I personally detest it, and prefer to use Process Hacker, or Process Explorer, or even command line, but&#8230; I guess if all this fancy, detail-hiding stuff in newer Windows versions means some sort of progress (tablets-centric interface, and laptops will die), then it means I am probably the old-fashioned problem here&#8230; and I currently solve it by using proper old-school tools \ud83d\ude42<\/p>\n\n\n\n<p>Anyways&#8230;<\/p>\n\n\n\n<p>As much as I hate new Task Manager in win8\/win10, I have to look at what it does, even if it&#8217;s just from a &#8216;curiosity&#8217; perspective &#8211; one that focuses on forensics artifacts it creates, and various ways we can abuse these new &#8216;features&#8217;&#8230;<\/p>\n\n\n\n<p>One of the less known Registry entries utilized by the standard &#8216;startup&#8217; routine (i.e. the one that is primarily driven by Windows Explorer e.g. Run, RunOnce keys, Startup folder, etc.), after the userinit.exe finishes its work, are these three locations in the Registry:<\/p>\n\n\n\n<ul><li>HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\StartupApproved\\&lt;entries&gt;<\/li><li>HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo\\1\\RunStuffHasBeenRun<\/li><li>HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\SessionInfo\\1\\StartupHasBeenRun<\/li><\/ul>\n\n\n\n<p>For the first one, the &lt;entries> refer to &#8216;standard&#8217; startup entries like Run Key, Startup folder, etc.. This key is populated by Task Manager\/Startup tab when we enable\/disable entries:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup1.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup1.png\" alt=\"\" class=\"wp-image-5993\" width=\"444\" height=\"114\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup1.png 666w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup1-300x77.png 300w\" sizes=\"(max-width: 444px) 100vw, 444px\" \/><\/a><\/figure>\n\n\n\n<p>Some people claim it is already <a href=\"https:\/\/www.wilderssecurity.com\/threads\/spymel-info-stealing-trojan-evades-antivirus-detection-via-stolen-certificates.382957\/\">abused<\/a> by malware, but I have not tested it.<\/p>\n\n\n\n<p>We can use Procmon to track this activity e.g. for 3 Run entries we can see this enumeration and each entry is checked against the <em>StartupApproved<\/em> list:<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup2.png\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup2-1024x261.png\" alt=\"\" class=\"wp-image-5995\" width=\"512\" height=\"131\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup2-1024x261.png 1024w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup2-300x76.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup2-768x196.png 768w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2019\/02\/startup2.png 1127w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n\n\n\n<p>For the second entry&#8230; when I searched for it online, I quickly discovered that it seems to be really old and was discussed many times. For example, one of the older twits from <a href=\"https:\/\/twitter.com\/SwiftOnSecurity\">@swiftonsecurity<\/a> mentions <a href=\"https:\/\/twitter.com\/SwiftOnSecurity\/status\/484429245603532802\">it<\/a> (in 2014!). <\/p>\n\n\n\n<p>What is its meaning though? <\/p>\n\n\n\n<p>Basically, if the value is not set, it is set when Explorer starts (note that it is for a specific session registry node for which the function <a href=\"https:\/\/www.geoffchappell.com\/studies\/windows\/shell\/shell32\/api\/regfldr\/createsessionkey.htm\">SHCreateSessionKey<\/a> opens a dedicated volatile Registry entry created during logon by userinit.exe). It then guards the repetitive execution of most of the legacy autostart and Registry startup entries.<\/p>\n\n\n\n<p>For the third entry, it&#8217;s very similar to the second one, it just guards a different set of startup execution. If the entry exists, it prevents the Startup folders from being enumerated over and over again for a given session.<\/p>\n\n\n\n<p>I think the primary reasons for these two entries is to prevent recurring execution of programs that are meant to execute during logon, but should not execute when e.g. Windows Explorer crashes and is restarted, or perhaps when sessions flips between interactive (user with a direct access to the box), and Terminal session\/RDP (? need to test if userinit creates separate sessions for this; may depend on the licenses stipulating number of concurrent sessions available). There may be other scenarios(?).<\/p>\n\n\n\n<p>Since we talk about things happening around startup, I want to refer to a more recent discovery that I already <a href=\"https:\/\/www.hexacorn.com\/blog\/2019\/02\/09\/event-logs\/\">briefly discussed<\/a> on this blog, and which has been discovered by <a href=\"https:\/\/twitter.com\/SBousseaden\">Samir<\/a> (kudos!). Thanks to his <a href=\"https:\/\/twitter.com\/SBousseaden\/status\/1087290113904791553\">analysis<\/a> we can now track execution of at least some of the autostart entries. We can do so by looking at <em>Microsoft-Windows-Shell-Core\/Operational<\/em> logs and its 9707\/9708 events.<\/p>\n\n\n\n<p>Last, but not least, if you see Registry entries, or folders named <em>AutorunsDisabled<\/em> you will of course know these have been &#8216;imprisoned&#8217; by someone using Autoruns and ticking off some entries.<\/p>\n\n\n\n<p>Now&#8230; for the bonus part&#8230;<\/p>\n\n\n\n<p>When we talk about startup locations, it&#8217;s easy to forget that all of them are executed in a sequence. For example, as a part of this sequence, Windows Explorer enumerates and executes Run keys first, only then it executes stuff from the Startup folders. With that knowledge it is possible to create a number of artifacts that are clean, perhaps even volatile (only exist during the start-up process). Autoruns and other tools will see bogus entries, or entries that on their own look non-malicious. One could use Run keys to create a new file on the system, which in turn could be executed by the shell:startup folder from a .lnk file pointing to the non-existing file (more precisely, file that only exists during startup, and is then deleted &#8211; see next sentence). After that, the temporarily file could be deleted by another startup entry. I think race conditions like this could be an interesting development in the future.<\/p>\n\n\n\n<p>Finally, one more entry to look at:<\/p>\n\n\n\n<ul><li>HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Serialize\\StartupDelayInMSec<\/li><\/ul>\n\n\n\n<p>The default value is 10000 ms. The max value is 3600000 ms. When changed, it affects how long the OS will wait for the &#8216;standard&#8217; startup entries to execute. Many optimizing guides suggest changes to this registry entry (making it 0 removes all the delays).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s entry is not about new persistence mechanism, but about a few relatively less known mechanisms that are involved in the Windows startup on newer versions of the OS, and are primarily involved during the user log on process. Newer &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2019\/02\/23\/beyond-good-ol-run-key-part-104\/\">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],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5992"}],"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=5992"}],"version-history":[{"count":9,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5992\/revisions"}],"predecessor-version":[{"id":6004,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5992\/revisions\/6004"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=5992"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=5992"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=5992"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}