29C3: A Rambling Walk Through an EMV Transaction (EN)

Christiaan008
30 Dec 201259:33

Summary

TLDRThe speaker, Tim Becker, provides an in-depth analysis of the EMV (Europay, Mastercard, and Visa) protocol, which is the communication standard between chip-based credit cards and payment terminals. He discusses the history and technicalities of the protocol, highlighting its age and pragmatic design from the 1980s. Becker demonstrates how the protocol works at a low level, explaining the use of APDU (Application Protocol Data Units) for data exchange and the reliance on static data authentication. He also touches on the security aspects, including the potential for man-in-the-middle attacks and the fact that the data transmitted between the card and reader is unencrypted. The talk concludes with a live demonstration of interacting with a card using a card reader and custom Ruby code, emphasizing the accessibility of understanding and experimenting with EMV technology.

Takeaways

  • 📍 EMV stands for Europay, Mastercard, and Visa, and it's a payment protocol that facilitates communication between a chip card and a payment terminal.
  • 🔍 The presenter has extensive experience in credit card processing and fraud management, having worked at a German bank and a consultancy, and is currently an independent contractor.
  • 💡 EMV technology is being mandated in the United States, which will lead to a significant increase in its usage, despite its age and known security shortcomings.
  • 🛠 The session covered both basic and low-level aspects of EMV, including text, numbers, and technical specifications, without revealing secrets or sophisticated hacks.
  • 💳 The presenter demonstrated how to use a card reader to interact with a chip card, showcasing that no special terminal is needed, and that the process is standardized and accessible.
  • 🔗 PC/SC (PCSC) is the method used to connect a card reader to a computer, and most operating systems support it to some extent.
  • 📚 ISO 7816 is the standard that defines the low-level characteristics of how the physical layer communicates with the card, which uses a simple serial interface.
  • 🛂 APDU (Application Protocol Data Unit) is the method of exchanging packets between the card and the host, and it's a straightforward process of sending and receiving data bits.
  • 🔐 The EMV protocol includes various security features such as key derivation, certificates, and data dictionaries, although not all cards use the most secure options like DDA (Dynamic Data Authentication).
  • 📈 The general flow of EMV transactions includes card and terminal introduction, application selection, data verification, cardholder verification, and the generation of a cryptogram to validate the transaction.
  • ⚠️ The EMV protocol has been criticized for its age and lack of robust security features, and these concerns are carried over to new technologies like contactless payments.

Q & A

  • What does EMV stand for and what is its purpose?

    -EMV stands for Europay, Mastercard, and Visa. It is a global standard for credit and debit card transactions that defines the protocols between the chip on the card and the payment terminal.

  • What is the significance of the ATR (Answer to Reset) in the context of EMV?

    -The ATR is a series of bytes sent by a smart card to the card reader after the card is powered up. It provides essential information for the terminal to communicate with the card, including the supported communication protocols and other settings.

  • What does PCSC stand for and what is its role in smart card communication?

    -PCSC stands for PC/SC, which is a framework for smart card communication. It allows a smart card reader to communicate with a smart card when connected to a PC, enabling the card to be used for various applications.

  • What is APDU and how does it relate to EMV transactions?

    -APDU stands for Application Protocol Data Unit. It is the format of the packets exchanged between the card and the host during an EMV transaction. APDUs carry the commands and data used in the transaction process.

  • What are the main components of the EMV specifications?

    -The main components of the EMV specifications are divided into four books: Book 1 covers general information, Book 2 deals with cryptography, Book 3 specifies the APDUs and card commands, and Book 4 describes the card acceptance environment.

  • How does the EMV protocol handle security and authentication?

    -The EMV protocol uses a combination of chip-based technology, cryptography, and secure messaging to ensure security and authentication. It includes features like static data authentication, dynamic data authentication, and cardholder verification methods.

  • What is the role of the issuer certificate in EMV transactions?

    -The issuer certificate is used in EMV transactions to authenticate the card and ensure the data on the card is from a legitimate issuer. It contains the issuer's public key, which is used to verify a hash of the card's static data.

  • What is the significance of the AFL (Application File Locator) in an EMV card?

    -The AFL is a list of file identifiers on the EMV card that tells the terminal which files to read during a transaction. It is crucial for the terminal to access the correct data, such as the cardholder name, account number, and other relevant information.

  • How does the EMV protocol handle cardholder verification?

    -The EMV protocol provides several methods for cardholder verification, including PIN verification by the card, signature verification, and PIN verification by the bank. The terminal will attempt to use the most secure method supported by the card and available at the terminal.

  • What are the potential security weaknesses in the EMV protocol?

    -Despite its security features, the EMV protocol has potential weaknesses, such as the lack of encryption in the communication between the card and the terminal, which makes it susceptible to man-in-the-middle attacks. Additionally, the reliance on static data authentication can make cards easier to clone.

  • How does the EMV protocol compare to magnetic stripe transactions in terms of security?

    -The EMV protocol is designed to be more secure than magnetic stripe transactions due to its chip-based technology and cryptographic authentication. However, magnetic stripe data is still present on EMV cards, which can be read and potentially cloned, representing a weaker link in the security chain.

Outlines

00:00

😀 Introduction to EMV and Personal Background

The speaker introduces EMV, which stands for Europay, Mastercard, and Visa, and explains it is a payment protocol between a chip and a payment terminal. They share their professional background in credit card processing and involvement in software projects related to chip card technology. The talk aims to cover both basic and low-level aspects of EMV, and the speaker expresses their motivation for discussing a topic that, while old and rudimentary, is gaining traction in the United States and has interesting security considerations.

05:00

📘 Basic Interaction with the Card and EMV Standards

The speaker dives into the basic interaction with an EMV card, mentioning the use of the ISO 7816 standard for low-level communication and the concept of Application Protocol Data Units (APDUs) for exchanging information between the card and the terminal. They discuss the structure of APDUs, including the use of class bytes, instruction bytes, and data fields. The talk touches on the historical bytes in the card's ATR that can help identify the card vendor.

10:01

🔍 In-Depth Analysis of APDU and EMV Specifications

The speaker provides a detailed look at APDU commands, such as 'select', and how they are used to interact with the card's file system. They explain the use of Elementary Files (EF), Directory Files (DF), and the Master File (MF). The talk also covers the importance of the EMV books 1 through 4, which contain specifications for the EMV application framework, including cryptographic practices, key derivation algorithms, and the data dictionary for understanding tags.

15:02

🛍️ Transaction Flow and Cardholder Verification

The speaker outlines the general flow of EMV transactions, starting from the introduction between the card and terminal to the selection of the appropriate application. They discuss how the terminal requests information from the card, the cardholder verification methods (such as PIN or signature), and the generation of a cryptogram to secure the transaction. The talk highlights the misconception that the chip is only for data storage, emphasizing that it acts as a small computer performing cryptographic operations.

20:02

🔐 Static Data Authentication and Security Considerations

The speaker explains the process of static data authentication (SDA), which involves hashing data and comparing it with a certificate signed by the issuer to verify the card's authenticity. They discuss the limitations of SDA, such as the ease of card cloning due to static certificates on the card. The talk also touches on the potential for man-in-the-middle attacks and the lack of encryption in the communication between the card and the terminal.

25:03

💳 Issuer Authentication and Cardholder Verification Methods

The speaker details the process of issuer authentication and the various cardholder verification methods (CVM) supported by the card. They explain how the terminal decides which verification method to use based on the CVM list provided by the card. The talk also covers the concept of issue action codes and how they influence the terminal's decision to perform an online or offline transaction.

30:05

🛡️ Terminal Risk Management and Cryptogram Generation

The speaker discusses the terminal's role in risk management and how it uses the card's application file locator (AFL) to determine which data to read and authenticate. They explain the generation of cryptogram by the card, which is essential for proving the card's involvement in a transaction. The talk also highlights the importance of the transaction counter and the card's ability to approve or decline transactions based on the provided data.

35:06

📑 Certificates and Data Authentication in EMV

The speaker provides an in-depth look at the issuer certificate and how it is used to decrypt data on the card. They explain the structure of the certificate, including headers, trailers, and public key modulus. The talk also covers the process of static data authentication using a certificate that contains a hash of the card data, allowing verification of the data's integrity.

40:06

🔎 Exploring the EMV Transaction Process

The speaker walks through the EMV transaction process, from confirming the cardholder's identity with a PIN to generating a cryptogram for transaction authorization. They discuss the use of different fields in the transaction data, such as the amount, transaction type, and random number. The talk also touches on the card's ability to approve transactions offline and the potential for online authorization.

45:08

📉 Limitations and Risks of the EMV Protocol

The speaker concludes by highlighting the limitations and risks associated with the EMV protocol, including its age and the reluctance of card organizations to move away from legacy technology. They discuss the solid nature of the crypto and hardware but emphasize that the protocol's general problems are more significant. The talk also mentions the transfer of these risks to new technologies, such as contactless payments.

