-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirefox_rdr.py
More file actions
215 lines (195 loc) · 7.9 KB
/
firefox_rdr.py
File metadata and controls
215 lines (195 loc) · 7.9 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import sqlite3
from pprint import pprint
import sys
import glob
import json
import os
import gzip
from gen_html import gen_html
import webbrowser
args = sys.argv
base_path = args[1] if len(args) > 1 else '.'
paths = {
"history": base_path + "/Profiles/*.default-release/places.sqlite",
"cookies": base_path + "/Profiles/*.default-release/cookies.sqlite",
"cache": base_path + "/Profiles/*.default-release/cache2/entries/",
"bookmarks": base_path + "/Profiles/*.default-release/places.sqlite"
}
print(paths["cookies"])
def get_cookies():
print(glob.glob(paths["cookies"]))
cnn = sqlite3.connect(glob.glob(paths["cookies"])[0])
# cnn = sqlite3.connect("Cookies.db")
crs = cnn.cursor()
cookies_sql = """
select
id,
originAttributes,
name,
value,
host,
path,
strftime('%m-%d-%Y', expiry/1000000, 'unixepoch'),
strftime('%m-%d-%Y', lastAccessed/1000000, 'unixepoch'),
strftime('%m-%d-%Y', creationTime/1000000, 'unixepoch'),
case when isSecure = 1 then true else false end as has_expires,
isHttpOnly,
inBrowserElement,
sameSite,
rawSameSite,
schemeMap
from moz_cookies
"""
crs.execute(cookies_sql)
rows = crs.fetchall()
headers = "id,originAttributes,name,value,host,path,expiry,lastAccessed,creationTime,isSecure,isHttpOnly,inBrowserElement,sameSite,rawSameSite,schemeMap"
html = gen_html(title="Firefox Cookies", headers=headers, data=rows)
with open("firefox_cookies.html", 'w') as f:
f.write(html)
webbrowser.open_new_tab(os.path.join(os.getcwd(), "firefox_cookies.html"))
# pprint(rows)
return rows
def get_history():
cnn = sqlite3.connect(glob.glob(paths["history"])[0])
crs = cnn.cursor()
history_sql = """
select
h.id,
p.url,
p.title,
p.description,
h.from_visit,
h.place_id,
strftime('%m-%d-%Y', h.visit_date/1000000, 'unixepoch'),
h.visit_type,
h.session,
h.source,
h.triggeringPlaceId
from moz_historyvisits h join moz_places p on h.place_id = p.id
"""
crs.execute(history_sql)
rows = crs.fetchall()
headers = "id,url,title,description,from_visit,place_id,visit_date,visit_type,session,source,triggeringPlaceId".split(",")
html = gen_html(title="Firefox History", headers=headers, data=rows)
with open ("firefox_history.html", 'w') as f:
f.write(html)
webbrowser.open_new_tab(os.path.join(os.getcwd(), "firefox_history.html"))
# pprint(rows)
return rows
def get_cache(output_path):
print(output_path)
files = os.listdir(glob.glob(paths['cache'])[0])
for file in files:
# print(os.path.join(paths['cache'], file))
# continue
if os.path.isdir(os.path.join(glob.glob(paths['cache'])[0], file)):
continue
try:
with open(os.path.join(glob.glob(paths['cache'])[0], file), 'rb') as f:
bytes = f.read()
# print(f"for file {file}: f[0] = {hex(bytes[0])} and f[1] = {hex(bytes[1])}")
if bytes[0] == 0xff and bytes[1] == 0xd8:
print(f"{file} is jpg")
if output_path is not None:
with open(os.path.join(output_path, file + ".jpg"), 'wb') as fout:
fout.write(bytes)
print(f"path to file is {os.path.join(output_path, file + '.jpg')}")
elif bytes[0] == 0x89 and bytes[1] == 0x50 and bytes[2] == 0x4e and bytes[3] == 0x47 and bytes[4] == 0x0d and bytes[5] == 0x0a and bytes[6] == 0x1a and bytes[7] == 0x0a:
print(f"{file} is png")
if output_path is not None:
with open(os.path.join(output_path, file + ".png"), 'wb') as fout:
fout.write(bytes)
print(f"path to file is {os.path.join(output_path, file + '.png')}")
elif bytes[0] == 0x47 and bytes[1] == 0x49 and bytes[2] == 0x46 and bytes[3] == 0x38 and bytes[4] == 0x37 and bytes[5] == 0x61:
print(f"{file} is gif")
if output_path is not None:
with open(os.path.join(output_path, file + ".gif"), 'wb') as fout:
fout.write(bytes)
print(f"path to file is {os.path.join(output_path, file + '.gif')}")
elif bytes[0] == 0x47 and bytes[1] == 0x49 and bytes[2] == 0x46 and bytes[3] == 0x38 and bytes[4] == 0x39 and bytes[5] == 0x61:
print(f"{file} is gif")
if output_path is not None:
with open(os.path.join(output_path, file + ".gif"), 'wb') as fout:
fout.write(bytes)
print(f"path to file is {os.path.join(output_path, file + '.gif')}")
elif bytes[0] == 0x87 and bytes[1] == 0x45 and bytes[2] == 0x42 and bytes[3] == 0x50:
print(f"{file} is webp")
if output_path is not None:
with open(os.path.join(output_path, file + ".webp"), 'wb') as fout:
fout.write(bytes)
print(f"path to file is {os.path.join(output_path, file + '.webp')}")
elif bytes[0] == 0x1f and bytes[1] == 0x8b and bytes[2] == 0x08:
print(f"{file} is gzip archive")
decompressed_bytes = gzip.decompress(bytes)
if output_path is not None:
with open(os.path.join(output_path, file + ".txt"), 'wb') as fout:
fout.write(decompressed_bytes)
print(f"path to file is {os.path.join(output_path, file + '.txt')}")
except:
continue
def get_bookmarks():
cnn = sqlite3.connect(glob.glob(paths['bookmarks'])[0])
crs = cnn.cursor()
bookmarks_sql = """
select
b.id,
p.url,
p.title,
p.description,
b.type,
b.fk,
b.parent,
b.position,
b.title,
b.keyword_id,
b.folder_type,
b.dateAdded,
b.lastModified,
b.guid,
b.syncStatus,
b.syncChangeCounter
from moz_bookmarks b join moz_places p on b.fk = p.id
"""
crs.execute(bookmarks_sql)
bookmarks = crs.fetchall()
headers = "id,url,title,description,type,fk,parent,position,title,keyword_id,folder_type,dateAdded,lastModified,guid,syncStatus,syncChangeCounter".split(",")
html = gen_html(title="Firefox Bookmarks", headers=headers, data=bookmarks)
with open ("firefox_bookmarks.html", 'w') as f:
f.write(html)
webbrowser.open_new_tab(os.path.join(os.getcwd(), "firefox_bookmarks.html"))
return bookmarks
if __name__ == "__main__":
if len(args) < 2:
print("""usage: python chrome_rdr <chrome_directory> [<option>]
options: --history: Chrome browsing history
--cookies: Chrome cookies""")
exit()
if args[1] == "-h":
print("""usage: python chrome_rdr <chrome_directory> [<option>]
options: --history: Chrome browsing history
--cookies: Chrome cookies""")
exit()
if len(args) < 3:
print("Firefox history")
pprint(get_history())
print("Firefox cookies")
pprint(get_cookies())
elif args[2] == "--history":
print("Firefox history")
pprint(get_history())
elif args[2] == "--cookies":
print("Firefox cookies")
pprint(get_cookies())
elif args[2] == "--bookmarks":
print("Firefox bookmarks")
pprint(get_bookmarks())
elif args[2] == "--cache":
output_path = None
try:
output_path = args[3]
print(f"writing to path {output_path}")
except:
print("no output path specified. printing hints")
print("firefox cache")
get_cache(output_path)
exit()