{"id":5195,"date":"2018-07-28T00:47:17","date_gmt":"2018-07-28T00:47:17","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=5195"},"modified":"2018-07-28T01:16:27","modified_gmt":"2018-07-28T01:16:27","slug":"beyond-good-ol-run-key-part-81","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2018\/07\/28\/beyond-good-ol-run-key-part-81\/","title":{"rendered":"Beyond good ol\u2019 Run key, Part 81"},"content":{"rendered":"<p>I love Windows Explorer. It offers so many opportunities for persistence.<\/p>\n<p>In my <a href=\"https:\/\/www.hexacorn.com\/blog\/2018\/05\/28\/beyond-good-ol-run-key-part-78-2\/\">older post<\/a> I described how you can modify the HCKR shell entries by adding a new verb and changing the default behavior of Windows Explorer to use that verb when it enters folders.<\/p>\n<p>Here&#8217;s another trick you can pull off.<\/p>\n<p>There <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/hh127467(v=vs.85).aspx\">is a way to add cascading menus<\/a> for different file types &#8211; it enables everyone to enrich the GUI experience, and of course, can be abused.<\/p>\n<p>Say&#8230; we want to change the handling of .txt files to &#8216;default&#8217; to our own Cascading menu which we call, well&#8230; &#8216;Open&#8217; and make it look like this:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/SubCommandsKey1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-5196\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/SubCommandsKey1.png\" alt=\"\" width=\"500\" height=\"332\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/SubCommandsKey1.png 593w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/SubCommandsKey1-300x199.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><br \/>\nI bet users seeing such change will still go for the &#8216;bold&#8217; default action and Launch the Notepad.<\/p>\n<p>Except it will launch Calculator.<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/SubCommandsKey2.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-5197\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/SubCommandsKey2.gif\" alt=\"\" width=\"500\" height=\"439\" \/><\/a>How did we get there?<\/p>\n<p>All we have to do is:<\/p>\n<ul>\n<li>Introduce a cascading menu for .txt files\n<ul>\n<li>HKCR\\txtfile\\shell\\submenu\n<ul>\n<li>&#8220;MUIVerb&#8221;=&#8221;Open&#8221;<\/li>\n<li>&#8220;SubCommands&#8221;=&#8221;Windows.testverb&#8221;<\/li>\n<li>&#8220;Position&#8221;=&#8221;Top&#8221;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>The above ensures the new cascading menu goes on the top of the list + is called &#8216;Open&#8217; + when it launches it calls the verb &#8216;Windows.testverb&#8217;<\/li>\n<li>Define the &#8216;Windows.testverb&#8217; verb under<br \/>\nHKLM\\SOFTWARE\\Microsoft\\Windows\\<br \/>\nCurrentVersion\\Explorer\\CommandStore\\<br \/>\nshell\\Windows.testverb<\/p>\n<ul>\n<li>MUIVerb=Notepad<\/li>\n<li>command\n<ul>\n<li>(Default)=@=&#8221;c:\\\\windows\\\\system32\\\\calc.exe&#8221;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>The above defines the verb as one that is called &#8216;Notepad&#8217; and that launches a calculator when the verb is triggered<\/li>\n<\/ul>\n<p>It&#8217;s pretty simple and may fool some users.<\/p>\n<p>Then there is an additional bonus entry. As if there was not enough confusion yet&#8230;<\/p>\n<p>It looks like there is another way to add cascading menus &#8211; via ExtendedSubCommandsKey.<\/p>\n<p>Again, it&#8217;s <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/shell\/how-to-create-cascading-menus-with-the-extendedsubcommandskey-registry-entry\">documented<\/a>, but I couldn&#8217;t make it work at first, until I started toying around with the existing entries in Registry &#8211; they used &#8216;ExtendedSubCommandsKey&#8217; not as a key, but as a value.<\/p>\n<p>This is how it works&#8230;<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/ExtendedSubCommandsKey.gif\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-5199\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/ExtendedSubCommandsKey.gif\" alt=\"\" width=\"500\" height=\"442\" \/><\/a><br \/>\nAnd this is how to set it up:<\/p>\n<ul>\n<li>Add HKCR\\txtfile\\shell\\extsub\n<ul>\n<li>MUIVerb=Open<\/li>\n<li>ExtendedSubCommandsKey=txtfile\\\\shell\\\\extsub<\/li>\n<li>Position=Top<\/li>\n<\/ul>\n<\/li>\n<li>Add HKCR\\txtfile\\shell\\extsub\\Shell\\Notepad, and underneath\n<ul>\n<li>command\n<ul>\n<li>@=&#8221;c:\\\\windows\\\\system32\\\\calc.exe&#8221;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>So.. the &#8216;ExtendedSubCommandsKey&#8217; key tells Shell where to look for the definition of the cascading menu &#8211; note the nested &#8216;shell\\extsub\\shell\\notepad\\command&#8217; key (case insensitive) vs &#8216;shell\\open\\command&#8217;:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/ExtendedSubCommandsKey1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-5205\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/ExtendedSubCommandsKey1.png\" alt=\"\" width=\"500\" height=\"142\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/ExtendedSubCommandsKey1.png 713w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/ExtendedSubCommandsKey1-300x85.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>And because of that&#8230; there is more.<\/p>\n<p>Instead of dropping the definition of the cascading menu under the obvious location &#8216;txtfile&#8217;, one could define it like this:<\/p>\n<ul>\n<li>Add HKCR\\txtfile\\shell\\extsub\n<ul>\n<li>MUIVerb=Open<\/li>\n<li>ExtendedSubCommandsKey=foofile<\/li>\n<li>Position=Top<\/li>\n<\/ul>\n<\/li>\n<li>Add HKCR\\foofile\\Shell\\Notepad\n<ul>\n<li>command<\/li>\n<li>@=&#8221;c:\\\\windows\\\\system32\\\\calc.exe&#8221;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>So&#8230; the malware could add a new &#8216;filetype&#8217; called &#8216;foofile&#8217; and use it as a definition for the cascading menu that is referenced by the &#8216;ExtendedSubCommandsKey&#8217; entry.<\/p>\n<p>I think you might have noticed that the demos show the multiple &#8216;Open&#8217; entries on the menu. One could remove the definition of the &#8216;Open&#8217; verb from the respective keys, but while it&#8217;s easy, it could trigger some EDR\/AV alerts. I may be a bit too optimistic, but I bet many people will still follow the &#8216;bold&#8217; menu item first, despite menu item duplications (&#8216;it&#8217;s Windows, after all&#8217;).<\/p>\n<p>And yes, there is more&#8230;<\/p>\n<p>Shell uses at least 2 more mechanisms to add menus or redefine how the verbs are used on the selected items in Windows Explorer.<\/p>\n<ul>\n<li>There is a documented <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/shell\/how-to-create-cascading-menus-with-the-iexplorercommand-interface\">IExplorerCommand<\/a> interface<\/li>\n<li>There are <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/shell\/context-menu-handlers\">special entries<\/a> under the HKCR that can be used to modify the behavior of the respective menu items\n<ul>\n<li>DefaultAppliesTo<\/li>\n<li>AppliesTo<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>I am not describing the first one (you need to develop a COM DLL), but the second one deserves some attention.<\/p>\n<p>Turns out that there is a way to implement conditional menu items for Windows Explorer. Yup. Windows Explorer understands a language called <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/lwef\/-search-2x-wds-aqsreference\">Advanced Query Syntax<\/a>. There are not too many practical examples of its usage online, the best (practical) information I could find is in <a href=\"https:\/\/superuser.com\/questions\/183785\/windows-7-context-menu-for-folders-if-folder-contains-certain-filetypes\">this post<\/a>. Plus, there are default Windows 10 Registry settings we can explore.<\/p>\n<p>Have a look at these keys:<\/p>\n<ul>\n<li>HKCR\\*\\shell\\UpdateEncryptionSettingsWork<\/li>\n<\/ul>\n<p>The AppliesTo includes this query:<\/p>\n<pre>System.StorageProviderId:&lt;&gt;\"network\" AND \r\nSystem.StorageProviderProtectionMode:&lt;&gt;1 AND \r\nSystem.StorageProviderProtectionMode:&lt;&gt;2<\/pre>\n<ul>\n<li>HKCR\\DeviceDisplayObject\\AllItems\\Shell\\Microsoft.DxpOpen<\/li>\n<\/ul>\n<pre>System.Devices.LaunchDeviceStageFromExplorer:=\r\nSystem.StructuredQueryType.Boolean#True<\/pre>\n<ul>\n<li>HKCR\\Drive\\shell\\change-passphrase\\command<\/li>\n<\/ul>\n<pre>(\r\nSystem.Volume.BitLockerProtection:=\r\nSystem.Volume.BitLockerProtection#On OR \r\nSystem.Volume.BitLockerProtection:=\r\nSystem.Volume.BitLockerProtection#Encrypting OR\r\nSystem.Volume.BitLockerProtection:=\r\nSystem.Volume.BitLockerProtection#Suspended\r\n)\r\nAND \r\nSystem.Volume.BitLockerCanChangePassphraseByProxy:=\r\nSystem.StructuredQueryType.Boolean#True<\/pre>\n<p>and others&#8230; (just search for &#8216;AppliesTo&#8217; under HKCR).<\/p>\n<p>Every single one that is &#8216;predefined&#8217; (command is set) can be modified and help to establish yet another persistence mechanism that is triggered only when conditions are met (e.g. as per the above &#8211; when drive is encrypted malware could be launched when the user tries to change the passphrase).<\/p>\n<p>I guess it&#8217;s yet another not-so-much-explored area in case you are looking for forensics\/malware topics for your final thesis \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I love Windows Explorer. It offers so many opportunities for persistence. In my older post I described how you can modify the HCKR shell entries by adding a new verb and changing the default behavior of Windows Explorer to use &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2018\/07\/28\/beyond-good-ol-run-key-part-81\/\">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":[43,35],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5195"}],"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=5195"}],"version-history":[{"count":9,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5195\/revisions"}],"predecessor-version":[{"id":5204,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5195\/revisions\/5204"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=5195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=5195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=5195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}