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

Added "s" option to specify sectors to crack #43

Open
wants to merge 1 commit 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
39 changes: 35 additions & 4 deletions src/mfoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ int main(int argc, char *const argv[])
mftag t;
mfreader r;
denonce d = {NULL, 0, DEFAULT_DIST_NR, DEFAULT_TOLERANCE, {0x00, 0x00, 0x00}};

// Pointer to target sectors
uint8_t *ts = NULL;
uint8_t scount = 1;

// Pointers to possible keys
pKeys *pk;
Expand Down Expand Up @@ -199,6 +203,24 @@ int main(int argc, char *const argv[])
defKeys_len = defKeys_len + 6;

break;
case 's': {
char *sval;
i = 0;
for (i = 0; optarg[i] != '\0'; i++) {
if (optarg[i] == ',') {
scount++;
}
}
if ((ts = (uint8_t *) malloc(scount*sizeof(uint8_t))) == NULL) {
ERR("Cannot allocate memory for ts");
goto error;
}
for (i = 0; sval=strtok(optarg,","); i++) {
ts[i] = atoi(sval);
optarg = NULL;
}
}
break;
case 'O':
// File output
if (!(pfDump = fopen(optarg, "wb"))) {
Expand Down Expand Up @@ -477,7 +499,7 @@ int main(int argc, char *const argv[])
if (e_sector == -1) break; // All keys are default, I am skipping recovery mode
for (j = 0; j < (t.num_sectors); ++j) {
memcpy(mp.mpa.abtAuthUid, t.nt.nti.nai.abtUid + t.nt.nti.nai.szUidLen - 4, sizeof(mp.mpa.abtAuthUid));
if ((dumpKeysA && !t.sectors[j].foundKeyA) || (!dumpKeysA && !t.sectors[j].foundKeyB)) {
if ((ts == NULL || is_in_array(j, ts, scount)) && ((dumpKeysA && !t.sectors[j].foundKeyA) || (!dumpKeysA && !t.sectors[j].foundKeyB))) {

// First, try already broken keys
skip = false;
Expand Down Expand Up @@ -650,7 +672,7 @@ int main(int argc, char *const argv[])


for (i = 0; i < (t.num_sectors); ++i) {
if ((dumpKeysA && !t.sectors[i].foundKeyA) || (!dumpKeysA && !t.sectors[i].foundKeyB)) {
if ((ts == NULL || is_in_array(i, ts, scount)) && ((dumpKeysA && !t.sectors[i].foundKeyA) || (!dumpKeysA && !t.sectors[i].foundKeyB))) {
fprintf(stdout, "\nTry again, there are still some encrypted blocks\n");
succeed = 0;
break;
Expand Down Expand Up @@ -755,7 +777,7 @@ 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 key] [-f file] ... [-P probnum] [-T tolerance] [-s sectors] [-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");
Expand All @@ -765,7 +787,7 @@ void usage(FILE *stream, int errno)
// fprintf(stream, " S number of sets with keystreams, default is 5\n");
fprintf(stream, " P number of probes per sector, instead of default of 20\n");
fprintf(stream, " T nonce tolerance half-range, instead of default of 20\n (i.e., 40 for the total range, in both directions)\n");
// fprintf(stream, " s specify the list of sectors to crack, for example -s 0,1,3,5\n");
fprintf(stream, " s specify the list of sectors to crack, for example -s 0,1,3,5\n");
fprintf(stream, " O file in which the card contents will be written (REQUIRED)\n");
fprintf(stream, " D file in which partial card info will be written in case PRNG is not vulnerable\n");
fprintf(stream, "\n");
Expand Down Expand Up @@ -1261,3 +1283,12 @@ long long unsigned int bytes_to_num(uint8_t *src, uint32_t len)
}
return num;
}

bool is_in_array(int val, uint8_t *arr, uint8_t size) {
int i;
for (i = 0; i < size; i++) {
if (arr[i] == val)
return true;
}
return false;
}
1 change: 1 addition & 0 deletions src/mfoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ int compar_special_int(const void *a, const void *b);
countKeys *uniqsort(uint64_t *possibleKeys, uint32_t size);
void num_to_bytes(uint64_t n, uint32_t len, uint8_t *dest);
long long unsigned int bytes_to_num(uint8_t *src, uint32_t len);
bool is_in_array(int val, uint8_t *arr, uint8_t size);