SANS Holiday Hack 2019 Objective 5 - Determine Compromised System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/use/bin/env python3 | |
# SANS Holiday Hack 2019 Objective 5 - Determine Compromised System | |
import dateutil.parser | |
from datetime import timedelta, datetime | |
from os import listdir | |
from os.path import isfile, join | |
import pprint | |
# target_time = dateutil.parser.parse('2019-11-19T12:21:35.327998') | |
# ten_mins_after = target_time + timedelta(minutes=10) | |
# ten_mins_prior = target_time + timedelta(minutes=-10) | |
tgt_dir = 'elfu-zeeklogs' | |
log_files = [ | |
f for f in listdir(tgt_dir) | |
if isfile(join(tgt_dir, f)) | |
and f.startswith('conn') | |
# and ten_mins_after > dateutil.parser.parse(f.split('_')[1][:-4]) > ten_mins_prior | |
] | |
parsed_logs = list() | |
for log in log_files: | |
with open(join(tgt_dir, log)) as f: | |
data = f.read().split('\n') | |
data = [d for d in data if '\t' in d and '#' not in d] | |
for row in data: | |
field_names = [ | |
'ts', 'uid', 'id.orig_h', 'id.orig_p', 'id.resp_h', 'id.resp_p', 'proto', 'service', 'duration', 'orig_bytes','conn_state', | |
'local_orig', 'local_resp', 'missed_bytes', 'history', 'orig_pkts', 'orig_ip_bytes', 'resp_pkts', 'resp_ip_bytes', 'tunnel_parents' | |
] | |
#types: time string addr port addr port enum string interval count count | |
# string bool bool count string count count count count set[string] | |
parsed_logs.append(dict(zip(field_names, row.split('\t')))) | |
focus = [l for l in parsed_logs if int(l['id.orig_p']) == 4444 or int(l['id.resp_p']) == 4444] | |
output = list() | |
for i in focus: | |
i['ts'] = datetime.utcfromtimestamp(int(i['ts'].split('.')[0])).isoformat() | |
output.append({k: v for (k,v) in i.items() if k in ['duration', 'id.orig_h', 'id.orig_p', 'id.resp_h', 'id.resp_p', 'ts']}) | |
output.sort(key=lambda x: x['duration']) | |
pprint.pprint(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output:
This was based on a hunch because I saw port 4444 earlier in Sysmon.
Unfortunately this didn't help me find the solution, but was fun nonetheless.