50:09

🤝 Closing Remarks and Q&A Session

The speaker wraps up the talk with an invitation for questions, emphasizing the availability of the presentation slides and software on GitHub. They address audience questions about the possibility of using magnetic stripe data for transactions, the potential for tampering with magnetic stripe data, and the aspects of card data that are signed and authenticated. The speaker also comments on the variability of the ISO 8583 standard across different countries and its impact on transaction processing.

Mindmap

Keywords

💡EMV

EMV stands for Europay, Mastercard, and Visa, referring to the global standard for credit and debit card transactions that use a chip (integrated circuit) to store and protect cardholder data. It is central to the video's theme as it discusses the protocol's security, history, and technical aspects.

💡APDU

APDU stands for Application Protocol Data Unit, which is the protocol used for communication between a smart card and a card reader. In the context of the video, APDU is a key concept as it explains the packet structure for data exchange between the card and the terminal during a transaction.

💡PCSC

PC/SC is a set of standards that define a method for application programs to communicate with smart cards. In the video, PCSC is mentioned as a way to connect a card reader to a laptop, which is crucial for the speaker's demonstration of interacting with the card.

💡Smart Card

A smart card is a plastic card that contains an embedded microprocessor. In the video, the smart card is the primary subject, as it delves into how data is stored and processed on these cards, particularly in the context of EMV transactions.

💡Cryptogram

A cryptogram is a piece of information that has been encrypted in some way. In the context of the video, the cryptogram is a key element in the transaction process, used to authenticate the card and ensure the transaction's legitimacy.

💡Magnetic Stripe

The magnetic stripe is the band on the back of a credit card that stores the cardholder's account information. The video discusses the magnetic stripe as a fallback or supplementary method to the chip in cases where chip technology is not used or fails.

💡Contactless Payment

Contactless payment involves using a card or device with near-field communication (NFC) to make a payment without physically inserting or swiping the card into a reader. The video touches on this technology as an evolution of the EMV standard, noting its similarities and security considerations.

💡Cardholder Verification Method (CVM)

CVM refers to the method used to verify the identity of the person presenting the card, such as a PIN, signature, or biometric verification. In the video, CVM is discussed as a critical part of the transaction process, highlighting the different types and the order of verification methods.

💡ISO 7816

ISO 7816 is a series of standards that define smart cards and their interfaces. The video mentions ISO 7816 as the standard that deals with the physical characteristics and communication protocols of the card, which is foundational to understanding how the card operates.

💡Tag-Length-Value (TLV)

TLV is a method of encoding data in a form that is widely used in computer networking and storage. In the video, TLV is discussed in the context of how data on the card is structured, with the speaker explaining the importance of understanding TLV for parsing data from the card.

💡Man-in-the-Middle Attack

A man-in-the-middle attack is a type of cyber attack where the attacker secretly relays and possibly alters the communication between two parties who believe they are directly communicating with each other. The video discusses this type of attack in the context of card transactions, highlighting the vulnerabilities present in the unencrypted data transmission between the card and the reader.

Highlights

EMV stands for Europay, Mastercard, and Visa, and is the protocol used between the chip on a card and the payment terminal.

The presenter has extensive experience in credit card processing and fraud management, having worked in a German bank and later as an independent contractor.

The EMV protocol is quite old, dating back to the 1980s, and is pragmatic in nature with less emphasis on security.

The technology behind EMV is being mandated in the United States, which will lead to a significant increase in its usage.

The presenter demonstrates how to use a card reader that costs around $20 to perform transactions, indicating low barriers to entry for this technology.

ISO 7816 is the standard that defines the physical characteristics and communication with the card, which is handled by the PC/SC (PCSC).

APDU (Application Protocol Data Unit) is the method of exchanging packets between the card and the host.

The EMV specifications are extensive, with the main application framework described in four books totaling around 800 pages.

Book three of the EMV specifications is particularly important as it contains the specific APDUs and instructions exchanged with the cards.

The PSSE (Payment System Specific Environment) is a file that lists the applications on a card that the card wants the terminal to know about.

The process of authenticating a card and confirming a transaction involves several steps, including static data authentication and cardholder verification.

The card itself performs cryptographic functions and is not just a storage device for data, contrary to common misconceptions.

Contactless payment technologies operate on similar principles to the EMV protocol, with the same potential vulnerabilities.

The presenter discusses the potential for man-in-the-middle attacks due to the unencrypted nature of data transmission between the card and the terminal.

The risk of skimming attacks persists even with chip cards, as fraudsters can insert skimmers into ATMs to capture data.

The EMV protocol has many specifications that are not always implemented perfectly, leading to potential security vulnerabilities.

The presenter's software and slides are available on GitHub, providing a resource for further exploration of the topics discussed.

Transcripts

play00:15

okay hi um and I don't know if anybody

play00:17

doesn't know what EMV is and just sort

play00:18

of came in here by random luck EMV is

play00:21

stands for europay master visa and it's

play00:24

it's the protocol that's spoken between

play00:25

the chip and and and the payment

play00:27

terminal that you have um

play00:30

the Euro pay thing should already

play00:32

suggest to you how old this is because

play00:33

Euro pay hasn't not been around uh for a

play00:37

long time um about myself I worked for a

play00:40

long time at a at a big German Bank uh

play00:42

in the in the credit card processing in

play00:43

the backend and then I was working the

play00:45

last several years at a at a consultancy

play00:49

doing mainly uh well doing General

play00:51

technical things but mainly focused

play00:54

on uh credit card processing backends

play00:57

fraud management stuff like that and was

play01:00

involved in several projects where we

play01:01

actually wrote the software that that

play01:03

runs on the

play01:04

chip um since this year I've been I've

play01:06

been working as an independent

play01:07

contractor and and working on a lot of

play01:09

the same sort of

play01:11

um uh

play01:13

topics um the motivation for this talk

play01:16

this talk is kind of weird it's it's

play01:17

it's it's sort of a strange mixture it's

play01:19

really basic really introductory to EMV

play01:22

on the other hand it's super low level

play01:24

so there's a lot of bits and bites um

play01:26

we're not going to see a lot of pictures

play01:28

or anything it's going to be a lot of

play01:30

text and

play01:31

numbers I'm not really revealing any

play01:33

secrets of the credit card industry I'm

play01:36

not showing any super special hacks and

play01:39

this stuff is really really old I think

play01:41

on the first Congress that I was at the

play01:43

18 C3 um there was already a talk about

play01:47

this and so the question is why would

play01:49

you actually want to deal with it one of

play01:51

the things is um this technology is

play01:55

being mandated in in the United States

play01:57

soon so there's going to be a giant

play02:00

uptake in usage and the other really

play02:03

part of the thing that makes it

play02:04

interesting is that this protocol is so

play02:05

old and this was always a very um

play02:08

pragmatic protocol and this back in the

play02:11

80s so there's not a lot of um Security

play02:13

in it um I'm also not really going to go

play02:16

into low-level Hardware stuff um

play02:19

attacking these chips I'm not going to

play02:21

go into any any attacks on the crypto

play02:23

and what you'll see though is that this

play02:25

this protocol is so rudimentary and

play02:28

weird that it's not really necessary

play02:30

there's so much more that you can do and

play02:32

it's also if you were at Carson and

play02:33

Dexter's talk um about you know scraping

play02:37

off the chips and and actually taking

play02:39

pictures uh and and probing the chip in

play02:41

operation that's I mean they said this

play02:44

was this would be an this is easy but um

play02:47

this is a lot easier I mean you can you

play02:48

can you can just look into your own card

play02:50

see what sort of data is stored on it

play02:51

and and do these own transactions with a

play02:53

with a card reader that cost maybe maybe

play02:55

20

play02:56

bucks so I'm going to go through a

play03:00

this is more or less to get you started

play03:01

on on doing the stuff yourself so I'm

play03:03

going to go through a bunch of acronyms

play03:04

and specifications and stuff I mean the

play03:07

the stuff that the card can do or that

play03:08

it could do in the 80s was really really

play03:11

rudimentary so the protocol is actually

play03:12

really easy the hard thing is though

play03:15

that it's a very steep learning curve

play03:16

there's a lot of weird technology and

play03:19

acronyms and and and things that aren't

play03:21

really in common usage that you're not

play03:22

really used to so going to start off

play03:24

with pcsc uh pcsc is how you're going to

play03:27

connect to how you're going to connect a

play03:28

reader to your um to your to your laptop

play03:33

basically almost all um operating

play03:35

support pcsc on some level most

play03:37

languages have bindings the transactions

play03:40

that I'm going to do are with some Ruby

play03:42

code I wrote um this smart card project

play03:45

is are the um are the pcsc bindings for

play03:48

Ruby um my um the stemo code that I'm

