Пример #1
0
def Test_DES():
    """
        *** GetCardVersion()
        TX CMAC:  50 20 EC 82 60 86 DF 12
        Sending:  00 00 FF 04 FC <D4 40 01 60> 8B 00
        Response: 00 00 FF 0B F5 <D5 41 00 AF 04 01 01 01 00 1A 05> 15 00 AA AA AA AA AA AA AA AA
        Sending:  00 00 FF 04 FC <D4 40 01 AF> 3C 00
        Response: 00 00 FF 0B F5 <D5 41 00 AF 04 01 01 01 04 1A 05> 11 00 AA AA AA AA AA AA AA AA
        Sending:  00 00 FF 04 FC <D4 40 01 AF> 3C 00
        Response: 00 00 FF 1A E6 <D5 41 00 00 04 06 3F 72 63 34 80 BA 45 19 E3 20 49 13 CD C8 10 BA FA 40 17 59> 98 00
        RX CMAC:  CD C8 10 BA FA 40 17 59
        """

    print('Test Des')
    reader = DummyPCSCDevice()

    reader = DummyPCSCDevice()
    #Auth
    reader.addResponse('45', [
        '00 0F 01', '00 0F 02 25 DD 8D 77 31 B1 CF D5',
        '00 0D 02 61 3F B2 D3 F4 53 D2 E4'
    ])
    reader.addResponse(
        '1A 00', ['AF 5D 99 4C E0 85 F2 40 89', 'AF 84 76 D1 CF 30 24 B7 C7'])
    reader.addResponse('AF 21 D0 AD 5F 2F D9 74 54 A7 46 CC 80 56 7F 1B 1C',
                       ['00 91 3C 6D ED 84 22 1C 41'])
    #Get Card information
    reader.addResponse('60', ['AF 04 01 01 01 00 1A 05'])
    reader.addResponse('AF', [
        'AF 04 01 01 01 04 1A 05',
        '00 04 06 3F 72 63 34 80 BA 45 19 E3 20 49 13 CD C8 10 BA FA 40 17 59'
    ])
    #Format Card
    reader.addResponse('FC', ['00 9C 2C 81 3A 06 5C 45 F7'])
    #Create Application 2 Key 2K3DES
    reader.addResponse('CA 16 DE 00 0F 02', ['00 0A 13 79 B0 1D 85 AD 47'])
    #Create Application 1 Key 2K3DES
    reader.addResponse('CA CC BB AA 0F 01', ['00 F1 1A C0 73 8E F8 38 78'])
    #Create Application AES
    reader.addResponse('CA 16 AE 00 0F 82', ['00 3B 68 D7 2A 3B E0 D2 0C'])
    #Create Application 3K3DES
    reader.addResponse('CA 24 DE 00 0F 42', ['00 5D 73 AE 52 87 A1 BB E4'])
    #Get Application IDS
    reader.addResponse('6A', [
        '00 16 DE 00 24 DE 00 16 AE 00 CC BB AA 27 39 15 4E 26 30 D6 50',
        '00 16 DE 00 24 DE 00 16 AE 00 52 0E 51 E0 0A F0 6D 5E'
    ])
    #Delete Application
    reader.addResponse('DA CC BB AA', ['00 A9 AF 19 05 22 92 F6 62'])
    #Select Application
    reader.addResponse('5A 16 DE 00', ['00'])
    #Authenticate 2
    reader.addResponse('AF DA C6 7A B7 43 76 3D C9 FA F8 A0 AE 50 4E 80 C5',
                       ['00 13 E9 E4 FA 43 88 BF 16'])
    #Cange Key Setting
    reader.addResponse('54 27 88 28 05 FC 3F D4 9D',
                       ['00 A6 28 37 83 74 27 0A CD'])

    desfire = DESFire(reader)
    key_setting = desfire.getKeySetting()
    desfire.authenticate(0, key_setting, '84 9B 36 C5 F8 BF 4A 09')
    desfire.getCardVersion()
    desfire.formatCard()
    desfire.createApplication("00 DE 16", [
        DESFireKeySettings.KS_ALLOW_CHANGE_MK,
        DESFireKeySettings.KS_LISTING_WITHOUT_MK,
        DESFireKeySettings.KS_CREATE_DELETE_WITHOUT_MK,
        DESFireKeySettings.KS_CONFIGURATION_CHANGEABLE
    ], 2, DESFireKeyType.DF_KEY_2K3DES)
    desfire.createApplication("00 DE 24", [
        DESFireKeySettings.KS_ALLOW_CHANGE_MK,
        DESFireKeySettings.KS_LISTING_WITHOUT_MK,
        DESFireKeySettings.KS_CREATE_DELETE_WITHOUT_MK,
        DESFireKeySettings.KS_CONFIGURATION_CHANGEABLE
    ], 2, DESFireKeyType.DF_KEY_3K3DES)
    desfire.createApplication("00 AE 16", [
        DESFireKeySettings.KS_ALLOW_CHANGE_MK,
        DESFireKeySettings.KS_LISTING_WITHOUT_MK,
        DESFireKeySettings.KS_CREATE_DELETE_WITHOUT_MK,
        DESFireKeySettings.KS_CONFIGURATION_CHANGEABLE
    ], 2, DESFireKeyType.DF_KEY_AES)
    desfire.createApplication("AA BB CC", [
        DESFireKeySettings.KS_ALLOW_CHANGE_MK,
        DESFireKeySettings.KS_LISTING_WITHOUT_MK,
        DESFireKeySettings.KS_CREATE_DELETE_WITHOUT_MK,
        DESFireKeySettings.KS_CONFIGURATION_CHANGEABLE
    ], 1, DESFireKeyType.DF_KEY_2K3DES)
    desfire.getApplicationIDs()
    desfire.deleteApplication("AA BB CC")
    desfire.getApplicationIDs()
    desfire.selectApplication('00 DE 16')
    key_setting.setKey('00 00 00 00 00 00 00 00')
    desfire.authenticate(0, key_setting, '49 EC 63 DE CD E0 07 72')
    desfire.getKeySetting()
    desfire.changeKeySettings([
        DESFireKeySettings.KS_ALLOW_CHANGE_MK,
        DESFireKeySettings.KS_CREATE_DELETE_WITHOUT_MK,
        DESFireKeySettings.KS_CONFIGURATION_CHANGEABLE
    ])
    desfire.getKeySetting()

    print('[+] Test_DES Succsess')
