]> git.zerfleddert.de Git - proxmark3-svn/commitdiff
Merge branch 'master' of https://github.com/Proxmark/proxmark3
authoriceman1001 <iceman@iuse.se>
Mon, 25 May 2015 11:13:06 +0000 (13:13 +0200)
committericeman1001 <iceman@iuse.se>
Mon, 25 May 2015 11:13:06 +0000 (13:13 +0200)
Conflicts:
armsrc/mifarecmd.c
client/cmdhfmf.c

1  2 
armsrc/mifarecmd.c
client/cmdhfmf.c

diff --combined armsrc/mifarecmd.c
index 9c17ce3cb3490b066a1f6c65d4c71d084604d256,8355cd1946172da7c7cdf272938179bc95fef66a..ff9fb16a786ca20f441bb8776309f2b398ef655e
  \r
  #include "crc.h"\r
  \r
 -// the block number for the ISO14443-4 PCB\r
 -uint8_t pcb_blocknum = 0;\r
 -// Deselect card by sending a s-block. the crc is precalced for speed\r
 -static  uint8_t deselect_cmd[] = {0xc2,0xe0,0xb4};\r
 -\r
 -\r
  //-----------------------------------------------------------------------------\r
  // Select, Authenticate, Read a MIFARE tag. \r
  // read block\r
@@@ -169,7 -175,7 +169,7 @@@ void MifareUReadBlock(uint8_t arg0, uin
                return;\r
        }\r
  \r
 -      cmd_send(CMD_ACK,1,0,0,dataout,16);\r
 +    cmd_send(CMD_ACK,1,0,0,dataout,16);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
  }\r
