Python Tool For ACR122U NFC Reader-Writer (VERY GOOD) [PDF]

  • 0 0 0
  • Suka dengan makalah ini dan mengunduhnya? Anda bisa menerbitkan file PDF Anda sendiri secara online secara gratis dalam beberapa menit saja! Sign Up
File loading please wait...
Citation preview

ACS-ACR122U-Tool GitHub - rocky112358/ACS-ACR122U-Tool: Python tool for ACR122 NFC Reader/Writer



Python tool for ACR122U NFC Reader/Writer



Notice (2020-02-25 fixed) There will be no update from me for a while because I don't have the hardware now. Pull requests are welcome.



Enviroment 



pyscard 1.9.4







python 2.7.10



Command List (Help Page) $ python nfctool.py



Before executing command, make sure that a card is being tagged on the reader. 



help: Show this command list







mute: Disable beep sound when card is tagged. (This setting is volatile. Lasts till device off.)







unmute: Enable beep sound when card is tagged.







getuid: Print UID of the tagged card.







info: Print card type and available protocols.







loadkey : Load key (6byte hexstring) for auth. (The loaded key is volatile. Lasts till device off.)







read : Read sector with loaded key.







firmver: Print the firmware version of the reader.



How to read data







Connect the reader to computer and put a card on the reader. Check connection with 'getuid' or 'info' command.







Load key with 'loadkey' command (This procedure is not needed for MIFARE Ultralight)



 



$ python nfctool.py loadkey FFFFFFFFFFFF



Read sector with 'read' command







$ python nfctool.py read 4



TODO 



Make options for 'read' command



Copyright Copyright © 2016 Kim Dong Min. The MIT License (MIT)



135 lines (119 sloc)  4.95 KB Raw Blame



   from smartcard.System import readers from smartcard.util import toHexString from smartcard.ATR import ATR from smartcard.CardType import AnyCardType import sys



if len(sys.argv) < 2: print "usage: nfcTool.py \nList of available commands: help, mute, unmute, getuid, info, loadkey, read, firmver" sys.exit()



r = readers()



if len(r) < 1: print "error: No readers available!" sys.exit()



print "Available readers: ", r



reader = r[0] print "Using: ", reader



connection = reader.createConnection() connection.connect()



#detect command cmd = sys.argv[1]



if cmd == "help": print "usage: python nfctool.py \nList of available commands: help, mute, unmute, getuid" print "Before executing command, make sure that a card is being tagged on the reader." print "\thelp\tShow this help page" print "\tmute\tDisable beep sound when card is tagged." print "\tunmute\tEnable beep sound when card is tagged." print "\tgetuid\tPrint UID of the tagged card." print "\tinfo\tPrint card type and available protocols." print "\tloadkey \tLoad key (6byte hexstring) for auth." print "\tread \tRead sector with loaded key." #print "\tread [-s ] [-h | -a] [-d | -t] \tRead sector (or all sectors) with loaded key. Print as [hex | ascii]. Print [data only | trailer only]" print "\tfirmver\tPrint the firmware version of the reader." sys.exit()



cmdMap = { "mute":[0xFF, 0x00, 0x52, 0x00, 0x00], "unmute":[0xFF, 0x00, 0x52, 0xFF, 0x00], "getuid":[0xFF, 0xCA, 0x00, 0x00, 0x00],



"firmver":[0xFF, 0x00, 0x48, 0x00, 0x00], }



COMMAND = cmdMap.get(cmd, cmd)



#send command if type(COMMAND) == list: data, sw1, sw2 = connection.transmit(COMMAND) if cmd == "firmver": print cmd +": "+ ''.join(chr(i) for i in data)+chr(sw1)+chr(sw2) else: print cmd + ": " + toHexString(data) print "Status words: %02X %02X" % (sw1, sw2) if (sw1, sw2) == (0x90, 0x0): print "Status: The operation completed successfully." elif (sw1, sw2) == (0x63, 0x0): print "Status: The operation failed."



elif type(COMMAND) == str: if COMMAND == "info": print "###Tag Info###" atr = ATR(connection.getATR()) hb = toHexString(atr.getHistoricalBytes()) cardname = hb[-17:-12] cardnameMap = { "00 01": "MIFARE Classic 1K", "00 02": "MIFARE Classic 4K", "00 03": "MIFARE Ultralight", "00 26": "MIFARE Mini", "F0 04": "Topaz and Jewel", "F0 11": "FeliCa 212K", "F0 11": "FeliCa 424K" } name = cardnameMap.get(cardname, "unknown") print "Card Name: "+ name print "T0 supported: ", atr.isT0Supported() print "T1 supported: ", atr.isT1Supported() print "T15 suppoerted: ", atr.isT15Supported()



elif COMMAND == "loadkey": if (len(sys.argv) < 3): print "usage: python nfctool.py loadkey " print "ex) python nfctool.py loadkey FFFFFFFFFFFF" sys.exit()



COMMAND = [0xFF, 0x82, 0x00, 0x00, 0x06] key = [sys.argv[2][0:2], sys.argv[2][2:4], sys.argv[2][4:6], sys.argv[2][6:8], sys.argv[2][8:10], sys.argv[2][10:12]] for i in range(6): key[i] = int(key[i], 16) COMMAND.extend(key)



data, sw1, sw2 = connection.transmit(COMMAND) print "Status words: %02X %02X" % (sw1, sw2) if (sw1, sw2) == (0x90, 0x0): print "Status: Key is loaded successfully to key #0." elif (sw1, sw2) == (0x63, 0x0): print "Status: Failed to load key."



elif COMMAND == "read": # decrypt first block of sector with key. if succeed, sector is unlocked # if other sector is unlocked, previous sector is locked COMMAND = [0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, int(sys.argv[2])*4, 0x60, 0x00] data, sw1, sw2 = connection.transmit(COMMAND) if (sw1, sw2) == (0x90, 0x0): print "Status: Decryption sector "+ sys.argv[2] +" using key #0 as Key A successful." elif (sw1, sw2) == (0x63, 0x0): print "Status: Decryption sector "+ sys.argv[2] +" failed. Trying as Key B" COMMAND = [0xFF, 0x86, 0x00, 0x00, 0x05, 0x01, 0x00, int(sys.argv[2])*4, 0x61, 0x00] data, sw1, sw2 = connection.transmit(COMMAND) if (sw1, sw2) == (0x90, 0x0): print "Status: Decryption sector "+ sys.argv[2] +" using key #0 as Key B successful." elif (sw1, sw2) == (0x63, 0x0): print "Status: Decryption sector "+ sys.argv[2] +"



failed." sys.exit() # TODO -h -a for hex/ascii, -d -t for data/trailer, none for all, -s for certain sector print "---------------------------------Sector "+ sys.argv[2] +"---------------------------------" for block in range(int(sys.argv[2])*4, int(sys.argv[2])*4+4): COMMAND = [0xFF, 0xB0, 0x00] COMMAND.append(block) COMMAND.append(16) data, sw1, sw2 = connection.transmit(COMMAND) print "block "+ str(block) +":\t"+ toHexString(data) +" | "+''.join(chr(i) for i in data) print "Status words: %02X %02X" % (sw1, sw2) if (sw1, sw2) == (0x90, 0x0): print "Status: The operation completed successfully." elif (sw1, sw2) == (0x63, 0x0): print "Status: The operation failed. Maybe auth is needed."



else: print "error: Undefined command: "+ cmd +"\nUse \"help\" command for command list." sys.exit()







© 2021 GitHub, Inc.