{"id":5081,"date":"2018-07-07T11:41:28","date_gmt":"2018-07-07T11:41:28","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=5081"},"modified":"2018-07-07T11:42:52","modified_gmt":"2018-07-07T11:42:52","slug":"sysmon-doing-lines-part-4","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2018\/07\/07\/sysmon-doing-lines-part-4\/","title":{"rendered":"Sysmon doing lines, part 4"},"content":{"rendered":"<p>Two days ago Mark <a href=\"https:\/\/twitter.com\/markrussinovich\/status\/1015017015768113152\">released<\/a> a new version of sysmon &#8211; version 8.0. It adds new features and addresses the issue I highlighted in my <a href=\"https:\/\/www.hexacorn.com\/blog\/2018\/06\/29\/sysmon-doing-lines-part-3\/\">previous post<\/a>.<\/p>\n<p>This post is not about new version of sysmon though.<\/p>\n<p>It&#8217;s more about its inner workings that I looked at a while ago.<\/p>\n<p>Sysmon has two primary components &#8211; sysmon driver and sysmon service process (we will skip the architectural differences between sysmon&#8217;s x86 vs. x64 versions). The first one (driver) intercepts the events, the second (service process) writes them to the Event Log in a loop, using the DeviceIoControl to talk to the driver.<\/p>\n<p>If you ever patched binary in memory or on disk, you know where it is going&#8230;<\/p>\n<p>The core functionality that actually logs the stuff to the Windows Event Logs is called from the inside of the sysmon.exe service process. It&#8217;s nothing unusual, but obviously it&#8217;s also a potential weakness.<\/p>\n<p>Since it&#8217;s a process &#8211; it can be patched. I tried it on a file level, and the results of a single byte patch are shown below &#8211; not a single event is being logged:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/sysmon_patch.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-5082\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/sysmon_patch.png\" alt=\"\" width=\"500\" height=\"139\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/sysmon_patch.png 664w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/07\/sysmon_patch-300x84.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>Assuming the attacker detects sysmon, and can acquire the required rights to modify it &#8211; patching in memory or on disk is pretty trivial and can basically disable the functionality of the tool&#8230;<\/p>\n<p>Obviously, this applies to _any_ tool and any process or component using <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/winbase\/nf-winbase-reporteventa\">ReportEvent<\/a> or <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/desktop\/api\/evntprov\/nf-evntprov-eventwrite\">EventWrite<\/a> APIs, so want to reiterate how the availability of tools bias security researchers&#8230; Sysmon is used here more as a scapegoat to demonstrate the old-school rootkit technique than a targeted crusade against this fantastic tool.<\/p>\n<p>How to fix it?<\/p>\n<p>Perhaps sysmon could do some sanity checks of its integrity on a driver level? &#8211; It&#8217;s much harder to modify the driver and load its patched version than an .exe (especially on 64-bit Windows). Perhaps driver could also do occasional checks if the number of Events written to Event Logs is as expected\/increasing? And if the sysmon is a dependency, any admin or EDR tool using it should probably verify the integrity of the file prior to launching it? Including automation? I believe there is no generic solution here at the moment, but basic self-checks could simply rely on verifying the signatures of the file (for file patch). For in-memory patches, this is much harder as you need a dedicated code that compares images on disk vs. images\u00a0 in-memory. You may be surprised, but some EDR solutions actually attempt to do that &#8211; it&#8217;s often much better than then &#8216;see-it-all&#8217; approach that generates lots of noise.<\/p>\n<p>Going back to rootkits &#8211; I used this term on purpose. Applying a single-byte patch will give you zero logging. It&#8217;s silly and easily detectable. A more complex patch could simply rootkit the bad guys activities out of the event log (just need to hook either the sysmon itself, or Event reporting APIs). As usual&#8230; whoever gets there first&#8230; wins.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Two days ago Mark released a new version of sysmon &#8211; version 8.0. It adds new features and addresses the issue I highlighted in my previous post. This post is not about new version of sysmon though. It&#8217;s more about &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2018\/07\/07\/sysmon-doing-lines-part-4\/\">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,13,52,19,46,9],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5081"}],"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=5081"}],"version-history":[{"count":10,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5081\/revisions"}],"predecessor-version":[{"id":5096,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/5081\/revisions\/5096"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=5081"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=5081"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=5081"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}