{"id":1345,"date":"2017-07-28T14:37:58","date_gmt":"2017-07-28T22:37:58","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/commandline\/?p=1345"},"modified":"2019-02-18T13:29:44","modified_gmt":"2019-02-18T21:29:44","slug":"how-to-determine-what-just-ran-on-windows-console","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/commandline\/how-to-determine-what-just-ran-on-windows-console\/","title":{"rendered":"How to Determine What Just Ran on Windows Console"},"content":{"rendered":"<p>Ever wonder what was run in that Console window that briefly appeared on your screen? In this guest post, <a href=\"https:\/\/twitter.com\/craigaloewen\">Craig Loewen<\/a> &#8211; our awesome summer intern explains how you can find out what command-line applications run on your machine. Over to you Craig &#8230;<\/p>\n<hr \/>\n<p><i>[This article includes samples from <\/i><a href=\"https:\/\/blogs.technet.microsoft.com\/nathangau\/2017\/04\/20\/using-scom-to-capture-suspicious-process-creation-events\/\">Nathan Gau\u2019s Blog on Using SCOM to Capture Suspicious Process Creation<\/a><i>]<\/i><\/p>\n<p>At some point during any user\u2019s time using Windows, they have probably had a Console Window pop open for a millisecond and then disappear, leaving them to wonder \u2018What was that?\u2019.<\/p>\n<p>I had exactly the same experience which led me to investigate, answer that question, and reveal a way to obtain a list of every process that attached itself to a console window!<\/p>\n<p>For some background, a console window (running as ConHost.exe) opens &amp; is attached to a command-line application when executed. When Windows launches a new process, an event with <a href=\"https:\/\/www.ultimatewindowssecurity.com\/securitylog\/encyclopedia\/event.aspx?eventID=4688\">ID 4688<\/a> is generated. This event is disabled by default, and needs to be turned-on through a Group Policy Object setting before it can be tracked.<\/p>\n<h2>Enabling Console Window Creation Events to be Recorded<\/h2>\n<p><span style=\"text-decoration: underline\"><strong>Note:<\/strong><\/span><span> <\/span><span>Take a minute to consider whether you should enable command line auditing before doing so. <\/span><a href=\"https:\/\/blogs.technet.microsoft.com\/nathangau\/2017\/04\/20\/using-scom-to-capture-suspicious-process-creation-events\/\">Nathan Gau wrote a blog post about this<\/a><span> where he detailed the following:<\/span><\/p>\n<blockquote><p>\u201c[enabling command line auditing] will generate a lot of security events. If you have tools such as ArcSight, Splunk, OMS, or SCOM collecting these events, you\u2019d be wise to do this incrementally to ensure that you aren\u2019t overloading these tools, and I\u2019d add that if you don\u2019t have a plan in place to review and respond to what you find, then you should think about that before you start turning on auditing that won\u2019t be looked at.\u00a0 The other problem is that by turning on command line auditing, anyone that can read security events could read the contents, and potentially read something sensitive. So please, think this through carefully. A full write up on TechNet <a href=\"https:\/\/technet.microsoft.com\/windows-server-docs\/identity\/ad-ds\/manage\/component-updates\/command-line-process-auditing?f=255&amp;MSPPError=-2147217396\">can be found here<\/a>.\u201d<\/p><\/blockquote>\n<p>Once you are sure that this is the right course of action for your system, enabling command line auditing is very straightforward. <a href=\"http:\/\/windowsitpro.com\/security\/understanding-and-enabling-command-line-auditing\">Full instructions can be found here<\/a>, but let&#8217;s step through the process:<u><\/u><\/p>\n<p>Here are some screenshots of how to enable logging on your system.<\/p>\n<p>1) First, open the Group Policy Editor: hit start, type &#8220;group&#8221;, and hit the &#8220;Edit Group Policy&#8221; item in your search results.<\/p>\n<p>2) Enable Audit Process Creation:<\/p>\n<p>Navigate to:<\/p>\n<p style=\"padding-left: 30px\">Local Computer Policy<\/p>\n<p style=\"padding-left: 60px\">Computer Configuration<\/p>\n<p style=\"padding-left: 90px\">Windows Settings<\/p>\n<p style=\"padding-left: 120px\">Security Settings<\/p>\n<p style=\"padding-left: 150px\">Advanced Audit Policy Configuration<\/p>\n<p style=\"padding-left: 180px\">System Audit Policies<\/p>\n<p style=\"padding-left: 210px\">Detailed Tracking<\/p>\n<p>Double click the &#8220;Audit Process Creation&#8221; item, check the &#8220;Success&#8221; box and hit OK.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/GroupPolicyEditor1.png\"><img decoding=\"async\" width=\"600\" height=\"417\" class=\"alignnone size-medium wp-image-1355\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/GroupPolicyEditor1-600x417.png\" \/><\/a><\/p>\n<p>3) Enable command line process creation<\/p>\n<p>Navigate to the following items:<\/p>\n<p style=\"padding-left: 30px\">Local Computer Policy<\/p>\n<p style=\"padding-left: 60px\">Computer Configuration<\/p>\n<p style=\"padding-left: 90px\">Administrative Templates<\/p>\n<p style=\"padding-left: 120px\">System<\/p>\n<p style=\"padding-left: 150px\">Audit Process Creation<\/p>\n<p>Double-click the &#8220;<span>Include command line in process creation events<\/span>&#8221; setting, select the &#8220;Enabled&#8221; field and hit OK.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/GroupPolicyEditor.png\"><img decoding=\"async\" width=\"600\" height=\"426\" class=\"alignnone size-medium wp-image-1346\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/GroupPolicyEditor-600x426.png\" \/><\/a><\/p>\n<p>Be sure to reboot your PC so that process tracking is fully enabled. After rebooting, your machine should now start logging process creation events.<\/p>\n<p><span>Let&#8217;s<\/span><strong> <\/strong>find and view these process creation events:<\/p>\n<h2>Viewing the List of What Created a Console Window<\/h2>\n<p>You can view process creation events in one of two ways, either with PowerShell, or Windows Event Viewer.<\/p>\n<h2>In PowerShell<\/h2>\n<p>Open a PowerShell window <b>with administrative privileges<\/b>, this is necessary to access the logs. Then simply type the command:<\/p>\n<pre>Get-WinEvent Security | ? id -eq 4688 | ? { $_.Properties[5].Value -match 'conhost' } | Select TimeCreated,@{ Label = \"ParentProcess\"; Expression = { $_.Properties[13].Value } } | Select -First 10<\/pre>\n<p>The number at the end of the command (currently 10) determines how many processes to show you before PowerShell stops looking for them.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/ProcessList.png\"><img decoding=\"async\" width=\"600\" height=\"175\" class=\"alignnone size-medium wp-image-1365\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/ProcessList-600x175.png\" \/><\/a><\/p>\n<h2>In Windows Event Viewer<\/h2>\n<p>If you prefer a GUI based approach, it is also possible to view this list in Windows Event Viewer. Open Event Viewer and create a custom view:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/EventViewer.png\"><img decoding=\"async\" width=\"600\" height=\"154\" class=\"alignnone size-medium wp-image-1375\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/EventViewer-600x154.png\" \/><\/a><\/p>\n<p>Navigate to the XML tab and click \u2018Edit Query Manually\u2019 and press \u2018OK\u2019 on the dialogue box that will open:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/EventViewer21.png\"><img decoding=\"async\" width=\"600\" height=\"452\" class=\"alignnone size-medium wp-image-1395\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/EventViewer21-600x452.png\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><span>Into the text box, paste the following piece of XML:<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre>&lt;QueryList&gt;\n  &lt;Query Id=\"0\" Path=\"Security\"&gt;\n    &lt;Select Path=\"Security\"&gt; *[System[(EventID=4688)] and EventData[Data[@Name='NewProcessName'] and (Data='C:\\Windows\\System32\\conhost.exe')]]\n    &lt;\/Select&gt;\n  &lt;\/Query&gt;\n&lt;\/QueryList&gt;<\/pre>\n<p>Press OK, give your Custom view a name and description, and then you should see items inside of the event view. To find out what process created the console window click on an item and look at the \u2018Creator Process Name\u2019:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/EventViewer3.png\"><img decoding=\"async\" width=\"600\" height=\"416\" class=\"alignnone size-medium wp-image-1386\" alt=\"\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/33\/2019\/02\/EventViewer3-600x416.png\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>Finishing Up<\/h2>\n<p>Once you\u2019ve finished recording your data and discovering what processes were launched, please disable command line auditing which will stop tracking when processes are created. And just to be sure that tracking is fully disabled, be sure to reboot your PC. Your computer will then run just the same as before.<\/p>\n<hr \/>\n<p>We hope you find this guide useful if you ever need to track down what command-line processes are running on your machine.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever wonder what was run in that Console window that briefly appeared on your screen? In this guest post, Craig Loewen &#8211; our awesome summer intern explains how you can find out what command-line applications run on your machine. Over to you Craig &#8230; [This article includes samples from Nathan Gau\u2019s Blog on Using SCOM [&hellip;]<\/p>\n","protected":false},"author":910,"featured_media":4568,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[10,2,6,9],"tags":[27,31],"class_list":["post-1345","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cmd","category-command-line","category-windows-console","category-bash-on-ubuntu-on-windows","tag-cmd","tag-console"],"acf":[],"blog_post_summary":"<p>Ever wonder what was run in that Console window that briefly appeared on your screen? In this guest post, Craig Loewen &#8211; our awesome summer intern explains how you can find out what command-line applications run on your machine. Over to you Craig &#8230; [This article includes samples from Nathan Gau\u2019s Blog on Using SCOM [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts\/1345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/users\/910"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/comments?post=1345"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/posts\/1345\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/media\/4568"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/media?parent=1345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/categories?post=1345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/commandline\/wp-json\/wp\/v2\/tags?post=1345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}