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

add -K option to use an extended keys set instead of the default keys set #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
212 changes: 206 additions & 6 deletions src/mfoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ int main(int argc, char *const argv[])
bool failure = false;
bool skip = false;

uint8_t (*currentKeys)[6];
int currentKeysSize;

// Next default key specified as option (-k)
uint8_t *defKeys = NULL, *p;
size_t defKeys_len = 0;
Expand All @@ -107,7 +110,200 @@ int main(int argc, char *const argv[])
{0xa0, 0x47, 0x8c, 0xc3, 0x90, 0x91},
{0x53, 0x3c, 0xb6, 0xc7, 0x23, 0xf6},
{0x8f, 0xd0, 0xa4, 0xf2, 0x56, 0xe9}
};
currentKeysSize = sizeof(defaultKeys) / sizeof(defaultKeys[0]);
currentKeys= defaultKeys;

// Array with extended Mifare Classic keys
uint8_t extendedKeys[][6] = {
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // Default key (first key used by program if no user defined key)
{0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5}, // NFCForum MAD key
{0xd3, 0xf7, 0xd3, 0xf7, 0xd3, 0xf7}, // NFCForum content key
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Blank key
{0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5},
{0x4d, 0x3a, 0x99, 0xc3, 0x51, 0xdd},
{0x1a, 0x98, 0x2c, 0x7e, 0x45, 0x9a},
{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
{0x71, 0x4c, 0x5c, 0x88, 0x6e, 0x97},
{0x58, 0x7e, 0xe5, 0xf9, 0x35, 0x0f},
{0xa0, 0x47, 0x8c, 0xc3, 0x90, 0x91},
{0x53, 0x3c, 0xb6, 0xc7, 0x23, 0xf6},
{0x8f, 0xd0, 0xa4, 0xf2, 0x56, 0xe9},
{0xa6, 0x45, 0x98, 0xa7, 0x74, 0x78},
{0x26, 0x94, 0x0b, 0x21, 0xff, 0x5d},
{0xfc, 0x00, 0x01, 0x87, 0x78, 0xf7},
{0x00, 0x00, 0x0f, 0xfe, 0x24, 0x88},
{0x5c, 0x59, 0x8c, 0x9c, 0x58, 0xb5},
{0xe4, 0xd2, 0x77, 0x0a, 0x89, 0xbe},
{0x43, 0x4f, 0x4d, 0x4d, 0x4f, 0x41},
{0x43, 0x4f, 0x4d, 0x4d, 0x4f, 0x42},
{0x47, 0x52, 0x4f, 0x55, 0x50, 0x41},
{0x47, 0x52, 0x4f, 0x55, 0x50, 0x42},
{0x50, 0x52, 0x49, 0x56, 0x41, 0x41},
{0x50, 0x52, 0x49, 0x56, 0x41, 0x42},
{0x02, 0x97, 0x92, 0x7c, 0x0f, 0x77},
{0xee, 0x00, 0x42, 0xf8, 0x88, 0x40},
{0x72, 0x2b, 0xfc, 0xc5, 0x37, 0x5f},
{0xf1, 0xd8, 0x3f, 0x96, 0x43, 0x14},
{0x54, 0x72, 0x61, 0x76, 0x65, 0x6c},
{0x77, 0x69, 0x74, 0x68, 0x75, 0x73},
{0x4a, 0xf9, 0xd7, 0xad, 0xeb, 0xe4},
{0x2b, 0xa9, 0x62, 0x1e, 0x0a, 0x36},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc},
{0xb1, 0x27, 0xc6, 0xf4, 0x14, 0x36},
{0x12, 0xf2, 0xee, 0x34, 0x78, 0xc1},
{0x34, 0xd1, 0xdf, 0x99, 0x34, 0xc5},
{0x55, 0xf5, 0xa5, 0xdd, 0x38, 0xc9},
{0xf1, 0xa9, 0x73, 0x41, 0xa9, 0xfc},
{0x33, 0xf9, 0x74, 0xb4, 0x27, 0x69},
{0x14, 0xd4, 0x46, 0xe3, 0x33, 0x63},
{0xc9, 0x34, 0xfe, 0x34, 0xd9, 0x34},
{0x19, 0x99, 0xa3, 0x55, 0x4a, 0x55},
{0x27, 0xdd, 0x91, 0xf1, 0xfc, 0xf1},
{0xa9, 0x41, 0x33, 0x01, 0x34, 0x01},
{0x99, 0xc6, 0x36, 0x33, 0x44, 0x33},
{0x43, 0xab, 0x19, 0xef, 0x5c, 0x31},
{0xa0, 0x53, 0xa2, 0x92, 0xa4, 0xaf},
{0x50, 0x52, 0x49, 0x56, 0x54, 0x41},
{0x50, 0x52, 0x49, 0x56, 0x54, 0x42},
{0xfc, 0x00, 0x01, 0x87, 0x7b, 0xf7},
{0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0},
{0xa1, 0xb1, 0xc1, 0xd1, 0xe1, 0xf1},
{0xbd, 0x49, 0x3a, 0x39, 0x62, 0xb6},
{0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
{0x11, 0x11, 0x11, 0x11, 0x11, 0x11},
{0x22, 0x22, 0x22, 0x22, 0x22, 0x22},
{0x33, 0x33, 0x33, 0x33, 0x33, 0x33},
{0x44, 0x44, 0x44, 0x44, 0x44, 0x44},
{0x55, 0x55, 0x55, 0x55, 0x55, 0x55},
{0x66, 0x66, 0x66, 0x66, 0x66, 0x66},
{0x77, 0x77, 0x77, 0x77, 0x77, 0x77},
{0x88, 0x88, 0x88, 0x88, 0x88, 0x88},
{0x99, 0x99, 0x99, 0x99, 0x99, 0x99},
{0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa},
{0xbb, 0xbb, 0xbb, 0xbb, 0xbb, 0xbb},
{0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc},
{0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd},
{0xee, 0xee, 0xee, 0xee, 0xee, 0xee},
{0x01, 0x23, 0x45, 0x67, 0x89, 0xab},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x0a},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x0b},
{0x10, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x20, 0x00, 0x00, 0x00, 0x00, 0x00},
{0xa0, 0x00, 0x00, 0x00, 0x00, 0x00},
{0xb0, 0x00, 0x00, 0x00, 0x00, 0x00},
{0xab, 0xcd, 0xef, 0x12, 0x34, 0x56},
{0xf4, 0xa9, 0xef, 0x2a, 0xfc, 0x6d},
{0x4b, 0x0b, 0x20, 0x10, 0x7c, 0xcb},
{0x56, 0x93, 0x69, 0xc5, 0xa0, 0xe5},
{0x63, 0x21, 0x93, 0xbe, 0x1c, 0x3c},
{0x64, 0x46, 0x72, 0xbd, 0x4a, 0xfe},
{0x8f, 0xe6, 0x44, 0x03, 0x87, 0x90},
{0x9d, 0xe8, 0x9e, 0x07, 0x02, 0x77},
{0xb5, 0xff, 0x67, 0xcb, 0xa9, 0x51},
{0xef, 0xf6, 0x03, 0xe1, 0xef, 0xe9},
{0xf1, 0x4e, 0xe7, 0xca, 0xe8, 0x63},
{0x44, 0xab, 0x09, 0x01, 0x08, 0x45},
{0x85, 0xfe, 0xd9, 0x80, 0xea, 0x5a},
{0x31, 0x4b, 0x49, 0x47, 0x49, 0x56},
{0x56, 0x4c, 0x50, 0x5f, 0x4d, 0x41},
{0x02, 0x63, 0xde, 0x12, 0x78, 0xf3},
{0x06, 0x7d, 0xb4, 0x54, 0x54, 0xa9},
{0x0d, 0xb5, 0xe6, 0x52, 0x3f, 0x7c},
{0x10, 0x05, 0x33, 0xb8, 0x93, 0x31},
{0x13, 0x6b, 0xdb, 0x24, 0x6c, 0xac},
{0x15, 0xfc, 0x4c, 0x76, 0x13, 0xfe},
{0x16, 0xf2, 0x1a, 0x82, 0xec, 0x84},
{0x16, 0xf3, 0xd5, 0xab, 0x11, 0x39},
{0x17, 0x75, 0x88, 0x56, 0xb1, 0x82},
{0x18, 0x6d, 0x8c, 0x4b, 0x93, 0xf9},
{0x1f, 0xc2, 0x35, 0xac, 0x13, 0x09},
{0x22, 0xc1, 0xba, 0xe1, 0xaa, 0xcd},
{0x24, 0x3f, 0x16, 0x09, 0x18, 0xd1},
{0x25, 0x09, 0x4d, 0xf6, 0xf1, 0x48},
{0x27, 0x35, 0xfc, 0x18, 0x18, 0x07},
{0x2a, 0x3c, 0x34, 0x7a, 0x12, 0x00},
{0x2a, 0xba, 0x95, 0x19, 0xf5, 0x74},
{0x2b, 0x7f, 0x32, 0x53, 0xfa, 0xc5},
{0x32, 0x4f, 0x5d, 0xf6, 0x53, 0x10},
{0x32, 0xac, 0x3b, 0x90, 0xac, 0x13},
{0x35, 0xc3, 0xd2, 0xca, 0xee, 0x88},
{0x3a, 0x42, 0xf3, 0x3a, 0xf4, 0x29},
{0x3a, 0x4b, 0xba, 0x8a, 0xda, 0xf0},
{0x3d, 0xf1, 0x4c, 0x80, 0x00, 0xa1},
{0x3e, 0x35, 0x54, 0xaf, 0x0e, 0x12},
{0x3e, 0x65, 0xe4, 0xfb, 0x65, 0xb3},
{0x40, 0xea, 0xd8, 0x07, 0x21, 0xce},
{0x45, 0x48, 0x41, 0x58, 0x54, 0x43},
{0x46, 0x07, 0x22, 0x12, 0x25, 0x10},
{0x48, 0xff, 0xe7, 0x12, 0x94, 0xa0},
{0x49, 0x1c, 0xdc, 0xfb, 0x77, 0x52},
{0x4a, 0xd1, 0xe2, 0x73, 0xea, 0xf1},
{0x4b, 0x79, 0x1b, 0xea, 0x7b, 0xcc},
{0x51, 0x11, 0x9d, 0xae, 0x52, 0x16},
{0x51, 0x28, 0x4c, 0x36, 0x86, 0xa6},
{0x52, 0x8c, 0x9d, 0xff, 0xe2, 0x8c},
{0x5e, 0xb8, 0xf8, 0x84, 0xc8, 0xd1},
{0x5f, 0x14, 0x67, 0x16, 0xe3, 0x73},
{0x62, 0x02, 0xa3, 0x8f, 0x69, 0xe2},
{0x63, 0x38, 0xa3, 0x71, 0xc0, 0xed},
{0x63, 0xf1, 0x7a, 0x44, 0x9a, 0xf0},
{0x64, 0x3f, 0xb6, 0xde, 0x22, 0x17},
{0x64, 0xe3, 0xc1, 0x03, 0x94, 0xc2},
{0x65, 0x3a, 0x87, 0x59, 0x40, 0x79},
{0x67, 0x36, 0x2d, 0x90, 0xf9, 0x73},
{0x68, 0x2d, 0x40, 0x1a, 0xbb, 0x09},
{0x68, 0xd3, 0x02, 0x88, 0x91, 0x0a},
{0x69, 0x31, 0x43, 0xf1, 0x03, 0x68},
{0x6a, 0x47, 0x0d, 0x54, 0x12, 0x7c},
{0x73, 0x06, 0x8f, 0x11, 0x8c, 0x13},
{0x74, 0x0e, 0x9a, 0x4f, 0x9a, 0xaf},
{0x75, 0xcc, 0xb5, 0x9c, 0x9b, 0xed},
{0x75, 0xd8, 0x69, 0x0f, 0x21, 0xb6},
{0x75, 0xed, 0xe6, 0xa8, 0x44, 0x60},
{0x7d, 0xe0, 0x2a, 0x7f, 0x60, 0x25},
{0x82, 0xf4, 0x35, 0xde, 0xdf, 0x01},
{0x83, 0xe3, 0x54, 0x9c, 0xe4, 0x2d},
{0x84, 0xfd, 0x7f, 0x7a, 0x12, 0xb6},
{0x85, 0x67, 0x5b, 0x20, 0x00, 0x17},
{0x87, 0x1b, 0x8c, 0x08, 0x59, 0x97},
{0x87, 0x65, 0xb1, 0x79, 0x68, 0xa2},
{0x93, 0x7a, 0x4f, 0xff, 0x30, 0x11},
{0x97, 0x18, 0x4d, 0x13, 0x62, 0x33},
{0x97, 0xd1, 0x10, 0x1f, 0x18, 0xb0},
{0x9a, 0xfa, 0x6c, 0xb4, 0xfc, 0x3d},
{0x9a, 0xfc, 0x42, 0x37, 0x2a, 0xf1},
{0x9f, 0x13, 0x1d, 0x8c, 0x20, 0x57},
{0xa2, 0x7d, 0x38, 0x04, 0xc2, 0x59},
{0xa3, 0xf9, 0x74, 0x28, 0xdd, 0x01},
{0xa7, 0x3f, 0x5d, 0xc1, 0xd3, 0x33},
{0xa8, 0x96, 0x6c, 0x7c, 0xc5, 0x4b},
{0xa9, 0xf9, 0x53, 0xde, 0xf0, 0xa3},
{0xaa, 0xfb, 0x06, 0x04, 0x58, 0x77},
{0xac, 0x0e, 0x24, 0xc7, 0x55, 0x27},
{0xae, 0x3d, 0x65, 0xa3, 0xda, 0xd4},
{0xae, 0x3f, 0xf4, 0xee, 0xa0, 0xdb},
{0xb0, 0xc9, 0xdd, 0x55, 0xdd, 0x4d},
{0xb2, 0x0b, 0x83, 0xcb, 0x14, 0x5c},
{0xb7, 0x36, 0x41, 0x26, 0x14, 0xaf},
{0xbf, 0x23, 0xa5, 0x3c, 0x1f, 0x63},
{0xc4, 0x65, 0x2c, 0x54, 0x26, 0x1c},
{0xc6, 0xad, 0x00, 0x25, 0x45, 0x62},
{0xc7, 0xc0, 0xad, 0xb3, 0x28, 0x4f},
{0xc8, 0x2e, 0xc2, 0x9e, 0x32, 0x35},
{0xcb, 0x9a, 0x1f, 0x2d, 0x73, 0x68},
{0xd3, 0x9b, 0xb8, 0x3f, 0x52, 0x97},
{0xd4, 0x9e, 0x28, 0x26, 0x66, 0x4f},
{0xd8, 0xa2, 0x74, 0xb2, 0xe0, 0x26},
{0xdf, 0x27, 0xa8, 0xf1, 0xcb, 0x8e},
{0xe2, 0xc4, 0x25, 0x91, 0x36, 0x8a},
{0xe3, 0x42, 0x92, 0x81, 0xef, 0xc1},
{0xe4, 0x44, 0xd5, 0x3d, 0x35, 0x9f},
{0xf1, 0x24, 0xc2, 0x57, 0x8a, 0xd0},
{0xf5, 0x9a, 0x36, 0xa2, 0x54, 0x6d},
{0xfe, 0xe4, 0x70, 0xa4, 0xcb, 0x58}
};

