{"id":5028,"date":"2018-06-29T23:18:46","date_gmt":"2018-06-29T23:18:46","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=5028"},"modified":"2018-07-05T23:44:32","modified_gmt":"2018-07-05T23:44:32","slug":"sysmon-doing-lines-part-3","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2018\/06\/29\/sysmon-doing-lines-part-3\/","title":{"rendered":"Sysmon doing lines, part 3"},"content":{"rendered":"<p><strong>Update<\/strong><\/p>\n<p>This issue was fixed by <a href=\"https:\/\/twitter.com\/markrussinovich\/status\/1015017015768113152\">Mark Russinovich on 2018-07-06<\/a>; that was pretty quick!<\/p>\n<p><strong>Old<\/strong><\/p>\n<p>Sysmon is an easy target, because it&#8217;s easily downloadable and everyone can poke around in its code or toy around with the system and see what sysmon logs. It&#8217;s obviously not fair &#8211; if other EDR code was that easily available I am pretty sure we would see a cascade of &#8216;funny stuff&#8217; in these products as well.<\/p>\n<p>Anyway&#8230;<\/p>\n<p>In my <a href=\"https:\/\/www.hexacorn.com\/blog\/2017\/10\/02\/sysmon-doing-lines\/\">older post<\/a> I presented a simple technique that may fool parsers and their state machines into &#8216;thinking&#8217; they are parsing correct records while in fact they are processing data some malicious software meticulously crafted for them. This is not necessarily sysmon&#8217;s problem, but who would read that old post if there was no clickbait value in the title, right?<\/p>\n<p>Back to sysmon and poking around&#8230; once you start looking at it you can quickly discover that it can be run in a so-called debug mode &#8211; all we have to do is provide an undocumented command line switch &#8216;-t&#8217; when we install it. When I first discovered it I got really excited, only to immediately get a bucket of cold water thrown by the Twitter post by <a href=\"https:\/\/twitter.com\/mattifestation\">@mattifestation<\/a> who figured it out in&#8230; <a href=\"https:\/\/twitter.com\/mattifestation\/status\/949050133752070144\">Jan 2018<\/a>.<\/p>\n<p>It&#8217;s a really cool feature.<\/p>\n<p>When you run &#8216;sysmon -t -i&#8217; the program will start throwing a lot messages to the console and some of them will eventually trigger your interest. Especially if you &#8216;help&#8217; them a bit to appear \ud83d\ude42<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-5029\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_1.png\" alt=\"\" width=\"511\" height=\"114\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_1.png 511w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_1-300x67.png 300w\" sizes=\"(max-width: 511px) 100vw, 511px\" \/><\/a>So&#8230; what we see in this error message is a very crucial information.<\/p>\n<p>The sysmon had to truncate a very long command line which I have provided to a test process. It was so long that it had to be trimmed.<\/p>\n<p>A-ha&#8230; but how long?<\/p>\n<p>Well, it turns out sysmon doesn&#8217;t like command line longer than 0x2000 characters &#8211; i.e. this a number of wide characters it can swallow, before trimming down the rest.<\/p>\n<p>Now this 0x2000 (Wide characters) is actually 16384 bytes only.<\/p>\n<p>I was curious where the 0x2000 came from, because after reading various versions of MSDN pages about <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/processthreadsapi\/nf-processthreadsapi-createprocessa\">CreateProcess<\/a> I know very well that the lpCommandLine argument can be much longer; as per the MSDN:<\/p>\n<pre style=\"padding-left: 30px;\">The maximum length of this string is 32,768 characters,<\/pre>\n<pre style=\"padding-left: 30px;\">including the Unicode terminating null character.<\/pre>\n<p>So&#8230; this is an interesting discrepancy.<\/p>\n<p>I have a hypothesis (and I am totally guessing it) that the sysmon author used the arbitrary limit imposed on cmd.exe command line arguments.<\/p>\n<p>Such discrepancy is a nice gift and we can of course abuse it.<\/p>\n<p>Since we can&#8217;t pass the command line arguments that are longer than 0x2000 characters to cmd.exe let&#8217;s try to use powershell instead.<\/p>\n<p>If you run &#8216;powershell &lt;0x2000 spaces&gt; calc&#8217; you will spawn Windows Calculator.<\/p>\n<p>What will you see in the logs?<\/p>\n<p>This:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-5030\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_2.png\" alt=\"\" width=\"385\" height=\"105\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_2.png 385w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_2-300x82.png 300w\" sizes=\"(max-width: 385px) 100vw, 385px\" \/><\/a>And if you export it to TXT or XML you will get this:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-5031\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_3.png\" alt=\"\" width=\"612\" height=\"212\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_3.png 612w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/sysmon_3-300x104.png 300w\" sizes=\"(max-width: 612px) 100vw, 612px\" \/><\/a>So&#8230; using long command line arguments provided to executables that can work with such madness (e.g. powershell) can help to evade sysmon logs&#8230;<\/p>\n<p>If you want to test it, grab this <a href=\"https:\/\/hexacorn.com\/examples\/2018-06-30_sysmon-test.exe\">.exe<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update This issue was fixed by Mark Russinovich on 2018-07-06; that was pretty quick! Old Sysmon is an easy target, because it&#8217;s easily downloadable and everyone can poke around in its code or toy around with the system and see &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2018\/06\/29\/sysmon-doing-lines-part-3\/\">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,52,19,46,9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5028"}],"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=5028"}],"version-history":[{"count":8,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5028\/revisions"}],"predecessor-version":[{"id":5074,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5028\/revisions\/5074"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=5028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=5028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=5028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}