def __init__(self): ''' initializes like an ISO7816-4 card with CLA=0x00 and checks available AID (Application ID) read from EF_DIR initializes on the MF ''' # initialize like a UICC ISO7816.__init__(self, CLA=0x00) self.AID = [] if self.dbg >= 2: log(3, '(UICC.__init__) type definition: %s' % type(self)) log(3, '(UICC.__init__) CLA definition: %s' % hex(self.CLA)) # USIM selection from AID if self.dbg: log(3, '(USIM.__init__) UICC AID found:') self.get_AID() for aid in self.AID: if tuple(aid[0:5]) == (0xA0, 0x00, 0x00, 0x00, 0x87) \ and tuple(aid[5:7]) == (0x10, 0x02) : usim = self.select(addr=aid, type='aid') if usim is None and self.dbg: log(2, '(USIM.__init__) USIM AID selection failed') if usim is not None: self.USIM_AID = aid if self.dbg: log(3, '(USIM.__init__) USIM AID selection succeeded\n')
def __init__(self): ''' initialize like an ISO7816-4 card with CLA=0xA0 can also be used for USIM working in SIM mode, ''' ISO7816.__init__(self, CLA=0xA0) if self.dbg: print '[DBG] type definition: %s' % type(self) print '[DBG] CLA definition: %s' % hex(self.CLA) self.caller = { 'Kc': self.get_Kc, 'IMSI': self.get_imsi, 'LOCI': self.get_loci, 'HPLMN': self.get_subscr_sim_hplmn, 'PLMN_SEL': self.get_subscr_sim_plmnsel, 'ICCID': self.get_subscr_iccid, 'SPN': self.get_subscr_sim_spn, 'ACC': self.get_subscr_sim_acc, 'FPLMN': self.get_subscr_sim_fplmn, 'MSISDN': self.get_subscr_sim_msisdn, 'PRINT_ALL': self.print_sim_card_info, 'Kc-W': self.write_subscr_Kc, 'LOCI-W': self.write_subscr_loci, 'SMSP': self.get_subscr_smsp, 'GSM_ALGO': self.run_gsm_algorithm }
def __init__(self): ''' initializes like an ISO7816-4 card with CLA=0x00 and checks available AID (Application ID) read from EF_DIR initializes on the MF ''' # initialize like a UICC ISO7816.__init__(self, CLA=0x00) self.AID = [] self.dbg = 0 if self.dbg >= 2: log(3, '(UICC.__init__) type definition: %s' % type(self)) log(3, '(UICC.__init__) CLA definition: %s' % hex(self.CLA)) # USIM selection from AID if self.dbg: log(3, '(USIM.__init__) UICC AID found:') self.get_AID() for aid in self.AID: if tuple(aid[0:5]) == (0xA0, 0x00, 0x00, 0x00, 0x87) \ and tuple(aid[5:7]) == (0x10, 0x02) : usim = self.select(addr=aid, type='aid') if usim is None and self.dbg: log(2, '(USIM.__init__) USIM AID selection failed') if usim is not None: self.USIM_AID = aid if self.dbg: log(3, '(USIM.__init__) USIM AID selection succeeded\n')
def __init__(self): ''' initializes like an ISO7816-4 card with CLA=0x00 and checks available AID (Application ID) read from EF_DIR initializes on the MF ''' # initialize like a UICC ISO7816.__init__(self, CLA=0x00) self.AID = [] if self.dbg: print '[DBG] type definition: %s' % type(self) print '[DBG] CLA definition: %s' % hex(self.CLA) # USIM selection from AID print '[+] UICC AID found:' self.get_AID() for aid in self.AID: if tuple(aid[0:5]) == (0xA0, 0x00, 0x00, 0x00, 0x87) \ and tuple(aid[5:7]) == (0x10, 0x04) : isim = self.select(Data=aid, typ='aid') if isim is None: print '[+] ISIM AID selection failed' else: print '[+] ISIM AID selection succeeded\n'
def __init__(self): ''' initialize like an ISO7816-4 card with CLA=0xA0 can also be used for USIM working in SIM mode, ''' ISO7816.__init__(self, CLA=0xA0) if self.dbg >= 2: log(3, '(SIM.__init__) type definition: %s' % type(self)) log(3, '(SIM.__init__) CLA definition: %s' % hex(self.CLA))
def __init__(self): """ initialize like an ISO7816-4 card with CLA=0xA0 can also be used for USIM working in SIM mode, """ ISO7816.__init__(self, CLA=0xA0) if self.dbg >= 2: log(3, '(SIM.__init__) type definition: %s' % type(self)) log(3, '(SIM.__init__) CLA definition: %s' % hex(self.CLA))
def __init__(self): ''' initializes like an ISO7816-4 card with CLA=0x00 and check available AID (Application ID) read straight after card init ''' ISO7816.__init__(self, CLA=0x00) self.AID = [] if self.dbg >= 2: log(3, '(UICC.__init__) type definition: %s' % type(self)) log(3, '(UICC.__init__) CLA definition: %s' % hex(self.CLA))
def __init__(self): ''' initializes like an ISO7816-4 card with CLA=0x00 and checks available AID (Application ID) read from EF_DIR initializes on the MF ''' # initialize like a UICC ISO7816.__init__(self, CLA=0x00) self.AID = [] if self.dbg >= 2: log(3, '(UICC.__init__) type definition: %s' % type(self)) log(3, '(UICC.__init__) CLA definition: %s' % hex(self.CLA)) self.SELECT_ADF_USIM()
def __init__(self, reader=''): """ initializes like an ISO7816-4 card with CLA=0x00 and checks available AID (Application ID) read from EF_DIR initializes on the MF """ # initialize like a UICC ISO7816.__init__(self, CLA=0x00, reader=reader) self.AID = [] self.AID_GP = {} self.AID_USIM = None self.AID_ISIM = None # if self.dbg >= 2: log(3, '(UICC.__init__) type definition: %s' % type(self)) log(3, '(UICC.__init__) CLA definition: %s' % hex(self.CLA)) # self.SELECT_ADF_USIM()
def __init__(self): ''' initialize like an ISO7816-4 card with CLA=0xA0 can also be used for USIM working in SIM mode, ''' ISO7816.__init__(self, CLA=0xA0) if self.dbg: print '[DBG] type definition: %s' % type(self) print '[DBG] CLA definition: %s' % hex(self.CLA) self.caller = { 'KC' : self.get_Kc, 'IMSI' : self.get_imsi, 'LOCI' : self.get_loci, 'HPPLMN' : self.get_hpplmn, 'PLMN_SEL' : self.get_plmnsel, 'ACC' : self.get_acc, 'ICCID' : self.get_iccid, 'FPLMN' : self.get_fplmn, 'MSISDN' : self.get_msisdn, 'SMSP' : self.get_smsp, }
def sw_status(self, sw1, sw2): ''' sw_status(sw1=int, sw2=int) -> string extends SW status bytes interpretation from ISO7816 with ETSI / 3GPP SW codes helps to speak with the smartcard! ''' status = ISO7816.sw_status(self, sw1, sw2) if sw1 == 0x91: status = 'normal processing, with extra info ' \ 'containing a command for the terminal: length of the ' \ 'response data %d' % sw2 elif sw1 == 0x9E: status = 'normal processing, SIM data download ' \ 'error: length of the response data %d' % sw2 elif sw1 == 0x9F: status = 'normal processing: length of the ' \ 'response data %d' % sw2 elif (sw1, sw2) == (0x93, 0x00): status = 'SIM application toolkit ' \ 'busy, command cannot be executed at present' elif sw1 == 0x92: status = 'memory management' if sw2 < 16: status += ': command successful but after %d '\ 'retry routine' % sw2 elif sw2 == 0x40: status += ': memory problem' elif sw1 == 0x94: status = 'referencing management' if sw2 == 0x00: status += ': no EF selected' elif sw2 == 0x02: status += ': out of range (invalid address)' elif sw2 == 0x04: status += ': file ID or pattern not found' elif sw2 == 0x08: status += ': file inconsistent with the command' elif sw1 == 0x98: status = 'security management' if sw2 == 0x02: status += ': no CHV initialized' elif sw2 == 0x04: status += ': access condition not fulfilled, ' \ 'at least 1 attempt left' elif sw2 == 0x08: status += ': in contradiction with CHV status' elif sw2 == 0x10: status += ': in contradiction with ' \ 'invalidation status' elif sw2 == 0x40: status += ': unsuccessful CHV verification, ' \ 'no attempt left' elif sw2 == 0x50: status += ': increase cannot be performed, ' \ 'max value reached' elif sw2 == 0x62: status += ': authentication error, ' \ 'application specific' elif sw2 == 0x63: status += ': security session expired' return status
def sw_status(sw1, sw2): ''' sw_status(sw1=int, sw2=int) -> string extends SW status bytes interpretation from ISO7816 with ETSI / 3GPP SW codes helps to speak with the smartcard! ''' status = ISO7816.sw_status(sw1, sw2) if sw1 == 0x91: status = 'normal processing, with extra info ' \ 'containing a command for the terminal: length of the ' \ 'response data %d' % sw2 elif sw1 == 0x9E: status = 'normal processing, SIM data download ' \ 'error: length of the response data %d' % sw2 elif sw1 == 0x9F: status = 'normal processing: length of the ' \ 'response data %d' % sw2 elif (sw1, sw2) == (0x93, 0x00): status = 'SIM application toolkit ' \ 'busy, command cannot be executed at present' elif sw1 == 0x92 : status = 'memory management' if sw2 < 16: status += ': command successful but after %d '\ 'retry routine' % sw2 elif sw2 == 0x40: status += ': memory problem' elif sw1 == 0x94: status = 'referencing management' if sw2 == 0x00: status += ': no EF selected' elif sw2 == 0x02: status += ': out of range (invalid address)' elif sw2 == 0x04: status += ': file ID or pattern not found' elif sw2 == 0x08: status += ': file inconsistent with the command' elif sw1 == 0x98: status = 'security management' if sw2 == 0x02: status += ': no CHV initialized' elif sw2 == 0x04: status += ': access condition not fulfilled, ' \ 'at least 1 attempt left' elif sw2 == 0x08: status += ': in contradiction with CHV status' elif sw2 == 0x10: status += ': in contradiction with ' \ 'invalidation status' elif sw2 == 0x40: status += ': unsuccessful CHV verification, ' \ 'no attempt left' elif sw2 == 0x50: status += ': increase cannot be performed, ' \ 'max value reached' elif sw2 == 0x62: status += ': authentication error, ' \ 'application specific' elif sw2 == 0x63: status += ': security session expired' return status
# Python library to work on # USIM card # communication based on ISO7816 card # and commands and formats based on UICC card # # needs pyscard from: # http://pyscard.sourceforge.net/ ################################# import hashlib from optparse import OptionParser import os import random import re import sys from card.ICC import ISO7816 if __name__ == '__main__': def __init__(self): ''' connect smartcard and defines class CLA code for communication uses "pyscard" library services creates self.CLA attribute with CLA code and self.coms attribute with associated "apdu_stack" instance ''' print "Checking ATR Value" iso = ISO7816() iso.ATR_scan()