mftag t;
Expand Down Expand Up @@ -139,7 +335,7 @@ int main(int argc, char *const argv[])
struct slre_cap caps[2];

// Parse command line arguments
while ((ch = getopt(argc, argv, "hD:s:BP:T:S:O:k:t:f:")) != -1) {
while ((ch = getopt(argc, argv, "hKD:s:BP:T:S:O:k:t:f:")) != -1) {
switch (ch) {
case 'P':
// Number of probes
Expand Down Expand Up @@ -184,7 +380,11 @@ int main(int argc, char *const argv[])
j += i;
}
}
break;
break;
case 'K':
currentKeysSize = sizeof(extendedKeys) / sizeof(extendedKeys[0]);
currentKeys= extendedKeys;
break;
case 'k':
// Add this key to the default keys
p = realloc(defKeys, defKeys_len + 6);
Expand Down Expand Up @@ -345,15 +545,14 @@ int main(int argc, char *const argv[])
// Set the authentication information (uid)
memcpy(mp.mpa.abtAuthUid, t.nt.nti.nai.abtUid + t.nt.nti.nai.szUidLen - 4, sizeof(mp.mpa.abtAuthUid));
// Iterate over all keys (n = number of keys)
n = sizeof(defaultKeys) / sizeof(defaultKeys[0]);
size_t defKey_bytes_todo = defKeys_len;
key = 0;
while (key < n || defKey_bytes_todo) {
while (key < currentKeysSize || defKey_bytes_todo) {
if (defKey_bytes_todo > 0) {
memcpy(mp.mpa.abtKey, defKeys + defKeys_len - defKey_bytes_todo, sizeof(mp.mpa.abtKey));
defKey_bytes_todo -= sizeof(mp.mpa.abtKey);
} else {
memcpy(mp.mpa.abtKey, defaultKeys[key], sizeof(mp.mpa.abtKey));
memcpy(mp.mpa.abtKey, currentKeys[key], sizeof(mp.mpa.abtKey));
key++;
}
fprintf(stdout, "[Key: %012llx] -> ", bytes_to_num(mp.mpa.abtKey, 6));
Expand Down Expand Up @@ -755,10 +954,11 @@ int main(int argc, char *const argv[])

void usage(FILE *stream, int errno)
{
fprintf(stream, "Usage: mfoc [-h] [-k key] [-f file] ... [-P probnum] [-T tolerance] [-O output]\n");
fprintf(stream, "Usage: mfoc [-h] [-K] [-k key] [-f file] ... [-P probnum] [-T tolerance] [-O output]\n");
fprintf(stream, "\n");
fprintf(stream, " h print this help and exit\n");
// fprintf(stream, " B instead of 'A' dump 'B' keys\n");
fprintf(stream, " K use extended keys set instead of default keys set\n");
fprintf(stream, " k try the specified key in addition to the default keys\n");
fprintf(stream, " f parses a file of keys to add in addition to the default keys \n");
// fprintf(stream, " D number of distance probes, default is 20\n");
Expand Down