play03:54

going to I'm going to be showing that

play03:55

I'll be talking with this card with um

play03:58

is available in in my GitHub r

play03:59

repository under 29 C3 and while I'm

play04:02

showing URLs there is this open scdp

play04:06

Smart Card shell which is a JavaScript

play04:08

implementation which is a lot more

play04:09

feature complete so if you want to play

play04:11

around with smart cards that's a really

play04:13

good suggestions and they also have

play04:14

stuff for for dealing with Sims or

play04:16

German the German health card and and

play04:18

things like

play04:19

that um so basically that was already

play04:22

the first point I mean you don't need a

play04:24

special terminal all of the stuff and

play04:26

and talking to the card is entirely

play04:27

standardized you don't need to buy

play04:29

something like this you can just go to

play04:30

Amazon and get one of these Swiss army

play04:31

knife uh card readers that um if you're

play04:34

paying 20 bucks for them you're getting

play04:36

ripped off um and they will work just as

play04:38

good as anything else so it's it's it's

play04:40

a very very low entry to uh barrier to

play04:43

entry um so I'll I'll go ahead and start

play04:48

my little shell and basically this is

play04:50

just I can see now I have one reader

play04:53

plugged in fantastic I'll put my card

play04:56

in

play04:58

um

play05:00

um and then what is it dump card dump

play05:03

card

play05:05

data show card show card um that will

play05:08

come later um so this is this is already

play05:11

the basic interaction with the card

play05:13

we're connected to the card and and the

play05:15

session has has already started at this

play05:19

point um and it's you know we're maybe

play05:23

two or 3 minutes into the talk so

play05:28

um all this low-level stuff of how chip

play05:31

cards are dealt with is is is taken care

play05:33

of in in ISO

play05:35

7816 uh you don't really have to worry

play05:37

about those standards you don't really

play05:38

need to get them if you are really into

play05:40

standards you need book three and four

play05:45

um they Define sort of the low-level

play05:47

characteristics of how um the the

play05:49

physical layer communication with the

play05:51

card which is basically just a uart it's

play05:54

just a simple serial

play05:56

interface um and level four uh is is

play06:00

sort of the the the transport layer

play06:02

there's rudimentary how how how to talk

play06:05

back and forth with the card uh again

play06:07

you don't need any of this the next five

play06:09

slides will sort of be all you need to

play06:11

know about it first thing that we saw

play06:14

here down here this answer to reset um

play06:17

is basically just the um ATR is the

play06:20

thing that you will hear it basically is

play06:23

just the terminal um settings the B rate

play06:26

and things like that there's one

play06:28

interesting thing about it if if we're

play06:29

approaching it from a from a really high

play06:31

application Level like we are which is

play06:32

the historical btes um and the vendor

play06:35

can put anything in there so sometimes

play06:37

it helps to have those historical bites

play06:39

to identify who the vendor of a of a

play06:41

card is that you're dealing with but you

play06:43

normally don't need to do that because

play06:44

most of the cards if you look at yours

play06:46

will have the actual um vendor printed

play06:49

on the back of the card um you will see

play06:52

like credit card numbers and stuff from

play06:53

this card this is a demo card so you

play06:55

don't need to worry about that I'm I'm

play06:58

I'm being a total idiot yet um and I'm

play07:00

using a demo card for the one hand I

play07:02

don't want my credit card number to be

play07:04

uh known to you guys and on the other

play07:06

hand um for the demo cards that that get

play07:09

handed out at like trade fairs and stuff

play07:11

you know the keys that are on the card

play07:13

so you can uh you can you can reverse

play07:15

engineer the crypto um with

play07:17

them um so 78164 does a it describes a

play07:21

couple of further things first they have

play07:24

this weird file system like thing that

play07:26

you don't really need to know much about

play07:28

but if you see terms like EF MF DF those

play07:31

are either directories EFS are

play07:33

Elementary files MF is the master start

play07:37

of the file but don't really they call

play07:40

it a file system but don't really think

play07:41

of it as a file system a file in on a

play07:44

smart card can be anything from an

play07:45

application to some sort of cyclic

play07:47

buffer to to all sorts of things but um

play07:51

em doesn't use a lot of that so we can

play07:54

we can skip it the main thing that you

play07:55

need to know is apdu apdu is basically

play07:59

the the packets that get exchanged

play08:01

between the card and and the host um and

play08:03

it's just a bunch of um bites which I

play08:08

purposely put an exclamation mark behind

play08:10

it it really I mean you're just

play08:12

basically assembling five or six bites

play08:15

sending them to the card and getting

play08:16

them back there's very little crypto

play08:18

involved in in the communication so all

play08:21

of the communication that you'll see in

play08:23

my demo I'm I'm not doing anything

play08:25

special to decrypt what's going on I

play08:27

mean these are really the bites that are

play08:28

getting back and forth um so I'll just

play08:31

go through it on one example if you want

play08:32

to select one of these files or in this

play08:35

case um an application there's always a

play08:38

class bite a class bite of zero says

play08:40

this is this apdu select file is defined

play08:45

in the ISO standards most of the EMV

play08:47

ones start with 80 that means it's a

play08:48

proprietary apdu stuff like that I'm

play08:51

just going to skip over because it's not

play08:52

really that important to to to dealing

play08:54

with and then there will be some

play08:56

instruction bites um some some apdus

play08:59

will take uh parameters so there's two

play09:01

bytes for parameters then if you're

play09:04

transmitting data you you there's one

play09:06

bite for the length of the data and

play09:08

finally um the data that you want to um

play09:11

transmit so this is basically the

play09:13

application name of a visa application

play09:16

on a card what we're doing here is

play09:18

selecting the visa application to to

play09:20

make a to make a payment

play09:23

transaction um there's one more thing

play09:25

that we

play09:26

saw here that this card speaks in the

play09:29

protocol t t equals

play09:31

z um there's there's two low-level

play09:34

Communications protocols defined as I

play09:36

said this whole thing is just a uart and

play09:38

there's one character-based way of doing

play09:40

it and one block based doing it and all

play09:43

that you really need to know

play09:45

is you can't if you are using t0 um you

play09:51

can't send and receive data in the same

play09:54

um packet so if you wanted to have this

play09:57

last Le is length expected if you you

play09:59

expect data back from the card you have

play10:00

to tell the card how much data um you

play10:02

want back and um if you're using T

play10:05

equals z you can't send data and expect

play10:07

to receive data in the same uh packet

play10:10

but we'll see how that will work in a in

play10:12

in just a second um but basically what

play10:15

you really need to know is that the

play10:16

difference uh doesn't really matter

play10:18

because T1 is complicated the terminals

play10:20

all speak both and nobody actually uses

play10:23

T1 uh at least in in payment cards so

play10:25

just ignore that so we we just learned

play10:27

this select command

play10:29

and

play10:31

um and we'll just execute it against the

play10:34

card I don't know is this large enough

play10:36

to see or should

play10:38

I yeah so basically

play10:43

um right here are the bites that we saw

play10:45

on the slide uh and I used a different

play10:48

file name I used the one. pay no one

play10:51

pay. cy. DDF 01 DF is a directory file

play10:58

um but basically this is just a

play11:00

well-known file name for a file that's

play11:03

called the psse the payment service

play11:05

environment which um Can is basically a

play11:10

table of contents for the card a card

play11:11

can have several applications and these

play11:14

are the applic and the psse lists the

play11:17

applications that the card wants you to

play11:20

know about and use so there could be

play11:21

other applications on the card um but

play11:24

there don't necessarily need to be you

play11:25

don't always need a PSC we can um

play11:29

the response that we get back so I said

play11:31

you can't send and respond in the same

play11:35

in the same Transaction what happens

play11:37

when you do that when you need to do

play11:38

that anyway in t equals z is

play11:42

um okay uh if you're this 9,000 is is

play11:46

interesting the card always um responds

play11:48

with two status words one and two and if

play11:51

you get 9,000 that's perfect that's okay

play11:54

so that's a HTTP 200 um most other

play11:57

status codes mean errors um but

play12:01

basically this select gets a 6126 back

play12:04

and all the

play12:06

61 status word one error codes mean

play12:10

there's more data coming and it will be

play12:12

26

play12:14

bytes so basically this is one

play12:17

transaction you can you can ignore the

play12:19

second one the second one gets um gets

play12:21

executed automatically when you get the

play12:24

6100 um response and it says please give

play12:28

me back the 26 bytes that you told me

play12:31

that you that you

play12:33

um that you can give me back so we can

play12:37

look at the

play12:38

response uh this is all tag length value

play12:41

um in here and this is something that's

play12:44

called the file control information this

play12:47

is a basically a metadata that

play12:49

contains

play12:51

um data about the file that you just

play12:54

selected one of the things it this one

play12:56

contains is the name of of the actual

play12:59

file that we selected thanks very much

