mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-22 22:23:38 -07:00
added sketch for command CMD_MIFARE_CWIPE
This commit is contained in:
parent
0957f6690f
commit
f1158df995
6 changed files with 91 additions and 7 deletions
|
@ -1199,6 +1199,9 @@ void UsbPacketReceived(uint8_t *packet, int len)
|
|||
break;
|
||||
|
||||
// Work with "magic Chinese" card
|
||||
case CMD_MIFARE_CWIPE:
|
||||
MifareCWipe(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
||||
break;
|
||||
case CMD_MIFARE_CSETBLOCK:
|
||||
MifareCSetBlock(c->arg[0], c->arg[1], c->arg[2], c->d.asBytes);
|
||||
break;
|
||||
|
|
|
@ -134,7 +134,8 @@ void MifareEMemClr(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain)
|
|||
void MifareEMemSet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void MifareEMemGet(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); // Work with "magic Chinese" card
|
||||
void MifareCWipe(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain); // Work with "magic Chinese" card
|
||||
void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void MifareCGetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void MifareCIdent(); // is "magic chinese" card?
|
||||
void MifareUSetPwd(uint8_t arg0, uint8_t *datain);
|
||||
|
|
|
@ -1170,6 +1170,72 @@ void MifareECardLoad(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
|
|||
// Work with "magic Chinese" card (email him: ouyangweidaxian@live.cn)
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void MifareCWipe(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
|
||||
// var
|
||||
byte_t isOK = 0;
|
||||
uint8_t numSectors = arg0;
|
||||
uint8_t needWipe = arg1;
|
||||
uint8_t needPut = arg2;
|
||||
|
||||
uint8_t receivedAnswer[MAX_MIFARE_FRAME_SIZE];
|
||||
uint8_t receivedAnswerPar[MAX_MIFARE_PARITY_SIZE];
|
||||
|
||||
// card commands
|
||||
uint8_t wupC1[] = { 0x40 };
|
||||
uint8_t wipeC[] = { 0x41 };
|
||||
|
||||
// iso14443 setup
|
||||
LED_A_ON();
|
||||
LED_B_OFF();
|
||||
LED_C_OFF();
|
||||
iso14443a_setup(FPGA_HF_ISO14443A_READER_LISTEN);
|
||||
|
||||
// tracing
|
||||
clear_trace();
|
||||
set_tracing(true);
|
||||
|
||||
while (true){
|
||||
// wipe
|
||||
if (needWipe){
|
||||
ReaderTransmitBitsPar(wupC1,7,0, NULL);
|
||||
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||
if (MF_DBGLEVEL >= 1) Dbprintf("wupC1 error");
|
||||
break;
|
||||
};
|
||||
|
||||
ReaderTransmit(wipeC, sizeof(wipeC), NULL);
|
||||
if(!ReaderReceive(receivedAnswer, receivedAnswerPar) || (receivedAnswer[0] != 0x0a)) {
|
||||
if (MF_DBGLEVEL >= 1) Dbprintf("wipeC error");
|
||||
break;
|
||||
};
|
||||
|
||||
if(mifare_classic_halt(NULL, 0)) {
|
||||
if (MF_DBGLEVEL > 2) Dbprintf("Halt error");
|
||||
};
|
||||
};
|
||||
|
||||
// put default data
|
||||
if (needPut){
|
||||
for (int i = 0; i < numSectors; i++) {
|
||||
// MifareCSetBlock here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// send response
|
||||
LED_B_ON();
|
||||
cmd_send(CMD_ACK,isOK,0,0,NULL,0);
|
||||
LED_B_OFF();
|
||||
|
||||
// reset fpga
|
||||
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);
|
||||
LEDsoff();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain){
|
||||
|
||||
// params
|
||||
|
@ -1240,7 +1306,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
|
|||
break;
|
||||
};
|
||||
|
||||
if(mifare_classic_halt(NULL, cuid)) {
|
||||
if(mifare_classic_halt(NULL, 0)) {
|
||||
if (MF_DBGLEVEL > 2) Dbprintf("Halt error");
|
||||
// Continue, some magic tags misbehavies and send an answer to it.
|
||||
// break;
|
||||
|
@ -1284,7 +1350,7 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datai
|
|||
if (workFlags & 0x04) {
|
||||
// do no issue halt command for gen1b magic tag (#db# halt error. response len: 1)
|
||||
if (!(workFlags & 0x40)) {
|
||||
if (mifare_classic_halt(NULL, cuid)) {
|
||||
if (mifare_classic_halt(NULL, 0)) {
|
||||
if (MF_DBGLEVEL > 2) Dbprintf("Halt error");
|
||||
// Continue, some magic tags misbehavies and send an answer to it.
|
||||
// break;
|
||||
|
|
|
@ -1887,15 +1887,18 @@ int CmdHF14AMfCWipe(const char *Cmd)
|
|||
bool setCard = false;
|
||||
|
||||
if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {
|
||||
PrintAndLog("Usage: hf mf cwipe <card size> [w]");
|
||||
PrintAndLog("Usage: hf mf cwipe [card size] [w] [p]");
|
||||
PrintAndLog("sample: hf mf cwipe 1 w s");
|
||||
PrintAndLog("w - Wipe for magic Chinese card (only works with such cards)");
|
||||
PrintAndLog("[card size]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
|
||||
PrintAndLog("w - Wipe magic Chinese card (only works with gen:1a cards)");
|
||||
PrintAndLog("p - Put default data to the card ");
|
||||
return 0;
|
||||
}
|
||||
|
||||
gen = mfCIdentify();
|
||||
|
||||
// here check 1a 1b
|
||||
|
||||
char cardSize = param_getchar(Cmd, 1);
|
||||
numSectors = ParamGetCardSize(cardSize);
|
||||
|
||||
|
@ -1906,10 +1909,13 @@ int CmdHF14AMfCWipe(const char *Cmd)
|
|||
|
||||
if (gen == 2) {
|
||||
/* generation 1b magic card */
|
||||
res = mfCWipe(numSectors, wipeCard, setCard); // wipeCard, CSETBLOCK_SINGLE_OPER | CSETBLOCK_MAGIC_1B
|
||||
if (wipeCard) {
|
||||
PrintAndLog("WARNING: can't wipe magic card 1b generation");
|
||||
}
|
||||
res = mfCWipe(numSectors, false, setCard);
|
||||
} else {
|
||||
/* generation 1a magic card by default */
|
||||
res = mfCWipe(numSectors, wipeCard, setCard); // wipeCard, CSETBLOCK_SINGLE_OPER
|
||||
res = mfCWipe(numSectors, wipeCard, setCard);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
|
@ -2467,6 +2473,7 @@ static command_t CommandTable[] =
|
|||
{"esave", CmdHF14AMfESave, 0, "Save to file emul dump"},
|
||||
{"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},
|
||||
{"ekeyprn", CmdHF14AMfEKeyPrn, 0, "Print keys from simulator memory"},
|
||||
{"cwipe", CmdHF14AMfCWipe, 0, "Wipe magic Chinese card"},
|
||||
{"csetuid", CmdHF14AMfCSetUID, 0, "Set UID for magic Chinese card"},
|
||||
{"csetblk", CmdHF14AMfCSetBlk, 0, "Write block - Magic Chinese card"},
|
||||
{"cgetblk", CmdHF14AMfCGetBlk, 0, "Read block - Magic Chinese card"},
|
||||
|
|
|
@ -453,6 +453,12 @@ int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uin
|
|||
}
|
||||
|
||||
int mfCWipe(uint8_t numSectors, bool wantWipe, bool wantSet) {
|
||||
UsbCommand c = {CMD_MIFARE_CWIPE, {ISO14A_CONNECT | ISO14A_NO_DISCONNECT, 0, 0}};
|
||||
SendCommand(&c);
|
||||
|
||||
UsbCommand resp;
|
||||
WaitForResponse(CMD_ACK,&resp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,7 @@ typedef struct{
|
|||
#define CMD_MIFARE_CSETBLOCK 0x0605
|
||||
#define CMD_MIFARE_CGETBLOCK 0x0606
|
||||
#define CMD_MIFARE_CIDENT 0x0607
|
||||
#define CMD_MIFARE_CWIPE 0x0608
|
||||
|
||||
#define CMD_SIMULATE_MIFARE_CARD 0x0610
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue