]> cvs.zerfleddert.de Git - proxmark3-svn/blame_incremental - tools/mfkey/mfkey.c
added: readed blocks (password mode) into tag.sectors[]. 'lf hitag sim' simulates...
[proxmark3-svn] / tools / mfkey / mfkey.c
... / ...
CommitLineData
1// Test-file: test2.c
2#include "crapto1.h"
3#include <stdio.h>
4
5int main (int argc, char *argv[]) {
6 struct Crypto1State *revstate;
7 uint64_t lfsr;
8 uint8_t* plfsr = (uint8_t*)&lfsr;
9 uint32_t uid; // serial number
10 uint32_t nt; // tag challenge
11 uint32_t nr_enc; // encrypted reader challenge
12 uint32_t ar_enc; // encrypted reader response
13 uint32_t at_enc; // encrypted tag response
14 uint32_t ks2; // keystream used to encrypt reader response
15 uint32_t ks3; // keystream used to encrypt tag response
16
17 printf("MIFARE Classic key recovery\n\n");
18
19 if (argc < 6) {
20 printf(" syntax: %s <uid> <nt> <{nr}> <{ar}> <{at}>\n\n",argv[0]);
21 return 1;
22 }
23
24 sscanf(argv[1],"%x",&uid);
25 sscanf(argv[2],"%x",&nt);
26 sscanf(argv[3],"%x",&nr_enc);
27 sscanf(argv[4],"%x",&ar_enc);
28 sscanf(argv[5],"%x",&at_enc);
29
30 printf("Recovering key for:\n");
31 printf(" uid: %08x\n",uid);
32 printf(" nt: %08x\n",nt);
33 printf(" {nr}: %08x\n",nr_enc);
34 printf(" {ar}: %08x\n",ar_enc);
35 printf(" {at}: %08x\n",at_enc);
36
37/*
38 uint32_t uid = 0x9c599b32;
39 uint32_t tag_challenge = 0x82a4166c;
40 uint32_t nr_enc = 0xa1e458ce;
41 uint32_t reader_response = 0x6eea41e0;
42 uint32_t tag_response = 0x5cadf439;
43*/
44 // Generate lfsr succesors of the tag challenge
45 printf("\nLFSR succesors of the tag challenge:\n");
46 printf(" nt': %08x\n",prng_successor(nt, 64));
47 printf(" nt'': %08x\n",prng_successor(nt, 96));
48
49 // Extract the keystream from the messages
50 printf("\nKeystream used to generate {ar} and {at}:\n");
51 ks2 = ar_enc ^ prng_successor(nt, 64);
52 ks3 = at_enc ^ prng_successor(nt, 96);
53 printf(" ks2: %08x\n",ks2);
54 printf(" ks3: %08x\n",ks3);
55
56 revstate = lfsr_recovery64(ks2, ks3);
57 lfsr_rollback_word(revstate, 0, 0);
58 lfsr_rollback_word(revstate, 0, 0);
59 lfsr_rollback_word(revstate, nr_enc, 1);
60 lfsr_rollback_word(revstate, uid ^ nt, 0);
61 crypto1_get_lfsr(revstate, &lfsr);
62 printf("\nFound Key: [%02x %02x %02x %02x %02x %02x]\n\n",plfsr[5],plfsr[4],plfsr[3],plfsr[2],plfsr[1],plfsr[0]);
63 crypto1_destroy(revstate);
64
65 return 0;
66}
Impressum, Datenschutz