play13:01

uh just typed that in and um this file

play13:04

is also identifiable by a short file ID

play13:08

now the special file has

play13:11

records and each

play13:15

record uh

play13:18

basically tells us about one application

play13:22

on the

play13:23

card um so this first one this first uh

play13:28

record

play13:29

um

play13:30

contains so this this card contains two

play13:34

application one is a Visa debit card and

play13:36

one is a credit

play13:37

card um and so I I read the first record

play13:41

out of this PSC file and it tells me

play13:43

okay this there's one application that's

play13:44

called Visa debit and sometimes you get

play13:46

that shown in in a uh in a terminal that

play13:49

you're that you're that you're paying

play13:51

with and it also says the priority of

play13:53

that application so if you need to make

play13:55

a choice terminal this one has Priority

play13:58

One so so then we can look at uh check

play14:01

for more

play14:03

records um there's a second application

play14:07

on here the credit application that has

play14:09

priority too so um and then we the

play14:14

terminal will keep doing this until it

play14:15

has a list of all the records finally it

play14:17

gets a there's no such record um you can

play14:20

you can quit looking

play14:23

now okay so that was the basic of how an

play14:26

apdu works just these these

play14:30

these the bites on the screen get sent

play14:32

back and forth and clear text that's

play14:34

that's it and and the pcsc libraries

play14:37

have a command transmit data and you

play14:39

just give it a raw buffer of

play14:42

data so it's fairly easy to program but

play14:45

very low

play14:46

level um

play14:48

so em has has a huge number of

play14:52

specifications um the the main

play14:54

application framework is defined in

play14:56

books 1 2 3 and four that's about 800

play14:59

Pages um and I'm just going to skip over

play15:01

really quickly what what which ones are

play15:03

important and and which ones you should

play15:05

look at um book one is maybe interesting

play15:08

because it contains a summary of all of

play15:10

the stuff that's in the iso Norms how

play15:12

these apdus are set up how the lowlevel

play15:14

UR communication is how the ATR is set

play15:17

up and stuff like that so it's just a

play15:19

review of how this stuff works that's

play15:20

something that that's good to look at um

play15:23

book two is the one of the most

play15:26

interesting um books it contains all of

play15:28

the crypto that's done by the card so um

play15:31

the card doesn't get

play15:33

its it gets its own keys but those are

play15:36

derived for master keys from the bank

play15:38

all of these key derivation algorithms

play15:40

are described in here all of the

play15:43

certificates that are um uh placed onto

play15:47

the card the format of these

play15:48

certificates are described in this book

play15:51

too and the interesting thing is if you

play15:53

think certificates usually you think

play15:54

x509 certificates but um in the EM SP

play15:58

everything was reinvented and and is a

play16:00

little bit different than than you would

play16:01

expect it to be um the the most

play16:04

important book to look at is is book

play16:06

three which um contains all of the

play16:09

specific apdus and the instructions that

play16:12

are exchanged with the cards um how

play16:15

those work how those

play16:16

interact um and one of the most

play16:19

important things and I put a little

play16:21

heart to emphasize this point is that

play16:23

there's a data dictionary that explains

play16:26

what all of the tags mean you know I um

play16:31

so so here all of the the the you know

play16:33

the tags are are separated um but

play16:36

basically you know you don't know what

play16:38

50 means but you have to look it up and

play16:40

and know that oh this is application

play16:42

label and the statea dictionary is

play16:44

really the thing that you work with most

play16:45

when when when you're dealing with the

play16:47

data in the in the card um another thing

play16:51

that you could look at and this is also

play16:53

freely available on the net where um

play16:55

this tlv be is is is is defined this

play16:58

this is an um International

play17:00

telecommunications Union standard um and

play17:04

there's some tricky bits to to doing tlv

play17:06

the way that they want you to do it then

play17:09

there's a book four which you can

play17:10

basically ignore I mean it's it's kind

play17:12

of funny because it it it tells you all

play17:13

sorts of stuff of how you should enter

play17:15

the pin and and how you could Implement

play17:17

a virtual machine whether you should

play17:19

interpret by code or or translate it

play17:22

into the native instruction set of your

play17:24

terminals Hardware

play17:26

architecture all the way to um what what

play17:29

the receipt is supposed to look like

play17:31

that that the thing prints um but it

play17:34

fails to mention stuff like what data of

play17:36

the transactions the terminal supposed

play17:38

to save to present to the bank later

play17:40

it's it's really weird I've never used

play17:41

it it's it's it's sort of fun to skim

play17:43

through but it's not useful um CPS is

play17:46

you probably won't ever need it this is

play17:48

the application that's on the card

play17:50

before it's in the field that in the

play17:52

personalization Bureau will be used to

play17:54

place your personal data onto the card

play17:57

but if if you're dealing with if if you

play17:59

want to take a closer look at cards this

play18:00

is something useful to look at because

play18:02

it um provides some some really useful

play18:05

Insight of how data is structured in the

play18:07

card and what what data is is actually

play18:09

placed on

play18:11

it finally um there is CPA so these

play18:16

books one through four they

play18:18

describe um a general framework of how

play18:21

to

play18:23

make uh applications for financial

play18:26

transactions they don't actually

play18:29

describe an

play18:30

implementation um EMV published one

play18:34

standard for an application and this is

play18:37

sort of interesting to look at to see

play18:39

what actually goes on um books 1 through

play18:42

4 describe really well the the external

play18:45

interface but they don't really give you

play18:47

a good indication of what the card is

play18:48

supposed to do internally how it's

play18:50

supposed to check the data they also

play18:52

leave open a lot of data structures and

play18:55

what they mean they just say what we'll

play18:57

see later for example get card

play18:58

verification results which is a big bit

play19:01

map of literal checks that the card did

play19:04

but it doesn't say how what what each

play19:06

bit is supposed to mean the the actual

play19:09

implementation um specifies that sort of

play19:12

information there's also what you will

play19:14

come across CCD which is also called

play19:17

doublin core uh it's Common Core

play19:19

definitions and that goes that's spread

play19:22

out through all of um through all of the

play19:25

standards it it specifies some of the

play19:28

missing pieces so you can um like like

play19:32

it it will specify a base card

play19:34

verification results bitfield what you

play19:36

should put in

play19:37

there um the specifications that would

play19:40

be most

play19:42

interesting

play19:44

are but you don't really need at the

play19:46

level that that we're dealing with are

play19:48

the mchip and bsdc specifications those

play19:50

are the concrete implementations for

play19:52

MasterCard and Visa unfortunately those

play19:54

are proprietary and you can't really get

play19:56

at those um with MasterCard you really

play19:59

you can't even get the names or the

play20:01

current versions of them unless you're a

play20:03

MasterCard vendor um thisa you can at

play20:06

least get a list of what the current

play20:08

specifications are called and and which

play20:09

ones are available but you'll have a

play20:11

hard time um finding

play20:14

them um Okay so we've we've gone over

play20:17

all the specifications and we're going

play20:18

to go into uh into actually what happens

play20:21

and and do a try to get one pound off of

play20:24

this card um so the general flow of the

play20:27

trans trans actions in in in normal

play20:30

human terms would be card and terminal

play20:32

introduce each other um figure out which

play20:35

application to use so that's that's the

play20:38

part we've done so far um then this is

play20:41

what I call First worst first date ever

play20:43

it's not just tell me a little bit about

play20:46

yourself but it's a tell me what

play20:48

questions to ask you about

play20:51

myself

play20:53

um that's what the terminal says to the

play20:55

card and then the card responds with a

play20:57

number

play20:58

of records that it wants the terminal to

play21:01

read um it doesn't really check that it

play21:04

reads those records or only those

play21:06

records um but

play21:08

it that that's how the mechanism worked

play21:10

just to introduce it then there's some

play21:12

simple mechanisms to make sure that the

play21:14

data that the card returns are actually

play21:16

valid data and that they come from a

play21:17

real bank and stuff like that um then

play21:21

there's

play21:22

uh what's called card holder

play21:24

verification so that might be something

play21:26

as simple as you sign a piece of paper

play21:29

so it happens totally offline it might

play21:31

be something that the card checks the

play21:33

pin or that the terminal or the ATM

play21:35

sends the PIN to the bank to be checked

play21:37

and gets a response back and finally the

play21:40

card will generate a cryptogram with a

play21:43

um with a symmetric secret key um that

play21:47

the merchant who owns the terminal can

play21:50

later present to the bank to prove that

play21:52

this card was actually involved in the

play21:54

transaction so one of the common

play21:56

misconceptions is that the chip is

play21:59

basically just a dumb storage of data

play22:01

that's going on so that's not really

play22:04

what's happening the chip itself is a

play22:06

little computer um and what

play22:10

theoretically happens there's a there's

play22:12

a key on the on the card that can't be

play22:18

extracted

play22:21

