-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdumper.py
82 lines (63 loc) · 2.21 KB
/
dumper.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import os
import filetype
import sqlite3
from prettytable import PrettyTable
import json
def dump(files, ftype, dest):
fname = '{}/dump_{}.txt'.format(dest,ftype)
f = open(fname, 'w')
for file in files:
kind = filetype.guess(file)
if 'xml' in ftype:
if '.xml' in file:
with open(file, 'r') as fxml:
xml = fxml.read()
f.write("[+] Dump of %s \n\n" %file)
f.write(xml)
f.write("\n\n\n")
elif 'sqlite' in ftype:
try:
if kind.mime == 'application/x-sqlite3':
db_data = dump_db(file)
f.write("[+] Dump of %s \n" %file)
for k, val in db_data.items():
f.write("[+] Table %s \n\n" % k)
f.write(val)
f.write("\n\n\n")
except AttributeError:
pass
elif '.json' in file:
with open(file, 'r') as fjson:
f.write("[+] Dump of %s \n" %file)
j = json.load(fjson)
json.dump(j, f, indent=4, sort_keys=True)
f.write("\n\n\n")
"""try:
fxml.close()
fjson.close()
except UnboundLocalError:
pass"""
print("[+] Content of the files dumped correctly in %s" % fname)
f.close()
def fast_scandir(dirname):
filelist = []
for path, subdirs, files in os.walk(dirname):
for name in files:
filelist.append(os.path.join(path, name))
return filelist
def dump_db(file):
data = {}
conn = sqlite3.connect(file)
conn.text_factory = str
cur = conn.cursor()
res = cur.execute("SELECT name FROM sqlite_master WHERE type='table';").fetchall()
table_names = sorted(list(zip(*res))[0])
for table_name in table_names:
table = PrettyTable()
res = cur.execute("PRAGMA table_info('%s')" % table_name).fetchall()
table.field_names = list(zip(*res))[1]
res = cur.execute("SELECT * FROM %s;" % table_name).fetchall()
for row in res:
table.add_row(row)
data[table_name] = table.get_string()
return data