]> cvs.zerfleddert.de Git - proxmark3-svn/blobdiff - armsrc/iso14443a.c
Check keys in hf mf nested and hf mf chk (#414)
[proxmark3-svn] / armsrc / iso14443a.c
index b18a2fe60265c0ef5a4750a2c873c0bb8d7f3002..e9ad25355b4c498c46c2f5f8fe6c1a534df2e66b 100644 (file)
@@ -1733,7 +1733,8 @@ int ReaderReceive(uint8_t *receivedAnswer, uint8_t *parity)
 // fills the card info record unless NULL
 // if anticollision is false, then the UID must be provided in uid_ptr[] 
 // and num_cascades must be set (1: 4 Byte UID, 2: 7 Byte UID, 3: 10 Byte UID)
-int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_hi14a_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades) {
+// requests ATS unless no_rats is true
+int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_hi14a_card, uint32_t *cuid_ptr, bool anticollision, uint8_t num_cascades, bool no_rats) {
        uint8_t wupa[]       = { 0x52 };  // 0x26 - REQA  0x52 - WAKE-UP
        uint8_t sel_all[]    = { 0x93,0x20 };
        uint8_t sel_uid[]    = { 0x93,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
@@ -1868,24 +1869,24 @@ int iso14443a_select_card(byte_t *uid_ptr, iso14a_card_select_t *p_hi14a_card, u
        // non iso14443a compliant tag
        if( (sak & 0x20) == 0) return 2; 
 
-       // Request for answer to select
-       AppendCrc14443a(rats, 2);
-       ReaderTransmit(rats, sizeof(rats), NULL);
+       if (!no_rats) {
+               // Request for answer to select
+               AppendCrc14443a(rats, 2);
+               ReaderTransmit(rats, sizeof(rats), NULL);
 
-       if (!(len = ReaderReceive(resp, resp_par))) return 0;
+               if (!(len = ReaderReceive(resp, resp_par))) return 0;
 
-       
-       if(p_hi14a_card) {
-               memcpy(p_hi14a_card->ats, resp, sizeof(p_hi14a_card->ats));
-               p_hi14a_card->ats_len = len;
-       }
-
-       // reset the PCB block number
-       iso14_pcb_blocknum = 0;
+               if(p_hi14a_card) {
+                       memcpy(p_hi14a_card->ats, resp, len);
+                       p_hi14a_card->ats_len = len;
+               }
 
-       // set default timeout based on ATS
-       iso14a_set_ATS_timeout(resp);
+               // reset the PCB block number
+               iso14_pcb_blocknum = 0;
 
+               // set default timeout based on ATS
+               iso14a_set_ATS_timeout(resp);
+       }
        return 1;       
 }
 
@@ -1971,7 +1972,7 @@ void ReaderIso14443a(UsbCommand *c)
                iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
                if(!(param & ISO14A_NO_SELECT)) {
                        iso14a_card_select_t *card = (iso14a_card_select_t*)buf;
-                       arg0 = iso14443a_select_card(NULL, card, NULL, true, 0);
+                       arg0 = iso14443a_select_card(NULL, card, NULL, true, 0, param & ISO14A_NO_RATS);
                        cmd_send(CMD_ACK,arg0,card->uidlen,0,buf,sizeof(iso14a_card_select_t));
                }
        }
@@ -2168,7 +2169,7 @@ void ReaderMifare(bool first_try)
                        SpinDelay(100);
                }
                
-               if(!iso14443a_select_card(uid, NULL, &cuid, true, 0)) {
+               if(!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) {
                        if (MF_DBGLEVEL >= 1)   Dbprintf("Mifare: Can't select card");
                        continue;
                }
@@ -2352,18 +2353,6 @@ void ReaderMifare(bool first_try)
        set_tracing(false);
 }
 
-typedef struct {
-  uint32_t cuid;
-  uint8_t  sector;
-  uint8_t  keytype;
-  uint32_t nonce;
-  uint32_t ar;
-  uint32_t nr;
-  uint32_t nonce2;
-  uint32_t ar2;
-  uint32_t nr2;
-} nonces_t;
-
 /**
   *MIFARE 1K simulate.
   *
@@ -2418,8 +2407,8 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
        //Here, we collect UID,sector,keytype,NT,AR,NR,NT2,AR2,NR2
        // This will be used in the reader-only attack.
 
-       //allow collecting up to 8 sets of nonces to allow recovery of up to 8 keys
-       #define ATTACK_KEY_COUNT 8 // keep same as define in cmdhfmf.c -> readerAttack()
+       //allow collecting up to 7 sets of nonces to allow recovery of up to 7 keys
+       #define ATTACK_KEY_COUNT 7 // keep same as define in cmdhfmf.c -> readerAttack() (Cannot be more than 7)
        nonces_t ar_nr_resp[ATTACK_KEY_COUNT*2]; //*2 for 2 separate attack types (nml, moebius)
        memset(ar_nr_resp, 0x00, sizeof(ar_nr_resp));
 
@@ -2562,7 +2551,10 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
                                LED_A_ON();
                        }
                }
-               if (cardSTATE == MFEMUL_NOFIELD) continue;
+               if (cardSTATE == MFEMUL_NOFIELD) {
+                       button_pushed = BUTTON_PRESS();
+                       continue;
+               }
 
                //Now, get data
                res = EmGetCmd(receivedCmd, &len, receivedCmd_par);
Impressum, Datenschutz