这段代码需要在管理员权限下才能运行,不然没有权限访问系统日志文件。其实直接读取也不会有什么问题,只是我个人为了安全起见,拷贝了一份。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import ctypes, sys
import os
from evtx import PyEvtxParser
import shutil


def main():
shutil.copy("C:/Windows/System32/winevt/Logs/System.evtx", "D:/项目/Windows取证/data_file/System.evtx")
parser = PyEvtxParser("D:/项目/Windows取证/data_file/System.evtx")
for record in parser.records():
if record["event_record_id"] == 6005:
print(f'Event Record ID: {record["event_record_id"]}')
print(f'Event Timestamp: {record["timestamp"]}')
print(record['data'])
print(f'------------------------------------------')
break
else:
print(f'Event Record ID: {record["event_record_id"]}')

def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False

if __name__ == "__main__":
main()