from pySim.transport.pcsc import PcscSimLink sl = PcscSimLink(opts.pcsc_dev) # Create command layer scc = SimCardCommands(transport=sl) # Wait for SIM card sl.wait_for_card() # Program the card print("Reading ...") # EF.IMSI (res, sw) = scc.read_binary(['3f00', '7f20', '6f07']) if sw == '9000': print("IMSI: %s" % (dec_imsi(res),)) else: print("IMSI: Can't read, response code = %s" % (sw,)) imsi = dec_imsi(res) # run the algorithm here and output results print('%-16s %-32s %-8s %s' % ('# IMSI', 'RAND', 'SRES', 'Kc')) for i in xrange(opts.iterations): rand = ''.join('%02x' % ord(x) for x in os.urandom(16)) (res, sw) = scc.run_gsm(rand) if sw == '9000': SRES, Kc = res[:8], res[8:] print('%s,%s,%s,%s' % (imsi, rand, SRES, Kc)) if i % 5 == 0: time.sleep(2) else: print('cannot run gsm algo. response code = %s' % (sw,))
sl.wait_for_card() # Program the card print("Reading ...") # EF.ICCID (res, sw) = scc.read_binary(['3f00', '2fe2']) if sw == '9000': print("ICCID: %s" % (dec_iccid(res), )) else: print("ICCID: Can't read, response code = %s" % (sw, )) # EF.IMSI (res, sw) = scc.read_binary(['3f00', '7f20', '6f07']) if sw == '9000': print("IMSI: %s" % (dec_imsi(res), )) else: print("IMSI: Can't read, response code = %s" % (sw, )) # EF.SMSP (res, sw) = scc.read_record(['3f00', '7f10', '6f42'], 1) if sw == '9000': print("SMSP: %s" % (res, )) else: print("SMSP: Can't read, response code = %s" % (sw, )) # EF.PLMNsel try: (res, sw) = scc.read_binary(EF['PLMNsel']) if sw == '9000': print("PLMNsel: %s" % (res))
from pySim.transport.pcsc import PcscSimLink sl = PcscSimLink(opts.pcsc_dev) # Create command layer scc = SimCardCommands(transport=sl) # Wait for SIM card sl.wait_for_card() # Program the card #print("Reading ...") # EF.IMSI (res, sw) = scc.read_binary(['3f00', '7f20', '6f07']) if sw == '9000': print("# IMSI: %s" % (dec_imsi(res), )) else: sys.stderr.write("IMSI: Can't read, response code = %s" % (sw, )) imsi = dec_imsi(res) with open('hnilist.csv', 'r') as f: reader = csv.reader(f) for row in reader: if row[0] == imsi[:6] or row[0] == imsi[:5]: print '# ' + row[2] mcc = row[3] mnc = row[4] if len(mnc) == 2: mnc = '0' + mnc break