diff --git a/.gitignore b/.gitignore index 1488245..a65cb6a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ src/mfoc src/mfoc.exe stamp-h1 *.o +.history/ diff --git a/debian/rules b/debian/rules old mode 100755 new mode 100644 diff --git a/src/mfoc.c b/src/mfoc.c index 0be0140..545c6c6 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -73,6 +73,20 @@ uint32_t unknownSector = 0; char unknownKeyLetter = 'A'; uint32_t unexpected_random = 0; + +// Sectors 0 to 31 have 4 blocks per sector. +// Sectors 32 to 39 have 16 blocks per sector. + +uint8_t sector_to_block(uint8_t sector) +{ + if (sector<32) { + return sector<<2; + } + sector -= 32; + + return 128+(sector<<4); +} + int main(int argc, char *const argv[]) { int ch, i, k, n, j, m; @@ -131,14 +145,18 @@ int main(int argc, char *const argv[]) FILE * fp; char line[20]; char * read; - + + bool use_default_key=true; //Regexp declarations static const char *regex = "([0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f])"; 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, "hCD:s:BP:T:S:O:k:t:f")) != -1) { switch (ch) { + case 'C': + use_default_key=false; + break; case 'P': // Number of probes if (!(probes = atoi(optarg)) || probes < 1) { @@ -182,7 +200,7 @@ int main(int argc, char *const argv[]) j += i; } } - break; + break; case 'k': // Add this key to the default keys p = realloc(defKeys, defKeys_len + 6); @@ -222,10 +240,10 @@ int main(int argc, char *const argv[]) } } - if (!pfDump) { - ERR("parameter -O is mandatory"); - exit(EXIT_FAILURE); - } + // if (!pfDump) { + // ERR("parameter -O is mandatory"); + // exit(EXIT_FAILURE); + // } // Initialize reader/tag structures mf_init(&r); @@ -341,9 +359,34 @@ int main(int argc, char *const argv[]) fprintf(stdout, "\nTry to authenticate to all sectors with default keys...\n"); fprintf(stdout, "Symbols: '.' no key found, '/' A key found, '\\' B key found, 'x' both keys found\n"); // Set the authentication information (uid) + bool did_hardnested=false; + check_keys: + if (did_hardnested) { + printf("\nChecking for key reuse...\n"); + int i=0; + defKeys_len=0; + free(defKeys); + defKeys=malloc(0); + for (int i=0;i=0;--i) { + if (t.sectors[i].foundKeyB) { + fprintf(stdout, "\n\nUsing sector %02d as an exploit sector\n", i); + return i; + } + } + for (i = t.num_sectors-1; i>=0;--i) { + if (t.sectors[i].foundKeyA) { fprintf(stdout, "\n\nUsing sector %02d as an exploit sector\n", i); return i; }