um and the terminal gives that key a

play22:24

random number it encrypts that random

play22:27

number and that way

play22:28

uh the merchant can prove that this card

play22:30

was actually physically involved in the

play22:32

transaction and then nobody just copied

play22:34

the the card

play22:35

number okay so we'll do the um tell me

play22:40

what to

play22:41

uh uh tell you about myself or whatever

play22:44

I called it um so first we want we we we

play22:48

um we want to select this the vstc

play22:51

application which we figured out the

play22:53

file name of which we figured out from

play22:56

um from reading the psse and we get

play23:02

um we get back another thing of uh file

play23:05

information data uh basically the same

play23:08

thing again it tells me the the file

play23:10

name it tells me the application labels

play23:12

and some proprietary discretionary stuff

play23:15

as soon as you see issue or

play23:16

discretionary or discretionary or

play23:18

something like that you know you can

play23:19

ignore it um and it also contains an

play23:22

application priority indicator that was

play23:24

in the PSC as well so a lot of cards

play23:26

don't actually have this PS see they

play23:29

um the the terminal will just try to um

play23:33

select the applications directly and and

play23:35

we'll put them in the right

play23:37

order so after

play23:40

we've um after we've selected the first

play23:43

thing we do is is a get processing

play23:45

options

play23:47

command and

play23:52

uh now I can see this is pretty opaque

play23:55

data this is response message template

play23:57

form format one whatever that means um

play24:00

but this is kind of the most important

play24:02

um part so um get processing options

play24:06

there can be something that's called a

play24:08

processing data object list which would

play24:11

be returned in the FCI and the select

play24:14

that wasn't the case here that will be

play24:16

the card telling the terminal what sort

play24:18

of data the terminal should provide to

play24:21

it so the it could say um please when

play24:24

you call this get processing options

play24:26

command tell me what sort of terminal

play24:28

type you are are you an ATM are you a

play24:30

candy vending machine or whatever um

play24:34

what the card returns are two data two

play24:36

pieces of data AIP and

play24:38

AFL um and this is format one you

play24:41

remembered that from the

play24:44

response message template format

play24:47

one um and it contains two bytes of

play24:54

AIP so and the second one is really easy

play24:57

to explain because all those bits in

play24:59

there are reserved for future use so

play25:01

they're they're they're always zero and

play25:03

in this case um 5c I've circled all the

play25:06

all the bits out of the specifications

play25:07

what they uh what they mean um this card

play25:10

supports

play25:12

stda um card holder verification is

play25:15

supported it's that's always supported

play25:17

terminal risk management is to be

play25:19

performed so the card tells the terminal

play25:22

kind of what to do which you need to

play25:23

keep in the back of your head it does

play25:25

that quite a lot um

play25:28

and issue issuer authentication is

play25:30

supported so most of these things don't

play25:31

really make sense because issue

play25:33

authentication is always supported card

play25:35

holder verification is always

play25:37

supported um and the thing to explain

play25:39

here is DDA and CDA down here in the

play25:42

bottom this card only supports SDA

play25:44

that's static data analysis and that is

play25:48

how uh in the in the next step once we

play25:51

have all the data how we check that this

play25:52

data is actually from the bank in the

play25:54

static data authentication all of the

play25:56

data that's to be authenticated is

play25:58

hashed that hash is put into a

play26:01

certificate that's signed by the issuer

play26:04

and so I can get all the data off off of

play26:07

the card hash it decrypt the certificate

play26:10

make sure the

play26:11

hashes um are identical and then I can

play26:14

see well at least this is the data that

play26:17

the issuer intended to be on this card

play26:21

why this is important we'll we'll we'll

play26:22

see in a minute um unfortunately this is

play26:26

because it's static um it's it makes the

play26:30

card sort of trivial to clone because

play26:31

the certificate is on the card and you

play26:33

can just read it off of the card and you

play26:35

can just write it onto another card and

play26:37

so any copy that you make of this card

play26:39

will automatically have a correct um

play26:43

certificate um DDA will also

play26:47

have um a public will have a public key

play26:51

mechanism where the um where the

play26:53

terminal can give the card a random

play26:56

number and it will cryp that with its

play26:58

private key and the terminal can decrypt

play27:00

it so it knows all of the data is

play27:01

correct and this card is actually in

play27:05

possession of a secret that's that's

play27:07

supposed to be on it that I can verify

play27:09

because the general key on the card is

play27:11

symmetric only the bank can verify that

play27:14

the terminal can never can never check

play27:16

if if any cryptogram that the card

play27:17

provides is is actually authentic or

play27:21

real but again this was a pragmatic

play27:24

protocol back in the 80s and back then

play27:26

having calculating uh RSA or something

play27:29

like that was quite expensive putting a

play27:31

crypto processor on the cards is still

play27:33

quite expensive um so you can save 50

play27:35

cents per card or something by not

play27:37

supporting it I think they're starting

play27:39

to mandate using it now but this is

play27:40

still this is still fairly uh recent

play27:43

card so the next point I'm not going to

play27:45

go into it too much this is the

play27:47

application file locator and it's a list

play27:49

of four byte entries so these are three

play27:51

application file locator entries the

play27:54

first bite of each entry um contains the

play27:59

short file ID that the card wants you to

play28:03

read um and it's for some reason it's

play28:05

shifted by three so it's it's the high

play28:08

five bytes of that uh the second bite is

play28:11

the first record to start reading the

play28:14

next bite is the last record that you to

play28:17

read so this basically means short file

play28:19

ID one read the first record only short

play28:22

file ID read records 1 to three short

play28:25

file ID 3 read records one and two and

play28:28

the last bite here is interesting

play28:32

because that indicates which record will

play28:34

actually go into the static data

play28:36

authentication so even though this isn't

play28:39

really a safe way of authenticating the

play28:41

card not even all of the data that's

play28:43

being read from the card is being

play28:46

authenticated um

play28:49

so so here read records so it does it

play28:53

goes through here um that Parts the AFL

play28:57

and it read records uh short file ID

play29:00

record short file ID one record one 2

play29:04

one two and

play29:07

three

play29:10

and two records from short file ID 3 so

play29:14

I did that correctly in the

play29:17

slides This Record here short file ID 3

play29:20

record one is the only one that is ever

play29:25

authenticated so

play29:28

even with this and we can I still have

play29:31

the last one in the buffer so we can

play29:32

look at that and that's that's really

play29:37

a all of this information that we'll go

play29:40

into into more detail um like the

play29:42

currency that the card expects the the

play29:45

expiration date and the effective date

play29:46

of the card things like that aren't ever

play29:49

checked for authenticity in this

play29:50

specific card um usually this is this

play29:53

this information will also go into into

play29:55

the

play29:55

certificates so

play29:58

this is where the dump card data um came

play30:01

from so this is all the data that we

play30:02

collected from the

play30:04

card um the first the first field is is

play30:07

fairly simple it's the card holder name

play30:09

your name would be in that field here

play30:11

it's simply one because it's

play30:13

a marketing thing um this is quite

play30:17

interesting um and also as a as a

play30:20

general attack um track two and track

play30:23

one data if you've done anything with

play30:25

cards this might seem familiar because

play30:28

this is how magnetic stripes are

play30:29

structured so basically this card this

play30:33

this uh this smart card provides the

play30:36

precise data that's also on the magnetic

play30:39

card so if you can read out all of this

play30:41

data you have enough data to clone the

play30:43

magnetic stripe and and it's already

play30:45

perfectly formatted in the in in the way

play30:47

that it's supposed to be formatted on

play30:48

the magnetic stripe the reason for this

play30:50

is is that the the bank backend systems

play30:53

are very very old and they don't

play30:55

necessarily check all of this uh all of

play30:58

all of this uh C data that's coming

play31:00

because it's more complicated and so

play31:02

what you can do is you can just take uh

play31:04

on some intermediary system throw away

play31:06

everything else but these track data

play31:08

things and then process the transaction

play31:10

as if it were a normal magnetic stripe

play31:12

based

play31:14

transaction um or you can hire uh Visa

play31:18

MasterCard to do something called stip

play31:20

where they will have a system in front

play31:22

of your own back end check all of the um

play31:25

check all of the chip stuff for you and

play31:26

just give you the the magnetic stripe

play31:28

data or you can just ignore to do that

play31:30

and and and and just not check the check

play31:32

the EMB stuff at all um then there's um

play31:36

the issuer certificate the terminals

play31:39

have lots of CA certificates those sign

play31:42

these issuer certificates and you need

play31:43

the issuer certificate to get um to be

play31:48

able to decrypt the uh the the

play31:51

certificate that contains the hash with

play31:53

the with the data that's on the card um

play31:56

and the rest of the data is is basically

play31:58

standard the pan is is is the card

play32:00

number um the expiration date the

play32:02

effective date this is a card that's

play32:05

that's issued in England and in pounds

