Tuesday, February 21, 2012

Deconstructing a Credit Card's Data

By Brad Antoniewicz.

Modern credit cards in the United States have three interfaces:

Physical

MagStripe Data

RFID/NFC Data

This obviously varies from bank to bank and card manufacturer to card manufacturer. The purpose of this post is to evaluate all three interfaces of the card and see how they differ. Note that some data has been changed to protect the card holder's (my) information.

Physical Attributes

This interface is probably the most widely known and understood because its been around the longest and its the easiest to inspect. It's sort of good to understand the components of this interface because they're present in to the other interfaces (but a little different).

From a physical perspective, your card should have four main attributes:

Name

Expiration Date

Credit Card Number

Card Verification Value

Names and Expiration dates are pretty straightforward and don't need much explaining.

Credit Card Number - Also known as "Primary Account Number" (PAN). The one thing to point out is that credit card numbers have some unique properties. For instance, the first number of the card number will vary depending on the type of card.

Card Verification Value (CVV2) - Note the version number. This is a three (MasterCard, Visa, Discover) or four (American Express, called the "CID") code printed on the card to help prevent against fraud. The idea behind it, is it proves possession of the card and is required when the card is not present. On American Express cards, this value is printed on the front, while MasterCard, Visa, and Discover cards have it printed on the back, usually in the signature box.

MagStripe Data

The magnetic stripe on the back of the card is broken up horizontally into three "tracks", the tracks often contain duplicate data and most times track 3 doesn't really contain any data.

ISO/IEC 7813 Defines the attributes of this data, and these sites describe the data available on each track in detail:

To read the data, you'll need a magstripe reader that will support reading all three tracks. Most magstripe readers emulate a HID (human input device), so its surprisingly easy to read from them - just open a text capturing program and swipe a card.

So you can see that Track 2 actually contains much data already present in track 1. You'll also notice that there is a difference in the discretionary data between track 1 and 2.

But where the heck is that Track 3 data? Well.. it doesn't appear that any data is written to it, or at least my reader isn't picking it up.

RFID Interface (EMV Chip)

In the last couple of years, the RFID Interface has been most talked about. Something about the idea of an attacker reading your credit card out of your pocket, seems to bother people :)

The RFID Interface specifications were designed by a group of representatives from Europay, MasterCard, and Visa (EMV) and is thus often referenced as the "EMV Chip" or just "EMV". The three things that differentiate this interface from the others are:

Card Holder Name - On most cards the cardholder name is not stored within the chip, instead its replaced by something like "VALUED CUSTOMER" or "NOT SUPPLIED"

Service Code - The service code that permits where the card is used (and for what) changes on the contactless interface.

iCVV or Dynamic CVV - Rather then using the same CVV that is stored on the MagStripe, the smartcard capabilities allows for extended functionality, and so the designers created something called a Dynamic CVV. This CVV changes which each read of the card.

VivoPay 4500

Probably the easiest way to read the RFID interface of a credit card is to buy an equipped point of sale (POS) reader and connect it up to your computer. The VivoPay 4500 will handle all of the RFID communication and output the data on the RFID interface in plaintext over it's serial connection.

Prolific PL-2303

The Prolific PL-2303 is a USB to Serial adapter which helps when connecting to the VivoPay's Serial output. If you want to make this all work on Mac OS X 10.7.3 (like i am) you have to do a little bit of work:

Insert your USB adapter then check to make sure the driver created a device interface (your interface might be named differently):

system:Extensions user$ ls /dev/tty.PL*
/dev/tty.PL2303-000013FA

pwnpass.py

pwnpass.py is a python script created by Eric Johnson (and others) which allows you to interact with VivoPay Devices. To use it, you may have to first install py-serial to get it running. I'm using mac ports to manage all of the python packages.

sudo port install python26 py26-serial

Next edit line 103 of pwnpass.py so that your device is appropriately defined. The default timeout for the open source driver is 1 second, I've changed it to 0.3 which seems to work better.

return serial.Serial('/dev/tty.PL2303-000011FD', 19200, timeout=0.3)

So if we run it on the same card we used before, we see the following raw data:

Mac OSX 10.7.3 Setup

Making it all work on Mac OS X 10.7.3 can be a bit of a pain to figure out, but I should have most of the difficulties worked out here. First off, you'll need to install Python 2.6, and the Crypto modules.

sudo port install python26 py26-crypto

Next select and download the Mac OSX drivers from HID. Initially, the driver version that was available to download was ifdokrfid_mac_10.6_i386-2.4.0.1.pkg, which didn't work with 10.7.3. I had to modify the installer so that it worked for 10.7:

As it turns out, HID has since released a newer version of the driver that "just works" (ifdokrfid_mac_universal-2.5.0.2.pkg). I did notice some problems with connecting the reader before running pcscd, so keep that in mind.

You can just launch pcscd from the command line:

sudo pcscd

If something isn't working, you can enable debugging and tell it to run in the foreground with:

sudo pcscd -f -d

With the driver installed, pcscd running, and the reader connected, you can use RFIDiot to check if the reader was properly detected:

TouchaTag (ACR122U) Reader Config

The Touchatag reader is another commercial off the shelf reader like the Omnikey Cardman 5321. It's popular because of its libNFC support, however with the tasks we're doing using RFIDiot, it doesn't really matter. I'm providing configuration information here for diversity. Once you connect the reader to your system, you'll likely notice its light seems to blink rather then staying lit. To fix this, it will require a quick little driver configuration change:

Using RFIDiot to Read Card Data

In most situations, RFIDiot's ChAP.py should be able to query the card's data. On an RFID level, the card is first queried with a generic "tell me your file structure" method, and if the card doesn't respond, the reader sends requests for specific application ID's (AIDs) that are known structures for different vendors (Mastercard, Visa, etc...). In the rare case that ChAP.py doesn't work well, you may have to define your own specific AID in ChAP.py or write your own parser like I did for the Chase Visa PayPass cards.

By default ChAP.py will attempt to parse the data from the card and translate it so we can make sense out of each byte. Instead, I'll tell ChAP.py not do that and just display the raw data (-r).

The following table breaks out the raw data from the magstripe and RFID interface to make it a little easier when comparing the two.

Track 1 Data

MagStripe

RFID

Value

%

%

Start

B

B

Format Code (B=Bank)

5XXXXXXXXXXXXXX2

5XXXXXXXXXXXXXX2

Primary Account Number (PAN)

^

^

Separator

ANTONIEWICZ

SUPPLIED

Last Name

/

/

Name Separator

BRAD

NOT

First Name

^

^

Separator

11

11

Expiration Year

03

03

Expiration Month

101

502

Service Code

000000001000000003000000

000000001000000637291901

Discretionary Data

?

?

End

Track 2 Data

;

;

Start Track 2 Data

5XXXXXXXXXXXXXX2

5XXXXXXXXXXXXXX2

Primary Account Number (PAN)

=

=

Separator

11

11

Expiration Year

03

03

Expiration Month

101

502

Service Code

000000300001

0000072029191

Discretionary Data

?

?

End

N/A

I

Trailing Data (Unknown)

Service Code - One interesting thing to note is the Service code differs. According to ISO/IEC 7813:2006(E), page 6, the service codes break down to:

101 - Can be used internationally with normal authorization, for any goods, with no PIN requirements

502 - Can be used nationally with normal authorization, for goods and services with no PIN requirements

So there are clearly some restrictions for where and how you can use the card.

You'll notice that the discretionary data on both track 1 and track 2 differ from that of the magstripe. Although the contents of the data stored within the discretionary data field are particular to the card manufacturer, we know that in here is where the CVV is stored. On the magstripe, CVV1 is used, while the RFID interface uses iCVV or Dynamic CVV.

You'll notice that the discretionary data changes on both tracks. That's the "dynamic" part of dynamic CVV.

Kristen Paget just gave a talk a Shmoocon and said that "check digits" (I believe the dynamic CVV is the only check that this applies to) can only be used once and if it is used a second time, the card is immediately frozen and the RFID chip can no longer be used.

