{"id":4455,"date":"2017-11-24T23:45:21","date_gmt":"2017-11-24T23:45:21","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=4455"},"modified":"2017-11-25T10:30:52","modified_gmt":"2017-11-25T10:30:52","slug":"enter-sandbox-part-15-remnumneration-games","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2017\/11\/24\/enter-sandbox-part-15-remnumneration-games\/","title":{"rendered":"Enter Sandbox \u2013 part 15: rE[mn]u[mn]eration games"},"content":{"rendered":"<p>Observing a malware is one thing. Observing the very same malware in a rich context is another.<\/p>\n<p>The traditional approach to sandboxes focuses on scoring the sample&#8217;s badness, extracting IOCs, and not focusing that much on the in-depth analysis. It&#8217;s understandable, because in-depth analysis are not the ultimate goal. Still&#8230; being able to extract more information that may help with the manual analysis is always welcome. And it&#8217;s actually getting better &#8211; the competition is slowly changing the landscape and newer sandboxes support memory dumping, PE file rebuilding, show nice process \/ thread trees, various graphs, etc&#8230; and place more and more hooks in place. And then again, even if they intercept the most popular APIs, <a href=\"https:\/\/www.hexacorn.com\/blog\/2017\/03\/16\/enter-sandbox-part-14-reading-the-old-delphi-scrolls\/\">inline functions<\/a>, or even intercept <a href=\"https:\/\/www.hexacorn.com\/blog\/2015\/06\/09\/enter-sandbox-part-2-com-babe-com\/\">virtual tables<\/a>, it may still not be enough.<\/p>\n<p>I thought, what would happen if I intercepted not only the most popular APIs that are used by malware, but also these that are less-frequently looked at, and in particular, these that may help to understand a flow of events in a better context &#8211; enriching the data that sandbox presents and making the in-depth analysis easier.<\/p>\n<p>What are these APIs?<\/p>\n<p>Let me show you an example&#8230;<\/p>\n<p>Imagine you intercept the function CreateToolhelp32Snapshot to take a note of the fact that the malware is enumerating processes. This may add to the &#8216;badness&#8217; weight, but on its own is not a malicious feature per se. Lots of &#8216;clean&#8217; processes enumerate processes.<\/p>\n<p>What if we not only did that, but also intercepted Process32First and Process32Next?<\/p>\n<p>This could be the result (output is simplified to demo the idea):<\/p>\n<pre>CreateToolhelp32Snapshot\r\nProcess32First: [System Process]\r\nProcess32Next: System\r\nProcess32Next: smss.exe\r\nProcess32Next: csrss.exe\r\nProcess32Next: winlogon.exe\r\nProcess32Next: services.exe\r\nProcess32Next: lsass.exe\r\nProcess32Next: svchost.exe\r\nProcess32Next: svchost.exe\r\nProcess32Next: svchost.exe\r\nProcess32Next: svchost.exe\r\nProcess32Next: svchost.exe\r\nProcess32Next: spoolsv.exe\r\nProcess32Next: explorer.exe\r\nOpens Process: %WINDOWS%\\explorer.exe\r\nVirtualAllocEx: %WINDOWS%\\explorer.exe\r\nNtWriteVirtualMemory: %WINDOWS%\\explorer.exe\r\nVirtualAllocEx: %WINDOWS%\\explorer.exe\r\nNtWriteVirtualMemory: %WINDOWS%\\explorer.exe\r\nVirtualAllocEx: %WINDOWS%\\explorer.exe\r\nNtWriteVirtualMemory: %WINDOWS%\\explorer.exe\r\nVirtualAllocEx: %WINDOWS%\\explorer.exe\r\nNtWriteVirtualMemory: %WINDOWS%\\explorer.exe\r\nVirtualAllocEx: %WINDOWS%\\explorer.exe\r\nNtWriteVirtualMemory: %WINDOWS%\\explorer.exe\r\nCreateRemoteThread: %WINDOWS%\\explorer.exe\r\nNtResumeThread: %WINDOWS%\\explorer.exe<\/pre>\n<p>Analysing a log like this tells you straight away that the malware is enumerating processes, and when it finds explorer.exe, it injects a bunch of buffers into it (possibly mapping sections of the PE payload?), and then creates a remote thread. As a result, the explorer.exe process now is hosting malicious payload.<\/p>\n<p>While the code injection into explorer.exe can be deducted from manual dynamic analysis, or may be even obviously apparent when we are evaluating the process tree and network connections from a report generated by a sandbox, there is a subtle difference. The context these 2 additional intercepted APIs provide allows to be quite certain that the malware is actually quite specifically looking for the explorer.exe, and not for the other process.<\/p>\n<p>It also tells us HOW the process is found.<\/p>\n<p>And mind you, this is actually not a trivial question if you are doing in-depth malware analysis.<\/p>\n<p>There are cases where this determination is very important. Having an ability to quickly determine if we are missing some target process on the test system can save us a lot of time spent on mundane manual analysis. This is actually one of the first questions your customer will ask you, especially when it comes to targeted attacks. It is a very responsible job to deliver the results and not to miss stuff!<\/p>\n<p>When you look at malware that is highly targeted, f.ex. malware that is targeting Point of Sale systems, running it through a sandbox may _not_ give you any good results, because you either won&#8217;t see the process enumeration at all, or may miss the name of the process that the malware is looking for. The malware will look &#8216;broken&#8217; to us. I can&#8217;t count how many times I wasted time on manual analysis and even incorrectly concluded that the malware is &#8216;broken&#8217; while looking at heavily obfuscated, or bloatwarish malware samples. Until I started looking at the context of the early exit.<\/p>\n<p>It is really helpful to be able to cheat a bit.<\/p>\n<p>For the case of the process enumeration one can not only intercept the Process32First and Process32Next functions, but also enhance the results with the interception of string comparison functions.<\/p>\n<p>If we get lucky, the result could look like this:<\/p>\n<pre>Process32First: [System Process]\r\nlstrcmpiA ([System Process], explorer.exe)\r\nProcess32Next: System\r\nlstrcmpiA (System, explorer.exe)\r\nProcess32Next: smss.exe\r\nlstrcmpiA (smss.exe, explorer.exe)\r\nProcess32Next: csrss.exe\r\nlstrcmpiA (csrss.exe, explorer.exe)\r\nProcess32Next: winlogon.exe\r\nlstrcmpiA (winlogon.exe, explorer.exe)\r\nProcess32Next: services.exe\r\nlstrcmpiA (services.exe, explorer.exe)\r\nProcess32Next: lsass.exe\r\nlstrcmpiA (lsass.exe, explorer.exe)\r\nProcess32Next: vmacthlp.exe\r\nlstrcmpiA (vmacthlp.exe, explorer.exe)\r\nProcess32Next: svchost.exe\r\nlstrcmpiA (svchost.exe, explorer.exe)\r\nProcess32Next: svchost.exe\r\nlstrcmpiA (svchost.exe, explorer.exe)\r\nProcess32Next: svchost.exe\r\nlstrcmpiA (svchost.exe, explorer.exe)\r\nProcess32Next: svchost.exe\r\nlstrcmpiA (svchost.exe, explorer.exe)\r\nProcess32Next: svchost.exe\r\nlstrcmpiA (svchost.exe, explorer.exe)\r\nProcess32Next: spoolsv.exe\r\nlstrcmpiA (spoolsv.exe, explorer.exe)\r\nProcess32Next: PERSFW.exe\r\nlstrcmpiA (PERSFW.exe, explorer.exe)\r\nProcess32Next: explorer.exe\r\nlstrcmpiA (explorer.exe, explorer.exe)<\/pre>\n<p>That makes the in-depth malware analysis supereasy, doesn&#8217;t?<\/p>\n<p>I think there is a potential market for supporting in-depth malware analysis with sandbox technology &#8211; make the interception configurable (offer a list of APIs to monitor, allow time to run to be selected manually, rebuild files, perhaps give live access to the analysis box, etc.).<\/p>\n<p>Reversing ykS is the limit.<\/p>\n<p>And while I do commercial in-depth analysis and I may be shooting myself in a foot here, I can&#8217;t stress enough how important ROI is for both you and the customer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Observing a malware is one thing. Observing the very same malware in a rich context is another. The traditional approach to sandboxes focuses on scoring the sample&#8217;s badness, extracting IOCs, and not focusing that much on the in-depth analysis. It&#8217;s &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2017\/11\/24\/enter-sandbox-part-15-remnumneration-games\/\">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":[44,41],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4455"}],"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=4455"}],"version-history":[{"count":6,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4455\/revisions"}],"predecessor-version":[{"id":4461,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4455\/revisions\/4461"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=4455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=4455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=4455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}