Пример #2
0
def Test_2k3DES():
    reader = DummyPCSCDevice()
    #Get key Settings
    reader.addResponse('45', ['00 0F 01'])
    #Select Application
    reader.addResponse('5A 16 DE 00', ['D5 41 00 00'])
    #Auth DES
    reader.addResponse('1A 00', [
        'AF DE 50 F9 23 10 CA F5 A5', 'AF B2 95 57 99 26 15 5A E3',
        'AF 94 14 81 9C C8 BB 62 C3', 'AF 53 A6 70 D7 8C 0D FF D6'
    ])
    reader.addResponse('AF E0 06 16 66 87 04 D5 54 9C 8D 6A 13 A0 F8 FC ED',
                       ['00 1D 9D 29 54 69 7D E7 60'])
    #Change Key
    reader.addResponse(
        'C4 00 BE DE 0F C6 ED 34 7D CF 0D 51 C7 17 DF 75 D9 7D 2C 5A 2B A6 CA C7 47 9D',
        ['00'])
    #Auth 2
    reader.addResponse('AF 70 F3 49 74 0C 94 5D AE 15 9B A9 FE DB CC 46 1A',
                       ['00 B8 FD 7F E5 6B 24 1F C4'])
    #Change Key 2
    reader.addResponse(
        'C4 00 94 E4 F7 09 DC 2A 2B 07 55 26 10 A1 96 6E 5C 49 EC 90 F6 16 ED EC A5 5B',
        ['00'])
    #Auth 3
    reader.addResponse('AF 93 7E 6B 18 54 A6 D9 2E 0F D9 75 D9 90 90 01 E8',
                       ['00 E0 55 D1 1D D9 53 50 60'])
    #Get key version
    reader.addResponse('64 00', ['00 10 33 45 AA 95 F2 D9 56 CF'])
    #Change Key 3
    reader.addResponse(
        'C4 00 FC 9E 20 FD 77 19 1E 2A AB 0C FD 53 D9 99 99 84 BC 59 E8 86 BF EB 42 D0',
        ['00'])
    #Auth4
    reader.addResponse('AF B3 08 40 8B 57 5A 20 25 25 3D 49 D6 93 CC C2 9C',
                       ['00 52 5B B0 1E 5B 70 B7 94'])
    #change Key other numeber(1)
    reader.addResponse(
        'C4 01 4E B6 69 E4 8D CA 58 47 49 54 2E 1B E8 9C B4 C7 84 5A 38 C5 7D 19 DE 59',
        ['00 2E AD 04 DC F1 21 E0 FE'])
    #change key 1 second
    reader.addResponse(
        'C4 01 FA 7B EF A6 78 2C 93 E8 D6 9C F7 35 2C FD 33 DF 5B C8 AC 4F BA 49 06 FC',
        ['00 CB 0A 50 64 05 51 28 93'])

    desfire = DESFire(reader)
    key_setting = desfire.getKeySetting()
    desfire.authenticate(0, key_setting, 'C9 6C E3 5E 4D 60 87 F2')
    new_key = desfire.createKeySetting(
        '00 10 20 31 40 50 60 70 80 90 A0 B0 B0 A0 90 80', 0,
        DESFireKeyType.DF_KEY_2K3DES, [])
    desfire.changeKey(0, new_key, key_setting)
    desfire.authenticate(0, new_key, '53 0E 3D 90 F7 A2 01 C4')
    new_key2 = desfire.createKeySetting(
        '10 18 20 29 30 38 40 48 50 58 60 68 70 78 80 88', 0,
        DESFireKeyType.DF_KEY_2K3DES, [])
    desfire.changeKey(0, new_key2, new_key)
    desfire.authenticate(0, new_key2, 'DD B0 97 C2 A1 E4 7B 96')
    desfire.getKeyVersion(0)
    new_key3 = desfire.createKeySetting(
        '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00', 0,
        DESFireKeyType.DF_KEY_2K3DES, [])
    desfire.changeKey(0, new_key3, new_key2)
    desfire.authenticate(0, key_setting, 'CB A6 75 E8 EF BA B9 9C')
    new_key4 = desfire.createKeySetting(
        '00 10 20 31 40 50 60 70 80 90 A0 B0 B0 A0 90 80', 0,
        DESFireKeyType.DF_KEY_2K3DES, [])
    desfire.changeKey(1, new_key4, key_setting)
    new_key5 = desfire.createKeySetting(
        '10 18 20 29 30 38 40 48 50 58 60 68 70 78 80 88', 0,
        DESFireKeyType.DF_KEY_2K3DES, [])
    desfire.changeKey(1, new_key5, new_key4)