@@@ -209,7 -215,7 +209,7 @@@ void MifareReadSector(uint8_t arg0, uin
                isOK = 0;\r
                if (MF_DBGLEVEL >= 1)   Dbprintf("Can't select card");\r
        }\r
 -\r
 +      \r
        \r
        if(isOK && mifare_classic_auth(pcs, cuid, FirstBlockOfSector(sectorNo), keyType, ui64Key, AUTH_FIRST)) {\r
                isOK = 0;\r
        LEDsoff();\r
  }\r
  \r
 +// arg0 = blockNo (start)\r
 +// arg1 = Pages (number of blocks)\r
 +// arg2 = useKey\r
 +// datain = KEY bytes\r
  void MifareUReadCard(uint8_t arg0, uint16_t arg1, uint8_t arg2, uint8_t *datain)\r
  {\r
        // free eventually allocated BigBuf memory\r
        BigBuf_free();\r
 -      // clear trace\r
        clear_trace();\r
  \r
        // params\r
                        Dbprintf("Data exceeds buffer!!");\r
                        break;\r
                }\r
 -      \r
 -              len = mifare_ultra_readblock(blockNo + i, dataout + 4 * i);\r
  \r
 +              len = mifare_ultra_readblock(blockNo + i, dataout + 4 * i);\r
 +              \r
                if (len) {\r
                        if (MF_DBGLEVEL >= MF_DBG_ERROR) Dbprintf("Read block %d error",i);\r
                        // if no blocks read - error out\r
                        if (i==0){\r
                                OnError(2);\r
 -                              return;\r
 +                      return;\r
                        } else {\r
                                //stop at last successful read block and return what we got\r
                                break;\r
        if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Blocks read %d", countblocks);\r
  \r
        countblocks *= 4;\r
-       cmd_send(CMD_ACK, 1, countblocks, BigBuf_max_traceLen(),, 0);\r
+       cmd_send(CMD_ACK, 1, countblocks, BigBuf_max_traceLen(), 0, 0);\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 +      \r
 +      BigBuf_free();\r
  }\r
  \r
  //-----------------------------------------------------------------------------\r
@@@ -449,17 -450,9 +449,17 @@@ void MifareUWriteBlock(uint8_t arg0, ui
        LEDsoff();\r
  }\r
  \r
 -void MifareUWriteBlock_Special(uint8_t arg0, uint8_t *datain)\r
 +// Arg0   : Block to write to.\r
 +// Arg1   : 0 = use no authentication.\r
 +//          1 = use 0x1A authentication.\r
 +//          2 = use 0x1B authentication.\r
 +// datain : 4 first bytes is data to be written.\r
 +//        : 4/16 next bytes is authentication key.\r
 +void MifareUWriteBlock_Special(uint8_t arg0, uint8_t arg1, uint8_t *datain)\r
  {\r
        uint8_t blockNo = arg0;\r
 +      bool useKey = (arg1 == 1); //UL_C\r
 +      bool usePwd = (arg1 == 2); //UL_EV1/NTAG\r
        byte_t blockdata[4] = {0x00};\r
  \r
        memcpy(blockdata, datain,4);\r
                return;\r
        };\r
  \r
 +      // UL-C authentication\r
 +      if ( useKey ) {\r
 +              uint8_t key[16] = {0x00};       \r
 +              memcpy(key, datain+4, sizeof(key) );\r
 +\r
 +              if ( !mifare_ultra_auth(key) ) {\r
 +                      OnError(1);\r
 +                      return;                 \r
 +              }\r
 +      }\r
 +      \r
 +      // UL-EV1 / NTAG authentication\r
 +      if (usePwd) { \r
 +              uint8_t pwd[4] = {0x00};\r
 +              memcpy(pwd, datain+4, 4);\r
 +              uint8_t pack[4] = {0,0,0,0};\r
 +              if (!mifare_ul_ev1_auth(pwd, pack)) {\r
 +                      OnError(1);\r
 +                      return;                 \r
 +              }\r
 +      }\r
 +      \r
        if(mifare_ultra_special_writeblock(blockNo, blockdata)) {\r
                if (MF_DBGLEVEL >= 1) Dbprintf("Write block error");\r
                OnError(0);\r
@@@ -1034,12 -1005,12 +1034,12 @@@ void MifareCSetBlock(uint32_t arg0, uin
                if (workFlags & 0x01) {\r
                        if(!iso14443a_select_card(uid, NULL, &cuid)) {\r
                                if (MF_DBGLEVEL >= 1)   Dbprintf("Can't select card");\r
 -                              break;\r
 +                              //break;\r
                        };\r
  \r
                        if(mifare_classic_halt(NULL, cuid)) {\r
                                if (MF_DBGLEVEL >= 1)   Dbprintf("Halt error");\r
 -                              break;\r
 +                              //break;\r
                        };\r
                };\r
        \r
@@@ -1218,74 -1189,7 +1218,74 @@@ void MifareCIdent()
        cmd_send(CMD_ACK,isOK,0,0,0,0);\r
  }\r
  \r
 -                      //\r
 +void MifareCollectNonces(uint32_t arg0, uint32_t arg1){\r
 +\r
 +      BigBuf_free();\r
 +\r
 +      uint32_t iterations = arg0;\r
 +      uint8_t uid[10] = {0x00};\r
 +\r
 +      uint8_t *response = BigBuf_malloc(MAX_MIFARE_FRAME_SIZE);\r
 +      uint8_t *responsePar = BigBuf_malloc(MAX_MIFARE_PARITY_SIZE);\r
 +\r
 +      uint8_t mf_auth[] = { 0x60,0x00,0xf5,0x7b };\r
 +      \r
 +      // get memory from BigBuf.\r
 +      uint8_t *nonces = BigBuf_malloc(iterations * 4);\r
 +\r
 +      LED_A_ON();\r
 +      LED_B_OFF();\r
 +      LED_C_OFF();\r
 +\r
 +      clear_trace();\r
 +      set_tracing(TRUE);\r
 +      iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
 +      \r
 +      for (int i = 0; i < iterations; i++) {\r
 +                                              \r
 +              WDT_HIT();\r
 +\r
 +              // Test if the action was cancelled\r
 +              if(BUTTON_PRESS()) break;\r
 +              \r
 +              //              if(mifare_classic_halt(pcs, cuid)) {\r
 +              //                      if (MF_DBGLEVEL >= 1) Dbprintf("Halt error");\r
 +              //}\r
 +\r
 +              if(!iso14443a_select_card(uid, NULL, NULL)) {\r
 +                      if (MF_DBGLEVEL >= 1) Dbprintf("Can't select card");\r
 +                      continue;\r
 +              };\r
 +\r
 +              // Transmit MIFARE_CLASSIC_AUTH.\r
 +              ReaderTransmit(mf_auth, sizeof(mf_auth), NULL);\r
 +\r
 +              // Receive the (4 Byte) "random" nonce\r
 +              if (!ReaderReceive(response, responsePar)) {\r
 +                      if (MF_DBGLEVEL >= 1)   Dbprintf("Couldn't receive tag nonce");\r
 +                      continue;\r
 +              }       \r
 +              \r
 +              nonces[i*4] = bytes_to_num(response, 4);\r
 +      }\r
 +              \r
 +      int packLen =  iterations * 4;\r
 +      int packSize = 0;\r
 +      int packNum = 0;\r
 +      while (packLen > 0) {\r
 +              packSize = MIN(USB_CMD_DATA_SIZE, packLen);\r
 +              LED_B_ON();\r
 +              cmd_send(CMD_ACK, 77, 0, packSize, nonces - packLen, packSize);\r
 +              LED_B_OFF();\r
 +\r
 +              packLen -= packSize;\r
 +              packNum++;\r
 +      }\r
 +      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
 +      LEDsoff();\r
 +}\r
 +\r
 +//\r
  // DESFIRE\r
  //\r
  \r
@@@ -1293,7 -1197,7 +1293,7 @@@ void Mifare_DES_Auth1(uint8_t arg0, uin
  \r
        byte_t dataout[11] = {0x00};\r
        uint8_t uid[10] = {0x00};\r
 -      uint32_t cuid;\r
 +      uint32_t cuid = 0x00;\r
      \r
        clear_trace();\r
        iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);\r
@@@ -1319,22 -1223,39 +1319,22 @@@ void Mifare_DES_Auth2(uint32_t arg0, ui
  \r
        uint32_t cuid = arg0;\r
        uint8_t key[16] = {0x00};\r
 -      byte_t isOK = 0;\r
        byte_t dataout[12] = {0x00};\r
 +      byte_t isOK = 0;\r
      \r
        memcpy(key, datain, 16);\r
        \r
        isOK = mifare_desfire_des_auth2(cuid, key, dataout);\r
        \r
        if( isOK) {\r
 -          if (MF_DBGLEVEL >= MF_DBG_EXTENDED) \r
 -                      Dbprintf("Authentication part2: Failed");  \r
 -              //OnError(4);\r
 +          if (MF_DBGLEVEL >= MF_DBG_EXTENDED) Dbprintf("Authentication part2: Failed");  \r
 +              OnError(4);\r
                return;\r
        }\r
  \r
 -      if (MF_DBGLEVEL >= MF_DBG_EXTENDED) \r
 -              DbpString("AUTH 2 FINISHED");\r
 +      if (MF_DBGLEVEL >= MF_DBG_EXTENDED) DbpString("AUTH 2 FINISHED");\r
  \r
        cmd_send(CMD_ACK, isOK, 0, 0, dataout, sizeof(dataout));\r
        FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
        LEDsoff();\r
 -}\r
 -\r
 -void OnSuccess(){\r
 -      pcb_blocknum = 0;\r
 -      ReaderTransmit(deselect_cmd, 3 , NULL);\r
 -      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
 -      LEDsoff();\r
 -}\r
 -\r
 -void OnError(uint8_t reason){\r
 -      pcb_blocknum = 0;\r
 -      ReaderTransmit(deselect_cmd, 3 , NULL);\r
 -      FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);\r
 -      cmd_send(CMD_ACK,0,reason,0,0,0);\r
 -      LEDsoff();\r
 -}\r
 +}
