-
Notifications
You must be signed in to change notification settings - Fork 34
/
makedfxml.py
executable file
·63 lines (57 loc) · 1.59 KB
/
makedfxml.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
'''
Runs Digital Forensic XML.
'''
import os
import sys
import argparse
import walk_to_dfxml
from lxml import etree
def parse_args(args_):
'''
Parse command line arguments.
'''
parser = argparse.ArgumentParser(
description='Prints Digital Forensics XML to your terminal'
'Proof of concept - hashes are turned off for now. no logging etc..'
' Written by Kieran O\'Leary.'
)
parser.add_argument(
'input',
help='full path of input directory.'
)
parser.add_argument(
'-o',
help='full path to an output XML file'
)
parser.add_argument(
'-n',
action="store_true", help="Do not calculate any hashes"
)
parsed_args = parser.parse_args(args_)
return parsed_args
def main(args_):
'''
Launches the functions that will print your digital forensics XML.
Hashes are turned off by default.
'''
args = parse_args(args_)
if args.o:
if not args.o.endswith("xml"):
print('output file must be XML')
source = args.input
os.chdir(source)
if args.n:
hash_arg = ["-n"]
else:
hash_arg = []
output = walk_to_dfxml.main(hash_arg)
parser = etree.XMLParser(remove_blank_text=True)
dfxml_out = etree.fromstring((output), parser=parser)
if args.o:
with open(args.o, 'w') as xml_doc:
xml_doc.write(etree.tostring(dfxml_out, pretty_print=True).decode('ascii'))
else:
print(etree.tostring(dfxml_out, pretty_print=True).decode('ascii'))
if __name__ == '__main__':
main(sys.argv[1:])