{"id":4935,"date":"2018-06-09T00:14:27","date_gmt":"2018-06-09T00:14:27","guid":{"rendered":"http:\/\/www.hexacorn.com\/blog\/?p=4935"},"modified":"2018-06-09T18:42:03","modified_gmt":"2018-06-09T18:42:03","slug":"logman-the-windows-volverine","status":"publish","type":"post","link":"https:\/\/www.hexacorn.com\/blog\/2018\/06\/09\/logman-the-windows-volverine\/","title":{"rendered":"Logman, the Windows volverine"},"content":{"rendered":"<p><strong>Update<\/strong><\/p>\n<p>Coincidentally, <a href=\"https:\/\/twitter.com\/HECFBlog\">@HECFBlog<\/a> <a href=\"https:\/\/twitter.com\/nicoleibrahim\">@nicoleibrahim<\/a>\u00a0<a href=\"http:\/\/www.hecfblog.com\/2018\/06\/etw-event-tracing-for-windows-and-etl.html\">released<\/a> a tool ETL Parser that helps to at last extract raw buffers and as a result it produces a CSV file with data that can be analyzed row by row. This is the closest so far that I have seen for a tool to be able to help analyze the output of api trace log. Have a look at the screenshot:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman7.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-4954\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman7.png\" alt=\"\" width=\"721\" height=\"858\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman7.png 721w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman7-252x300.png 252w\" sizes=\"(max-width: 721px) 100vw, 721px\" \/><\/a><\/p>\n<p><strong>Old Post<\/strong><\/p>\n<p>Almost everyone is excited about .etl files that are produced as a result of <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/bb968803(v=vs.85).aspx\">Event Tracing for Windows<\/a>.<\/p>\n<p>Almost, because not me.<\/p>\n<p>This feature is so rich in &#8230; features. Except it&#8217;s only for MS internal consumption. At least, it seems to be the case in some very really interesting&#8230; well&#8230; cases&#8230;<\/p>\n<p>&#8230;<\/p>\n<p>It all started when I looked at the logman tool command line arguments; one that immediately <a href=\"https:\/\/docs.microsoft.com\/en-us\/previous-versions\/windows\/it-pro\/windows-server-2008-R2-and-2008\/cc788057%28v%3dws.10%29\">caught my attention<\/a> was this one:<\/p>\n<pre style=\"padding-left: 30px;\">logman create api<\/pre>\n<p>Aha&#8230; A basic API Monitor!<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman6.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-4950\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman6.png\" alt=\"\" width=\"481\" height=\"156\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman6.png 481w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman6-300x97.png 300w\" sizes=\"(max-width: 481px) 100vw, 481px\" \/><\/a><\/p>\n<p>But not only that. It allows to run API Monitoring across different systems!!!<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman4.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-4945\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman4.png\" alt=\"\" width=\"519\" height=\"57\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman4.png 519w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman4-300x33.png 300w\" sizes=\"(max-width: 519px) 100vw, 519px\" \/><\/a><\/p>\n<p>Oh&#8230; this could be a nice covert channel to transfer data between systems. Write one piece that constantly calls a monitored API and feeds it with the data to transfer, and then &#8211; on the other end &#8211; collect this data on the other system using logman tool. You could definitely implement it in a duplex set-up too.<\/p>\n<p>Simple.<\/p>\n<p>So I thought.<\/p>\n<p>First, I immediately tested the &#8216;create api&#8217; bit it and it worked like a charm:<\/p>\n<pre style=\"padding-left: 30px;\">logman create api foo -f bincirc -exe c:\\windows\\notepad.exe -o c:\\test\\notepad.etl\r\n\r\nlogman start foo<\/pre>\n<p>Now you have to simply run Notepad.exe (c:\\windows\\notepad.exe) and the .etl log will be created&amp;updated as long as notepad.exe runs; the example content of the binary .etl file is as follows:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman1.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-4937\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman1.png\" alt=\"\" width=\"500\" height=\"422\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman1.png 654w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman1-300x253.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a>You can clearly see the APIs being recorded when Notepad is running:<\/p>\n<ul>\n<li>RegisterClassW with the Unicode class &#8216;OleMainThreadWndClass&#8217;<\/li>\n<li>GetAppCompatFlags2<\/li>\n<li>IsProcessDPIAware<\/li>\n<li>GdiReleaseDC<\/li>\n<li>etc.<\/li>\n<\/ul>\n<p>The only problem remaining:<br \/>\n&#8211; how to convert this binary blob into something more readable?<\/p>\n<p>After googling around, I discovered that the tool basically embraces the api tracng functionality offered by the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/windows\/desktop\/aa371918(v=vs.85).aspx\">IApiTracingDataCollector<\/a> interface. When you read into the docs of this interface you will soon realize that logman&#8217;s command line argument &#8216;-f&#8217; that is supposed to determine the file type for the output file can be only&#8230; binary. So any attempts to specify TSV, or CSV will fail \ud83d\ude41<\/p>\n<p>Okay.<\/p>\n<p>Since I couldn&#8217;t bite it from this end, I started looking at Windows Performance Analyzer (WPA) and other tracing and trace conversion tools.<\/p>\n<p>No matter which one I used, I could only get a basic flow of the events, but w\/o these interesting gore details of each API call:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman2.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-4938\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman2.png\" alt=\"\" width=\"500\" height=\"357\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman2.png 1268w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman2-300x214.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman2-768x549.png 768w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman2-1024x732.png 1024w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman2-222x160.png 222w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><\/p>\n<p>It&#8217;s all nice and eye candy, but the problem is already visible:<br \/>\n&#8211; if you don&#8217;t know how to parse, you simply don&#8217;t.<\/p>\n<p>As a last resort I tried &#8216;tracerpt&#8217;:<\/p>\n<pre style=\"padding-left: 30px;\">tracerpt &lt;log&gt; -o &lt;output&gt; -of CSV<\/pre>\n<p>.. and it provided a similar enigmatic output:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman3.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-4939\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman3.png\" alt=\"\" width=\"500\" height=\"126\" srcset=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman3.png 1270w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman3-300x75.png 300w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman3-768x193.png 768w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman3-1024x257.png 1024w, https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman3-990x250.png 990w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a>Some more googling around and now I know I need to get a .PDB file for the api trace provider, or some other schema files that will allow WPA to parse it properly&#8230;<\/p>\n<p>Sigh&#8230;<\/p>\n<p>The provider&#8217;s GUID is 7535aef9-4a3b-482b-91eb-25db0299995d.<\/p>\n<p>It is nowhere to be found.<\/p>\n<p>Eventually I gave up &amp; I asked on <a href=\"https:\/\/twitter.com\/Hexacorn\/status\/1005225900483411968\">Twitter<\/a>.<\/p>\n<p>Unfortunately, <a href=\"https:\/\/twitter.com\/aionescu\">Alex Ionescu<\/a>, and <a href=\"https:\/\/twitter.com\/zacbrown\">Zac Brown<\/a> are both pessimistic \ud83d\ude41 Still, I am grateful to them for chipping in and providing the useful feedback &#8211; if they can&#8217;t do it, I guess we explored all the &#8216;normal&#8217; possibilities.<\/p>\n<p>But then I am thinking&#8230; so&#8230; if it is an internal schema, then there is only one way out.<\/p>\n<p>Brute-Force attack.<\/p>\n<p>I may cover it in the next post.<\/p>\n<p>From the blue team&#8217;s perspective, if you want to detect logman&#8217;s activity, in particular api tracing, you may be interested in this process tree:<\/p>\n<p><a href=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman5.png\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-full wp-image-4948\" src=\"https:\/\/www.hexacorn.com\/blog\/wp-content\/uploads\/2018\/06\/logman5.png\" alt=\"\" width=\"214\" height=\"57\" \/><\/a><\/p>\n<p>The example command line arguments from my VM test run are as follows:<\/p>\n<ul>\n<li>C:\\Windows\\system32\\svchost.exe -k netsvcs\n<ul>\n<li>taskeng.exe {A7B77AA7-00E9-45C4-92C5-31C3868DB30D} S-1-5-18:NT AUTHORITY\\System:Service:\n<ul>\n<li>C:\\Windows\\system32\\rundll32.exe C:\\Windows\\system32\\pla.dll,PlaHost &#8220;foo&#8221; &#8220;0x934_0x91c_0x2a045dff88a&#8221;<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>One thing is also worth mentioning &#8211; many logman command line option talk about running some task when some event happens; at first I thought it may be a new persistence mechanism, until I realized the tasks names required by these commands are task names registered using a Task Scheduler. So&#8230; yet another fail on the documentation, as it is very cryptic and talks about these various traces in a very superficial way \ud83d\ude41<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update Coincidentally, @HECFBlog @nicoleibrahim\u00a0released a tool ETL Parser that helps to at last extract raw buffers and as a result it produces a CSV file with data that can be analyzed row by row. This is the closest so far &hellip; <a href=\"https:\/\/www.hexacorn.com\/blog\/2018\/06\/09\/logman-the-windows-volverine\/\">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":[9,67],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4935"}],"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=4935"}],"version-history":[{"count":11,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4935\/revisions"}],"predecessor-version":[{"id":4956,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/posts\/4935\/revisions\/4956"}],"wp:attachment":[{"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/media?parent=4935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/categories?post=4935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexacorn.com\/blog\/wp-json\/wp\/v2\/tags?post=4935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}