mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-07-12 08:16:09 -07:00
mf 1k sim reader attack cleanup
add abort options - keyboard & button press.
This commit is contained in:
parent
bbd118760b
commit
73ab92d14c
2 changed files with 37 additions and 31 deletions
|
@ -2504,7 +2504,8 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
|
||||||
set_tracing(TRUE);
|
set_tracing(TRUE);
|
||||||
|
|
||||||
bool finished = FALSE;
|
bool finished = FALSE;
|
||||||
while (!BUTTON_PRESS() && !finished && !usb_poll_validate_length()) {
|
bool button_pushed = BUTTON_PRESS();
|
||||||
|
while (!button_pushed && !finished && !usb_poll_validate_length()) {
|
||||||
WDT_HIT();
|
WDT_HIT();
|
||||||
|
|
||||||
// find reader field
|
// find reader field
|
||||||
|
@ -2956,6 +2957,7 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
button_pushed = BUTTON_PRESS();
|
||||||
}
|
}
|
||||||
|
|
||||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||||
|
@ -2996,7 +2998,7 @@ void Mifare1ksim(uint8_t flags, uint8_t exitAfterNReads, uint8_t arg2, uint8_t *
|
||||||
if(flags & FLAG_INTERACTIVE)// Interactive mode flag, means we need to send ACK
|
if(flags & FLAG_INTERACTIVE)// Interactive mode flag, means we need to send ACK
|
||||||
{
|
{
|
||||||
//Send the collected ar_nr in the response
|
//Send the collected ar_nr in the response
|
||||||
cmd_send(CMD_ACK,CMD_SIMULATE_MIFARE_CARD,0,0,&ar_nr_resp,sizeof(ar_nr_resp));
|
cmd_send(CMD_ACK,CMD_SIMULATE_MIFARE_CARD,button_pushed,0,&ar_nr_resp,sizeof(ar_nr_resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1100,7 +1100,7 @@ int usage_hf14_mf1ksim(void) {
|
||||||
PrintAndLog(" i (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");
|
PrintAndLog(" i (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");
|
||||||
PrintAndLog(" x (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");
|
PrintAndLog(" x (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");
|
||||||
PrintAndLog(" e (Optional) set keys found from 'reader attack' to emulator memory");
|
PrintAndLog(" e (Optional) set keys found from 'reader attack' to emulator memory");
|
||||||
PrintAndLog(" f (Optional) get UIDs to use for 'reader attack' from file 'f <filename.txt>'");
|
PrintAndLog(" f (Optional) get UIDs to use for 'reader attack' from file 'f <filename.txt>' (implies x and i)");
|
||||||
PrintAndLog("samples:");
|
PrintAndLog("samples:");
|
||||||
PrintAndLog(" hf mf sim u 0a0a0a0a");
|
PrintAndLog(" hf mf sim u 0a0a0a0a");
|
||||||
PrintAndLog(" hf mf sim u 11223344556677");
|
PrintAndLog(" hf mf sim u 11223344556677");
|
||||||
|
@ -1109,6 +1109,7 @@ int usage_hf14_mf1ksim(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int CmdHF14AMf1kSim(const char *Cmd) {
|
int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
|
UsbCommand resp;
|
||||||
uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
uint8_t exitAfterNReads = 0;
|
uint8_t exitAfterNReads = 0;
|
||||||
uint8_t flags = 0;
|
uint8_t flags = 0;
|
||||||
|
@ -1182,11 +1183,8 @@ int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
//Validations
|
//Validations
|
||||||
if(errors) return usage_hf14_mf1ksim();
|
if(errors) return usage_hf14_mf1ksim();
|
||||||
|
|
||||||
// attack from file implies nr ar attack...
|
// attack from file implies nr ar attack and interactive...
|
||||||
if (!(flags & FLAG_NR_AR_ATTACK) && attackFromFile) flags |= FLAG_NR_AR_ATTACK;
|
if (!(flags & FLAG_NR_AR_ATTACK) && attackFromFile) flags |= FLAG_NR_AR_ATTACK | FLAG_INTERACTIVE;
|
||||||
|
|
||||||
UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads,0}};
|
|
||||||
UsbCommand resp;
|
|
||||||
|
|
||||||
//get uid from file
|
//get uid from file
|
||||||
if (attackFromFile) {
|
if (attackFromFile) {
|
||||||
|
@ -1197,7 +1195,8 @@ int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
PrintAndLog("File %s not found or locked", filename);
|
PrintAndLog("File %s not found or locked", filename);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
while(!feof(f)){
|
PrintAndLog("Loading file and simulating. Press keyboard to abort");
|
||||||
|
while(!feof(f) && !ukbhit()){
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
memset(uidBuffer, 0, sizeof(uidBuffer));
|
memset(uidBuffer, 0, sizeof(uidBuffer));
|
||||||
|
|
||||||
|
@ -1208,43 +1207,47 @@ int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
if(strlen(buf) && feof(f)) break;
|
||||||
|
|
||||||
if (strlen(buf) < uidlen) {
|
uidlen = strlen(buf);
|
||||||
if(strlen(buf) && feof(f))
|
switch(uidlen) {
|
||||||
break;
|
case 20: flags = FLAG_10B_UID_IN_DATA; break; //not complete
|
||||||
PrintAndLog("File content error. Block data must include %d HEX symbols", uidlen);
|
case 14: flags = FLAG_7B_UID_IN_DATA; break;
|
||||||
fclose(f);
|
case 8: flags = FLAG_4B_UID_IN_DATA; break;
|
||||||
return 2;
|
default:
|
||||||
|
PrintAndLog("uid in file wrong length at %d",count);
|
||||||
|
fclose(f);
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < uidlen; i += 2) {
|
for (uint8_t i = 0; i < uidlen; i += 2) {
|
||||||
sscanf(&buf[i], "%02x", (unsigned int *)&uidBuffer[i / 2]);
|
sscanf(&buf[i], "%02x", (unsigned int *)&uidBuffer[i / 2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLog("mf 1k sim uid: %s, numreads:%d, flags:%d (0x%02x) ",
|
PrintAndLog("mf 1k sim uid: %s, numreads:%d, flags:%d (0x%02x) - press button to abort",
|
||||||
flags & FLAG_4B_UID_IN_DATA ? sprint_hex(uid,4):
|
flags & FLAG_4B_UID_IN_DATA ? sprint_hex(uid,4):
|
||||||
flags & FLAG_7B_UID_IN_DATA ? sprint_hex(uid,7):
|
flags & FLAG_7B_UID_IN_DATA ? sprint_hex(uid,7):
|
||||||
flags & FLAG_10B_UID_IN_DATA ? sprint_hex(uid,10): "N/A"
|
flags & FLAG_10B_UID_IN_DATA ? sprint_hex(uid,10): "N/A"
|
||||||
, exitAfterNReads, flags, flags);
|
, exitAfterNReads, flags, flags);
|
||||||
|
|
||||||
|
UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads,0}};
|
||||||
memcpy(c.d.asBytes, uid, sizeof(uid));
|
memcpy(c.d.asBytes, uid, sizeof(uid));
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
||||||
if(flags & FLAG_INTERACTIVE) {
|
while(! WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
||||||
PrintAndLog("Press pm3-button to abort simulation");
|
//We're waiting only 1.5 s at a time, otherwise we get the
|
||||||
while(! WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
|
// annoying message about "Waiting for a response... "
|
||||||
//We're waiting only 1.5 s at a time, otherwise we get the
|
}
|
||||||
// annoying message about "Waiting for a response... "
|
//got a response
|
||||||
}
|
nonces_t ar_resp[ATTACK_KEY_COUNT*2];
|
||||||
//got a response
|
memcpy(ar_resp, resp.d.asBytes, sizeof(ar_resp));
|
||||||
if (flags & FLAG_NR_AR_ATTACK) {
|
readerAttack(ar_resp, setEmulatorMem);
|
||||||
nonces_t ar_resp[ATTACK_KEY_COUNT*2];
|
if (resp.arg[1]) {
|
||||||
memcpy(ar_resp, resp.d.asBytes, sizeof(ar_resp));
|
PrintAndLog("Device button pressed - quitting");
|
||||||
readerAttack(ar_resp, setEmulatorMem);
|
fclose(f);
|
||||||
}
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
@ -1256,6 +1259,7 @@ int CmdHF14AMf1kSim(const char *Cmd) {
|
||||||
flags & FLAG_10B_UID_IN_DATA ? sprint_hex(uid,10): "N/A"
|
flags & FLAG_10B_UID_IN_DATA ? sprint_hex(uid,10): "N/A"
|
||||||
, exitAfterNReads, flags, flags);
|
, exitAfterNReads, flags, flags);
|
||||||
|
|
||||||
|
UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads,0}};
|
||||||
memcpy(c.d.asBytes, uid, sizeof(uid));
|
memcpy(c.d.asBytes, uid, sizeof(uid));
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommand(&c);
|
SendCommand(&c);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue