Easy tutorial about hacking our first MIFAR/RFID Tag. RFID is a technology widely used in our lives, from our building access badges, to payment facilities, or even our gates’ remotes. As we’ve seen in the previous post here, some of them are utilizing little to no security mechanisms, like MIFARE. Today we will start working on a really basic series of hacks.

What you will need


What’s covered can be done with a simple RFID card reader found on Amazon for ~30€ (~35$). Mine was the [easyazon_link identifier=”B07FCLY4S9″ locale=”US” tag=”hackm01-20″]ACS ACR122U[/easyazon_link] simply because it was the most mentioned one on a few forums and blog posts I had read at the time. Consequently, it would make things easier for support if any issues arise.

With the previous post, we saw that tags a have a specific block of memory reserved to the manufacturer, including an UID (Unique IDentifier). If you want to try and clone a tag, you will need to be able to spoof this UID, so I also ordered a few tags ( [easyazon_link identifier=”B072P1L9LR” locale=”US” tag=”hackm01-20″]blank cards[/easyazon_link] and [easyazon_link identifier=”B0784NP1MR” locale

=”US” tag=”hackm01-20″]key-fobs[/easyazon_link] ) with an UID rewritable.



Any *NIX distribution will do the trick (Windows too eventually), but after a bit of trial and error, I figured out working on RFID and NFC works better with security oriented distributions like Kali or ParrotSec. They already include all the tools and libraries needed to do the job.

I also found out working in Virtual Machines (VMs) can sometimes be a pain. The host always keep a bit of control over the USB ports (via probes). This is annoying bc our card reader needs full access to those ports at any time. Without full access time-outs during read/write operations will occur and can permanently damage a tag.

NB: For those of you getting an error when trying to run any NFC related operations on an ACR122. The following command removes the USB module off your OS and “reset” the USB port so your reader can freely access it.

sudo rmmod pn533_usb

The best combination/setup (aka the one I struggled the less with) was the following:

  • ParrotSec 4.19 (as a guest OS)
  • Super user rights (most NFC commands will require it, just saving you some time here)
  • The latest libusb (just a C library to handle generic USB peripherals, should be present on any decent distribution anyway)
  • The latest libcrypto (belongs to the OpenSSL package, but can be used for various cryptographic operations, like cracking keys *wink wink*)

Basic exploitation


Let’s start with nfc-list which will try to connect to the reader and read any tags in range:

nfc-list – Figure 2.1

When done, the device is detected and active, interface is opened, and there is an ISO/IEC 14443A compliant tag in range. This tag is a barbaric term for a MIFARE card. Our first relevant information, this MIFARE tag’s UID is 7BE88C21.

MFOC – MiFare classic Offline Cracker

The easiest and most basic tool to use against MIFARE tags, is MFOC. It tries different keys against a MIFARE tags. Once MFOC finds a correct key the tool can “guess” the other keys and dump the memory of the tag. (Figure 2.2)

MFOC attack – Figure 2.2

In Figure 2.2, I have launched a MFOC attack, asking the tool to dump the memory of the tag into a file using the -O <file> option.
Just like nfc-list, MFOC will detect the tag on the reader as a MIFARE Classic 1K, gives us the UID, and then starts trying the keys from his own dictionary against every sector of the tag.

The output of MFOC is quite simple:
– the key FFFFFFFFFFFF is not used by any sector
– the key A0A1A2A3A4A5 is used as a key A onto all sectors from 0 to 15
– the key B0B1B2B3B4B5 is used as a key B onto sectors 0 to 11

As MFOC runs, we obtain keys A & B for 12 sectors; now the A keys for the last 4 sectors, and the missing 4 keys are able to fully read. 

Enter MFOC’s phase 2:

MFOC’s black magic – Figure 2.3

In figure 2.3, MFOC is using the sector 00 as an exploit sector simply because both A & B keys are known for this tag (hence any sector from 0 to 11 could be used as an exploit sector). MFOC is then sending probes onto the “uncracked” sectors and will compare the answer’s delay with a positive one onto sector 00, similar to how a time-based blind SQL injection works.

With the last 4 uncracked sectors have unveiled their B keys, MFOC is able to authenticate. Now we have both A & B keys. Now we will dump the memory of the entire tag in the file location specified, as seen in Figure 2.4.

MFOC dumping the content of the tag – Figure 2.4

Reading the Tag dump:

A simple hexadecimal tool like hexeditor can be used read and edit the dump file, as seen in Figure 2.5:

Hexeditor of the dump file – Figure 2.5

In Figure 2.5 above, the red area is actually a whole sector as we detailed in the first article, and on line 2B0 you can see the A key, A0A1A2A3A4A5, and B key, B0B1B2B3B4B5, which is separated by the 8 access bits 78 77 88 69 of the concerned sector.


The tag I worked on is the building access tag for my apartment. Lucky for me all sectors were using a default key and the dump only took me ~20-25 seconds. From here I copied my building badge. I did this to see if my building’s scanner could tell the difference between the original tag and a clone (UID included).

This brings us to a new tool nfc-mfclassic. This tool will allow us to write dump files on the new tag and is quite simple to use. A quick look at the man page is all that is needed. This tells us all we need to know. We can write dumps on a new tag with a w options, but a W (notice the uppercase) will not only write the whole dump’s data but will also rewrite the UID.
Let’s try to write the dump we just created with mfoc onto the new tag ordered on Amazon, using the A keys stored in the dump file itself (Figure 2.6):

Figure 2.6

As we wrote to the tag, it tells us the previous UID of the tag was 949E0139, and that 64 blocks of data have been written on it. Using nfc-list again to read a tag will show us the UID of the new tag has been changed and is now identical to my original building’s tag (Figure 2.7).

Figure 2.7


In conclusion, we’ve identified how to use a few basic NFC and MIFARE commands to read and detect a tag. With the few more MFOC commands we were able to crack a generic NFC key. Eventually, we dump the content of the tag’s memory if it was using default keys. This makes up more than 75% of the tags I have tried so far. With this information,the knowledge of cloning different MIFARE classic tags. A few things you might be asking yourself…

  • What to do if no default keys are used?
  • What if you want to edit the content of the data and give you access somewhere you shouldn’t be ?

That, my friends, will be for the next article of this RFID series. Stay tuned. 😉

You were not leaving your cart just like that, right?

Enter your details below to save your shopping cart for later. And, who knows, maybe we will even send you a sweet discount code :)