You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On fresh Sysmon installations, the loop that looks for the Sysmon Configuration Update Event (ID 16) does not always find the event despite the event being logged on the local host. I believe this is some kind of race condition where the Sysmon Config Update Event gets logged after the loop has gone through all the events. Subsequent runs on the same machine result in SysmonConfigPusher successfully finding the event.
Might be a decent idea to decouple the 'config validation' portion to a separate button, although it's nice to have it in the main loop.
Relent code:
// XPath Query for Event ID 16s only, this is the "Sysmon config state changed" event - later we specify the log channel and extract the SHA256 value of the configuration file hash as it exists on the remote hoststringlogQuery="*[System[(EventID = 16)]]";//Establish a remote event log session on the computer in this for loopEventLogSessionsession=newEventLogSession(SelectedComputer.ToString());EventLogQueryquery=newEventLogQuery("Microsoft-Windows-Sysmon/Operational",PathType.LogName,logQuery);query.Session=session;EventLogReaderlogReader=newEventLogReader(query);// Loop through the events that were returned in the above queryfor(EventRecordeventdetail=logReader.ReadEvent();eventdetail!=null;eventdetail=logReader.ReadEvent()){// EventData variable contains the detail of each event in XML format, I tried to use LINQ to extract the XML elements instead of regex but found regex to be simpler, please don't hate me for the upcoming dirty regexesstringEventData=eventdetail.ToXml();// RegEx used to extract just the SHA256 hash from Event ID 16RegexSHA256=newRegex(@"[A-Fa-f0-9]{64}");// Put the matched regex (the SHA256) hash into a variable called SHA256ValueMatchSHA256Value=SHA256.Match(EventData);/// Another awful regex to extract the time stamp from Event ID 16 - the SHA256 value of the updated config as well as the time stamp get logged, this way you can validate that the right configuration file got pushed to the right computerRegexLoggedEventTime=newRegex(@"\d\d\d\d\-\d\d\-\d\d.\d\d\:\d\d\:\d\d\.\d\d\d");MatchMatchedLoggedEventTime=LoggedEventTime.Match(EventData);//Log showing that we found an Event ID 16 on the selected remote host, and we log the time and SHA256 value of the configuration file pushedLog.Information("Found Config Update Event on "+SelectedComputer+" Logged at "+MatchedLoggedEventTime+"."+" Updated with config file with the SHA256 Hash of: "+SHA256Value.ToString());
The text was updated successfully, but these errors were encountered:
On fresh Sysmon installations, the loop that looks for the Sysmon Configuration Update Event (ID 16) does not always find the event despite the event being logged on the local host. I believe this is some kind of race condition where the Sysmon Config Update Event gets logged after the loop has gone through all the events. Subsequent runs on the same machine result in SysmonConfigPusher successfully finding the event.
Might be a decent idea to decouple the 'config validation' portion to a separate button, although it's nice to have it in the main loop.
Relent code:
The text was updated successfully, but these errors were encountered: