Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
carmaa committed Apr 17, 2015
1 parent a9e0bbc commit b92db21
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 54 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ still vulnerable] [9].
Key data
--------

* Version: 0.4.0
* Version: 0.4.1
* License: GPL
* Author: Carsten Maartmann-Moe (carsten@carmaa.com) AKA ntropy
* Author: Carsten Maartmann-Moe (carsten@carmaa.com)
* Twitter: @breaknenter
* Site: http://www.breaknenter.org/projects/inception
* Source: https://github.com/carmaa/inception
Expand Down Expand Up @@ -103,22 +103,22 @@ Installation
------------

On Debian-based distributions the installation command lines can be summarized
as:
as (apply `sudo` as needed if you're not root):

sudo apt-get install git cmake g++ python3 python3-pip
apt-get install git cmake g++ python3 python3-pip

On OS X, you can install the tool requirements with [homebrew] [4]:

brew install git cmake python3

After installing the requirements, download and install libforensic1394:

git clone git://git.freddie.witherden.org/forensic1394.git
cd forensic1394
git clone git://github.com/FreddieWitherden/libforensic1394.git
cd libforensic1394
cmake CMakeLists.txt
sudo make install
make install
cd python
sudo python3 setup.py install
python3 setup.py install

### Download and install Inception

Expand Down Expand Up @@ -419,6 +419,7 @@ Development history
* 0.3.4 - Maestro!
* 0.3.5 - Added Ubuntu 10.10 and 10.04 x86 signatures
* 0.4.0 - Complete restructuring and rewrite. Added implant module
* 0.4.1 - Merged SLOTSCREAMER interface support


Disclaimer
Expand Down
96 changes: 51 additions & 45 deletions inception/interfaces/slotscreamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
This module provides the ability to use inception using SLOTSCREAMER.
Most of the code is adopted from the slotscreamer samples with slight
Most of the code is adopted from the slotscreamer samples with slight
modification.
Created on Jan 16th, 2015
Expand Down Expand Up @@ -69,68 +69,74 @@ def __init__(self):
cfg = dev.get_active_configuration()
intf = cfg[0, 0]

self.pciin = usb.util.find_descriptor(intf, custom_match=lambda e: e.bEndpointAddress==0x8e)
self.pciin = usb.util.find_descriptor(intf, custom_match=lambda e:
e.bEndpointAddress == 0x8e)
assert self.pciin is not None, 'SLOTSCREAMER pciin endpoint not found'
term.info('SLOTSCREAMER PCIIN found: '+str(self.pciin)+'\n')
term.info('SLOTSCREAMER PCIIN found: ' + str(self.pciin) + '\n')

self.pciout = usb.util.find_descriptor(intf, custom_match=lambda e: e.bEndpointAddress==0xe)
self.pciout = usb.util.find_descriptor(intf, custom_match=lambda e:
e.bEndpointAddress == 0xe)
assert self.pciout is not None, 'pciout endpoint not found'
term.info('SLOTSCREAMER PCIOUT found: '+str(self.pciout)+'\n')
self.cache=[]
term.info('SLOTSCREAMER PCIOUT found: ' + str(self.pciout) + '\n')
self.cache = []

def read(self, addr, numb, buf=None):
try:
# round down to multiple of 256
offset = addr % 256
baseAddress = addr - offset
endOffset = (addr+numb) % 256
endAddress = addr + numb - offset+256
base_addr = addr - offset
end_offset = (addr + numb) % 256
end_addr = addr + numb - offset + 256
# cache most recent read
# check if anything is cached
if (len(self.cache)>0):
if((self.cacheBase<=addr)and((self.cacheBase+len(self.cache))>(addr+numb))):
return bytes(self.cache[(addr-self.cacheBase):(addr+numb)-self.cacheBase])
self.cache=[]
self.cacheBase=baseAddress
while baseAddress<endAddress:
self.pciout.write(struct.pack('BBBBI',0xcf,0,0,0x40,baseAddress))
self.cache+=self.pciin.read(0x100)
baseAddress+=256
if (len(self.cache) > 0):
if((self.cacheBase <= addr) and
((self.cacheBase + len(self.cache)) > (addr + numb))):
return bytes(self.cache[(addr - self.cacheBase):
(addr + numb) - self.cacheBase])
self.cache = []
self.cacheBase = base_addr
while base_addr < end_addr:
self.pciout.write(struct.pack('BBBBI', 0xcf, 0, 0, 0x40,
base_addr))
self.cache += self.pciin.read(0x100)
base_addr += 256
except IOError:
self.cache=[]
self.cache = []
return bytes(b"bad" + b"\x10") * 64
return bytes(self.cache[offset:offset+numb])
return bytes(self.cache[offset:offset + numb])

def readv(self,req):
def readv(self, req):
# sort requests so sequential reads are cached
#req.sort()
# req.sort()
for r in req:
yield(r[0], self.read(r[0],r[1]))
yield(r[0], self.read(r[0], r[1]))

def write(self, addr, buf):
offset=addr%256
baseAddress=addr-offset
byteCount=len(buf)
endOffset=(addr+byteCount)%256
endAddress=addr+byteCount-endOffset+256

#readbuffer
readbuf=bytearray(self.read(baseAddress,endAddress-baseAddress))

#modify buffer
for i in range(offset,endOffset):
readbuf[i]=buf[i-offset]

#writebuffer
bufferIndex=0
while baseAddress<endAddress:
subbuf=readbuf[bufferIndex:bufferIndex+128]
self.pciout.write(struct.pack('BBBBI'+'B'*128,0x4f,0,0,0x20,baseAddress,*subbuf))
baseAddress+=128
bufferIndex+=128
offset = addr % 256
base_addr = addr - offset
byte_count = len(buf)
end_offset = (addr + byte_count) % 256
end_addr = addr + byte_count - end_offset + 256

# readbuffer
readbuf = bytearray(self.read(base_addr, end_addr - base_addr))

# modify buffer
for i in range(offset, end_offset):
readbuf[i] = buf[i - offset]

# writebuffer
buffer_index = 0
while base_addr < end_addr:
subbuf = readbuf[buffer_index:buffer_index + 128]
self.pciout.write(struct.pack('BBBBI' + 'B' * 128, 0x4f, 0, 0,
0x20, base_addr, *subbuf))
base_addr += 128
buffer_index += 128

global cache
self.cache=[]
self.cache = []

def close(self):
self.cache=[]
self.cache = []
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
try:
from setuptools import setup, find_packages
except ImportError as e:
print('Warning: setuptools not available, you will have to install'
print('Warning: setuptools not available, you will have to install '
'manually')
raise e

Expand Down

0 comments on commit b92db21

Please sign in to comment.