play32:07

and I'll go into what the other things

play32:09

mean right here service code again is

play32:11

something that comes from magnetic

play32:12

stripes that was one of the things on

play32:14

here I'm going to skip that because

play32:15

we're kind of I don't know if I'll even

play32:17

make it um the first thing that's

play32:19

interesting is application usage control

play32:22

um which is again similar

play32:24

to AIP it's a bunch of big that say what

play32:28

this card may be used for there's two

play32:31

two bites in it the first one is FF so

play32:34

the card could be used for all of these

play32:36

all of these things which and again

play32:39

these categories are are really

play32:41

arbitrary you know I mean what why

play32:43

differentiate between goods and services

play32:45

sometimes differentiating between

play32:46

domestic and international might make

play32:48

sense but why have a why have a card

play32:51

that I can pay with to get my haircut

play32:54

but I can't buy a bottle of shampoo with

play32:55

it you know this is good and services so

play32:58

so it's hard to even configure these

play32:59

things or figure out what they're good

play33:01

for um and the second bite is in in in

play33:03

this specific case because it's also

play33:05

this was the debit card it will allow

play33:07

domestic so if you're in your own home

play33:10

country you can get cash back which

play33:11

would be uh you pay for 10 pounds at at

play33:14

at the store and and you say well please

play33:16

give me 20 20 back um and you might not

play33:19

know where you are internationally so

play33:21

you might not trust stores anywhere else

play33:23

to to to do that validly so I mean I can

play33:26

see how that could make sense the next

play33:28

thing was the CVM list uh it starts off

play33:31

with with two amounts and this is a

play33:32

really really important one um these but

play33:35

these two amounts aren't aren't never

play33:36

used so I'm going to skip over this and

play33:38

then next is a variable length list um

play33:41

each entry is two bytes long so the

play33:43

color coding is is is one entry and

play33:46

these um tell the terminal what sort of

play33:50

cardholder verifications it should

play33:52

attempt to do under what

play33:54

circumstances the first by in in each

play33:57

entry describes the actual card holder

play34:00

verification that the card supports so

play34:03

in this case um this will allow plain

play34:07

text PIN verification by the card I can

play34:09

send the card the pin and it will tell

play34:11

me whether it was correct or not uh it

play34:13

will support signature it will support

play34:16

um the pin being sent to the bank and

play34:19

and being checked there and finally um

play34:22

this is the nicest one uh none it will

play34:25

support that as well

play34:27

and basically the terminal will go

play34:29

through and and basically if it can

play34:31

fulfill one of the conditions and these

play34:32

are the next one the second one is under

play34:34

which conditions should we use

play34:36

this um and if it can fulfill it it will

play34:40

do that else it will try the next one

play34:41

all the way to the end so basically

play34:43

these uh these conditions say um do PIN

play34:48

verification unencrypted if you can do

play34:51

signature if you can else send the PIN

play34:54

to the bank if you can and if not don't

play34:56

worry about it

play34:59

um so this is quite interesting because

play35:03

well we're sort of going to going to

play35:05

going to authenticate the card but um

play35:08

the card never doesn't know what sort of

play35:10

terminal you know it doesn't know if

play35:11

it's in a real terminal or if it's just

play35:13

sticking in a in a cheap card reader at

play35:14

some hacker conference so I can't really

play35:17

trust that I will actually do these uh

play35:19

these verification methods and

play35:20

especially not in this order provided uh

play35:23

another thing to note here and this was

play35:25

a this was a um this was a um one of the

play35:28

important hacks recently um as I said

play35:32

all the data being sent back and forth

play35:34

between the card and the reader is

play35:36

completely unencrypted there's no

play35:39

non-repudiation uh you know the data is

play35:41

not macked so this is perfect Target for

play35:43

man in the middle attacks and so the

play35:45

chip cards are supposed to were supposed

play35:47

to help to mitigate against skimming

play35:49

type um type attacks but it turned out

play35:51

it's a lot easier to actually insert a

play35:53

skimmer into say an ATM

play35:58

and then just um

play36:00

basically read the communication between

play36:03

the card and and and the and the ATM now

play36:06

on top of that it's also fairly simple

play36:08

to modify the um this communication so

play36:12

one of the hacks that was quite

play36:14

interesting so we saw that when when we

play36:16

uh when we read all the data we we we

play36:18

already have the magnetic stripe data

play36:20

ready for cloning and and and making our

play36:22

own card that we can use in Romania or

play36:25

somewhere to to to at an ATM but now we

play36:27

want the pin and

play36:30

technically cards aren't allowed to

play36:32

accept clear text unencrypted pins at

play36:35

ATMs I don't know why they're allowed to

play36:38

do it elsewhere I don't know nobody

play36:40

would ever install a skimmer in anything

play36:42

else but so this hack was basically

play36:44

there was a man in the middle attack a

play36:46

skimmer or a shim type attack that

play36:49

whenever the card um sent the sent the

play36:51

CVM list to the ATM it would say I only

play36:55

support un encrypt pin please give me

play36:57

the pin unencrypted and even though the

play36:59

ATMs wouldn't actually be allowed to do

play37:01

that I don't know maybe because they use

play37:04

like candy vending machine firmware in

play37:06

the ATM they decided okay well if you

play37:08

say you know send it to me unencrypted

play37:10

uh I'll just send it to you unencrypted

play37:12

and then you have the the pin and the

play37:14

and the Magnetic stripe data and if you

play37:16

have a nice GSM module in your in your

play37:18

shim then you can just send that off and

play37:20

immediately run to the next ATM to to to

play37:22

to get

play37:24

money um so and and the whole like I

play37:28

trust the terminal thing um goes on here

play37:31

these are issue or action codes and we

play37:33

have to sort

play37:35

of uh this gets this gets a little bit

play37:38

hairy I'm only going to skim over the

play37:39

details basically while the terminal for

play37:43

the terminal to um to think about what

play37:45

it's going to do it fills out this bit

play37:48

map and basically it has little bits for

play37:51

for each thing that happens like if the

play37:53

static data authentication fails it um

play37:57

it will set that bit if the card is

play38:00

expired it will set a bit here and this

play38:04

and there's basically five bytes of bit

play38:06

maps that can be set and if any of these

play38:08

correspond this condition will take

play38:10

effect so if this bit will get set while

play38:13

the terminal is verifying the card um

play38:17

the

play38:17

terminal the card would like the

play38:20

terminal to decline the transaction

play38:22

immediately so if we have a look that is

play38:26

requested service not allowed for card

play38:28

product so the card might say uh you

play38:30

know I I don't do domestic services so

play38:34

please decline that something like

play38:35

that um if any of these bits are set the

play38:40

card

play38:42

um the terminal should ask the card to

play38:45

go

play38:46

online and the card will generate a

play38:49

cryptogram that will get sent to the

play38:50

bank the bank will decide whether the

play38:52

transaction is uh authorized or not and

play38:55

and and it comes back so these are the

play38:58

conditions under under which that takes

play39:00

place and default is is quite

play39:02

interesting because it's if you should

play39:05

go online but you can't uh you can still

play39:09

do the uh transaction you can try to to

play39:12

to do the card off do the transaction

play39:14

offline with the card and so so I mean

play39:16

the thing to look at here would be the

play39:18

difference uh between those so only in

play39:22

this bit will it will the card actually

play39:23

have to go um online um

play39:28

um and that is transaction selected

play39:31

randomly for online processing so so

play39:35

again these are these are really weird

play39:37

uh combinations of things so if the

play39:38

merchant forced the transaction online

play39:40

if you pressed the button and said I

play39:41

want this to be authorized by the bank

play39:44

the terminal can still try to according

play39:46

to this uh to this information the

play39:47

terminal could still try to do it

play39:49

offline but if there's some sort of

play39:50

random selection mechanism for risk

play39:52

purposes to to you know take every 10th

play39:55

transaction and and send that to the

play39:56

bank and it can't do it then it could

play39:59

still it's it doesn't really make sense

play40:03

so okay so um we're going to confirm the

play40:06

data and I'm basically just

play40:12

uh we'll just show one of these um so we

play40:16

had that issue we had the issuer

play40:17

certificate if if we decrypt that with

play40:20

the um with Visa certificate Authority

play40:23

certificate we get this which based

play40:26

still looks like random

play40:28

bytes

play40:31

um skip over the details so but but this

play40:34

is described in book two because it's

play40:37

crypto related and and certificate

play40:39

related stuff you can see there's a

play40:41

header 6A and a hex value BC and there's

play40:45

a bunch of metadata about the

play40:46

certificate and then the issuers public

play40:49

key

play40:52

modulus um so if we look at the the data

play40:55

more specifically we can see the header

play40:57

6A the trailer uh BC there's an

play41:00

expiration date in there and the

play41:01

interesting part is this bit in the

play41:03

middle which is actually not the entire

