-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmetaforge.py
330 lines (274 loc) · 9.81 KB
/
metaforge.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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
#!/usr/bin/env python3
#=====================================================
#
# Metaforge
#
#=====================================================
#
#
#@version 1.3 (Pretty Reports Edition)
#@link https://github.com/chriswmorris/Metaforge
#@authors Chris Morris & Collin Mockbee
import os, sys
import errno
import subprocess
import string
import random
import shutil
import colorama
from colorama import Fore, Back, Style
from definitions import ROOT_DIR
from fileinteractions import stageset, checkdelete, jsonsort
from exiftool import exifJSON, exifHTML, exifHTMLDump
from filter import filterexec
from markups import filtershtml, rawmetahtml, hexmetahtml, statshtml
from shutil import copyfile
def credits():
print("")
print("")
print("███╗ ███╗███████╗████████╗ █████╗ ███████╗ ██████╗ ██████╗ ██████╗ ███████╗")
print("████╗ ████║██╔════╝╚══██╔══╝██╔══██╗██╔════╝██╔═══██╗██╔══██╗██╔════╝ ██╔════╝")
print("██╔████╔██║█████╗ ██║ ███████║█████╗ ██║ ██║██████╔╝██║ ███╗█████╗ ")
print("██║╚██╔╝██║██╔══╝ ██║ ██╔══██║██╔══╝ ██║ ██║██╔══██╗██║ ██║██╔══╝ ")
print("██║ ╚═╝ ██║███████╗ ██║ ██║ ██║██║ ╚██████╔╝██║ ██║╚██████╔╝███████╗")
print("╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝")
print("")
print("")
print(Fore.WHITE + "An OSINT Metadata analyzing tool that filters through tags and creates reports")
print("Version 1.3")
print(Style.RESET_ALL)
print(Fore.GREEN + "Authors: Chris Morris & Collin Mockbee")
print("github.com/chriswmorris/Metaforge")
print()
print("=========================================================")
print(Style.RESET_ALL)
print(Fore.RED + "Remember to place the files you wish to analyze in this directory!")
print(Style.BRIGHT +"--> "+ ROOT_DIR + "/media <--")
print(Style.RESET_ALL)
input("Press [ENTER] to continue")
print()
def condchecking():
print("=======================Step 1: Condition Checking =======================")
print()
print("Need to check to make sure that the program will run correctly...")
print()
input("Press [ENTER] to continue")
try:
stageset()
checkdelete()
print()
print(Fore.GREEN + "Done. Everything looks correct")
print(Style.RESET_ALL)
except IOError as er:
errno,strerror = er.args
print(Fore.RED + "I/O error({0}): {1}".format(errno,strerror))
print(Style.RESET_ALL)
except:
print(Fore.RED + "Error:", sys.exc_info()[0])
print(Style.RESET_ALL)
def projectcreation():
print("=========================Step 2: Project Creation=========================")
#userproj is either defined by user or 6 random digits
#This will create the file structure for the user's project
randominput = ''.join(random.choice(string.ascii_lowercase
+ string.digits) for _ in range(6))
print()
print()
print("Enter a name for your project. It will also be the name of the directory.")
print("(If you would like a random name, leave it blank and press enter)")
print()
userproj = input("Project Name--> ")
print()
if not userproj:
userproj = "proj_" + randominput
try:
os.makedirs(ROOT_DIR +"/User_Projects/"+ userproj, exist_ok=True)
projectdir = ROOT_DIR + "/User_Projects/" + userproj
print(Style.BRIGHT + "Your project is named: " + userproj)
print(Style.RESET_ALL)
print(Fore.GREEN + "Successfully created project folder!")
print(Style.RESET_ALL)
except:
print(Fore.RED + "ERROR: ", sys.exc_info()[0])
sys.exit("Quitting. You need a project folder")
print(Style.RESET_ALL)
return projectdir
def exifrun():
print("=======================Step 3: Running the Exiftool=======================")
print()
#Runs exiftool on media/ directory to exifdata/ then runs
#jsonsort to sort the json into designated folders
print("This is going to run the exiftool on all of the media you defined here:")
print(Fore.BLUE + ROOT_DIR + "/media")
print(Style.RESET_ALL)
print("It could take a while depending how many files you placed.")
print()
input("Press [ENTER] to continue")
try:
print()
exifJSON()
except:
print(Fore.RED + "Exiftool to JSON failed")
print("ERROR:", sys.exc_info()[0])
print(Style.RESET_ALL)
pass
try:
exifHTML()
except:
print(Fore.RED +"Exiftool to HTML failed")
print("ERROR:", sys.exc_info()[0])
print(Style.RESET_ALL)
pass
try:
exifHTMLDump()
except:
print(Fore.RED +"Exiftool to Hexadecimal HTML failed")
print("ERROR:", sys.exc_info()[0])
print(Style.RESET_ALL)
pass
print()
def filtering():
print("=============================Step 4: Filtering=============================")
print()
#This will...
#1) Sort the JSON into their respective folder
#2) Filter out the "unimportant tags"
jsondir = ROOT_DIR + "/exifdata/json/"
jsonsubdirs = ['odp', 'png', 'mp3', 'dll', 'torrent', 'pptx', 'ods', 'odt,' 'zip', 'exe',
'xlsx', 'svg', 'pdf', 'mp4', 'html', 'docx', 'gif', 'wav', 'jpeg', 'mkv']
print("Now going to sort the JSON into their respective (original) filetype folder")
print()
input("Press [ENTER] to continue")
print()
try:
jsonsort()
print(Fore.GREEN + "Sorting Successful in exifdata/json/")
print(Style.RESET_ALL)
except IOError as sorter:
errno,strerror = sorter.args
print(Fore.RED + "I/O error({0}): {1}".format(errno,strerror))
print(Style.RESET_ALL)
except:
print(Fore.RED + "ERROR:", sys.exc_info()[0])
print(Style.RESET_ALL)
print("Starting Filtering Process...")
try:
filterexec()
print(Fore.GREEN + "Filtering Successful!")
print(Style.RESET_ALL)
except IOError as filterer:
errno,strerror = filterer.args
print(Fore.RED + "I/O error({0}): {1}".format(errno,strerror))
print(Style.RESET_ALL)
except:
print(Fore.RED +"ERROR:", sys.exc_info()[0])
print(Style.RESET_ALL)
def makereport(PROJ_DIR):
print("=========================Step 5: Make Report=========================")
print()
print("This will make the HTML reports and set up the User Project directory")
print()
input("Press [ENTER] to continue")
print()
def copyfolders(src,dest):
try:
shutil.copytree(src,dest)
except OSERROR as exc:
if exc.errno == errno.ENOTDIR:
shutil.copy(src,dest)
else:
raise
#Make HTML Reports
try:
statshtml()
except:
print(Fore.RED + "ERROR: could not run stat html report", sys.exc_info()[0])
print(Style.RESET_ALL)
try:
filtershtml()
except:
print(Fore.RED + "ERROR: could not run filter html report", sys.exc_info()[0])
print(Style.RESET_ALL)
try:
rawmetahtml()
except:
print(Fore.RED + "ERROR: could not run rawmetahtml report", sys.exc_info()[0])
print(Style.RESET_ALL)
try:
hexmetahtml()
except:
print(Fore.RED + "ERROR: could not run hexmetahtml report", sys.exc_info()[0])
print(Style.RESET_ALL)
#Moving folders to project dir
try:
print("Copying exifdata to project directory")
copyfolders(ROOT_DIR + "/exifdata/" , PROJ_DIR + "/exifdata/")
except:
print(Fore.RED + "ERROR: could not copy exifdata to project dir: ", sys.exc_info()[0])
print(Style.RESET_ALL)
try:
print("Placing Template_Data into project dir...")
copyfolders(ROOT_DIR + "/Template_Data/", PROJ_DIR + "/Template_Data/")
except:
print(Fore.RED + "ERROR: Failed to copy Template_Data: ",sys.exc_info()[0])
print(Style.RESET_ALL)
#Placing reports from ROOT_DIR to PROJ_DIR
print("Placing reports into project dir...")
try:
copyfile(ROOT_DIR + "/" + "index.html", PROJ_DIR + "/index.html")
os.remove(ROOT_DIR + "/" + "index.html")
except:
print(Fore.RED + "ERROR: Failed to copy index.html-- ",sys.exc_info()[0])
print(Style.RESET_ALL)
try:
copyfile(ROOT_DIR + "/" + "filters.html", PROJ_DIR + "/filters.html")
os.remove(ROOT_DIR + "/" + "filters.html")
except:
print(Fore.RED + "ERROR: Failed to copy filters.html-- ",sys.exc_info()[0])
print(Style.RESET_ALL)
try:
copyfile(ROOT_DIR + "/" + "rawmeta.html", PROJ_DIR + "/rawmeta.html")
os.remove(ROOT_DIR + "/" + "rawmeta.html")
except:
print(Fore.RED + "ERROR: Failed to copy rawmeta.html-- ",sys.exc_info()[0])
print(Style.RESET_ALL)
try:
copyfile(ROOT_DIR + "/" + "hexdump.html", PROJ_DIR + "/hexdump.html")
os.remove(ROOT_DIR + "/" + "hexdump.html")
except:
print(Fore.RED + "ERROR: Failed to copy rawmeta.html-- ",sys.exc_info()[0])
print(Style.RESET_ALL)
#Removing exifdata/ since it exsists in PROJ_DIR
try:
shutil.rmtree(ROOT_DIR + "/exifdata/")
except:
print(Fore.RED + "ERROR: Failed to remove /exifdata/ dir: ",sys.exc_info()[0])
print(Style.RESET_ALL)
#Setting up exifdata dir for next run
try:
print("Setting up exifdata directory...")
stageset()
except:
print(Fore.RED + "Could not run the stageset function-- ", sys.exc_info()[0])
print(Style.RESET_ALL)
print()
print(Fore.GREEN + "FINISHED!")
print(Style.RESET_ALL)
print(Style.BRIGHT + "Project Folder is here:")
print(Style.RESET_ALL)
print(Back.WHITE+ Fore.BLACK+ PROJ_DIR)
print(Style.RESET_ALL)
print(Style.BRIGHT+ "To view the Report, click on the index.html file")
print(Style.RESET_ALL)
print("===============================================================")
print()
sys.exit(0)
def main():
credits()
condchecking()
PROJ_DIR = projectcreation()
exifrun()
filtering()
makereport(PROJ_DIR)
if __name__ == '__main__':
main()