Compare commits
2 Commits
master
...
users/dani
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d96d22c11 | ||
|
|
1d00c19d14 |
@@ -39,7 +39,7 @@ except ImportError:
|
|||||||
|
|
||||||
from pySim.commands import SimCardCommands
|
from pySim.commands import SimCardCommands
|
||||||
from pySim.cards import _cards_classes
|
from pySim.cards import _cards_classes
|
||||||
from pySim.utils import h2b, swap_nibbles, rpad, derive_milenage_opc, calculate_luhn
|
from pySim.utils import h2b, swap_nibbles, rpad, derive_milenage_opc, calculate_luhn, dec_iccid
|
||||||
from pySim.ts_51_011 import EF
|
from pySim.ts_51_011 import EF
|
||||||
|
|
||||||
def parse_options():
|
def parse_options():
|
||||||
@@ -128,6 +128,9 @@ def parse_options():
|
|||||||
parser.add_option("--read-imsi", dest="read_imsi", action="store_true",
|
parser.add_option("--read-imsi", dest="read_imsi", action="store_true",
|
||||||
help="Read the IMSI from the CARD", default=False
|
help="Read the IMSI from the CARD", default=False
|
||||||
)
|
)
|
||||||
|
parser.add_option("--read-iccid", dest="read_iccid", action="store_true",
|
||||||
|
help="Read the ICCID from the CARD", default=False
|
||||||
|
)
|
||||||
parser.add_option("-z", "--secret", dest="secret", metavar="STR",
|
parser.add_option("-z", "--secret", dest="secret", metavar="STR",
|
||||||
help="Secret used for ICCID/IMSI autogen",
|
help="Secret used for ICCID/IMSI autogen",
|
||||||
)
|
)
|
||||||
@@ -168,8 +171,8 @@ def parse_options():
|
|||||||
return options
|
return options
|
||||||
|
|
||||||
if options.source == 'csv':
|
if options.source == 'csv':
|
||||||
if (options.imsi is None) and (options.batch_mode is False) and (options.read_imsi is False):
|
if (options.imsi is None) and (options.batch_mode is False) and (options.read_imsi is False) and (options.read_iccid is False):
|
||||||
parser.error("CSV mode needs either an IMSI, --read-imsi or batch mode")
|
parser.error("CSV mode needs either an IMSI, --read-imsi, --read-iccid or batch mode")
|
||||||
if options.read_csv is None:
|
if options.read_csv is None:
|
||||||
parser.error("CSV mode requires a CSV input file")
|
parser.error("CSV mode requires a CSV input file")
|
||||||
elif options.source == 'cmdline':
|
elif options.source == 'cmdline':
|
||||||
@@ -399,7 +402,7 @@ def gen_parameters(opts):
|
|||||||
'ki' : ki,
|
'ki' : ki,
|
||||||
'opc' : opc,
|
'opc' : opc,
|
||||||
'acc' : acc,
|
'acc' : acc,
|
||||||
'pin_adm' : pin_adm,
|
'adm1' : pin_adm,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -414,6 +417,7 @@ def print_parameters(params):
|
|||||||
> Ki : %(ki)s
|
> Ki : %(ki)s
|
||||||
> OPC : %(opc)s
|
> OPC : %(opc)s
|
||||||
> ACC : %(acc)s
|
> ACC : %(acc)s
|
||||||
|
> ADM1 : %(adm1)s
|
||||||
""" % params
|
""" % params
|
||||||
|
|
||||||
|
|
||||||
@@ -427,18 +431,23 @@ def write_params_csv(opts, params):
|
|||||||
cw.writerow([params[x] for x in row])
|
cw.writerow([params[x] for x in row])
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def _read_params_csv(opts, imsi):
|
def _read_params_csv(opts, iccid=None, imsi=None):
|
||||||
import csv
|
import csv
|
||||||
row = ['name', 'iccid', 'mcc', 'mnc', 'imsi', 'smsp', 'ki', 'opc']
|
|
||||||
f = open(opts.read_csv, 'r')
|
f = open(opts.read_csv, 'r')
|
||||||
cr = csv.DictReader(f, row)
|
cr = csv.DictReader(f)
|
||||||
i = 0
|
i = 0
|
||||||
|
if not 'iccid' in cr.fieldnames:
|
||||||
|
raise Exception("CSV file in wrong format!")
|
||||||
for row in cr:
|
for row in cr:
|
||||||
if opts.num is not None and opts.read_imsi is False:
|
if opts.num is not None and opts.read_iccid is False and opts.read_imsi is False:
|
||||||
if opts.num == i:
|
if opts.num == i:
|
||||||
f.close()
|
f.close()
|
||||||
return row;
|
return row;
|
||||||
i += 1
|
i += 1
|
||||||
|
if row['iccid'] == iccid:
|
||||||
|
f.close()
|
||||||
|
return row;
|
||||||
|
|
||||||
if row['imsi'] == imsi:
|
if row['imsi'] == imsi:
|
||||||
f.close()
|
f.close()
|
||||||
return row;
|
return row;
|
||||||
@@ -446,8 +455,8 @@ def _read_params_csv(opts, imsi):
|
|||||||
f.close()
|
f.close()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def read_params_csv(opts, imsi):
|
def read_params_csv(opts, imsi=None, iccid=None):
|
||||||
row = _read_params_csv(opts, imsi)
|
row = _read_params_csv(opts, iccid=iccid, imsi=imsi)
|
||||||
if row is not None:
|
if row is not None:
|
||||||
row['mcc'] = int(row['mcc'])
|
row['mcc'] = int(row['mcc'])
|
||||||
row['mnc'] = int(row['mnc'])
|
row['mnc'] = int(row['mnc'])
|
||||||
@@ -628,7 +637,17 @@ if __name__ == '__main__':
|
|||||||
if opts.source == 'cmdline':
|
if opts.source == 'cmdline':
|
||||||
cp = gen_parameters(opts)
|
cp = gen_parameters(opts)
|
||||||
elif opts.source == 'csv':
|
elif opts.source == 'csv':
|
||||||
if opts.read_imsi:
|
imsi = None
|
||||||
|
iccid = None
|
||||||
|
if opts.read_iccid:
|
||||||
|
if opts.dry_run:
|
||||||
|
# Connect transport
|
||||||
|
print "Insert card now (or CTRL-C to cancel)"
|
||||||
|
sl.wait_for_card(newcardonly=not first)
|
||||||
|
(res,_) = scc.read_binary(['3f00', '2fe2'], length=10)
|
||||||
|
iccid = dec_iccid(res)
|
||||||
|
print iccid
|
||||||
|
elif opts.read_imsi:
|
||||||
if opts.dry_run:
|
if opts.dry_run:
|
||||||
# Connect transport
|
# Connect transport
|
||||||
print "Insert card now (or CTRL-C to cancel)"
|
print "Insert card now (or CTRL-C to cancel)"
|
||||||
@@ -637,7 +656,7 @@ if __name__ == '__main__':
|
|||||||
imsi = swap_nibbles(res)[3:]
|
imsi = swap_nibbles(res)[3:]
|
||||||
else:
|
else:
|
||||||
imsi = opts.imsi
|
imsi = opts.imsi
|
||||||
cp = read_params_csv(opts, imsi)
|
cp = read_params_csv(opts, imsi=imsi, iccid=iccid)
|
||||||
if cp is None:
|
if cp is None:
|
||||||
print "Error reading parameters\n"
|
print "Error reading parameters\n"
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|||||||
@@ -375,8 +375,8 @@ class GrcardSim(Card):
|
|||||||
#self._scc.verify_chv(4, h2b("4444444444444444"))
|
#self._scc.verify_chv(4, h2b("4444444444444444"))
|
||||||
|
|
||||||
# Authenticate using ADM PIN 5
|
# Authenticate using ADM PIN 5
|
||||||
if p['pin_adm']:
|
if p['adm1']:
|
||||||
pin = h2b(p['pin_adm'])
|
pin = h2b(p['adm1'])
|
||||||
else:
|
else:
|
||||||
pin = h2b("4444444444444444")
|
pin = h2b("4444444444444444")
|
||||||
self._scc.verify_chv(5, pin)
|
self._scc.verify_chv(5, pin)
|
||||||
@@ -495,8 +495,8 @@ class SysmoSIMgr2(Card):
|
|||||||
# P1: 3A for PIN, 3B for PUK
|
# P1: 3A for PIN, 3B for PUK
|
||||||
# P2: CHV number, as in VERIFY CHV for PIN, and as in UNBLOCK CHV for PUK
|
# P2: CHV number, as in VERIFY CHV for PIN, and as in UNBLOCK CHV for PUK
|
||||||
# P3: 08, CHV length (curiously the PUK is also 08 length, instead of 10)
|
# P3: 08, CHV length (curiously the PUK is also 08 length, instead of 10)
|
||||||
if p['pin_adm']:
|
if p['adm1']:
|
||||||
pin = p['pin_adm']
|
pin = p['adm1']
|
||||||
else:
|
else:
|
||||||
pin = h2b("4444444444444444")
|
pin = h2b("4444444444444444")
|
||||||
|
|
||||||
@@ -567,9 +567,9 @@ class SysmoUSIMSJS1(Card):
|
|||||||
def program(self, p):
|
def program(self, p):
|
||||||
|
|
||||||
# authenticate as ADM using default key (written on the card..)
|
# authenticate as ADM using default key (written on the card..)
|
||||||
if not p['pin_adm']:
|
if not p['adm1']:
|
||||||
raise ValueError("Please provide a PIN-ADM as there is no default one")
|
raise ValueError("Please provide a PIN-ADM as there is no default one")
|
||||||
self._scc.verify_chv(0x0A, h2b(p['pin_adm']))
|
self._scc.verify_chv(0x0A, p['adm1'])
|
||||||
|
|
||||||
# select MF
|
# select MF
|
||||||
r = self._scc.select_file(['3f00'])
|
r = self._scc.select_file(['3f00'])
|
||||||
|
|||||||
Reference in New Issue
Block a user