Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Autogenerate scripts (WIP) #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions sysmon-to-json.rb
@@ -0,0 +1,45 @@
#!/usr/bin/env ruby

require 'json'
require 'nokogiri'

def parse_xml(data)
# Extract all comments: <!-- .* -->
xml = Nokogiri::XML(data)
comments = xml.xpath('//comment()').map { |x| x.content }
# Accumulate sysmon event structure.
events = {}
ids = []
comments.each do |comment|
if comment.start_with?('SYSMON EVENT')
match = comment.match(/ID (.+) : (.+) \[(.+)\]/)
next unless match
id, desc, name = match.to_a.drop(1)
ids = id.split(' & ').map { |x| x.to_sym }
ids.each do |id|
events[id] = {
name: name,
desc: desc
}
end
end
if not ids.empty?
if comment.start_with?('EVENT')
id, details = comment.match(/EVENT (.+): "([^"]+)/).to_a.drop(1)
next unless events.has_key?(id.to_sym)
events[id.to_sym][:details] = details
end
if comment.start_with?('DATA')
args = comment[/DATA: (.*)/, 1].split(', ')
ids.each do |id|
events[id][:args] = args
end
end
end
end
return JSON[events]
end

if __FILE__ == $0
puts parse_xml(STDIN.read)
end