Overall, there isn't much explanation of exactly how the iCVV or the dynamic CVV is actually generated, so if feel free to use the comments below to let me know what you know!

Here are some more useful links about the different CVVs and how they're generated:

29 comments:

So, if the dynamic CVV is in fact used by the card issuers to validate the presence of a card when used for NFC payment, the risks of someone using data collected by terminal data interception, or pocket surfing is minimal. Would this be a correct assumption?

502 - Can be used nationally with normal authorization, for goods and services and requires a PIN

I'm looking at the chart you posted:(http://2.bp.blogspot.com/-m5uVjaxlkNA/Tyr-cEI1T2I/AAAAAAAAAMs/oMtD4roaqY0/s1600/screenshot.214.jpg)and I find myself confused. It would appear that a "2" in position 3 corresponds to:Goods and Services only, with no PIN requirement listed (a dash). Am I misreading the chart, or was this a typo?

RykE - overall i'd say the risks associated with pocket surfing are somewhat minimal. There are a lot of backend processes that reduce exactly how much money someone can charge to your card. For clarification, it's worth to point out that if you never use the RFID interface, then the dynamic CVV doesnt increment, and you cannot invalidate the CVV that was sniffed from you. That gives the attacker one transaction. However, as Kristen Paget pointed out, an attacker could just perform multiple reads to increase the number of transactions they can make.

Hi, OSR. I really like this article, however I have a little something about the track 3 data.According to ISO/IEC 4909 "Identification cards — Financial transaction cards — Magnetic stripe data content for track 3" (preview link: http://webstore.iec.ch/preview/info_isoiec4909%7Bed1.0%7Den.pdf)(store link: http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=43309)Track 3 does in fact contain data, I think that it was just your scanner that was not picking up the data. Hope this clears some stuff up, and I thought it might do well as a correction to that particular line.

Hey, how's it goin? You touched briefly on the subject of differences betweeen Track 1 and track 2 data. Could you maybe inform me as to what and how exactly the data could be converted (track 1 to track 2 )

Jordan, did you get any farther? I've been doing some RFID security research lately with the Proxmark3 and HID cards. I recently received a Vivopay 4500 in the mail and ran into the same problem. I'm going to build that datacable in the upcoming days and see what I can find out.

I knew nothing abut the tech you are talking about here. But I have a credtit card EMV chip that was accidentally dropped by burglars at our house. I would like to know what info I can get from the chip that can help us to locate the criminal, and how. Thanks! MM

I believed I had everything setup properly: Vivopay 4500, serial cable with Prolific adapter, Python 2.7, pyserial, edited pwnpass to ID the adapter (shows up as TTYUSB0 in Backtrack5), but when I run pwnpass, all I get is a spinning pipe symbol and the phrase "om nom nom..." Nothing else ever happens. This in in both Win7 and BT5.

This seems to refer to some lines in the pwnpass code:elif len(result) == 0: sys.stdout.write("\b\r" + outchar[iter] + " om nom nom...Any ideas or suggestions? Thank you so much for your help!!

Hi there, Just want to say thanks for this blog post. After watching Kristins conference talk I found your site.

I have a vivopay 4500 and followed your article and it definitely works with no problem - I am using Mac OS 10.6.8

Next I am going to get a Arc122u for my experiments.

Ps - if anybody is wondering when the pwnpass script is working it should say 'Feed me Seymour' and when your serial port isn't what it is expecting it will say 'om nom nom'. When it is successful the will say pwnzered! and spit out the 2 track data.

Hey, I doubt you'll see this, but I have a Vivopay 4500 that was not getting to 'Feed me Seymour' with pwnpass and tried it with Serial Tools and those settings, but I'm getting a bunch of Hex values in <>'s any help?

Is there anyway you could go through the pwnpass steps for Windows. Mainly how to set the correct path for the serial port. I'm not great with python, so the more info the better..... Anyone have any info? Would be a great hep

All content provided here is purely for educational purposes only. Review state and local laws before partaking in any activity. The views and statements here have not been reviewed, approved, or endorsed by Foundstone, McAfee, or Intel.