ACR122U, mfcuk, and mfoc: Cracking MIFARE Classic on Arch Linux
Aug 18, 2014
5 minutes read

Background

I recently bought an ACR122U reader [1] to play around with RFID, and especially MIFARE Classic cards because of their low security [2] [3] [4] [5] and widespread adoption.

The different sectors of the MIFARE Classic card are protected by different keys. To be able to decrypt the content of the card, the keys must be found. There are two well-known applications for this: mfcuk [6] and mfoc [7]. A typical attack scenario is to use mfcuk to find the first key of the card (which may take quite some time). When one key is found, mfoc can be used to find all other keys within minutes.

The problem

After installing libnfc [8], together with mfcuk and mfoc using AUR in Arch Linux, everything seemed to work. I launched an attack using mfcuk and got a key back after some time. The key was, however, incorrect. I assume that the bug described in [9] is the one causing trouble. The fix seems to be to use an older version of mfcuk. However, this will also require an older version of libnfc. This older version is, in turn, not compatible with mfoc.

Deep sigh.

So, let’s install duplicate copies of libnfc to get everything working.

Command-line frenzy

Note that # command means that the command should be executed as root, and that $ command should be executed as your own user. Also, take care to replace all instances of <user> with your own username.

I use yaourt to install packages from the AUR. You may use whatever tool you want.

mfcuk r65 and libnfc 1.5.1

A working combination of mfcuk and libnfc seems to be mfcuk r65 and libnfc 1.5.1. So let’s start by getting these, together with pcsclite and the PC/SC drivers for the ACR122U.

# pacman -S pcsclite
$ yaourt -S acsccid
$ mkdir -p ~/builds/nfc
$ cd ~/builds/nfc
$ wget https://libnfc.googlecode.com/files/libnfc-1.5.1.tar.gz
$ svn checkout -r 65 http://mfcuk.googlecode.com/svn/trunk/ mfcuk-r65
$ tar zxf libnfc-1.5.1.tar.gz

Now, let’s compile this older libnfc version and install it in a local directory to avoid messing up the system libraries.

$ cd libnfc-1.5.1
$ ./configure --prefix=/home/<user>/builds/nfc/prefix
$ make
$ make install
$ cd ..

Now, let’s compile mfcuk and make it use our newly compiled version of libnfc.

$ cd mfcuk-r65
$ autoreconf -is
$ LIBNFC_CFLAGS=-I/home/<user>/builds/nfc/prefix/include LIBNFC_LIBS="-L/home/<user>/builds/nfc/prefix/lib -lnfc" ./configure --prefix=/home/<user>/builds/nfc/prefix
$ make
$ make install
$ cd ..

Now lets continue to mfoc.

Note: You cannot use mfcuk just yet, because libnfc 1.7.1 needs to be installed to blacklist the kernel’s built-in drivers for the ACR122U, which will otherwise interfere with pcsclite.

mfoc 0.10.6 and libnfc 1.7.1

I will use the latest version of both libnfc and mfoc in the AUR, which (as of this writing) is 1.7.1 and 0.10.6.

$ yaourt -S libnfc mfoc

Done!

Cracking MIFARE Classic

To decrypt the contents of a MIFARE Classic card, we must first find the keys. This will be done in two steps.

Find the first key using mfcuk

Now, here is the tricky part. libnfc 1.5.1 must use pcsclite to be able to communicate with the reader, while newer versions of libnfc seem to prefer not to use pcsclite at all. Follow the instructions in the order written. If something goes wrong, unplug everything, remove the card, and try again from the beginning.

  • Open a terminal window and run (as root): pcscd -f to start the pcsclite daemon in foreground.
  • Connect your reader (without card)
  • Put card on reader.
  • Run mfcuk (as root) in a new window using the not-so-nice command-line: # LD_LIBRARY_PATH=/home/<user>/builds/nfc/prefix/lib /home/<user>/builds/nfc/prefix/bin/mfcuk -C -R 0:A -s 250 -S 250 -v 3 This will start cracking the first key of the first sector. This may take some time (up to hours).
  • When finished, the program will print something like (key censored as XXXXXXXXXXXX):
INFO: block 3 recovered KEY: XXXXXXXXXXXX
 1 2 3 4 5 6 7 8 9 a b c d e f


ACTION RESULTS MATRIX AFTER RECOVER - UID YY YY YY YY - TYPE 0x08 (MC1K)
---------------------------------------------------------------------
Sector	|    Key A	|ACTS | RESL	|    Key B	|ACTS | RESL
---------------------------------------------------------------------
0	|  XXXXXXXXXXXX	| . R | . R	|  000000000000	| . . | . .
1	|  000000000000	| . . | . .	|  000000000000	| . . | . .
2	|  000000000000	| . . | . .	|  000000000000	| . . | . .
3	|  000000000000	| . . | . .	|  000000000000	| . . | . .
4	|  000000000000	| . . | . .	|  000000000000	| . . | . .
5	|  000000000000	| . . | . .	|  000000000000	| . . | . .
6	|  000000000000	| . . | . .	|  000000000000	| . . | . .
7	|  000000000000	| . . | . .	|  000000000000	| . . | . .
8	|  000000000000	| . . | . .	|  000000000000	| . . | . .
9	|  000000000000	| . . | . .	|  000000000000	| . . | . .
10	|  000000000000	| . . | . .	|  000000000000	| . . | . .
11	|  000000000000	| . . | . .	|  000000000000	| . . | . .
12	|  000000000000	| . . | . .	|  000000000000	| . . | . .
13	|  000000000000	| . . | . .	|  000000000000	| . . | . .
14	|  000000000000	| . . | . .	|  000000000000	| . . | . .
15	|  000000000000	| . . | . .	|  000000000000	| . . | . .
  • Finally, kill the pcscd daemon with Ctrl-C.

This key can now be used together with mfoc to crack the remaining keys.

Find the remaining keys using mfoc

Since mfoc will use the newer version of libnfc, the command will be much simpler. Ensure that you have killed pcscd above before continuing. Replace XXXXXXXXXXXX with the key you got from mfcuk above.

# mfoc -O carddump.dmp -k XXXXXXXXXXXX

When finished, mfoc will dump the contents of your card both to the screen and to carddump.dmp.

References

[1] http://www.acs.com.hk/en/products/3/acr122u-usb-nfc-reader/

[2] https://www.usenix.org/legacy/events/sec08/tech/full_papers/nohl/nohl.pdf

[3] http://www.cs.ru.nl/~flaviog/publications/Attack.MIFARE.pdf

[4] http://www.cs.ru.nl/~flaviog/publications/Dismantling.Mifare.pdf

[5] http://www.cs.ru.nl/~flaviog/publications/Pickpocketing.Mifare.pdf

[6] https://code.google.com/p/mfcuk/

[7] https://code.google.com/p/mfoc/

[8] http://nfc-tools.org/index.php?title=Libnfc

[9] https://code.google.com/p/mfcuk/issues/detail?id=21


Back to posts


comments powered by Disqus