play41:06

issue public key because it could be

play41:08

just as long as as as the key that's on

play41:11

the

play41:13

uh as as the ca key and you it's okay so

play41:16

if you have a 1,24 bit um ca key and you

play41:20

want to encrypt something with it it has

play41:21

to be in multiples of 1,24 bits as well

play41:25

so if the ISS key is also 1,24 bits you

play41:29

can't encrypt it all with all of this

play41:31

metadata and you have to leave a bit of

play41:33

the assures public key out so this is

play41:36

called the remainder which was all also

play41:38

in here and so to verify this basically

play41:40

you have to take the

play41:43

leftmost digits then you put the

play41:46

remainder on it then you hash it and

play41:48

then you make sure that this hash

play41:50

corresponds instead of putting the whole

play41:52

key into the card and just putting the

play41:53

hash in there uh they make things rather

play41:56

diff difficult to deal

play41:57

with um so this SDA um certificate I

play42:02

won't go into too much it's very similar

play42:05

um if we decoded it it would look like

play42:07

this it has tons and tons of padding and

play42:09

then it only contains a hash and this

play42:12

hash is basically a hash over the record

play42:15

that was marked in the AFL the

play42:17

application file locator that has the

play42:19

weird short file ID shifted by three in

play42:22

it if you remember it it had one marker

play42:25

that says

play42:26

this is the data to authenticate which

play42:29

in our case was just the card holder the

play42:31

card number and this is basically a hash

play42:34

over that data so you can take that

play42:37

record hash it decrypt the certificate

play42:39

make sure the hash is coincide and then

play42:42

you know this is the way that the isure

play42:44

wanted the uh wanted actually put the

play42:47

data onto the card uh if this card

play42:50

supported um public key encryption there

play42:53

would also be uh there would be one

play42:55

further certificate

play42:56

um on the card which contains the card's

play42:59

public

play43:00

key um and if it's supported

play43:04

um and there's an option to put a third

play43:06

public key on there which will be used

play43:08

to to encrypt the pin um basically what

play43:11

happens is

play43:14

um the um the cards public key

play43:18

certificate will also contain all of the

play43:20

static data but it will also have a key

play43:24

uh inside of it so you can recover that

play43:27

key and then you send the card a random

play43:29

number the Rand the card will encrypt

play43:31

that random number with the private half

play43:33

of that key you can decrypt it and then

play43:35

you don't only know that the data that's

play43:37

on the card is what the issue intended

play43:39

to be on the card but that the card also

play43:41

contains the the corresponding secret

play43:43

and is able to to do calculations with

play43:46

it this is if you if you want to have a

play43:48

look at that it's in also in book three

play43:49

in the the uh the command is internal

play43:54

authenticate so finally finally we

play43:56

confirmed the card holder what we did in

play43:59

uh we saw this card

play44:02

does uh offline unencrypted pin the pin

play44:06

is formatted in this very special way uh

play44:09

two is an indicator that this is done in

play44:11

a very special way four is the length of

play44:14

the pin and then you have uh the pin is

play44:16

BCD coded um so you could have up to uh

play44:20

two two three four five six I think this

play44:22

is a you could have like TW a 12 digit

play44:25

PIN if wanted to on the card um so then

play44:28

we just say verify the pin I don't know

play44:30

if I need to put pin in yep and it was 1

play44:34

2 3

play44:36

4 which is incidentally the combination

play44:39

on my

play44:40

luggage um and the 9,000 again that's

play44:43

always the status word that says okay so

play44:44

this is the right pin as as the

play44:48

um the terminal now knows well this has

play44:51

to be a legitimate card

play44:52

holder

play44:54

um so finally we need to seal the deal

play44:59

now we had I left out two things and

play45:01

that was the SE doll we've heard doll

play45:02

before and now we get to C1 so this is

play45:05

basically lots of tag length value stuff

play45:08

I've again colorcoded the differences

play45:10

they're all stuck together and it this

play45:12

tells the

play45:14

terminal what data what transaction data

play45:17

and further data it expects from it to

play45:20

generate its cryptogram

play45:22

with um so basically it wants the amount

play45:25

amount would be for cashback it wants

play45:28

the country that it's in and the um and

play45:31

the currency code so it can do offline

play45:33

checks that it that it hasn't already

play45:35

authorized too much data on on offline

play45:39

um again transaction date you really

play45:42

don't know what it's going to do with it

play45:43

because this card has expired for like 3

play45:45

years and it doesn't really know that

play45:46

because I tell it that it's still

play45:48

2010 um and it wants a random number um

play45:51

in there

play45:54

so that's the data that that we stick

play45:56

together and then we have to request a

play45:58

type of um according to the terminal

play46:02

verification results and the um and the

play46:06

issue or action codes that we saw

play46:08

earlier we have to decide do we want to

play46:11

request this transaction to to be

play46:14

declined do we want it to be authorized

play46:17

by the bank or would we like the card to

play46:19

try to approve it so if we put this

play46:23

together um which I've already done for

play46:26

the sake of time these are all the

play46:29

fields um so amount one we want to get

play46:33

one pound uh amount two we're not going

play46:35

to do cash back we're in the

play46:37

UK um currency is the same it's October

play46:41

10th

play46:42

2010 transaction type is um it's it's 0

play46:47

is purchase um then this number is of

play46:49

course very random and I stick all of

play46:51

that together and that will be the

play46:52

seedall data that I sent to the card and

play46:55

then I can can do a first generate a

play47:00

c

play47:05

and so and and the response I get um is

play47:08

also sort of

play47:10

random um this is this is this is the

play47:14

clarification for the response the and

play47:16

this is different unfortunately so the

play47:20

first bit is the cryptogram information

play47:22

data and that will tell me just because

play47:24

I want the card to authorize something

play47:26

online doesn't mean it has to it can

play47:28

also say I want to talk to the bank or

play47:29

I'm going to just decline it right away

play47:31

so this basically says whether it was

play47:33

authorized or not um the application

play47:36

transaction counter is a lifetime

play47:37

counter the card can never do more than

play47:39

65,000 whatever

play47:41

transactions um the bit in the middle is

play47:43

the actual

play47:44

cryptogram and um the isser application

play47:47

data is what contains these these the

play47:50

card verification results we're not

play47:51

going to look at that so this

play47:54

cryptogram uh information

play47:56

data that I that I got when I was when I

play47:59

was trying it out with this card um was

play48:02

eight so was an arqc the card wanted to

play48:04

go

play48:05

online um in this case we got a

play48:09

40 so we we have a

play48:14

TC and um that's the card approved our

play48:17

transaction so we're done uh what we

play48:20

would do in case we we wanted to go

play48:23

online there's a SE doll 2 for second

play48:26

generate AC and that would want in this

play48:28

case the authorization Response Code

play48:31

from the bank and we can just tell it um

play48:33

and that worked just fine we can just

play48:34

tell it z z Bank said okay uh

play48:38

typically typically there'll also be

play48:40

some sort of cryptogram from the bank

play48:41

coming back and and the card will want

play48:43

that and we'll um and we'll par it so

play48:47

just in order to

play48:48

um so this this is basically who I got

play48:51

back now this is an but we can we can

play48:56

uh skip that so in conclusion I mean

play48:59

this is a really really old protocol it

play49:01

doesn't really mitigate the proper risks

play49:03

that that that go against it for example

play49:05

when you're when you're actually when

play49:07

you're making these cards um you take

play49:10

them to Laboratories the chips get

play49:12

stripped and and and they shoot lasers

play49:14

at it hoping that they'll flip some sort

play49:17

of bit that will make the card reveal

play49:19

its its secret key it's it's symmetric

play49:21

secret key um which is

play49:26

ridiculous because basically if I if I

play49:29

if I steal your card I mean the options

play49:31

are oh I can I can I can get a

play49:33

laboratory for €500,000 and shoot lasers

play49:35

at it and do all sorts of stuff or I can

play49:37

just hit you over the head until you

play49:38

tell me you're a pin because that one

play49:40

key that I extract from from your card

play49:42

will allow me to clone your card and not

play49:45

anything else um so all of these so so

play49:50

so the crypto and and and and and the

play49:52

hardware is fairly solid it's you could

play49:56

probably find lots of stuff too

play49:58

depending on which card you're using but

play50:00

just the

play50:02

general problems in the protocol are are

play50:05

much larger and and one of the one of

play50:07

the big problems is that these are these

play50:09

are being um transferred to new

play50:12

technology as well so the banks are

play50:14

really or or the card organizations are

play50:16

very reluctant to part with this Legacy

play50:19

technology um all of the contactless

play50:21

stuff that's that's coming into the

play50:22

field now work identically there's no

play50:26

there's there's no transport layer of

play50:28

protection to those either and and they

play50:30

they switch the commands around a little

play50:32

bit but basically it's exactly like uh

