SlideShare a Scribd company logo
1 of 45
Download to read offline
Next Presentation begins at 13:00
Demystifying Host Card Emulation Security
- Best Practices for Implementing Secure
Mobile Payments
Slawomir Jasek Wojtek Dworakowski
IT Security Expert IT Security Expert
Demystifying HCE Security -
Best Practices for Secure
Mobile Payments
Slawomir Jasek Wojtek Dworakowski
IT Security Expert IT Security Expert
Wojtek Dworakowski
- SecuRing CEO (since 2003)
- OWASP Poland Chapter Leader
$ login
Slawomir Jasek
- IT Security Expert at SecuRing
- since 2005, and still loves this job
• Background info
• History, uses of SE/HCE, Secure Element operation, HCE intro
• Risks
• Possible attacks
• HCE vs SE
• Best practices, example vulnerabilities
• Summary
• Q&A
Agenda
Background brief
Mobile payments
How did we get here?
2008
First concatless
payment cards.
2009
First pay-by-mobile
service (UK)
2011
Galaxy Nexus – Google
Wallet, Secure Element
2012
First HCE experiments
(SimplyTapp, Blackberry)
2013
Android 4.4
supports HCE
2014
Visa, Mastercard HCE
support, first commercial
implementations
2015
Apple Pay
enters UK
2016
Android Pay
enters UK
Image sources: Orange,
http://www.storagenewsletter.com/, http://9to5mac.com/
Secure Element (SE)
API exposing only functions, not data
Similar to physical contactless card
• Memory
• Processor
• Applet (javacard)
„Tamper-resistant platform (typically a one-chip
secure microcontroller) capable of securely
hosting applications and their confidential and
cryptographic data (e.g., key management) in
accordance with the rules and security
requirements set forth by a set of well-identified
trusted authorities.”
globalplatform.org
• SIM card
• Built in
• SD card
Secure Element
OS
Mobile app
Applet
NFC
Antena
Secure Element
Card data, payment
services
• Apps and OS have no access to card
data and to communication during
payment.
• User-land application are only for
configuration, monitoring, payment
initiation
SE communicates directly with NFC module
Android >=4.4, Blackberry OS,
Windows Phone
Software can emulate any
contactless smart card
• No direct communication
between app and NFC
• NFC communication
implemented in OS API
Host-based Card Emulation (HCE)
No API nor requirements for storing
card data and for secure transmission
Security should be explicitly
implemented by app
OS
Payment app
Mobile payments
Mobile tickets
Reward programs
Physical security
Hotel room access
Car/bicycle rental
…
The sky is the limit!
Image sources: https://www.ximedes.com,
http://www.ibonus.net/, http://www.frugalprototype.com/,
HCE uses
HCE vs app developer
The most important security aspects are fully dependent on programmer
Payment companies defined sets of security rules and validation process
• The requirements "state minimum level of security",
• They do not introduce technical details of available options, best practices, risk vs cost
analysis...
• Connected servers and back-end systems are not in scope of security assessment
Mobile payments risks
Selected attacks scenarios
Attack #1 – relay
Graphics source: https://sourceforge.net/p/nfcproxy/wiki/Home/
• Same risk profile as for
any contactless card
• Very close proximity
(mostly will not work
through the bag)
• Short window of
oportunityNFC Proxy
Secure Element
• The NFC usually works also with the
phone turned off (even dead battery).
• Easier to approach unsuspecting
victim's phone.
Host Card Emulation
• NFC works only with the screen turned
on (and – optionally – unlocked).
• More difficult to attack without the
victim's notice.
Attack #1 – relay
Additional risk mitigations
• Business/UX decisions:
enforce PIN for every transaction,
SE: activate NFC antenna only on demand
HCE: activate NFC antenna on screen unlock
• Communication delays due to proxing could be detected
Attack #2 – EMV downgrade
• Attacker simulates old, "magstripe" card reader mode to victim's card.
• Pre-plays all possible "challenge" values from terminal, and forces the card to compute
valid responses.
• Use matching response with the actual terminal.
Risk mitigations, attack conditions
• Requires physical contact with the victim's card for longer amount of time (at least
several minutes)
• Possible to invoke one transaction only, the victim cannot use the card in the meantime
• Depends on terminal configuration and generation of "unpredictable numbers"
• Attack possible to detect on the issuer's side
https://www.blackhat.com/docs/us-15/materials/us-15-Fillmore-Crash-Pay-How-
To-Own-And-Clone-Contactless-Payment-Devices.pdf
Attack #3 – steal card data in transit
Mobile
wallet app
Payment processorBank Third party
HCE LIB
NFC
Contactless
Card reader
"Secure
Element in
the cloud"
server
Online
payment
processing
system
Google Cloud
Messaging
Mobile wallet
server
Bank's Card
management
system
Secure Element on SIM
• Card data transmitted OTA by GSM
network.
• Theoretical possibility to intercept GSM
communication.
Risk: low
• The card data is transmitted only once
to mobile device.
• Intercepting GSM is still not trivial
Host Card Emulation
• Usually tokenized card data pushed to
device from the "cloud",
e.g. by Google Cloud Messaging
Risk: depends on implementation details
• Encryption layers
• Authentication, device fingerprinting...
• Various application features
(more on this later)
Attack #3 – steal card data in transit
Attack #4 – popular malware (no root)
Most popular mobile malware at this moment does not utilize "root" access.
Attack involves displaying overlay on top of targeted mobile app to steal
credentials.
Secure Element
• Mobile application does not have
access to card data. Stealing app
credentials will not reveal card
data.
• Malware will not be able to
invoke applet API, as it verifies
the mobile application signing
key.
Host Card Emulation
• Depending on implementation,
stealing mobile app credentials
may help with access to card data
• Mobile application vulnerabilities
(e.g. IPC, data storage) can be
exploited by other applications
on the same device
Secure Element
• Card data is not accessible
for mobile operating
system. Root access does
not help to steal the PAN.
• Malware as "proxy"
between SE and NFC?
Rather not possible, applet
should verify source of
communication (OS vs NFC
antenna).
Attack #5 – malware with root access
OS
Mobile app
Card data
OS
Mobile app
Applet
Host Card Emulation
• Root can access mobile
application storage,
including card data.
• The attacker has all the
information necessary to
"clone" the card on a
different physical device.
root > Device Administrator
Malware with root – is it real?
https://www.bluecoat.com/security-blog/2016-04-
25/android-exploit-delivers-dogspectus-ransomware
• Works on almost all Android 2.x – 6.0 devices
• Root exploit deployed from cloud, based on device
model and ROM version
CDCVM + malware with root?
CDCVM – mobile app
authorization instead
of PIN.
Malware can
intercept PIN and
make fraud payment
without limits.
Other vectors…
Stealing
Altering AID routing table
Attack on services in the cloud
Fake POS (e.g. PAN gathering + CNP fraud)
Power analysis
Social engineering
Apple Pay provisioning fraud
…
HCE best practices
Details and example vulnerabilities
Image:http://www.smartcardalliance.org/downloads/EMV-
Tokenization-Encryption-WP-FINAL.pdf
Tokenization
• Many one-time random "surrogate" card numbers
(tokens) replacing single static PAN
• Generated server-side, distributed to mobile
application ("secure element in the cloud")
• Mobile application stores several consecutive values
(for offline use)
• The token can be limited
– specific merchant or channel
– time
– capped to max amount
Typical architecture
Mobile
wallet app
Payment processorBank Third party
HCE LIB
NFC
Contactless
Card reader
"Secure
Element in
the cloud"
server
Online
payment
processing
system
Google Cloud
Messaging
Mobile wallet
server
Bank's Card
management
system
Tokenization - questions
• How are the card tokens transmitted?
• Google Cloud Messaging push, third party servers?
• How is the data encrypted? What is the key?
• What is required to renew the tokens?
• Does this operation involve user authorization, or is handled
automatically by the background service?
• What comprises the authentication key to get the tokens?
Code obfuscation
Good practice: even using free ProGuard you can alter default settings to make it more secure.
Original source:
ProGuard compression (most common)
Code obfuscation
Commercial obfuscator:
Data at rest encryption
Several encryption options:
• Static key hardcoded in application
code
• Individual device-specific key
(generated from e.g. deviceid)
• Individual per-installation key
• Key has to be unlocked with additional
user authorization (e.g. fingerprint,
password). Lower risk, worse UX.
Risk
Compliance requirement: Sensitive data at rest must be securely protected.
Card data is stored in application private folder.
Data at rest – example vulnerabilities
Data stored on the device (2011)
SQLite databases including credit card balance, limits,
expiration date, name on card, last 4 card digits, email
account, transaction dates, locations and more:
https://www.nowsecure.com/blog/2011/12/12/forensic-
security-analysis-of-google-wallet/
Offline brute-force (2012)
PIN stored as SHA-1 hash on the device. The PIN can only
be a 4-digit numeric value, so offline brute-force attack
would only require calculating, at most, 10,000 SHA256
hashes:
https://zvelo.com/google-wallet-security-pin-exposure-
vulnerability/
Integrity protections
• Was the application installed from official Play Store?
• Is the application signed by proper developer's key?
• Is the debug mode on?
• Does it work on emulator or real device?
• Mechanisms to enforce upgrade, do not allow rollback to earlier versions
• Deactivation and wipe on compromise detection
• Notifications, reporting
• ...
Integrity protections – details matter
How are the protections
implemented?
Simple boolean to switch in binary
(Xposed modules) vs Google
Safetynet.
https://www.cigital.com/blog/using-safetynet-api/
Image: CC lendingmemo.com
Fraud detection
Device risk scoring, compromise indicators:
• Root detection
• List of installed apps
• User-added CA Certificates
• Android version, patchlevel
• Tampering attempts?
Additional indicators: location, device uptime,
behavioral patterns, other...
Device scoring – details
What, when and how is reported to the server?
Cleartext (easy to intercept and tamper):
devicekey:AD407F0797FDDEC0F5F5A3CA7ABB97E9BA7D5BA464DA0095DBAFFD3,
config_update:1000,os.ver_up_to_date:0,os.rooted:0,os.rooted.nativ
e:0,os.rooted.hiders:0,malware.any:0,total.risk.generic:0
Encrypted (more effort required to tamper):
9Jyx4xpeoK6VEZCCjQuW8vc5+xCktgPGjNIqhkgLeYZOtae9MDEKtc7OBUuL7ZO6GW
6Z3yjcxKwQpglHqwrxvz+1JGMh/wv6R8U6S51+uA3tn+fqhcOxqGM4z7WP1/rLh9gD
QPVFC8dOQ8/hLf3K+Q==
Transmission encryption - pinning
Good practice: SSL certificate pinning.
• Hardcode server's certificate details in the mobile application.
• Goal: it will be more difficult to conduct Man-in-the-Middle attacks
Unfortunatelly, pinning implementation is problematic for developers, and often
introduces vulnerabilities ;)
Transmission encryption - pinning
SSL vulnerability example #1 – empty trustManager
sslcontext = SSLContext.getInstance("TLS");
atrustmanager = new TrustManager[1];
atrustmanager[0] = new EasyX509TrustManager(null);
sslcontext.init(null, atrustmanager, null);
The application accepts ALL the possible certificates ;)
Transmission encryption - pinning
SSL vulnerability example #2 – hostnameVerifier
SocketFactory sf = SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket) sf.createSocket("mail.google.com", 443);
SSLSession s = socket.getSession();
HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier();
if (!hv.verify("mail.google.com", s)) {
throw new SSLHandshakeException("Expected mail.google.com, found " +
s.getPeerPrincipal());
}
socket.close();
https://developer.android.com/training/articles/security-ssl.html#WarningsSslSocket
The application accepts all the certificates signed by the specific CA.
Additional encryption layers
How it works?
Public key
Session key sent to server
(encrypted by server's public key)
Data encrypted by session key
random
session
key
Server API
How to attack it?
The transmitted data must be at some
point in clear-text form on the device,
but it is difficult to tamper.
Our approach:
• Patch the app to generate static
encryption key instead of random
one.
• Develop Burp intercepting proxy
extension to decrypt the traffic using
the static key
How to attack it?
The transmitted data must be at some
point in clear-text form on the device,
but it is difficult to tamper.
Our approach:
• Patch the app to generate static
encryption key instead of random
one.
• Develop Burp intercepting proxy
extension to decrypt the traffic using
the static key
And of course the server-side vulnerabilities were
still there!
Summary
Wrap-up
• Rethink your decisions
Technology is complex and bad assumptions are in the roots of poor security
• Future proof your plan
Risk depends on many factors, and may change in time (mobile malware development)
• Use available options
It is possible to enforce many additional layers of security, which render the attacks more
difficult and mitigate the risk.
• Implementation details matters!
Bad implementation could introduce vulnerabilities even if the project is correct
• Perfom analysis and deep testing if you are planning to use HCE or similar technologies
Q&A
Whitepaper
Meet us at our UK partner stand T80
Wojciech.Dworakowski@securing.pl @wojdwo
Slawomir.Jasek@securing.pl @securingpl
Hope to meet you also at...
Internet banking safeguards vulnerabilities
Wojtek Dworakowski
GATTacking Bluetooth Smart devices –
introducing a new BLE MITM proxy tool
Sławomir Jasek

More Related Content

Viewers also liked

Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by defaultSecuRing
 
Certificate Pinning in Mobile Applications
Certificate Pinning in Mobile ApplicationsCertificate Pinning in Mobile Applications
Certificate Pinning in Mobile ApplicationsLuca Bongiorni
 
ICT security and Open Data
ICT security and Open DataICT security and Open Data
ICT security and Open DataSecuRing
 
My role as an Agile Manager
My role as an Agile ManagerMy role as an Agile Manager
My role as an Agile ManagerCprime
 
DC4420 2014 - NFC - The Non-Radio Bits
DC4420 2014 - NFC - The Non-Radio BitsDC4420 2014 - NFC - The Non-Radio Bits
DC4420 2014 - NFC - The Non-Radio BitsTom Keetch
 

Viewers also liked (6)

Applications secure by default
Applications secure by defaultApplications secure by default
Applications secure by default
 
Certificate Pinning in Mobile Applications
Certificate Pinning in Mobile ApplicationsCertificate Pinning in Mobile Applications
Certificate Pinning in Mobile Applications
 
ICT security and Open Data
ICT security and Open DataICT security and Open Data
ICT security and Open Data
 
My role as an Agile Manager
My role as an Agile ManagerMy role as an Agile Manager
My role as an Agile Manager
 
DC4420 2014 - NFC - The Non-Radio Bits
DC4420 2014 - NFC - The Non-Radio BitsDC4420 2014 - NFC - The Non-Radio Bits
DC4420 2014 - NFC - The Non-Radio Bits
 
Civintec introduction 2015
Civintec introduction 2015Civintec introduction 2015
Civintec introduction 2015
 

More from SecuRing

Developer in a digital crosshair, 2023 edition - 4Developers
Developer in a digital crosshair, 2023 edition - 4DevelopersDeveloper in a digital crosshair, 2023 edition - 4Developers
Developer in a digital crosshair, 2023 edition - 4DevelopersSecuRing
 
Developer in a digital crosshair, 2022 edition - Oh My H@ck!
Developer in a digital crosshair, 2022 edition - Oh My H@ck!Developer in a digital crosshair, 2022 edition - Oh My H@ck!
Developer in a digital crosshair, 2022 edition - Oh My H@ck!SecuRing
 
Developer in a digital crosshair, 2022 edition - No cON Name
Developer in a digital crosshair, 2022 edition - No cON NameDeveloper in a digital crosshair, 2022 edition - No cON Name
Developer in a digital crosshair, 2022 edition - No cON NameSecuRing
 
Is persistency on serverless even possible?!
Is persistency on serverless even possible?!Is persistency on serverless even possible?!
Is persistency on serverless even possible?!SecuRing
 
What happens on your Mac, stays on Apple’s iCloud?!
What happens on your Mac, stays on Apple’s iCloud?!What happens on your Mac, stays on Apple’s iCloud?!
What happens on your Mac, stays on Apple’s iCloud?!SecuRing
 
0-Day Up Your Sleeve - Attacking macOS Environments
0-Day Up Your Sleeve - Attacking macOS Environments0-Day Up Your Sleeve - Attacking macOS Environments
0-Day Up Your Sleeve - Attacking macOS EnvironmentsSecuRing
 
Developer in a digital crosshair, 2022 edition
Developer in a digital crosshair, 2022 editionDeveloper in a digital crosshair, 2022 edition
Developer in a digital crosshair, 2022 editionSecuRing
 
20+ Ways To Bypass Your Macos Privacy Mechanisms
20+ Ways To Bypass Your Macos Privacy Mechanisms20+ Ways To Bypass Your Macos Privacy Mechanisms
20+ Ways To Bypass Your Macos Privacy MechanismsSecuRing
 
How secure are webinar platforms?
How secure are webinar platforms?How secure are webinar platforms?
How secure are webinar platforms?SecuRing
 
20+ Ways to Bypass Your macOS Privacy Mechanisms
20+ Ways to Bypass Your macOS Privacy Mechanisms20+ Ways to Bypass Your macOS Privacy Mechanisms
20+ Ways to Bypass Your macOS Privacy MechanismsSecuRing
 
Serverless security: attack & defense
 Serverless security: attack & defense Serverless security: attack & defense
Serverless security: attack & defenseSecuRing
 
Abusing & Securing XPC in macOS apps
Abusing & Securing XPC in macOS appsAbusing & Securing XPC in macOS apps
Abusing & Securing XPC in macOS appsSecuRing
 
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsWebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsSecuRing
 
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsWebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsSecuRing
 
Let's get evil - threat modeling at scale
Let's get evil - threat modeling at scaleLet's get evil - threat modeling at scale
Let's get evil - threat modeling at scaleSecuRing
 
Attacking AWS: the full cyber kill chain
Attacking AWS: the full cyber kill chainAttacking AWS: the full cyber kill chain
Attacking AWS: the full cyber kill chainSecuRing
 
Web Apps vs Blockchain dApps (Smart Contracts): tools, vulns and standards
Web Apps vs Blockchain dApps (Smart Contracts): tools, vulns and standardsWeb Apps vs Blockchain dApps (Smart Contracts): tools, vulns and standards
Web Apps vs Blockchain dApps (Smart Contracts): tools, vulns and standardsSecuRing
 
Budowanie i hakowanie nowoczesnych aplikacji iOS
Budowanie i hakowanie nowoczesnych aplikacji iOSBudowanie i hakowanie nowoczesnych aplikacji iOS
Budowanie i hakowanie nowoczesnych aplikacji iOSSecuRing
 
We need t go deeper - Testing inception apps.
We need t go deeper - Testing inception apps.We need t go deeper - Testing inception apps.
We need t go deeper - Testing inception apps.SecuRing
 
Building & Hacking Modern iOS Apps
Building & Hacking Modern iOS AppsBuilding & Hacking Modern iOS Apps
Building & Hacking Modern iOS AppsSecuRing
 

More from SecuRing (20)

Developer in a digital crosshair, 2023 edition - 4Developers
Developer in a digital crosshair, 2023 edition - 4DevelopersDeveloper in a digital crosshair, 2023 edition - 4Developers
Developer in a digital crosshair, 2023 edition - 4Developers
 
Developer in a digital crosshair, 2022 edition - Oh My H@ck!
Developer in a digital crosshair, 2022 edition - Oh My H@ck!Developer in a digital crosshair, 2022 edition - Oh My H@ck!
Developer in a digital crosshair, 2022 edition - Oh My H@ck!
 
Developer in a digital crosshair, 2022 edition - No cON Name
Developer in a digital crosshair, 2022 edition - No cON NameDeveloper in a digital crosshair, 2022 edition - No cON Name
Developer in a digital crosshair, 2022 edition - No cON Name
 
Is persistency on serverless even possible?!
Is persistency on serverless even possible?!Is persistency on serverless even possible?!
Is persistency on serverless even possible?!
 
What happens on your Mac, stays on Apple’s iCloud?!
What happens on your Mac, stays on Apple’s iCloud?!What happens on your Mac, stays on Apple’s iCloud?!
What happens on your Mac, stays on Apple’s iCloud?!
 
0-Day Up Your Sleeve - Attacking macOS Environments
0-Day Up Your Sleeve - Attacking macOS Environments0-Day Up Your Sleeve - Attacking macOS Environments
0-Day Up Your Sleeve - Attacking macOS Environments
 
Developer in a digital crosshair, 2022 edition
Developer in a digital crosshair, 2022 editionDeveloper in a digital crosshair, 2022 edition
Developer in a digital crosshair, 2022 edition
 
20+ Ways To Bypass Your Macos Privacy Mechanisms
20+ Ways To Bypass Your Macos Privacy Mechanisms20+ Ways To Bypass Your Macos Privacy Mechanisms
20+ Ways To Bypass Your Macos Privacy Mechanisms
 
How secure are webinar platforms?
How secure are webinar platforms?How secure are webinar platforms?
How secure are webinar platforms?
 
20+ Ways to Bypass Your macOS Privacy Mechanisms
20+ Ways to Bypass Your macOS Privacy Mechanisms20+ Ways to Bypass Your macOS Privacy Mechanisms
20+ Ways to Bypass Your macOS Privacy Mechanisms
 
Serverless security: attack & defense
 Serverless security: attack & defense Serverless security: attack & defense
Serverless security: attack & defense
 
Abusing & Securing XPC in macOS apps
Abusing & Securing XPC in macOS appsAbusing & Securing XPC in macOS apps
Abusing & Securing XPC in macOS apps
 
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsWebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
 
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standardsWebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
WebApps vs Blockchain dApps (SmartContracts): tools, vulns and standards
 
Let's get evil - threat modeling at scale
Let's get evil - threat modeling at scaleLet's get evil - threat modeling at scale
Let's get evil - threat modeling at scale
 
Attacking AWS: the full cyber kill chain
Attacking AWS: the full cyber kill chainAttacking AWS: the full cyber kill chain
Attacking AWS: the full cyber kill chain
 
Web Apps vs Blockchain dApps (Smart Contracts): tools, vulns and standards
Web Apps vs Blockchain dApps (Smart Contracts): tools, vulns and standardsWeb Apps vs Blockchain dApps (Smart Contracts): tools, vulns and standards
Web Apps vs Blockchain dApps (Smart Contracts): tools, vulns and standards
 
Budowanie i hakowanie nowoczesnych aplikacji iOS
Budowanie i hakowanie nowoczesnych aplikacji iOSBudowanie i hakowanie nowoczesnych aplikacji iOS
Budowanie i hakowanie nowoczesnych aplikacji iOS
 
We need t go deeper - Testing inception apps.
We need t go deeper - Testing inception apps.We need t go deeper - Testing inception apps.
We need t go deeper - Testing inception apps.
 
Building & Hacking Modern iOS Apps
Building & Hacking Modern iOS AppsBuilding & Hacking Modern iOS Apps
Building & Hacking Modern iOS Apps
 

Recently uploaded

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

Demystifying Host Card Emulation Security - Best Practices for Implementing Secure Mobile Payments

  • 1. Next Presentation begins at 13:00 Demystifying Host Card Emulation Security - Best Practices for Implementing Secure Mobile Payments Slawomir Jasek Wojtek Dworakowski IT Security Expert IT Security Expert
  • 2. Demystifying HCE Security - Best Practices for Secure Mobile Payments Slawomir Jasek Wojtek Dworakowski IT Security Expert IT Security Expert
  • 3. Wojtek Dworakowski - SecuRing CEO (since 2003) - OWASP Poland Chapter Leader $ login Slawomir Jasek - IT Security Expert at SecuRing - since 2005, and still loves this job
  • 4. • Background info • History, uses of SE/HCE, Secure Element operation, HCE intro • Risks • Possible attacks • HCE vs SE • Best practices, example vulnerabilities • Summary • Q&A Agenda
  • 6. Mobile payments How did we get here? 2008 First concatless payment cards. 2009 First pay-by-mobile service (UK) 2011 Galaxy Nexus – Google Wallet, Secure Element 2012 First HCE experiments (SimplyTapp, Blackberry) 2013 Android 4.4 supports HCE 2014 Visa, Mastercard HCE support, first commercial implementations 2015 Apple Pay enters UK 2016 Android Pay enters UK
  • 7. Image sources: Orange, http://www.storagenewsletter.com/, http://9to5mac.com/ Secure Element (SE) API exposing only functions, not data Similar to physical contactless card • Memory • Processor • Applet (javacard) „Tamper-resistant platform (typically a one-chip secure microcontroller) capable of securely hosting applications and their confidential and cryptographic data (e.g., key management) in accordance with the rules and security requirements set forth by a set of well-identified trusted authorities.” globalplatform.org • SIM card • Built in • SD card
  • 8. Secure Element OS Mobile app Applet NFC Antena Secure Element Card data, payment services • Apps and OS have no access to card data and to communication during payment. • User-land application are only for configuration, monitoring, payment initiation SE communicates directly with NFC module
  • 9. Android >=4.4, Blackberry OS, Windows Phone Software can emulate any contactless smart card • No direct communication between app and NFC • NFC communication implemented in OS API Host-based Card Emulation (HCE) No API nor requirements for storing card data and for secure transmission Security should be explicitly implemented by app OS Payment app
  • 10. Mobile payments Mobile tickets Reward programs Physical security Hotel room access Car/bicycle rental … The sky is the limit! Image sources: https://www.ximedes.com, http://www.ibonus.net/, http://www.frugalprototype.com/, HCE uses
  • 11. HCE vs app developer The most important security aspects are fully dependent on programmer Payment companies defined sets of security rules and validation process • The requirements "state minimum level of security", • They do not introduce technical details of available options, best practices, risk vs cost analysis... • Connected servers and back-end systems are not in scope of security assessment
  • 12. Mobile payments risks Selected attacks scenarios
  • 13. Attack #1 – relay Graphics source: https://sourceforge.net/p/nfcproxy/wiki/Home/ • Same risk profile as for any contactless card • Very close proximity (mostly will not work through the bag) • Short window of oportunityNFC Proxy
  • 14. Secure Element • The NFC usually works also with the phone turned off (even dead battery). • Easier to approach unsuspecting victim's phone. Host Card Emulation • NFC works only with the screen turned on (and – optionally – unlocked). • More difficult to attack without the victim's notice. Attack #1 – relay Additional risk mitigations • Business/UX decisions: enforce PIN for every transaction, SE: activate NFC antenna only on demand HCE: activate NFC antenna on screen unlock • Communication delays due to proxing could be detected
  • 15. Attack #2 – EMV downgrade • Attacker simulates old, "magstripe" card reader mode to victim's card. • Pre-plays all possible "challenge" values from terminal, and forces the card to compute valid responses. • Use matching response with the actual terminal. Risk mitigations, attack conditions • Requires physical contact with the victim's card for longer amount of time (at least several minutes) • Possible to invoke one transaction only, the victim cannot use the card in the meantime • Depends on terminal configuration and generation of "unpredictable numbers" • Attack possible to detect on the issuer's side https://www.blackhat.com/docs/us-15/materials/us-15-Fillmore-Crash-Pay-How- To-Own-And-Clone-Contactless-Payment-Devices.pdf
  • 16. Attack #3 – steal card data in transit Mobile wallet app Payment processorBank Third party HCE LIB NFC Contactless Card reader "Secure Element in the cloud" server Online payment processing system Google Cloud Messaging Mobile wallet server Bank's Card management system
  • 17. Secure Element on SIM • Card data transmitted OTA by GSM network. • Theoretical possibility to intercept GSM communication. Risk: low • The card data is transmitted only once to mobile device. • Intercepting GSM is still not trivial Host Card Emulation • Usually tokenized card data pushed to device from the "cloud", e.g. by Google Cloud Messaging Risk: depends on implementation details • Encryption layers • Authentication, device fingerprinting... • Various application features (more on this later) Attack #3 – steal card data in transit
  • 18. Attack #4 – popular malware (no root) Most popular mobile malware at this moment does not utilize "root" access. Attack involves displaying overlay on top of targeted mobile app to steal credentials. Secure Element • Mobile application does not have access to card data. Stealing app credentials will not reveal card data. • Malware will not be able to invoke applet API, as it verifies the mobile application signing key. Host Card Emulation • Depending on implementation, stealing mobile app credentials may help with access to card data • Mobile application vulnerabilities (e.g. IPC, data storage) can be exploited by other applications on the same device
  • 19. Secure Element • Card data is not accessible for mobile operating system. Root access does not help to steal the PAN. • Malware as "proxy" between SE and NFC? Rather not possible, applet should verify source of communication (OS vs NFC antenna). Attack #5 – malware with root access OS Mobile app Card data OS Mobile app Applet Host Card Emulation • Root can access mobile application storage, including card data. • The attacker has all the information necessary to "clone" the card on a different physical device. root > Device Administrator
  • 20. Malware with root – is it real? https://www.bluecoat.com/security-blog/2016-04- 25/android-exploit-delivers-dogspectus-ransomware • Works on almost all Android 2.x – 6.0 devices • Root exploit deployed from cloud, based on device model and ROM version
  • 21. CDCVM + malware with root? CDCVM – mobile app authorization instead of PIN. Malware can intercept PIN and make fraud payment without limits.
  • 22. Other vectors… Stealing Altering AID routing table Attack on services in the cloud Fake POS (e.g. PAN gathering + CNP fraud) Power analysis Social engineering Apple Pay provisioning fraud …
  • 23. HCE best practices Details and example vulnerabilities
  • 24. Image:http://www.smartcardalliance.org/downloads/EMV- Tokenization-Encryption-WP-FINAL.pdf Tokenization • Many one-time random "surrogate" card numbers (tokens) replacing single static PAN • Generated server-side, distributed to mobile application ("secure element in the cloud") • Mobile application stores several consecutive values (for offline use) • The token can be limited – specific merchant or channel – time – capped to max amount
  • 25. Typical architecture Mobile wallet app Payment processorBank Third party HCE LIB NFC Contactless Card reader "Secure Element in the cloud" server Online payment processing system Google Cloud Messaging Mobile wallet server Bank's Card management system
  • 26. Tokenization - questions • How are the card tokens transmitted? • Google Cloud Messaging push, third party servers? • How is the data encrypted? What is the key? • What is required to renew the tokens? • Does this operation involve user authorization, or is handled automatically by the background service? • What comprises the authentication key to get the tokens?
  • 27. Code obfuscation Good practice: even using free ProGuard you can alter default settings to make it more secure. Original source: ProGuard compression (most common)
  • 29. Data at rest encryption Several encryption options: • Static key hardcoded in application code • Individual device-specific key (generated from e.g. deviceid) • Individual per-installation key • Key has to be unlocked with additional user authorization (e.g. fingerprint, password). Lower risk, worse UX. Risk Compliance requirement: Sensitive data at rest must be securely protected. Card data is stored in application private folder.
  • 30. Data at rest – example vulnerabilities Data stored on the device (2011) SQLite databases including credit card balance, limits, expiration date, name on card, last 4 card digits, email account, transaction dates, locations and more: https://www.nowsecure.com/blog/2011/12/12/forensic- security-analysis-of-google-wallet/ Offline brute-force (2012) PIN stored as SHA-1 hash on the device. The PIN can only be a 4-digit numeric value, so offline brute-force attack would only require calculating, at most, 10,000 SHA256 hashes: https://zvelo.com/google-wallet-security-pin-exposure- vulnerability/
  • 31. Integrity protections • Was the application installed from official Play Store? • Is the application signed by proper developer's key? • Is the debug mode on? • Does it work on emulator or real device? • Mechanisms to enforce upgrade, do not allow rollback to earlier versions • Deactivation and wipe on compromise detection • Notifications, reporting • ...
  • 32. Integrity protections – details matter How are the protections implemented? Simple boolean to switch in binary (Xposed modules) vs Google Safetynet. https://www.cigital.com/blog/using-safetynet-api/
  • 33. Image: CC lendingmemo.com Fraud detection Device risk scoring, compromise indicators: • Root detection • List of installed apps • User-added CA Certificates • Android version, patchlevel • Tampering attempts? Additional indicators: location, device uptime, behavioral patterns, other...
  • 34. Device scoring – details What, when and how is reported to the server? Cleartext (easy to intercept and tamper): devicekey:AD407F0797FDDEC0F5F5A3CA7ABB97E9BA7D5BA464DA0095DBAFFD3, config_update:1000,os.ver_up_to_date:0,os.rooted:0,os.rooted.nativ e:0,os.rooted.hiders:0,malware.any:0,total.risk.generic:0 Encrypted (more effort required to tamper): 9Jyx4xpeoK6VEZCCjQuW8vc5+xCktgPGjNIqhkgLeYZOtae9MDEKtc7OBUuL7ZO6GW 6Z3yjcxKwQpglHqwrxvz+1JGMh/wv6R8U6S51+uA3tn+fqhcOxqGM4z7WP1/rLh9gD QPVFC8dOQ8/hLf3K+Q==
  • 35. Transmission encryption - pinning Good practice: SSL certificate pinning. • Hardcode server's certificate details in the mobile application. • Goal: it will be more difficult to conduct Man-in-the-Middle attacks Unfortunatelly, pinning implementation is problematic for developers, and often introduces vulnerabilities ;)
  • 36. Transmission encryption - pinning SSL vulnerability example #1 – empty trustManager sslcontext = SSLContext.getInstance("TLS"); atrustmanager = new TrustManager[1]; atrustmanager[0] = new EasyX509TrustManager(null); sslcontext.init(null, atrustmanager, null); The application accepts ALL the possible certificates ;)
  • 37. Transmission encryption - pinning SSL vulnerability example #2 – hostnameVerifier SocketFactory sf = SSLSocketFactory.getDefault(); SSLSocket socket = (SSLSocket) sf.createSocket("mail.google.com", 443); SSLSession s = socket.getSession(); HostnameVerifier hv = HttpsURLConnection.getDefaultHostnameVerifier(); if (!hv.verify("mail.google.com", s)) { throw new SSLHandshakeException("Expected mail.google.com, found " + s.getPeerPrincipal()); } socket.close(); https://developer.android.com/training/articles/security-ssl.html#WarningsSslSocket The application accepts all the certificates signed by the specific CA.
  • 39. How it works? Public key Session key sent to server (encrypted by server's public key) Data encrypted by session key random session key Server API
  • 40. How to attack it? The transmitted data must be at some point in clear-text form on the device, but it is difficult to tamper. Our approach: • Patch the app to generate static encryption key instead of random one. • Develop Burp intercepting proxy extension to decrypt the traffic using the static key
  • 41. How to attack it? The transmitted data must be at some point in clear-text form on the device, but it is difficult to tamper. Our approach: • Patch the app to generate static encryption key instead of random one. • Develop Burp intercepting proxy extension to decrypt the traffic using the static key And of course the server-side vulnerabilities were still there!
  • 43. Wrap-up • Rethink your decisions Technology is complex and bad assumptions are in the roots of poor security • Future proof your plan Risk depends on many factors, and may change in time (mobile malware development) • Use available options It is possible to enforce many additional layers of security, which render the attacks more difficult and mitigate the risk. • Implementation details matters! Bad implementation could introduce vulnerabilities even if the project is correct • Perfom analysis and deep testing if you are planning to use HCE or similar technologies
  • 44. Q&A Whitepaper Meet us at our UK partner stand T80 Wojciech.Dworakowski@securing.pl @wojdwo Slawomir.Jasek@securing.pl @securingpl
  • 45. Hope to meet you also at... Internet banking safeguards vulnerabilities Wojtek Dworakowski GATTacking Bluetooth Smart devices – introducing a new BLE MITM proxy tool Sławomir Jasek