brutefid now can bruteforce fids below a DF and also gives nicer progress output with ETA

git-svn-id: svn+ssh://localhost/home/henryk/svn/cyberflex-shell/trunk@70 f711b948-2313-0410-aaa9-d29f33439f0b
This commit is contained in:
hploetz 2006-05-22 03:04:01 +00:00
parent ac08ac1ff8
commit c3890cf8fb
1 changed files with 36 additions and 4 deletions

View File

@ -1,30 +1,62 @@
#!/usr/bin/env python
# -*- coding: iso-8859-1 -*-
import pycsc, utils, cards, TLV_utils
import pycsc, utils, cards, TLV_utils, sys, binascii, time
STATUS_INTERVAL = 10
results_dir = {}
results_file = {}
top_level = None
start_time = time.time()
loop = 0
if __name__ == "__main__":
if len(sys.argv) > 1:
top_level = binascii.unhexlify("".join( sys.argv[1].split() ))
pycsc_card = pycsc.pycsc(protocol = pycsc.SCARD_PROTOCOL_ANY)
card = cards.new_card_object(pycsc_card)
cards.generic_card.DEBUG = False
print "Using %s" % card.DRIVER_NAME
print >>sys.stderr, "Using %s" % card.DRIVER_NAME
#for fid in (0x2f00, 0x5015): ## Test cases on an OpenSC formatted PKCS#15 card
for fid in range(0xffff):
card.change_dir()
if top_level is not None:
card.change_dir(top_level)
#objective = (0x2f00, 0x5015) ## Test cases on an OpenSC formatted PKCS#15 card
objective = range(0xffff)
for fid in objective:
data = chr(fid >> 8) + chr(fid & 0xff)
if loop % STATUS_INTERVAL == 0:
elapsed = time.time() - start_time
status = "(elapsed: %i:%02i:%02i" % (elapsed / 3600, (elapsed / 60) % 60, elapsed % 60)
try:
eta = (elapsed / loop) * (len(objective) - loop)
status = status + ", left: %i:%02i:%02i)" % (eta / 3600, (eta / 60) % 60, eta % 60)
except:
status = status + ")"
loop = loop + 1
result = card.change_dir(data)
if result.sw == card.SW_OK:
results_dir[fid] = result
card.change_dir()
if top_level is not None:
card.change_dir(top_level)
print >>sys.stderr, "\rDir %04X -> %02X%02X %s" % (fid, result.sw1, result.sw2, status),
result = card.open_file(data)
if result.sw == card.SW_OK:
results_file[fid] = result
print >>sys.stderr, "\rFile %04X -> %02X%02X %s" % (fid, result.sw1, result.sw2, status),
print >>sys.stderr
print "="*80
print "Results:"
for fid, result in results_dir.items():