play50:36

like what you saw

play50:38

so that was it um if somebody has

play50:43

questions I am also available after the

play50:45

talk these slides and the software

play50:49

um I showed are should be available on

play50:52

the Vicki I don't know if they're up

play50:53

uploaded

play50:54

yet um

play50:56

um yeah and if anybody has any questions

play50:59

I'd be happy to uh if you have any

play51:01

questions please line up at the

play51:12

microphones perfect we have one question

play51:15

on the right hi if I understood you

play51:17

correctly it's possible to just use the

play51:19

magnetic stripe data to do an

play51:21

transaction is that right well if you're

play51:24

in Europe at least you're so so what

play51:27

what's coming out now is is a lot of

play51:29

these things like square and in in

play51:32

Europe there's lots of clones off of

play51:35

that and square worked well because it

play51:37

just uses the magnetic stripe data in

play51:39

the United States cards only have

play51:41

magnetic stripe data the whole point of

play51:43

these credit card scheme was to have one

play51:45

card that you can use anywhere in the

play51:47

whole world

play51:50

so they can't really mandate that the

play51:53

terminals in use can only do can only do

play51:56

em because then Americans couldn't buy

play51:57

stuff here and the other way around they

play52:00

can not put magnetic stripes on European

play52:03

cards because then you couldn't go to

play52:05

the states and buy

play52:06

something and basically you can also

play52:09

just break them there was a there was a

play52:12

year 2010 bug in in German cards and the

play52:15

easiest way to get around it was just to

play52:16

smash the chip and break it and then it

play52:18

would fall back to Magnetic stripe um so

play52:22

yeah you still always have that weakest

play52:24

link of of processing through the

play52:26

magnetic stripe data yeah what I was

play52:28

wondering about is whether it's um

play52:29

possible to temper with the magnetic

play52:31

stripe data that sent oh yeah and um

play52:34

thereby check whether Banks actually

play52:36

check all the crypto things or whether

play52:38

Banks just do the easiest thing take the

play52:41

magn stripe data that sent and uh don't

play52:44

Implement all of the crypto things on

play52:47

the bank side is it possible to do

play52:48

experiments in such a way or

play52:50

not well I mean it would be I wouldn't

play52:54

do it because you

play52:56

would I mean that would be illegal right

play53:00

um and you would also have to do it in

play53:03

in in the field you know so playing

play53:06

around with this at home is absolutely

play53:07

no risk it's you know it's your card and

play53:10

even even if you break it uh if playing

play53:13

around with it you take it to the bank

play53:15

they won't see that anything's wrong

play53:16

with the chip because they can't look

play53:17

inside it nobody understands the stuff

play53:19

and they'll just say oh but we want you

play53:21

to use your card to buy so and you'll

play53:23

get a new card immediately so there's no

play53:24

risk in that

play53:25

you could that would be a good way to to

play53:27

to find out whether car whether banks

play53:29

are actually checking the magnetic

play53:30

stripe data but you would have to alter

play53:33

the data on the well okay if you clone

play53:36

the chip make your own

play53:38

card um just use random keys for the for

play53:42

the for the for for the for the

play53:44

cryptogram stuff um then you could check

play53:46

whether they actually check the

play53:48

cryptogram which they doesn't always

play53:50

happen yeah more like a sort experiment

play53:52

uh whether it's whether it would be

play53:54

possible to to test what the banks

play53:56

actually that would be a good way to

play53:58

test it yes but I they would also it be

play54:01

easy to get caught as

play54:03

well are there any more

play54:06

questions no please give a warm Applause

play54:09

to our speaker Tim Becker hello hello

play54:13

thank

play54:15

you one more question from the left hand

play54:19

micro um I have a short question um what

play54:24

what part of the stuff on the card is

play54:26

actually signed so for example if my

play54:28

card doesn't support cashbacks can I put

play54:31

it into a reader and set one in there

play54:34

and got the sh and got a cash back um

play54:36

that that that would be an interesting

play54:38

thing to look at for individual cards um

play54:41

I've never found anywhere where there's

play54:45

some suggestions of what you should sign

play54:47

but not everybody necessarily does that

play54:49

so for example all of in this card which

play54:52

is I mean it's a demo card from Visa

play54:54

it's obviously VI ly what they kind of

play54:56

expect you to do they didn't

play54:58

sign any of this stuff and that included

play55:01

the seedall data that the card needs to

play55:03

be sent to generate the cryptogram and

play55:05

more importantly it included these these

play55:08

risk action codes you know like when

play55:10

when are you supposed to decline a

play55:11

transaction when are you supposed to do

play55:12

that um and what it also didn't include

play55:16

was what it certainly didn't include

play55:18

because that's not usually in these

play55:19

records is the the application file

play55:22

locator that tells the terminal what

play55:24

data to read in the first place so

play55:26

you're authenticating something but you

play55:28

read that from the card and you don't

play55:30

really have any way to know that that's

play55:32

actually what the card wanted you to

play55:33

read um so what also wasn't um done here

play55:38

for example the the certificate

play55:40

Authority public key the way that you

play55:42

get that back so if those are ever

play55:43

revoked you could put you know you could

play55:45

use another key because that one was was

play55:49

crack um and and a part that I forgot to

play55:52

mention what um what what's quite

play55:54

important

play55:55

I said that the card isn't really a dumb

play55:57

storage for data what what most people

play55:59

think um all of the stuff that we got

play56:02

with read

play56:03

record um so all of this card

play56:06

data that part is just a dumb storage so

play56:10

the card doesn't know about any of this

play56:12

the card doesn't know its own card

play56:14

number it's just stored somewhere in a

play56:16

filing cabinet but it doesn't use that

play56:17

for any any any any um any calculations

play56:22

it doesn't know about any of these

play56:23

action codes so it doesn't know if the

play56:24

teral is actually doing the right thing

play56:26

or

play56:27

not um but yeah the way that what parts

play56:31

are actually um encrypted and and and

play56:33

people forget to put important Fields

play56:36

into into the certificates all the

play56:39

time or not all the time I mean they

play56:41

shouldn't um and but you I'm I'm sure

play56:44

you could find cards where um vital

play56:47

pieces are not um actually

play56:50

authenticated because this is really

play56:52

complic I mean try to put together stuff

play56:53

like this this is like that there there

play56:56

are these guidance rules but nobody you

play56:58

know it's just like well okay I'll do it

play56:59

like it says in the

play57:00

document and the people that make those

play57:03

decis sorry last last sentence you know

play57:06

and the people who make those decisions

play57:08

a lot of the times I mean either they're

play57:09

really really highly knowledgeable at

play57:11

Banks but a lot of the time they're just

play57:13

the project manager for some credit card

play57:15

project and the normal decisions they

play57:18

make is what picture goes on the card

play57:20

you know and then you expect them to

play57:21

like figure out all these these bit maps

play57:23

I mean that's not the usual case but

play57:24

that that happens as well so thank you

play57:27

very much and thank you there is another

play57:29

question from the right hand microphone

play57:31

um not really a question more like a

play57:34

comment you mentioned that uh that

play57:36

standard didn't uh tell anything about

play57:39

what gets sent to the bank for learning

play57:42

more about it it's ISO

play57:46

5853 8583 yeah which is uh funnily

play57:51

supposed to be a standard but it's

play57:52

somewhat different in different

play57:54

countries and and that leads to

play57:55

interesting hustle and another thing was

play57:58

you were seem to be wondering about why

play58:01

they would be caring about whether

play58:03

something is goods or services uh there

play58:06

are some some payment cards that only

play58:09

accept for example um paying for

play58:13

services and even paying for certain

play58:15

kind of services uh for example I have a

play58:18

card in my wallet that only let me pay

play58:20

for lunch ah okay yeah that would make

play58:22

sense internationally or the

play58:26

um uh at at the moment unfortunately

play58:29

only in Finland but maybe maybe the

play58:31

company that made it will spread um so

play58:34

8583 is is is at the last level towards

play58:39

the banks or the card institutions the

play58:41

protocol that will get spoken and that's

play58:43

even more than um than EMD is is it's

play58:47

kind of like XML it just it's just

play58:49

defines a general framework of how such

play58:51

a protocol should look and that's why

play58:53

every single implement a is different

play58:55

and it's really complicated and

play58:57

convoluted so the people who do the

play58:59

entire um specifications of the concrete

play59:03

protocols usually screw stuff up or make

play59:06

it make it very difficult to

play59:10

the any more

play59:14

questions doesn't look like it well give

play59:16

a nice round of

play59:23

applause

Rate This

5.0 / 5 (0 votes)

Etiquetas Relacionadas
EMV ProtocolChip CardCredit Card SecurityTransaction ProcessingSmart CardPayment TerminalCryptogramCard CloningRisk ManagementTechnical TalkFinancial Fraud
¿Necesitas un resumen en inglés?