-
Notifications
You must be signed in to change notification settings - Fork 6
/
easy_stegoCTF.py
166 lines (126 loc) · 4.71 KB
/
easy_stegoCTF.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
#!/usr/bin/python
import sys, os, getopt
from modules import Exif_module, Strings_module, Stego_module, LSB_module, Binwalk_module
def main(argv):
hlp = "-f <inputfile> -o <outputdirectory> [-s <String_to_search> [-g/--stego] [-m/--metadata] [-b/--binwalk] [-l/--lsb] [-t/--strings] [-x/--hexdump] [-e/--entropy] [-n/--noprint] [-r/--min-len <min_len_of_strings>]]"
try:
opts, args = getopt.getopt(argv,"hf:o:s:gmbltxenr:z",["help","ifile=","odir=","search=","stego","metadata","binwalk","lsb","strings","hexdump","entropy","noprint","min-len=","sanitize"])
except getopt.GetoptError, err:
print "~ %s" % str(err)
print hlp
sys.exit(2)
general_urls = []
stego_tools = []
search, out_dir, min_len = "", "", 5
try_all, print_each, try_stego, try_exif, try_binwalk, try_lsb, try_strings, try_hexdump, try_entropy, sanitize = True, True, False, False, False, False, False, False, False, False
for opt, arg in opts:
if opt == '-h':
print hlp
sys.exit(3)
elif opt in ("-f", "--ifile"):
inputfile = arg
filename = inputfile.split("/")[-1]
if (not os.path.isfile(inputfile)):
print "Not a file: "+filename
sys.exit(-1)
elif opt in ("-o","--odir"):
out_dir = arg
if not os.path.exists(out_dir):
try:
os.makedirs(out_dir)
except:
print "Not a directory or not enough permissions: "+out_dir
sys.exit(-2)
if not os.path.isdir(out_dir) or not os.access(out_dir, os.W_OK):
print "Not a directory or not enough permissions: "+out_dir
sys.exit(-2)
elif opt in ("-g","--stego"):
try_all = False
try_stego = True
elif opt in ("-m","--metadata"):
try_all = False
try_exif = True
elif opt in ("-b","--binwalk"):
try_all = False
try_binwalk = True
elif opt in ("-l","--lsb"):
try_all = False
try_lsb = True
elif opt in ("-t","--strings"):
try_all = False
try_strings = True
elif opt in ("-x","--hexdump"):
try_hexdump = True
try_all= False
elif opt in ("-e","--entropy"):
try_all = False
try_entropy = True
elif opt in ("-s", "--search"):
search = arg
elif opt in ("-n", "--noprint"):
print_each = False
elif opt in ("-r","--min-len"):
if arg.isdigit():
min_len = int(arg)
elif opt in ("-z", "--sanitize"):
sanitize = True
if not out_dir or not inputfile:
print "No out directory"
print hlp
sys.exit()
print "File input: "+filename+"\n"
# Binwalk MODULE
bwlk = Binwalk_module(inputfile, out_dir, try_hexdump, search, sanitize)
if (try_binwalk):
bwlk.execute()
# Exif MODULE
exif = Exif_module(inputfile, search)
if (try_exif):
exif.execute()
# Strings MODULE
strings = Strings_module(inputfile, search, min_len)
if (try_strings):
strings.execute()
# Stego MODULE
stego = Stego_module(inputfile, out_dir, search, min_len, try_all, try_stego, try_hexdump, try_entropy)
if (try_all or try_stego or try_hexdump or try_entropy):
stego.execute()
# LSB MODULE
lsb = LSB_module(inputfile, out_dir, search, min_len)
if (try_all or try_lsb):
lsb.execute()
######## Print output #########
print "###### General Usefull URLs ######"
for url in general_urls:
print url
for tool in stego_tools:
print tool
print "###### End URLs ######\n"
#Search MODULE
if search != "":
print "###### Search ######"
if bwlk.get_found():
print "!/\!/\!/\!/\!/\!/\! SEARCH FOUND IN BINWALK"
bwlk.print_found()
if exif.get_found():
print "!/\!/\!/\!/\!/\!/\! SEARCH FOUND IN EXIF"
exif.print_found()
if exif.get_found():
print "!/\!/\!/\!/\!/\!/\! SEARCH FOUND IN STRINGS"
strings.print_found()
if stego.get_found():
print "!/\!/\!/\!/\!/\!/\! SEARCH FOUND IN STEGO"
stego.print_found()
if lsb.get_found():
print "!/\!/\!/\!/\!/\!/\! SEARCH FOUND IN LSB"
lsb.print_found()
print "###### End Search ######"
print
if print_each:
bwlk.mprint()
exif.mprint()
strings.mprint()
stego.mprint()
lsb.mprint()
if __name__ == "__main__":
main(sys.argv[1:])