|
17 | 17 | # limitations under the License. |
18 | 18 | # |
19 | 19 | # Version v0.1 |
| 20 | +import Evtx.Evtx as evtx |
20 | 21 |
|
21 | 22 |
|
22 | | -import sys |
23 | | -import binascii |
24 | | -import mmap |
25 | | -import contextlib |
26 | | - |
27 | | -from Evtx.Evtx import FileHeader |
| 23 | +def main(): |
| 24 | + import argparse |
| 25 | + parser = argparse.ArgumentParser( |
| 26 | + description="Dump information about an EVTX file.") |
| 27 | + parser.add_argument("evtx", type=str, |
| 28 | + help="Path to the Windows EVTX event log file") |
| 29 | + args = parser.parse_args() |
28 | 30 |
|
| 31 | + with evtx.Evtx(args.evtx) as log: |
| 32 | + fh = log.get_file_header() |
29 | 33 |
|
30 | | -def main(): |
31 | | - with open(sys.argv[1], 'r') as f: |
32 | | - with contextlib.closing(mmap.mmap(f.fileno(), 0, |
33 | | - access=mmap.ACCESS_READ)) as buf: |
34 | | - fh = FileHeader(buf, 0x0) |
| 34 | + print("Information from file header:") |
| 35 | + print(("Format version : %d.%d" % (fh.major_version(), |
| 36 | + fh.minor_version()))) |
| 37 | + print(("Flags : 0x%08x" % (fh.flags()))) |
| 38 | + dirty_string = "clean" |
| 39 | + if fh.is_dirty(): |
| 40 | + dirty_string = "dirty" |
| 41 | + print(("File is : %s" % (dirty_string))) |
| 42 | + full_string = "no" |
| 43 | + if fh.is_full(): |
| 44 | + full_string = "yes" |
| 45 | + print(("Log is full : %s" % (full_string))) |
| 46 | + print(("Current chunk : %d of %d" % (fh.current_chunk_number(), |
| 47 | + fh.chunk_count()))) |
| 48 | + print(("Oldest chunk : %d" % (fh.oldest_chunk() + 1))) |
| 49 | + print(("Next record# : %d" % (fh.next_record_number()))) |
| 50 | + checksum_string = "fail" |
| 51 | + if fh.calculate_checksum() == fh.checksum(): |
| 52 | + checksum_string = "pass" |
| 53 | + print(("Check sum : %s" % (checksum_string))) |
| 54 | + print("") |
35 | 55 |
|
36 | | - print("Information from file header:") |
37 | | - print(("Format version : %d.%d" % (fh.major_version(), |
38 | | - fh.minor_version()))) |
39 | | - print(("Flags : 0x%08x" % (fh.flags()))) |
40 | | - dirty_string = "clean" |
41 | | - if fh.is_dirty(): |
42 | | - dirty_string = "dirty" |
43 | | - print(("File is : %s" % (dirty_string))) |
44 | | - full_string = "no" |
45 | | - if fh.is_full(): |
46 | | - full_string = "yes" |
47 | | - print(("Log is full : %s" % (full_string))) |
48 | | - print(("Current chunk : %d of %d" % (fh.current_chunk_number(), |
49 | | - fh.chunk_count()))) |
50 | | - print(("Oldest chunk : %d" % (fh.oldest_chunk() + 1))) |
51 | | - print(("Next record# : %d" % (fh.next_record_number()))) |
52 | | - checksum_string = "fail" |
53 | | - if fh.calculate_checksum() == fh.checksum(): |
54 | | - checksum_string = "pass" |
55 | | - print(("Check sum : %s" % (checksum_string))) |
56 | | - print("") |
| 56 | + if fh.is_dirty(): |
| 57 | + chunk_count = sum([1 for c in fh.chunks() if c.verify()]) |
57 | 58 |
|
58 | | - if fh.is_dirty(): |
59 | | - chunk_count = sum([1 for c in fh.chunks() if c.verify()]) |
| 59 | + last_chunk = None |
| 60 | + for chunk in fh.chunks(): |
| 61 | + if not chunk.verify(): |
| 62 | + continue |
| 63 | + last_chunk = chunk |
| 64 | + next_record_num = last_chunk.log_last_record_number() + 1 |
60 | 65 |
|
61 | | - last_chunk = None |
62 | | - for chunk in fh.chunks(): |
63 | | - if not chunk.verify(): |
64 | | - continue |
65 | | - last_chunk = chunk |
66 | | - next_record_num = last_chunk.log_last_record_number() + 1 |
| 66 | + print("Suspected updated header values (header is dirty):") |
| 67 | + print(("Current chunk : %d of %d" % (chunk_count, |
| 68 | + chunk_count))) |
| 69 | + print(("Next record# : %d" % (next_record_num))) |
| 70 | + print("") |
67 | 71 |
|
68 | | - print("Suspected updated header values (header is dirty):") |
69 | | - print(("Current chunk : %d of %d" % (chunk_count, |
70 | | - chunk_count))) |
71 | | - print(("Next record# : %d" % (next_record_num))) |
72 | | - print("") |
| 72 | + print("Information from chunks:") |
| 73 | + print(" Chunk file (first/last) log (first/last) Header Data") |
| 74 | + print("- ----- --------------------- --------------------- ------ ------") |
| 75 | + for (i, chunk) in enumerate(fh.chunks(), 1): |
| 76 | + note_string = " " |
| 77 | + if i == fh.current_chunk_number() + 1: |
| 78 | + note_string = "*" |
| 79 | + elif i == fh.oldest_chunk() + 1: |
| 80 | + note_string = ">" |
73 | 81 |
|
74 | | - print("Information from chunks:") |
75 | | - print(" Chunk file (first/last) log (first/last) Header Data") |
76 | | - print("- ----- --------------------- --------------------- ------ ------") |
77 | | - for (i, chunk) in enumerate(fh.chunks(), 1): |
78 | | - note_string = " " |
79 | | - if i == fh.current_chunk_number() + 1: |
80 | | - note_string = "*" |
81 | | - elif i == fh.oldest_chunk() + 1: |
82 | | - note_string = ">" |
| 82 | + if not chunk.check_magic(): |
| 83 | + if chunk.magic() == "\x00\x00\x00\x00\x00\x00\x00\x00": |
| 84 | + print("%s %4d [EMPTY]" % (note_string, i)) |
| 85 | + else: |
| 86 | + print("%s %4d [INVALID]" % (note_string, i)) |
| 87 | + continue |
83 | 88 |
|
84 | | - if not chunk.check_magic(): |
85 | | - if chunk.magic() == "\x00\x00\x00\x00\x00\x00\x00\x00": |
86 | | - print("%s %4d [EMPTY]" % (note_string, i)) |
87 | | - else: |
88 | | - print("%s %4d [INVALID]" % (note_string, i)) |
89 | | - continue |
| 89 | + header_checksum_string = "fail" |
| 90 | + if chunk.calculate_header_checksum() == chunk.header_checksum(): |
| 91 | + header_checksum_string = "pass" |
90 | 92 |
|
91 | | - header_checksum_string = "fail" |
92 | | - if chunk.calculate_header_checksum() == chunk.header_checksum(): |
93 | | - header_checksum_string = "pass" |
| 93 | + data_checksum_string = "fail" |
| 94 | + if chunk.calculate_data_checksum() == chunk.data_checksum(): |
| 95 | + data_checksum_string = "pass" |
94 | 96 |
|
95 | | - data_checksum_string = "fail" |
96 | | - if chunk.calculate_data_checksum() == chunk.data_checksum(): |
97 | | - data_checksum_string = "pass" |
| 97 | + print("%s %4d %8d %8d %8d %8d %s %s" % |
| 98 | + (note_string, |
| 99 | + i, |
| 100 | + chunk.file_first_record_number(), |
| 101 | + chunk.file_last_record_number(), |
| 102 | + chunk.log_first_record_number(), |
| 103 | + chunk.log_last_record_number(), |
| 104 | + header_checksum_string, |
| 105 | + data_checksum_string)) |
98 | 106 |
|
99 | | - print("%s %4d %8d %8d %8d %8d %s %s" % \ |
100 | | - (note_string, |
101 | | - i, |
102 | | - chunk.file_first_record_number(), |
103 | | - chunk.file_last_record_number(), |
104 | | - chunk.log_first_record_number(), |
105 | | - chunk.log_last_record_number(), |
106 | | - header_checksum_string, |
107 | | - data_checksum_string)) |
108 | 107 |
|
109 | 108 | if __name__ == "__main__": |
110 | 109 | main() |
0 commit comments