diff --combined client/cmdhfmf.c
index 94c4707206273e9fd8c25997a023db18560a944b,2b5a5b87965dd7b36e283e9f94fe876f2e740dc7..eb2479ff26308f61f5f5842b3c109b447a4747fa
@@@ -9,7 -9,6 +9,7 @@@
  //-----------------------------------------------------------------------------\r
  \r
  #include "cmdhfmf.h"\r
 +#include "nonce2key/nonce2key.h"\r
  \r
  static int CmdHelp(const char *Cmd);\r
  \r
@@@ -782,8 -781,8 +782,8 @@@ int CmdHF14AMfChk(const char *Cmd
                PrintAndLog("Usage:  hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t|d] [<key (12 hex symbols)>] [<dic (*.dic)>]");\r
                PrintAndLog("          * - all sectors");\r
                PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");\r
 -              PrintAndLog("d - write keys to binary file\n");\r
 -              PrintAndLog("t - write keys to emulator memory");\r
 +              PrintAndLog("d - write keys to binary file");\r
 +              PrintAndLog("t - write keys to emulator memory\n");\r
                PrintAndLog("      sample: hf mf chk 0 A 1234567890ab keys.dic");\r
                PrintAndLog("              hf mf chk *1 ? t");\r
                PrintAndLog("              hf mf chk *1 ? d");\r
@@@ -1064,29 -1063,15 +1064,29 @@@ int CmdHF14AMf1kSim(const char *Cmd
        SendCommand(&c);\r
  \r
        if(flags & FLAG_INTERACTIVE)\r
 -      {\r
 -              UsbCommand resp;\r
 +      {               \r
 +              uint64_t corr_uid =  bytes_to_num(uid,  ( flags & FLAG_4B_UID_IN_DATA ) ? 4 : 7 );\r
 +\r
                PrintAndLog("Press pm3-button to abort simulation");\r
 -              while(! WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
 -                      //We're waiting only 1.5 s at a time, otherwise we get the\r
 -                      // annoying message about "Waiting for a response... "\r
 +              \r
 +              uint8_t data[40];\r
 +              uint8_t key[6];\r
 +\r
 +              while(!ukbhit()){\r
 +                      UsbCommand resp;                \r
 +                      WaitForResponseTimeout(CMD_ACK,&resp,1500);\r
 +                      PrintAndLog("CMD_SIMULATE_MIFARE_CARD [%04X] -- %04X", CMD_SIMULATE_MIFARE_CARD, resp.arg[0]);                  \r
 +                      if ( (resp.arg[0] & 0xffff) == CMD_SIMULATE_MIFARE_CARD ){\r
 +                              memset(data, 0x00, sizeof(data));\r
 +                              memset(key, 0x00, sizeof(key));\r
 +                              int len = (resp.arg[1] > sizeof(data)) ? sizeof(data) : resp.arg[1];\r
 +                              memcpy(data, resp.d.asBytes, len);\r
 +                              tryMfk32(corr_uid, data, key);\r
 +                              //tryMfk64(corr_uid, data, key);\r
 +                              PrintAndLog("--");\r
 +                      }\r
                }\r
        }\r
 -      \r
        return 0;\r
  }\r
  \r
@@@ -1321,13 -1306,13 +1321,14 @@@ int CmdHF14AMfESave(const char *Cmd
                // get filename (UID from memory)\r
                if (mfEmlGetMem(buf, 0, 1)) {\r
                        PrintAndLog("Can\'t get UID from block: %d", 0);\r
-                       len = sprintf(fnameptr, "dump"); \r
+                       len = sprintf(fnameptr, "dump");\r
                        fnameptr += len;\r
                }\r
                else {\r
                        for (j = 0; j < 7; j++, fnameptr += 2)\r
-                               sprintf(fnameptr, "%02X", buf[j]); \r
+                               sprintf(fnameptr, "%02X", buf[j]);\r
+               }\r
 +              }\r
        } else {\r
                fnameptr += len;\r
        }\r
@@@ -1612,7 -1597,6 +1613,7 @@@ int CmdHF14AMfCLoad(const char *Cmd
                        if (fgets(buf, sizeof(buf), f) == NULL) {\r
                                fclose(f);\r
                                PrintAndLog("File reading error.");\r
 +                              fclose(f);\r
                                return 2;\r
                        }\r
  \r
@@@ -1766,12 -1750,10 +1767,12 @@@ int CmdHF14AMfCSave(const char *Cmd) 
                        // get filename\r
                        if (mfCGetBlock(0, buf, CSETBLOCK_SINGLE_OPER)) {\r
                                PrintAndLog("Cant get block: %d", 0);\r
 -                              return 1;\r
 +                              len = sprintf(fnameptr, "dump");\r
 +                              fnameptr += len;\r
 +                      } else {\r
 +                              for (j = 0; j < 7; j++, fnameptr += 2)\r
 +                                      sprintf(fnameptr, "%02x", buf[j]); \r
                        }\r
 -                      for (j = 0; j < 7; j++, fnameptr += 2)\r
 -                              sprintf(fnameptr, "%02x", buf[j]); \r
                } else {\r
                        memcpy(filename, Cmd, len);\r
                        fnameptr += len;\r
Impressum, Datenschutz