def test_random_read(self): ''' Test a reading from a random sample, with a random size and a random start address ''' sample = random.sample(self.samples, 1)[0] cfg.filename = sample self.assertTrue(os.path.exists(sample)) sample_size = os.path.getsize(sample) start = random.randrange(sample_size) size_range = sample_size - start dump_size = random.randrange(size_range) end = start + dump_size sys.stdout = StringIO() # Suppress output memdump.dump(start, end) sys.stdout = sys.__stdout__ # Restore output output_fn = '{0}_{1}-{2}.bin'.format(cfg.memdump_prefix, hex(start), hex(end)) self.assertTrue(os.path.exists(output_fn)) md5 = hashlib.md5() f = open(sample, 'rb') f.seek(start) read = f.read(dump_size) md5.update(read) self.assertEqual(md5.digest(), self.file_md5(output_fn)) f.close()
def lurk(): ''' Wait for devices to connect to the FireWire bus, and attack when they do ''' start = cfg.startaddress end = cfg.memsize bb = term.BeachBall() try: s = '\n'.join(cfg.wrapper.wrap('[-] Lurking in the shrubbery ' + 'waiting for a device to connect. ' + 'Ctrl-C to abort')) + '\r' print(s, end = '') # Initiate FireWire fw = firewire.FireWire() while True: # Loop until aborted, and poll for devices while len(fw.devices) == 0: # Draw a beach ball while waiting bb.draw() time.sleep(cfg.polldelay) print() # Newline term.info('FireWire device detected') memdump.dump(start, end) except KeyboardInterrupt: print() # TODO: Fix keyboard handling (interrupt handling) raise KeyboardInterrupt
def test_random_read(self): ''' Test a reading from a random sample, with a random size and a random start address ''' sample = random.sample(self.samples, 1)[0] cfg.filename = sample self.assertTrue(os.path.exists(sample)) sample_size = os.path.getsize(sample) start = random.randrange(sample_size) size_range = sample_size - start dump_size = random.randrange(size_range) end = start + dump_size sys.stdout = StringIO() # Suppress output memdump.dump(start, end) sys.stdout = sys.__stdout__ # Restore output output_fn = '{0}_{1}-{2}.bin'.format(cfg.memdump_prefix,hex(start), hex(end)) self.assertTrue(os.path.exists(output_fn)) md5 = hashlib.md5() f = open(sample, 'rb') f.seek(start) read = f.read(dump_size) md5.update(read) self.assertEqual(md5.digest(), self.file_md5(output_fn)) f.close()
def lurk(): ''' Wait for devices to connect to the FireWire bus, and attack when they do ''' start = cfg.startaddress end = cfg.memsize bb = term.BeachBall() try: s = '\n'.join( term.wrapper.wrap('[-] Lurking in the shrubbery ' + 'waiting for a device to connect. ' + 'Ctrl-C to abort')) + '\r' print(s, end='') # Initiate FireWire fw = firewire.FireWire() while True: # Loop until aborted, and poll for devices while len(fw.devices) == 0: # Draw a beach ball while waiting bb.draw() time.sleep(cfg.polldelay) print() # Newline term.info('FireWire device detected') memdump.dump(start, end) except KeyboardInterrupt: print() # TODO: Fix keyboard handling (interrupt handling) raise KeyboardInterrupt
def test_fulldump(self): start = 0x00000000 for sample in self.samples: cfg.filename = sample end = os.path.getsize(sample) sys.stdout = StringIO() # Suppress output memdump.dump(start, end) sys.stdout = sys.__stdout__ # Restore output output_fn = '{0}_{1}-{2}.bin'.format(cfg.memdump_prefix,hex(start), hex(end)) self.assertTrue(os.path.exists(output_fn)) self.assertEqual(self.file_md5(sample), self.file_md5(output_fn))
def test_fulldump(self): start = 0x00000000 for sample in self.samples: cfg.filename = sample end = os.path.getsize(sample) sys.stdout = StringIO() # Suppress output memdump.dump(start, end) sys.stdout = sys.__stdout__ # Restore output output_fn = memdump.filename self.assertTrue(os.path.exists(output_fn)) self.assertEqual(self.file_md5(sample), self.file_md5(output_fn))
def lurk(): start = settings.startaddress end = settings.memsize try: print('[*] Lurking in the shrubbery waiting for a device to connect. Ctrl-C to abort', end = '') sys.stdout.flush() # Initiate FireWire fw = firewire.FireWire() while True: # Loop until aborted while len(fw.devices) == 0: print('.', end = '') sys.stdout.flush() time.sleep(settings.polldelay) pass # Do nothing until a device connects print() # Newline memdump.dump(start, end) except KeyboardInterrupt: print() # TODO: Fix keyboard handling (interrupt handling) raise KeyboardInterrupt
def lurk(): start = settings.startaddress end = settings.memsize try: print( '[*] Lurking in the shrubbery waiting for a device to connect. Ctrl-C to abort', end='') sys.stdout.flush() # Initiate FireWire fw = firewire.FireWire() while True: # Loop until aborted while len(fw.devices) == 0: print('.', end='') sys.stdout.flush() time.sleep(settings.polldelay) pass # Do nothing until a device connects print() # Newline memdump.dump(start, end) except KeyboardInterrupt: print() # TODO: Fix keyboard handling (interrupt handling) raise KeyboardInterrupt
def lurk(): start = cfg.startaddress end = cfg.memsize bb = BeachBall() try: s = '\n'.join(cfg.wrapper.wrap('[-] Lurking in the shrubbery waiting ' + 'for a device to connect. Ctrl-C to ' + 'abort')) + '\r' print(s, end = '') # Initiate FireWire fw = firewire.FireWire() while True: # Loop until aborted, and poll for devices while len(fw.devices) == 0: bb.draw() time.sleep(cfg.polldelay) pass # Do nothing until a device connects print() # Newline info('FireWire device detected') memdump.dump(start, end) except KeyboardInterrupt: print() # TODO: Fix keyboard handling (interrupt handling) raise KeyboardInterrupt