Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

port cve-2021-34600 poc, fix device desfire aes crypto #1594

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion armsrc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ APP_CFLAGS = $(PLATFORM_DEFS) \

SRC_LF = lfops.c lfsampling.c pcf7931.c lfdemod.c lfadc.c
SRC_ISO15693 = iso15693.c iso15693tools.c
SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c
SRC_ISO14443a = iso14443a.c mifareutil.c mifarecmd.c epa.c mifaresim.c mfdessimulate.c
#UNUSED: mifaresniff.c
SRC_ISO14443b = iso14443b.c
SRC_FELICA = felica.c
Expand Down
23 changes: 23 additions & 0 deletions armsrc/appmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include "lfzx.h"
#include "mifarecmd.h"
#include "mifaredesfire.h"
#include "mfdessimulate.h"
#include "mifaresim.h"
#include "pcf7931.h"
#include "Standalone/standalone.h"
Expand Down Expand Up @@ -1657,6 +1658,28 @@ static void PacketReceived(PacketCommandNG *packet) {
MifareHasStaticNonce();
break;
}
case CMD_HF_MIFARE_EV1_GET_LOCK_CHALLENGE: {
struct p {
uint8_t tagtype;
uint16_t flags;
uint8_t uid[10];
uint8_t key[16];
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
SimulateMfDesfireEv1(payload->tagtype, payload->flags, payload->uid, payload->key, CMD_HF_MIFARE_EV1_GET_LOCK_CHALLENGE);
break;
}
case CMD_HF_MIFARE_EV1_OPEN_DOOR: {
struct p {
uint8_t tagtype;
uint16_t flags;
uint8_t uid[10];
uint8_t key[16];
} PACKED;
struct p *payload = (struct p *) packet->data.asBytes;
SimulateMfDesfireEv1(payload->tagtype, payload->flags, payload->uid, payload->key, CMD_HF_MIFARE_EV1_OPEN_DOOR);
break;
}
#endif

#ifdef WITH_NFCBARCODE
Expand Down
8 changes: 5 additions & 3 deletions armsrc/desfire_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,9 @@ void *mifare_cryto_postprocess_data(desfiretag_t tag, void *data, size_t *nbytes
break;
}

free(edata);
// TODO it doesn't build with this uncommented
// desfire_crypto.c:(.text.mifare_cryto_postprocess_data+0x4c): undefined reference to `free'
//free(edata);

break;
case MDCM_ENCIPHERED:
Expand Down Expand Up @@ -811,13 +813,13 @@ void mifare_cypher_single_block(desfirekey_t key, uint8_t *data, uint8_t *ivect,
case MCO_ENCYPHER: {
mbedtls_aes_init(&actx);
mbedtls_aes_setkey_enc(&actx, key->data, 128);
mbedtls_aes_crypt_cbc(&actx, MBEDTLS_AES_ENCRYPT, sizeof(edata), ivect, data, edata);
mbedtls_aes_crypt_ecb(&actx, MBEDTLS_AES_ENCRYPT, data, edata);
break;
}
case MCO_DECYPHER: {
mbedtls_aes_init(&actx);
mbedtls_aes_setkey_dec(&actx, key->data, 128);
mbedtls_aes_crypt_cbc(&actx, MBEDTLS_AES_DECRYPT, sizeof(edata), ivect, edata, data);
mbedtls_aes_crypt_ecb(&actx, MBEDTLS_AES_DECRYPT, data, edata);
break;
}
}
Expand Down
Loading