mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-12-27 10:34:08 +08:00
ADD: 'hf emv' - forgot to add some file
This commit is contained in:
parent
2e8d938bef
commit
6a1687cc3e
6 changed files with 294 additions and 21 deletions
|
@ -15,7 +15,8 @@ APP_CFLAGS = -DWITH_ISO14443a_StandAlone \
|
|||
-DWITH_ISO15693 -DWITH_ISO14443a -DWITH_ISO14443b -DWITH_ICLASS \
|
||||
-DWITH_LEGICRF -DWITH_HITAG -DWITH_CRC -DON_DEVICE -DWITH_HFSNOOP \
|
||||
-fno-strict-aliasing -ffunction-sections -fdata-sections
|
||||
#-DWITH_LCD
|
||||
# -DWITH_EMV \
|
||||
# -DWITH_LCD \
|
||||
|
||||
#SRC_LCD = fonts.c LCD.c
|
||||
SRC_LF = lfops.c hitag2.c hitagS.c lfsampling.c pcf7931.c lfdemod.c protocols.c
|
||||
|
@ -67,10 +68,8 @@ ARMSRC = fpgaloader.c \
|
|||
usb_cdc.c \
|
||||
cmd.c \
|
||||
parity.c \
|
||||
random.c
|
||||
# $(SRC_EMV) \
|
||||
#BigBuf.c \
|
||||
|
||||
random.c \
|
||||
# $(SRC_EMV) \
|
||||
|
||||
# Do not move this inclusion before the definition of {THUMB,ASM,ARM}SRC
|
||||
include ../common/Makefile.common
|
||||
|
|
|
@ -240,6 +240,6 @@ typedef struct {
|
|||
uint8_t tag_BF0C[222]; //File Control Information (FCI) Issuer Discretionary Data
|
||||
uint8_t tag_DFName[16];
|
||||
uint8_t tag_DFName_len;
|
||||
}emvtags;
|
||||
} emvtags;
|
||||
|
||||
#endif //__EMVCARD_H
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#ifndef __EMVCMD_H
|
||||
#define __EMVCMD_H
|
||||
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "common.h"
|
||||
#include "apps.h"
|
||||
|
|
|
@ -50,13 +50,6 @@ extern int EMV_DBGLEVEL;
|
|||
#define EMVEMUL_WORK 7
|
||||
#define EMVEMUL_HALTED 8
|
||||
#define EMVEMUL_ACK 9
|
||||
//#define cardSTATE_TO_IDLE() cardSTATE = EMVEMUL_IDLE; LED_B_OFF(); LED_C_OFF();
|
||||
//grabbed from iso14443a.c
|
||||
//static int EmGetCmd(uint8_t *received, int *len);
|
||||
//int EmSendCmdEx(uint8_t *resp, size_t respLen, bool correctionNeeded);//tag types
|
||||
//int EmSendCmd(uint8_t *resp, size_t respLen);
|
||||
//#define cardSTATE_TO_IDLE() cardSTATE = MFEMUL_IDLE; LED_B_OFF(); LED_C_OFF();
|
||||
//extern int iso14_apdu(uint8_t *cmd, uint16_t cmd_len, void *data);
|
||||
|
||||
//functions
|
||||
//int emv_sendapdu( uint8_t cla, uint8_t ins, uint8_t p1, uint8_t p2, uint8_t lc, uint8_t* data, uint8_t le);
|
||||
|
@ -73,13 +66,6 @@ int emv_generateAC(uint8_t refcontrolparam, uint8_t* cdolinput, uint8_t cdolinpu
|
|||
int emv_decodeAFL(uint8_t* AFL, uint8_t AFLlen);
|
||||
int emv_decodeAIP(uint8_t* AIP);
|
||||
int emv_decodeCVM(uint8_t* CVM, uint8_t CVMlen);
|
||||
//memory management
|
||||
//uint8_t* emv_get_bigbufptr(void);
|
||||
//uint8_t* emv_get_bigbufptr_sendbuf(void);
|
||||
//uint8_t* emv_get_bigbufptr_recbuf(void);
|
||||
|
||||
//emulator
|
||||
//void EMVsim();
|
||||
|
||||
//utils
|
||||
int emv_printtag(uint8_t* selected_tag,emvtags* inputcard, uint8_t* outputstring, uint8_t* outputlen);
|
||||
|
|
249
client/cmdhfemv.c
Normal file
249
client/cmdhfemv.c
Normal file
|
@ -0,0 +1,249 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2014 Peter Fillmore
|
||||
// 2017 iceman
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// High frequency EMV commands
|
||||
//-----------------------------------------------------------------------------
|
||||
#include "cmdhfemv.h"
|
||||
|
||||
static int CmdHelp(const char *Cmd);
|
||||
|
||||
int usage_hf_emv_trans(void){
|
||||
PrintAndLog("perform an EMV transaction");
|
||||
PrintAndLog("Usage: hf emv trans [h]");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h : this help");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Samples:");
|
||||
PrintAndLog(" hf emv trans");
|
||||
return 0;
|
||||
}
|
||||
int usage_hf_emv_getrnd(void){
|
||||
PrintAndLog("retrieve the UN number from a terminal");
|
||||
PrintAndLog("Usage: hf emv getrnd [h]");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h : this help");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Samples:");
|
||||
PrintAndLog(" hf emv getrnd");
|
||||
return 0;
|
||||
}
|
||||
int usage_hf_emv_eload(void){
|
||||
PrintAndLog("set EMV tags in the device to use in a transaction");
|
||||
PrintAndLog("Usage: hf emv eload [h] o <filename w/o .bin>");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h : this help");
|
||||
PrintAndLog(" o <filename> : filename w/o '.bin'");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Samples:");
|
||||
PrintAndLog(" hf emv eload o myfile");
|
||||
return 0;
|
||||
}
|
||||
int usage_hf_emv_sim(void){
|
||||
PrintAndLog("Simulates a EMV contactless card");
|
||||
PrintAndLog("Usage: hf emv sim [h]");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h : this help");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Samples:");
|
||||
PrintAndLog(" hf emv sim");
|
||||
return 0;
|
||||
}
|
||||
int usage_hf_emv_dump(void){
|
||||
PrintAndLog("Gets EMV contactless tag values.");
|
||||
PrintAndLog("and saves binary dump into the file `filename.bin` or `cardUID.bin`");
|
||||
PrintAndLog("Usage: hf emv dump [h] o <filename w/o .bin>");
|
||||
PrintAndLog("Options:");
|
||||
PrintAndLog(" h : this help");
|
||||
PrintAndLog(" o <filename> : filename w/o '.bin' to dump bytes");
|
||||
PrintAndLog("");
|
||||
PrintAndLog("Samples:");
|
||||
PrintAndLog(" hf emv dump");
|
||||
PrintAndLog(" hf emv dump o myfile");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//perform an EMV transaction
|
||||
int CmdHfEmvTrans(const char *Cmd) {
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
if ( cmdp == 'h' || cmdp == 'H') return usage_hf_emv_trans();
|
||||
UsbCommand c = {CMD_EMV_TRANSACTION, {0, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
//retrieve the UN number from a terminal
|
||||
int CmdHfEmvGetrng(const char *Cmd) {
|
||||
char cmdp = param_getchar(Cmd, 0);
|
||||
if ( cmdp == 'h' || cmdp == 'H') return usage_hf_emv_getrnd();
|
||||
UsbCommand c = {CMD_EMV_GET_RANDOM_NUM, {0, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
|
||||
//set EMV tags in the device to use in a transaction
|
||||
int CmdHfEmvELoad(const char *Cmd) {
|
||||
FILE * f;
|
||||
char filename[FILE_PATH_SIZE];
|
||||
char *fnameptr = filename;
|
||||
int len;
|
||||
bool errors = false;
|
||||
uint8_t cmdp = 0;
|
||||
|
||||
while(param_getchar(Cmd, cmdp) != 0x00) {
|
||||
switch(param_getchar(Cmd, cmdp)) {
|
||||
case 'h':
|
||||
case 'H':
|
||||
return usage_hf_emv_eload();
|
||||
case 'o':
|
||||
case 'O':
|
||||
len = param_getstr(Cmd, cmdp+1, filename);
|
||||
if (!len)
|
||||
errors = true;
|
||||
if (len > FILE_PATH_SIZE-5)
|
||||
len = FILE_PATH_SIZE-5;
|
||||
sprintf(fnameptr + len,".bin");
|
||||
cmdp += 2;
|
||||
break;
|
||||
default:
|
||||
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
if(errors) break;
|
||||
}
|
||||
|
||||
//Validations
|
||||
if(errors) return usage_hf_emv_eload();
|
||||
|
||||
// open file
|
||||
f = fopen(filename,"r");
|
||||
if (!f) {
|
||||
PrintAndLog("File %s not found or locked", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char line[512];
|
||||
char *token;
|
||||
uint16_t tag;
|
||||
|
||||
UsbCommand c = {CMD_EMV_LOAD_VALUE, {0,0,0}};
|
||||
|
||||
// transfer to device
|
||||
while (fgets(line, sizeof (line), f)) {
|
||||
printf("LINE = %s\n", line);
|
||||
|
||||
token = strtok(line, ":");
|
||||
tag = (uint16_t)strtol(token, NULL, 0);
|
||||
token = strtok(NULL,"");
|
||||
|
||||
c.arg[0] = tag;
|
||||
memcpy(c.d.asBytes, token, strlen(token));
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
|
||||
printf("Loaded TAG = %04x\n", tag);
|
||||
printf("Loaded VALUE = %s\n", token);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
PrintAndLog("loaded %s", filename);
|
||||
//PrintAndLog("\nLoaded %d bytes from file: %s to emulator memory", numofbytes, filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHfEmvDump(const char *Cmd){
|
||||
|
||||
bool errors = false;
|
||||
uint8_t cmdp = 0;
|
||||
|
||||
while(param_getchar(Cmd, cmdp) != 0x00) {
|
||||
switch(param_getchar(Cmd, cmdp)) {
|
||||
case 'h':
|
||||
case 'H':
|
||||
return usage_hf_emv_dump();
|
||||
default:
|
||||
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
if(errors) break;
|
||||
}
|
||||
|
||||
//Validations
|
||||
if(errors) return usage_hf_emv_dump();
|
||||
|
||||
UsbCommand c = {CMD_EMV_DUMP_CARD, {0, 0, 0}};
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
UsbCommand resp;
|
||||
if (!WaitForResponseTimeout(CMD_ACK, &resp, 3000)) {
|
||||
PrintAndLog("Command execute time-out");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
int CmdHfEmvSim(const char *Cmd) {
|
||||
|
||||
bool errors = false;
|
||||
uint8_t cmdp = 0;
|
||||
|
||||
while(param_getchar(Cmd, cmdp) != 0x00) {
|
||||
switch(param_getchar(Cmd, cmdp)) {
|
||||
case 'h':
|
||||
case 'H':
|
||||
return usage_hf_emv_sim();
|
||||
default:
|
||||
PrintAndLog("Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
||||
errors = true;
|
||||
break;
|
||||
}
|
||||
if(errors) break;
|
||||
}
|
||||
|
||||
//Validations
|
||||
if(errors) return usage_hf_emv_sim();
|
||||
|
||||
UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}};
|
||||
sscanf(Cmd, " %"lli" %"lli" %"lli, &c.arg[0], &c.arg[1], &c.arg[2]);
|
||||
clearCommandBuffer();
|
||||
SendCommand(&c);
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
int CmdHfEmvList(const char *Cmd) {
|
||||
CmdHFList("7816");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, 1, "This help"},
|
||||
{"trans", CmdHfEmvTrans, 0, "Perform EMV Reader Transaction"},
|
||||
{"getrng", CmdHfEmvGetrng, 0, "get random number from terminal"},
|
||||
{"eload", CmdHfEmvELoad, 0, "load EMV tag into device"},
|
||||
{"dump", CmdHfEmvDump, 0, "Dump EMV tag values"},
|
||||
// {"sim", CmdHfEmvSim, 0, "Start tag simulator"},
|
||||
{"list", CmdHfEmvList, 1, "[Deprecated] List ISO7816 history"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
int CmdHFEmv(const char *Cmd) {
|
||||
clearCommandBuffer();
|
||||
CmdsParse(CommandTable, Cmd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CmdHelp(const char *Cmd) {
|
||||
CmdsHelp(CommandTable);
|
||||
return 0;
|
||||
}
|
40
client/cmdhfemv.h
Normal file
40
client/cmdhfemv.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) 2014 Peter Fillmore
|
||||
// 2017 iceman
|
||||
//
|
||||
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
||||
// at your option, any later version. See the LICENSE.txt file for the text of
|
||||
// the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// High frequency EMV commands
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef CMDHFEMV_H__
|
||||
#define CMDHFEMV_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "proxmark3.h"
|
||||
#include "data.h"
|
||||
#include "ui.h"
|
||||
#include "cmdparser.h"
|
||||
#include "cmdmain.h"
|
||||
#include "util.h"
|
||||
#include "cmdhf.h" // "hf list"
|
||||
|
||||
int CmdHFEmv(const char *Cmd);
|
||||
|
||||
int CmdHfEmvTransaction(const char *Cmd);
|
||||
int CmdHfEmvGetrng(const char *Cmd);
|
||||
int CmdHfEmvELoad(const char *Cmd);
|
||||
int CmdHfEmvDump(const char *Cmd);
|
||||
//int CmdHfEmvSim(const char *Cmd);
|
||||
int CmdHfEmvList(const char *Cmd);
|
||||
|
||||
int usage_hf_emv_trans(void);
|
||||
int usage_hf_emv_getrnd(void);
|
||||
int usage_hf_emv_eload(void);
|
||||
int usage_hf_emv_dump(void);
|
||||
int usage_hf_emv_sim(void);
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue