{"id":5335,"date":"2018-09-02T00:50:59","date_gmt":"2018-09-02T00:50:59","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=5335"},"modified":"2018-09-02T01:01:22","modified_gmt":"2018-09-02T01:01:22","slug":"beyond-good-ol-run-key-part-86","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2018\/09\/02\/beyond-good-ol-run-key-part-86\/","title":{"rendered":"Beyond good ol\u2019 Run key, Part 86"},"content":{"rendered":"<p>It is a well-known fact that Windows features are the best persistence mechanisms, and&#8230; the one I am going to talk about is yet another one of these&#8230;<\/p>\n<p>If you ever ran into a problem of having not enough space on your hard drive you are certainly familiar with the Disk Cleanup program:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-5336 size-full\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr1.png\" alt=\"\" width=\"375\" height=\"454\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr1.png 375w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr1-248x300.png 248w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/a><\/p>\n<p>It turns out that the list of the &#8216;Files to delete&#8217; that we see on the GUI is not random. It is pulled from this Registry node:<\/p>\n<ul>\n<li>HKLM\\SOFTWARE\\Microsoft\\Windows\\<br \/>\nCurrentVersion\\Explorer\\<br \/>\nVolumeCaches<\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-5337\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr2.png\" alt=\"\" width=\"500\" height=\"406\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr2.png 786w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr2-300x244.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr2-768x623.png 768w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>So, it would seem the list is dynamic and we can add entries to it.<\/p>\n<p>Indeed.<\/p>\n<p>The process is actually well-documented in this Microsoft&#8217;s article: <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb776782%28v=vs.85%29.aspx#registration\">Registering a Disk Cleanup Handler<\/a>.<\/p>\n<p>So, adding these entries:<\/p>\n<ul>\n<li>HKLM\\SOFTWARE\\Microsoft\\Windows\\<br \/>\nCurrentVersion\\Explorer\\VolumeCaches\\<br \/>\nBadGuy=&lt;BADCLSID&gt;<\/li>\n<li>HKCR\\CLSID\\&lt;BADCLSID&gt;\\<br \/>\nInProcServer32 = &lt;BADDLL&gt;<\/li>\n<\/ul>\n<p>will launch the BADDLL anytime Clean Manager tool is launched. Notably, the GUI won&#8217;t show the BadGuy entry (unless additional required Registry entries are populated &#8211; refer to the information in the Microsoft article I provided the link to)!<\/p>\n<p>In my <a href=\"https:\/\/www.hexacorn.com\/blog\/2018\/08\/31\/beyond-good-ol-run-key-part-85\/\">previous<\/a> post I speculated that in some cases it is possible to design LOLbinish persistence mechanisms. We can start by adding e.g. Run key pointing to a legitimate OS binary and then ensure that when it&#8217;s launched during logon process it will run the second stage of the persistence mechanism. The Werfault program was a good example, and the Disk Cleanup program falls into this category as well!<\/p>\n<p>The executable that launches the Disk Cleanup is called cleanmgr.exe. Adding it to run during the start-up may not be the best idea, because it has a GUI, but&#8230; there are always command line arguments of this program that we can use e.g.<\/p>\n<ul>\n<li>\/autoclean<\/li>\n<li>\/setup<\/li>\n<\/ul>\n<p>Indeed, adding &#8216;cleanmgr \/autoclean&#8217; to &#8216;cleanmgr \/setup&#8217;\u00a0 to the &#8216;typical&#8217; start-up place e.g. Run key will ensure that there is no GUI when the cleanmgr.exe is launched, and in a background, the plug-ins are loaded as well. Including the bad one.<\/p>\n<p>From a forensic perspective, cleanmgr.exe updates the files in the following location:<\/p>\n<ul>\n<li>c:\\WINDOWS\\system32\\LogFiles\\setupcln\\setupact.log<br \/>\nc:\\WINDOWS\\system32\\LogFiles\\setupcln\\setuperr.log<\/li>\n<\/ul>\n<p>I have not seen these files being updated with any references to the plug-ins loaded, but it could be a helpful artifact nevertheless&#8230;<\/p>\n<p>And&#8230; there is more&#8230;<\/p>\n<p>The Disk Cleanup has a few more tricks for us to exploit.<\/p>\n<p>Many entries that we see listed under the VolumeCache node point to {C0E13E61-0CC6-11d1-BBB6-0060978B2AE6}. This CLSID refers to c:\\Windows\\System32\\dataclen.dll file which is a generic folder and file deletion tool!<\/p>\n<p>The values it relies on are:<\/p>\n<ul>\n<li>Folder &#8211; where to look for files to delete e.g. c:\\test (refer to Microsoft article for a syntax for multiple entries)<\/li>\n<li>Files &#8211; what files to look for e.g. *.foo (refer to Microsoft article for a syntax for multiple entries)<\/li>\n<li>StateFlags=1 &#8211; an internal flag<\/li>\n<li>Flags = 1 &#8211; a documented flag, here means &#8216;run the plug-in&#8217;, but it can also tell the tool to do more things (refer to Microsoft article for details)<\/li>\n<\/ul>\n<p>Once these are set-up the program will search for the file(s) inside the folder(s) as per the Registry values. If any is found it will remove them as usual&#8230;<\/p>\n<p>BUT<\/p>\n<p>if any of these values exist:<\/p>\n<ul>\n<li>PreCleanupString &#8211; a path to the program that will be executed prior to clean-up<\/li>\n<li>CleanupString &#8211; a path to the program that will be executed after the clean-up<\/li>\n<\/ul>\n<p>it will also execute these programs prior and after the deletion!<\/p>\n<p>Sounds interesting?<\/p>\n<p>To trigger this one has to constantly drop c:\\test\\somefile.foo on the system. This will ensure the deletion library finds something to do and uses these two cleanup string entries and&#8230; these programs will be automatically executed.<\/p>\n<p>So&#8230;<\/p>\n<p>One can add their own entry, or modify the existing entries e.g.:<\/p>\n<ul>\n<li>Diagnostic Data Viewer database files\n<ul>\n<li>CleanupString = rundll32.exe utcutil.dll,DiskCleanupEnd<\/li>\n<li>PreCleanupString = rundll32.exe utcutil.dll,DiskCleanupStart<\/li>\n<\/ul>\n<\/li>\n<li>Windows Error Reporting Files\n<ul>\n<li>PreCleanupString = wermgr.exe -purgestores<\/li>\n<\/ul>\n<\/li>\n<li>etc.<\/li>\n<\/ul>\n<p>There is also a dangerous bit. One could use this mechanism to delete any folder\/file on the system&#8230;<\/p>\n<p>Lastly, if you want the PreCleanupString \/ CleanupString programs to be launched w\/o gui, i.e. while using e.g. \/autoclean command line switch, just need to a dword value Autorun=1 to the same branch in the Registry e.g.:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-5342\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr3.png\" alt=\"\" width=\"618\" height=\"272\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr3.png 618w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/09\/cleanmgr3-300x132.png 300w\" sizes=\"(max-width: 618px) 100vw, 618px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is a well-known fact that Windows features are the best persistence mechanisms, and&#8230; the one I am going to talk about is yet another one of these&#8230; If you ever ran into a problem of having not enough space &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2018\/09\/02\/beyond-good-ol-run-key-part-86\/\">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\/5335"}],"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=5335"}],"version-history":[{"count":5,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5335\/revisions"}],"predecessor-version":[{"id":5343,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5335\/revisions\/5343"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=5335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=5335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=5335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}