|
1 | | -#!/usr/bin/env python |
2 | | -# This file is part of python-evtx. |
3 | | -# |
4 | | -# Copyright 2012, 2013 Willi Ballenthin <william.ballenthin@mandiant.com> |
5 | | -# while at Mandiant <http://www.mandiant.com> |
6 | | -# |
7 | | -# Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | -# you may not use this file except in compliance with the License. |
9 | | -# You may obtain a copy of the License at |
10 | | -# |
11 | | -# http://www.apache.org/licenses/LICENSE-2.0 |
12 | | -# |
13 | | -# Unless required by applicable law or agreed to in writing, software |
14 | | -# distributed under the License is distributed on an "AS IS" BASIS, |
15 | | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | -# See the License for the specific language governing permissions and |
17 | | -# limitations under the License. |
18 | | -# |
19 | | -# Version v0.1 |
20 | | - |
21 | | - |
22 | | -import sys |
23 | | -import binascii |
24 | | -import mmap |
25 | | -import contextlib |
26 | | - |
27 | | -from Evtx.Evtx import FileHeader |
28 | | - |
29 | | - |
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) |
35 | | - |
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 "" |
57 | | - |
58 | | - if fh.is_dirty(): |
59 | | - chunk_count = sum([1 for c in fh.chunks() if c.verify()]) |
60 | | - |
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 |
67 | | - |
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 "" |
73 | | - |
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 = ">" |
83 | | - |
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 |
90 | | - |
91 | | - header_checksum_string = "fail" |
92 | | - if chunk.calculate_header_checksum() == chunk.header_checksum(): |
93 | | - header_checksum_string = "pass" |
94 | | - |
95 | | - data_checksum_string = "fail" |
96 | | - if chunk.calculate_data_checksum() == chunk.data_checksum(): |
97 | | - data_checksum_string = "pass" |
98 | | - |
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 | | - |
109 | | -if __name__ == "__main__": |
110 | | - main() |
| 1 | +#!/usr/bin/env python |
| 2 | +# This file is part of python-evtx. |
| 3 | +# |
| 4 | +# Copyright 2012, 2013 Willi Ballenthin <william.ballenthin@mandiant.com> |
| 5 | +# while at Mandiant <http://www.mandiant.com> |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +# you may not use this file except in compliance with the License. |
| 9 | +# You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +# |
| 19 | +# Version v0.1 |
| 20 | + |
| 21 | + |
| 22 | +import sys |
| 23 | +import binascii |
| 24 | +import mmap |
| 25 | +import contextlib |
| 26 | + |
| 27 | +from Evtx.Evtx import FileHeader |
| 28 | + |
| 29 | + |
| 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) |
| 35 | + |
| 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("") |
| 57 | + |
| 58 | + if fh.is_dirty(): |
| 59 | + chunk_count = sum([1 for c in fh.chunks() if c.verify()]) |
| 60 | + |
| 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 |
| 67 | + |
| 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("") |
| 73 | + |
| 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 = ">" |
| 83 | + |
| 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 |
| 90 | + |
| 91 | + header_checksum_string = "fail" |
| 92 | + if chunk.calculate_header_checksum() == chunk.header_checksum(): |
| 93 | + header_checksum_string = "pass" |
| 94 | + |
| 95 | + data_checksum_string = "fail" |
| 96 | + if chunk.calculate_data_checksum() == chunk.data_checksum(): |
| 97 | + data_checksum_string = "pass" |
| 98 | + |
| 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 | + |
| 109 | +if __name__ == "__main__": |
| 110 | + main() |
0 commit comments