-
Notifications
You must be signed in to change notification settings - Fork 195
/
incept
executable file
·210 lines (171 loc) · 7.16 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
#!/usr/bin/env python3
'''
Inception - a FireWire physical memory manipulation and hacking tool exploiting
PCI-based and IEEE 1394 SBP-2 DMA.
Copyright (C) 2011-2014 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 <[email protected]> aka ntropy
'''
import atexit
import datetime
import optparse
import sys
import os
import traceback
import pkgutil
import inception.modules
import inception.interfaces
from inception import cfg, util, terminal, sound, memory
from inception.exceptions import InceptionException
CORE_MODULES = ['test', 'unload']
term = terminal.Terminal()
def banner():
'''
Print obligatory awesome ASCII banner
'''
if (term.width() > 79):
print('''
_| _| _| _|_|_| _|_|_|_| _|_|_| _|_|_| _| _|_| _| _|
_| _|_| _| _| _| _| _| _| _| _| _| _|_| _|
_| _| _| _| _| _|_|_| _|_|_| _| _| _| _| _| _| _|
_| _| _|_| _| _| _| _| _| _| _| _| _|_|
_| _| _| _|_|_| _|_|_|_| _| _| _| _|_| _| _|
''')
else:
print('''
INCEPTION
''')
term.write('v.{0} (C) Carsten Maartmann-Moe {1}'.format(
cfg.version, datetime.date.today().strftime('%Y')), indent=False
)
term.write('Download: {0} | Twitter: @MaartmannMoe'.format(cfg.url),
indent=False)
print()
def add_options(parser):
parser.add_option('-i', '--interface',
dest='interface',
help='set the interface to attack through. The default '
'is FireWire.',
default='firewire')
parser.add_option('-f', '--filename',
dest='filename',
help='use a file instead of FireWire data as input; '
'for example to facilitate attacks on VMware machine '
'memory files (.vmem) and to ease testing and '
'signature creation. Must be used with the "file" '
'interface.')
parser.add_option('-v', '--verbose',
action='store_true',
dest='verbose',
help='verbose mode - among other things, this prints '
'read data to stdout, useful for debugging.')
parser.add_option('-d', '--delay',
dest='delay',
help='delay attack by TIME seconds. Useful to increase '
'the chance that the target machine has successfully '
'granted the host DMA before attacking. '
'If the attack fails, try to increase this value. '
'Default delay is {0} seconds.'.format(cfg.delay),
default=cfg.delay,
type=int)
parser.add_option('--sound',
action='store_true',
dest='sound',
help='sound, inception style.')
def main(argv):
memspace = None
try:
cfg.encoding = sys.getdefaultencoding()
cfg.os = util.detectos()
# Register cleanup function
atexit.register(util.cleanup)
banner()
# Parse arguments and options
description = ('Inception is a physical memory manipulation '
'and hacking tool exploiting PCI-based DMA.')
usage = 'Usage: %prog module [options]'
parser = optparse.OptionParser(usage=usage, description=description)
add_options(parser)
try:
prog = sys.argv[0]
pkgpath = os.path.dirname(inception.modules.__file__)
modules = [name for _, name, _ in pkgutil.iter_modules([pkgpath])]
pkgpath = os.path.dirname(inception.interfaces.__file__)
ifaces = [name for _, name, _ in pkgutil.iter_modules([pkgpath])]
parser.epilog = ('Available modules: {}. '
'For module-specific help, '
'type: {} [module name] -h/--help. '
'Available interfaces: {}.'
.format(', '.join(modules), prog,
', '.join(ifaces)))
command = sys.argv[1]
if not command.startswith('-'):
module = __import__('inception.modules.{0}'
.format(command),
fromlist=modules)
group = optparse.OptionGroup(parser, 'Module description and '
'options', module.info)
module.add_options(group)
parser.add_option_group(group)
else:
parser.print_help()
sys.exit()
except IndexError as e:
parser.print_help()
sys.exit()
except ImportError as e:
raise InceptionException(e)
opts, args = parser.parse_args()
if opts.sound:
cfg.eggs.append(sound.play('resources/rien.mp3'))
# Load the selected interface
try:
interface = __import__('inception.interfaces.{0}'
.format(opts.interface),
fromlist=['inception.interfaces'])
except ImportError as e:
raise InceptionException(e)
# Initialize the interface, and wrap in memory space wrapper
if command not in CORE_MODULES:
device, memsize = interface.initialize(opts, module)
memspace = memory.MemorySpace(device, memsize)
# Here we go
module.run(opts, memspace)
# Successful
term.info('BRRRRRRRAAAAAWWWWRWRRRMRMRMMRMRMMMMM!!!')
if opts.sound:
sound.play('resources/inception.wav')
# Catch inception-related errors and print them as warnings
# TODO unless in debug mode?
except InceptionException as e:
term.error(e)
# Catch FireWire-related exeptions
except IOError as e:
term.error(e)
# Catch whatever that hasn't been catched elsewhere and print stack trace
except Exception as e:
term.warn('Something went dreadfully wrong, full stack trace below: '
'{0}'.format(e))
print()
traceback.print_exc()
print()
# Catch user interrupts
except KeyboardInterrupt:
print() # New line
term.warn('User aborted')
pass
if memspace:
memspace.release()
sys.exit()
if __name__ == '__main__':
main(sys.argv)