This commit is contained in:
iceman1001 2022-06-12 11:51:50 +02:00
commit 372ab2af98
9 changed files with 53 additions and 58 deletions

View file

@ -1196,7 +1196,7 @@ void MifareNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8
set_tracing(false); set_tracing(false);
} }
static void MifareFastStaticNestedImpl(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8_t targetKeyType, uint8_t* key, uint32_t* nt1, uint32_t* nt2, uint32_t* cuid, bool firstGet, int16_t* isOK) { static void MifareFastStaticNestedImpl(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8_t targetKeyType, uint8_t *key, uint32_t *nt1, uint32_t *nt2, uint32_t *cuid, bool firstGet, int16_t *isOK) {
uint64_t ui64Key = 0; uint64_t ui64Key = 0;
ui64Key = bytes_to_num(key, 6); ui64Key = bytes_to_num(key, 6);
@ -1206,7 +1206,7 @@ static void MifareFastStaticNestedImpl(uint8_t blockNo, uint8_t keyType, uint8_t
uint8_t receivedAnswer[10] = { 0x00 }; uint8_t receivedAnswer[10] = { 0x00 };
struct Crypto1State mpcs = { 0, 0 }; struct Crypto1State mpcs = { 0, 0 };
struct Crypto1State* pcs; struct Crypto1State *pcs;
pcs = &mpcs; pcs = &mpcs;
*isOK = 0; *isOK = 0;
@ -1261,7 +1261,7 @@ static void MifareFastStaticNestedImpl(uint8_t blockNo, uint8_t keyType, uint8_t
crypto1_deinit(pcs); crypto1_deinit(pcs);
} }
void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8_t targetKeyType, uint8_t* key) { void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo, uint8_t targetKeyType, uint8_t *key) {
int16_t isOK; int16_t isOK;
uint32_t cuid; uint32_t cuid;
@ -1307,7 +1307,7 @@ void MifareStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t targetBlockNo,
memcpy(payload.nt2_2, &nt2_2, 4); memcpy(payload.nt2_2, &nt2_2, 4);
LED_B_ON(); LED_B_ON();
reply_ng(CMD_HF_MIFARE_STATIC_NESTED, PM3_SUCCESS, (uint8_t*)&payload, sizeof(payload)); reply_ng(CMD_HF_MIFARE_STATIC_NESTED, PM3_SUCCESS, (uint8_t *)&payload, sizeof(payload));
LED_B_OFF(); LED_B_OFF();
FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF); FpgaWriteConfWord(FPGA_MAJOR_MODE_OFF);

View file

@ -480,7 +480,7 @@ static int CmdDbg(const char *Cmd) {
} }
uint8_t curr = resp.data.asBytes[0]; uint8_t curr = resp.data.asBytes[0];
const char* dbglvlstr; const char *dbglvlstr;
switch (curr) { switch (curr) {
case DBG_NONE: case DBG_NONE:
dbglvlstr = "none"; dbglvlstr = "none";

View file

@ -1993,7 +1993,7 @@ int CmdEM4x05Sniff(const char *Cmd) {
bool fwd = arg_get_lit(ctx, 2); bool fwd = arg_get_lit(ctx, 2);
CLIParserFree(ctx); CLIParserFree(ctx);
const char* cmdText; const char *cmdText;
char dataText[100]; char dataText[100];
char blkAddr[4]; char blkAddr[4];
char bits[80]; char bits[80];

View file

@ -50,7 +50,7 @@ static void print_result(const em4x50_word_t *words, int fwr, int lwr) {
for (int i = fwr; i <= lwr; i++) { for (int i = fwr; i <= lwr; i++) {
const char* s; const char *s;
switch (i) { switch (i) {
case EM4X50_DEVICE_PASSWORD: case EM4X50_DEVICE_PASSWORD:
s = _YELLOW_("password, write only"); s = _YELLOW_("password, write only");

View file

@ -581,11 +581,11 @@ out:
} }
int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t* resultKey) { int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo, uint8_t trgKeyType, uint8_t *resultKey) {
uint32_t uid; uint32_t uid;
StateList_t statelists[2]; StateList_t statelists[2];
struct Crypto1State* p1, * p2, * p3, * p4; struct Crypto1State *p1, * p2, * p3, * p4;
struct { struct {
uint8_t block; uint8_t block;
@ -602,7 +602,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
PacketResponseNG resp; PacketResponseNG resp;
clearCommandBuffer(); clearCommandBuffer();
SendCommandNG(CMD_HF_MIFARE_STATIC_NESTED, (uint8_t*)&payload, sizeof(payload)); SendCommandNG(CMD_HF_MIFARE_STATIC_NESTED, (uint8_t *)&payload, sizeof(payload));
if (!WaitForResponseTimeout(CMD_HF_MIFARE_STATIC_NESTED, &resp, 2000)) if (!WaitForResponseTimeout(CMD_HF_MIFARE_STATIC_NESTED, &resp, 2000))
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
@ -621,7 +621,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
uint8_t nt1_2[4]; uint8_t nt1_2[4];
uint8_t nt2_2[4]; uint8_t nt2_2[4];
} PACKED; } PACKED;
struct p* package = (struct p*)resp.data.asBytes; struct p *package = (struct p *)resp.data.asBytes;
// error during collecting static nested information // error during collecting static nested information
if (package->isOK == 0) return PM3_EUNDEF; if (package->isOK == 0) return PM3_EUNDEF;
@ -651,8 +651,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
dist = 161; dist = 161;
} }
} }
} } else {
else {
level = 0; level = 0;
} }
@ -677,7 +676,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
pthread_create(&t, NULL, nested_worker_thread, &statelists[0]); pthread_create(&t, NULL, nested_worker_thread, &statelists[0]);
// wait for thread to terminate: // wait for thread to terminate:
pthread_join(t, (void*)&statelists[0].head.slhead); pthread_join(t, (void *)&statelists[0].head.slhead);
// the first 16 Bits of the cryptostate already contain part of our key. // the first 16 Bits of the cryptostate already contain part of our key.
p1 = p3 = statelists[0].head.slhead; p1 = p3 = statelists[0].head.slhead;
@ -698,8 +697,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
p3->even = -1; p3->even = -1;
statelists[0].len = p3 - statelists[0].head.slhead; statelists[0].len = p3 - statelists[0].head.slhead;
statelists[0].tail.sltail = --p3; statelists[0].tail.sltail = --p3;
} } else { // fast decrypt static nested
else { // fast decrypt static nested
PrintAndLogEx(SUCCESS, "Fast staticnested decrypt running..."); PrintAndLogEx(SUCCESS, "Fast staticnested decrypt running...");
@ -729,7 +727,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
// wait for threads to terminate: // wait for threads to terminate:
for (uint8_t i = 0; i < 2; i++) for (uint8_t i = 0; i < 2; i++)
pthread_join(thread_id[i], (void*)&statelists[i].head.slhead); pthread_join(thread_id[i], (void *)&statelists[i].head.slhead);
// the first 16 Bits of the cryptostate already contain part of our key. // the first 16 Bits of the cryptostate already contain part of our key.
// Create the intersection of the two lists based on these 16 Bits and // Create the intersection of the two lists based on these 16 Bits and
@ -755,8 +753,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
p4++; p4++;
p2++; p2++;
} }
} } else {
else {
while (Compare16Bits(p1, p2) == -1) p1++; while (Compare16Bits(p1, p2) == -1) p1++;
while (Compare16Bits(p1, p2) == 1) p2++; while (Compare16Bits(p1, p2) == 1) p2++;
} }
@ -791,7 +788,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
uint32_t maxkeysinblock = IfPm3Flash() ? 1000 : KEYS_IN_BLOCK; uint32_t maxkeysinblock = IfPm3Flash() ? 1000 : KEYS_IN_BLOCK;
uint32_t max_keys_chunk = keycnt > maxkeysinblock ? maxkeysinblock : keycnt; uint32_t max_keys_chunk = keycnt > maxkeysinblock ? maxkeysinblock : keycnt;
uint8_t* mem = calloc((maxkeysinblock * 6) + 5, sizeof(uint8_t)); uint8_t *mem = calloc((maxkeysinblock * 6) + 5, sizeof(uint8_t));
if (mem == NULL) { if (mem == NULL) {
free(statelists[0].head.slhead); free(statelists[0].head.slhead);
return PM3_EMALLOC; return PM3_EMALLOC;
@ -803,10 +800,10 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
mem[3] = ((max_keys_chunk >> 8) & 0xFF); mem[3] = ((max_keys_chunk >> 8) & 0xFF);
mem[4] = (max_keys_chunk & 0xFF); mem[4] = (max_keys_chunk & 0xFF);
uint8_t* p_keyblock = mem + 5; uint8_t *p_keyblock = mem + 5;
uint8_t destfn[32]; uint8_t destfn[32];
strncpy((char*)destfn, "static_nested_000.bin", sizeof(destfn) - 1); strncpy((char *)destfn, "static_nested_000.bin", sizeof(destfn) - 1);
uint64_t start_time = msclock(); uint64_t start_time = msclock();
for (uint32_t i = 0; i < keycnt; i += max_keys_chunk) { for (uint32_t i = 0; i < keycnt; i += max_keys_chunk) {
@ -836,15 +833,14 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
mem[4] = (chunk & 0xFF); mem[4] = (chunk & 0xFF);
// upload to flash. // upload to flash.
res = flashmem_spiffs_load((char*)destfn, mem, 5 + (chunk * 6)); res = flashmem_spiffs_load((char *)destfn, mem, 5 + (chunk * 6));
if (res != PM3_SUCCESS) { if (res != PM3_SUCCESS) {
PrintAndLogEx(WARNING, "\nSPIFFS upload failed"); PrintAndLogEx(WARNING, "\nSPIFFS upload failed");
free(mem); free(mem);
return res; return res;
} }
res = mfCheckKeys_file(destfn, &key64); res = mfCheckKeys_file(destfn, &key64);
} } else {
else {
res = mfCheckKeys(statelists[0].blockNo, statelists[0].keyType, false, chunk, p_keyblock, &key64); res = mfCheckKeys(statelists[0].blockNo, statelists[0].keyType, false, chunk, p_keyblock, &key64);
} }
@ -862,8 +858,7 @@ int mfStaticNested(uint8_t blockNo, uint8_t keyType, uint8_t* key, uint8_t trgBl
sprint_hex(resultKey, 6) sprint_hex(resultKey, 6)
); );
return PM3_SUCCESS; return PM3_SUCCESS;
} } else if (res == PM3_ETIMEOUT || res == PM3_EOPABORTED) {
else if (res == PM3_ETIMEOUT || res == PM3_EOPABORTED) {
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
free(mem); free(mem);
return res; return res;