SlideShare a Scribd company logo
1 of 38
API Security
learning from a Pentesters POV
API Strategy Workshop March 2015
Dr. Ir. Stefaan Seys, ZIONSECURITY
Who am I
2
๏ฝ Stefaan Seys
๏ฝ Security Expert at ZIONSECURITY
๏ฝ Postdoc researcher at KU Leuven / COSIC
COSIC
Outline
3
๏ฝ (no exponential graphs on nr of attacks, etc.)
๏ฝ High level security architecture and objectives
๏ฝ API security threats and prevention
๏ฝ Authentication and SSL/TLS
๏ฝ History revisited
๏ฝ Messages to take home
High level API security architecture
End-to-End
Security Components
5
API ServiceConsumer
Threat Protection
Authentication /
Authorization
Logging /
Auditing
Security
Analytics
Confidentiality
Development
Access
Identity Service
Authentication /
Authorization
Confidentiality
Identity Service
API Consumption Security API Exposure Security
Threat Protection
Who is the Consumer?
6
API Service
Browser or Browser plug-in
Mobile App
Back-end Service
Not possible to hide
long-term secrets.
Very tempting to hide
long-term secrets.
OK to use long-term
secrets.
API Security Threats and Prevention
Discovery
8
Public APIs are designed to be used by โ€˜externalโ€™
parties
๏ฝ Documentation
๏ฝ API descriptors in standard formats
๏ฝ URI-style: Swagger, RAML, API-Blueprint, I/O Docs, etc.
๏ฝ SOAP: WSDL/XML-Schema
๏ฝ Hypermedia: JSON-LD, Siren, Hydra, etc.
๏ฝ This obviously helps in the discovery phase ๏Š
Swagger example
9
"paths": {
"/pet/{petId}": {
"delete": {
"tags": ["pet"],
"summary": "Deletes a pet",
"description": "",
"operationId": "deletePet",
"produces": ["application/json", "application/xml"],
"security": [{
"petstore_auth": ["write:pets", "read:pets"]
}]
"parameters": [{
"name": "petId",
"in": "path",
"description": "Pet id to delete",
"required": true,
"type": "integer",
"format": "int64"
}],
. . .
Attack point
HTTP method, how does it handle
unspecified methods?
OAUTH 2: which implementation?,
known vulnerabilities? How does it
validate tokens?
Scopes?
Is access validated? Link between user
and petId? Are IDs random? Injection?
XSS?
What if we do not set the โ€œpetIdโ€? What
if we do not give an int? Or > int64 max
size?
โ€œClassic Discoveryโ€ in case the API is secret
10
What about just keeping your API secret?
๏ฝ Local Proxy or network sniffer
๏ฝ Guess / brute-force APIs
๏ฝ http://api.*.com/api/v?/*.json
Public API with a secret API keyโ€ฆ
11
March 2014
Issue was already reported to them in 2010...
Story
12
๏ฝ Install the official Android App
๏ฝ Extract the APK file and install on an emulator
๏ฝ Use TCPDUMP to listen to traffic from App
๏ฝ Start App, enter garbage at login page
๏ฝ GET
/handler.php?CritickerKey=xxxxx&Function=UserSignin&UserName=asdf
asdf&Password=6d2dedb5b9e02d466a8d98b4c4398b1d
๏ฝ The Criticker API has a call to get the list of users!
๏ฝ GET handler.php?CritickerKey=xxxxx&Function=AccountUsers
๏ฝ And a call to request the current password! In
plaintext!!
๏ฝ GET
handler.php?CritickerKey=xxxxx&Function=LookupPassword&UserId=xxx
xx
What did they do wrong?
13
๏ฝ They created an API with โ€œuselessโ€, dangerous and
documented features
๏ฝ Call to get list of all users?
๏ฝ Call to get password of a any user?
๏ฝ Passwords are stored in plain text on the server
๏ฝ They use plain HTTP (no SSL)
๏ฝ The โ€œkeyโ€ is sent over the network with every call
Secret API with docs in error message
14
๏ฝ Basic authentication (over SSL, no cert pinning)
๏ฝ With static fixed username/password for all users
(embedded in App)
๏ฝ Only โ€˜authenticationโ€™ is the userID
๏ฝ This userID is sequential (not random)
๏ฝ Returns a help file if you send a wrong API request
Assume your API is publicโ€ฆ
Fuzzing and invalid input
16
http://api.openweathermap.org/data/2.5/weather?id=2172797
๏ฝ Attack vector:
๏ฝ Replace the id parameter with โ€œrandomlyโ€ generated
value
๏ฝ Purpose:
๏ฝ Get information through error message
๏ฝ Prevention
๏ฝ Ensure generic, consistent and correct error
messages that do not reveal any additional
information
Malicious Input
17
๏ฝ Attack vector
๏ฝ Craft malicious input that targets specific message parser,
implementation weakness, etc.
๏ฝ Vulnerable parser will recursively replace &lol9;
๏ฝ Resulting in a billion โ€˜lolโ€™s; taking up 3GByte of RAM
<?xml version="1.0"?>
<!DOCTYPE lolz [
<!ENTITY lol "lol">
<!ELEMENT lolz (#PCDATA)>
<!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
<!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
<!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
<!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
<!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
<!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
<!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
<!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
]>
<lolz>&lol9;</lolz>
Malicious Input
18
๏ฝ Purpose
๏ฝ Attempt to put server in insecure state (if lucky)
๏ฝ Crash server
๏ฝ Prevention
๏ฝ Only use proven parsers
๏ฝ Patch your system
๏ฝ Input validation and sanitation
(SQL) Injection
19
http://api.openweathermap.org/weather?id=2172797
โ€œSELECT * FROM forecast WHERE locID='โ€ + id +โ€โ€˜โ€;
๏ฝ Attack Vector
๏ฝ /weather?id=5โ€™%20or%20โ€™1โ€™=โ€™1
๏ฝ SELECT * FROM forecast WHERE locID=โ€˜5โ€™ or โ€˜1โ€™=โ€˜1โ€™
[xkcd]
(SQL) Injection
20
๏ฝ Purpose
๏ฝ If used for authentication: get access without credentials
๏ฝ Dump database
๏ฝ Clear database
๏ฝ Prevention
๏ฝ Never use String operations to create โ€˜semi-structuredโ€
data objects such as SQL queries, JSON, XML, Xpath,
etc.
๏ฝ Use a parameterized API to construct the object instead
๏ฝ If not available: carefully ensure escaping all special
characters depending on the syntax of the interpreter
Cross Site Scripting (XSS)
21
Persistent XSS
API Server
1. Inject malicious
script
๏ฝ Prevention
๏ฝ Use context-aware
auto-escaping
๏ฝ When?
Cross Site Request Forgery (CSRF)
22
MyFace.com
Authenticated Session
Victim lured to visit attackerโ€™s site
<a href=โ€œhttps://www.myface.com/
update.php?relationship=Single%2
0and%20Desperate>Free beer</a>
POST
Cross Site Request Forgery (CSRF)
23
๏ฝ Purpose
๏ฝ Force end-user to execute a state-changing request (as
attacker never sees response).
๏ฝ Change userโ€™s email address, reset password, transfer
funds, โ€ฆ
๏ฝ Prevention
๏ฝ Include a per request random authentication code that is
verified on the server (once!)
CSRF does not apply to APIsโ€ฆ
24
๏ฝ Normally SOAP and REST API authentication is not
done through a session (cookie)
๏ฝ Instead, every API call contains authentication
information
๏ฝ In a URL parameter
๏ฝ In the HTTP header (Oauth)
๏ฝ Part of the XML body (SOAP)
๏ฝ If you stick to these principles and use proper
authentication/authorization model, CSRF does not
apply.
Authentication and SSL
Authentication
26
๏ฝ Basic/Digest authentication
๏ฝ Uses HTTP headers to identify users
๏ฝ WS-Security SAML and Username Tokens
๏ฝ SOAP/XML based authentication, passes credentials and assertions in
SOAP message headers, optionally signed and encrypted
๏ฝ API Key based authentication
๏ฝ each request to an API contains a key uniquely identifying the client
๏ฝ OAuth 1.x/2
๏ฝ HTTP-based interactions and flows that authorize usage of HTTP
resources (API, Web, etc). OAuth indirectly includes a step for
authentication but makes no claims on how that authentication should be
done.
๏ฝ JSON web tokens
Username / password ?
27
Apple Celebrity photo hack
๏ฝ Hidden API to find your phone
๏ฝ https://fmipmobile.icloud.com/fmipservice/device/
<apple_id>/initClient
๏ฝ Basic Authentication through SSL tunnel
<apple_id> : <password>
๏ฝ So far so goodโ€ฆ
๏ฝ Server does not limit the number of attemptsโ€ฆ
๏ฝ Same password for all you i-things on Apple (iCloud)
SSLโ€™s Role
28
SSL โ€“ The Good
๏ฝ Secures the actual client authentication; as majority of
web authentication is based on passwords/tokens
๏ฝ Compatible with vast amount of clients and servers
๏ฝ โ€˜Easyโ€™ to set up (hard to do right)
๏ฝ Removes crypto burden from application developers
SSLโ€™s Role
29
SSL โ€“ The Bad
๏ฝ Compatibility -> Complexity -> Vulnerabilities
๏ฝ For APIs it is also mostly the only crypto layer
๏ฝ If broken -> huge impact
๏ฝ โ€œBut we are using SSLโ€ฆโ€: it does not magically make
your site secureโ€ฆ
๏ฝ If used with server side certs only, client side authentication is
not in scope
๏ฝ Transport layer security -> does not prevent many application
layer problems (injection, XSS, etc.)
How did we get here?
OWASP Top 10 โ€“ A History
31
2004 2007 2010 2013
A1 Unvalidated Input A1 Cross Site Scripting (XSS) A1 Injection A1 Injection
A2 Broken Access Control A2 Injection Flaws A2 Cross Site Scripting (XSS) A2
Broken Authentication and
Session Management
A3
Broken Authentication and
Session Management
A3 Malicious File Execution A3
Broken Authentication and
Session Management
A3 Cross-Site Scripting (XSS)
A4 Cross Site Scripting A4
Insecure Direct Object
Reference
A4
Insecure Direct Object
References
A4
Insecure Direct Object
References
A5 Buffer Overflow A5
Cross Site Request Forgery
(CSRF)
A5
Cross Site Request Forgery
(CSRF)
A5 Security Misconfiguration
A6 Injection Flaws A6
Information Leakage and
Improper Error Handling
A6 Security Misconfiguration A6 Sensitive Data Exposure
A7 Improper Error Handling A7
Broken Authentication and
Session Management
A7
Insecure Cryptographic
Storage
A7
Missing Function Level
Access Control
A8 Insecure Storage A8
Insecure Cryptographic
Storage
A8
Failure to Restrict URL
Access
A8
Cross-Site Request
Forgery (CSRF)
A9 Application Denial of Service A9 Insecure Communications A9
Insufficient Transport Layer
Protection
A9
Using Components with
Known Vulnerabilities
A10
Insecure Configuration
Management
A10
Failure to Restrict URL
Access
A10
Unvalidated Redirects and
Forwards
A10
Unvalidated Redirects and
Forwards
[Jim DelGrosso]
In Conclusion
Messages to take home
33
๏ฝ Security is very difficult to get right
๏ฝ Do not reinvent or worse, โ€œimproveโ€ the wheel yourself
๏ฝ Web APIโ€™s suffer more or less from the same general
โ€˜issuesโ€™ as web applications
๏ฝ However, API โ€˜structureโ€™ allows for dedicated security
enforcement point
๏ฝ Messaging (Request/Response)
๏ฝ Authentication
๏ฝ Authorization
๏ฝ Tailor (authentication mechanism) to your consumer
๏ฝ Take your SSL setup seriously
Questions
34
Thank you!
?
35
36
Whatโ€™s Up with SSL?
37
๏ฝ BEAST (2011, CBC padding crypto attack, <TLS1.1)
๏ฝ RC4 (2013, 223 encryptions required, RC4)
๏ฝ BREACH (2013, clever crypto attack, universal)
๏ฝ Heartbleed (2014, openssl buffer overread, 1.0.1 to
1.0.1f)
๏ฝ POODLE (2014, ~BEAST, SSL3.0, TLS?)
๏ฝ FREAK (2015, RSA_EXPORT factoring, various)
๏ฝ Who says you can trust
root certificates in your browser?
๏ฝ 177 root certs in Firefox
Cross Site Scripting (XSS)
38
Reflective XSS
API Server
๏ฝ Prevention
๏ฝ Use context-aware
auto-escaping
๏ฝ When?

More Related Content

What's hot

Testing REST Web Services
Testing REST Web ServicesTesting REST Web Services
Testing REST Web Services
Jan Algermissen
ย 

What's hot (20)

Pentesting Rest API's by :- Gaurang Bhatnagar
Pentesting Rest API's by :- Gaurang BhatnagarPentesting Rest API's by :- Gaurang Bhatnagar
Pentesting Rest API's by :- Gaurang Bhatnagar
ย 
Api security
Api security Api security
Api security
ย 
OWASP Top 10 Proactive Controls
OWASP Top 10 Proactive ControlsOWASP Top 10 Proactive Controls
OWASP Top 10 Proactive Controls
ย 
A How-to Guide to OAuth & API Security
A How-to Guide to OAuth & API SecurityA How-to Guide to OAuth & API Security
A How-to Guide to OAuth & API Security
ย 
Protecting Your APIs Against Attack & Hijack
Protecting Your APIs Against Attack & Hijack Protecting Your APIs Against Attack & Hijack
Protecting Your APIs Against Attack & Hijack
ย 
Practical API Security - PyCon 2018
Practical API Security - PyCon 2018Practical API Security - PyCon 2018
Practical API Security - PyCon 2018
ย 
Using & Abusing APIs: An Examination of the API Attack Surface
Using & Abusing APIs: An Examination of the API Attack SurfaceUsing & Abusing APIs: An Examination of the API Attack Surface
Using & Abusing APIs: An Examination of the API Attack Surface
ย 
API SECURITY
API SECURITYAPI SECURITY
API SECURITY
ย 
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
ย 
Securty Testing For RESTful Applications
Securty Testing For RESTful ApplicationsSecurty Testing For RESTful Applications
Securty Testing For RESTful Applications
ย 
OAuth for your API - The Big Picture
OAuth for your API - The Big PictureOAuth for your API - The Big Picture
OAuth for your API - The Big Picture
ย 
OWASP PDX May 2016 : Scanning with Swagger (OAS) 2.0
OWASP PDX May 2016 : Scanning with Swagger (OAS) 2.0 OWASP PDX May 2016 : Scanning with Swagger (OAS) 2.0
OWASP PDX May 2016 : Scanning with Swagger (OAS) 2.0
ย 
Rest API Security - A quick understanding of Rest API Security
Rest API Security - A quick understanding of Rest API SecurityRest API Security - A quick understanding of Rest API Security
Rest API Security - A quick understanding of Rest API Security
ย 
Rest API Security
Rest API SecurityRest API Security
Rest API Security
ย 
Checkmarx meetup API Security - API Security top 10 - Erez Yalon
Checkmarx meetup API Security -  API Security top 10 - Erez YalonCheckmarx meetup API Security -  API Security top 10 - Erez Yalon
Checkmarx meetup API Security - API Security top 10 - Erez Yalon
ย 
Mobile Application Security Testing (Static Code Analysis) of Android App
Mobile Application Security Testing (Static Code Analysis) of Android AppMobile Application Security Testing (Static Code Analysis) of Android App
Mobile Application Security Testing (Static Code Analysis) of Android App
ย 
Are You Properly Using JWTs?
Are You Properly Using JWTs?Are You Properly Using JWTs?
Are You Properly Using JWTs?
ย 
API Security and Management Best Practices
API Security and Management Best PracticesAPI Security and Management Best Practices
API Security and Management Best Practices
ย 
Qark DefCon 23
Qark DefCon 23Qark DefCon 23
Qark DefCon 23
ย 
Testing REST Web Services
Testing REST Web ServicesTesting REST Web Services
Testing REST Web Services
ย 

Similar to Web API Security

้ฆ™ๆธฏๅ…ญๅˆๅฝฉ
้ฆ™ๆธฏๅ…ญๅˆๅฝฉ้ฆ™ๆธฏๅ…ญๅˆๅฝฉ
้ฆ™ๆธฏๅ…ญๅˆๅฝฉ
baoyin
ย 
AppSec EU 2016: Automated Mobile Application Security Assessment with MobSF
AppSec EU 2016: Automated Mobile Application Security Assessment with MobSFAppSec EU 2016: Automated Mobile Application Security Assessment with MobSF
AppSec EU 2016: Automated Mobile Application Security Assessment with MobSF
Ajin Abraham
ย 
API Testing and Hacking.pdf
API Testing and Hacking.pdfAPI Testing and Hacking.pdf
API Testing and Hacking.pdf
Vishwas N
ย 
You wanna crypto in AEM
You wanna crypto in AEMYou wanna crypto in AEM
You wanna crypto in AEM
Damien Antipa
ย 

Similar to Web API Security (20)

Building Secure Apps in the Cloud
Building Secure Apps in the CloudBuilding Secure Apps in the Cloud
Building Secure Apps in the Cloud
ย 
OWASPAPISecurity
OWASPAPISecurityOWASPAPISecurity
OWASPAPISecurity
ย 
Securing RESTful API
Securing RESTful APISecuring RESTful API
Securing RESTful API
ย 
apidays Hong Kong - Attack API Architecture, Alvin Tam, Hong Kong Computer So...
apidays Hong Kong - Attack API Architecture, Alvin Tam, Hong Kong Computer So...apidays Hong Kong - Attack API Architecture, Alvin Tam, Hong Kong Computer So...
apidays Hong Kong - Attack API Architecture, Alvin Tam, Hong Kong Computer So...
ย 
้ฆ™ๆธฏๅ…ญๅˆๅฝฉ
้ฆ™ๆธฏๅ…ญๅˆๅฝฉ้ฆ™ๆธฏๅ…ญๅˆๅฝฉ
้ฆ™ๆธฏๅ…ญๅˆๅฝฉ
ย 
Owasp top 10_openwest_2019
Owasp top 10_openwest_2019Owasp top 10_openwest_2019
Owasp top 10_openwest_2019
ย 
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)
ย 
mobsf.pdf
mobsf.pdfmobsf.pdf
mobsf.pdf
ย 
AppSec EU 2016: Automated Mobile Application Security Assessment with MobSF
AppSec EU 2016: Automated Mobile Application Security Assessment with MobSFAppSec EU 2016: Automated Mobile Application Security Assessment with MobSF
AppSec EU 2016: Automated Mobile Application Security Assessment with MobSF
ย 
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
ย 
OWASP Portland - OWASP Top 10 For JavaScript Developers
OWASP Portland - OWASP Top 10 For JavaScript DevelopersOWASP Portland - OWASP Top 10 For JavaScript Developers
OWASP Portland - OWASP Top 10 For JavaScript Developers
ย 
APIDays Paris Security Workshop
APIDays Paris Security WorkshopAPIDays Paris Security Workshop
APIDays Paris Security Workshop
ย 
API Testing and Hacking (1).pdf
API Testing and Hacking (1).pdfAPI Testing and Hacking (1).pdf
API Testing and Hacking (1).pdf
ย 
API Testing and Hacking.pdf
API Testing and Hacking.pdfAPI Testing and Hacking.pdf
API Testing and Hacking.pdf
ย 
API Testing and Hacking.pdf
API Testing and Hacking.pdfAPI Testing and Hacking.pdf
API Testing and Hacking.pdf
ย 
Open APIs - Risks and Rewards (ร˜redev 2013)
Open APIs - Risks and Rewards (ร˜redev 2013)Open APIs - Risks and Rewards (ร˜redev 2013)
Open APIs - Risks and Rewards (ร˜redev 2013)
ย 
You wanna crypto in AEM
You wanna crypto in AEMYou wanna crypto in AEM
You wanna crypto in AEM
ย 
Cqcon2015
Cqcon2015Cqcon2015
Cqcon2015
ย 
Designing Secure APIs
Designing Secure APIsDesigning Secure APIs
Designing Secure APIs
ย 
OWASP Top10 2010
OWASP Top10 2010OWASP Top10 2010
OWASP Top10 2010
ย 

Recently uploaded

Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
SUHANI PANDEY
ย 
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRLLucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
imonikaupta
ย 
โ‚น5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] ๐Ÿ”|97111...
โ‚น5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] ๐Ÿ”|97111...โ‚น5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] ๐Ÿ”|97111...
โ‚น5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] ๐Ÿ”|97111...
Diya Sharma
ย 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
SUHANI PANDEY
ย 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
SUHANI PANDEY
ย 
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
SUHANI PANDEY
ย 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
singhpriety023
ย 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
SUHANI PANDEY
ย 

Recently uploaded (20)

Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
ย 
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
WhatsApp ๐Ÿ“ž 8448380779 โœ…Call Girls In Mamura Sector 66 ( Noida)
ย 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
ย 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
ย 
VVVIP Call Girls In Connaught Place โžก๏ธ Delhi โžก๏ธ 9999965857 ๐Ÿš€ No Advance 24HRS...
VVVIP Call Girls In Connaught Place โžก๏ธ Delhi โžก๏ธ 9999965857 ๐Ÿš€ No Advance 24HRS...VVVIP Call Girls In Connaught Place โžก๏ธ Delhi โžก๏ธ 9999965857 ๐Ÿš€ No Advance 24HRS...
VVVIP Call Girls In Connaught Place โžก๏ธ Delhi โžก๏ธ 9999965857 ๐Ÿš€ No Advance 24HRS...
ย 
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRLLucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
Lucknow โคCALL GIRL 88759*99948 โคCALL GIRLS IN Lucknow ESCORT SERVICEโคCALL GIRL
ย 
โ‚น5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] ๐Ÿ”|97111...
โ‚น5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] ๐Ÿ”|97111...โ‚น5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] ๐Ÿ”|97111...
โ‚น5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] ๐Ÿ”|97111...
ย 
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
๐“€คCall On 7877925207 ๐“€ค Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
ย 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
ย 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
ย 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
ย 
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now โ˜Ž 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
ย 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
ย 
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
VVIP Pune Call Girls Mohammadwadi WhatSapp Number 8005736733 With Elite Staff...
ย 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
ย 
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
ย 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
ย 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
ย 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
ย 
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
Ganeshkhind ! Call Girls Pune - 450+ Call Girl Cash Payment 8005736733 Neha T...
ย 

Web API Security

  • 1. API Security learning from a Pentesters POV API Strategy Workshop March 2015 Dr. Ir. Stefaan Seys, ZIONSECURITY
  • 2. Who am I 2 ๏ฝ Stefaan Seys ๏ฝ Security Expert at ZIONSECURITY ๏ฝ Postdoc researcher at KU Leuven / COSIC COSIC
  • 3. Outline 3 ๏ฝ (no exponential graphs on nr of attacks, etc.) ๏ฝ High level security architecture and objectives ๏ฝ API security threats and prevention ๏ฝ Authentication and SSL/TLS ๏ฝ History revisited ๏ฝ Messages to take home
  • 4. High level API security architecture
  • 5. End-to-End Security Components 5 API ServiceConsumer Threat Protection Authentication / Authorization Logging / Auditing Security Analytics Confidentiality Development Access Identity Service Authentication / Authorization Confidentiality Identity Service API Consumption Security API Exposure Security Threat Protection
  • 6. Who is the Consumer? 6 API Service Browser or Browser plug-in Mobile App Back-end Service Not possible to hide long-term secrets. Very tempting to hide long-term secrets. OK to use long-term secrets.
  • 7. API Security Threats and Prevention
  • 8. Discovery 8 Public APIs are designed to be used by โ€˜externalโ€™ parties ๏ฝ Documentation ๏ฝ API descriptors in standard formats ๏ฝ URI-style: Swagger, RAML, API-Blueprint, I/O Docs, etc. ๏ฝ SOAP: WSDL/XML-Schema ๏ฝ Hypermedia: JSON-LD, Siren, Hydra, etc. ๏ฝ This obviously helps in the discovery phase ๏Š
  • 9. Swagger example 9 "paths": { "/pet/{petId}": { "delete": { "tags": ["pet"], "summary": "Deletes a pet", "description": "", "operationId": "deletePet", "produces": ["application/json", "application/xml"], "security": [{ "petstore_auth": ["write:pets", "read:pets"] }] "parameters": [{ "name": "petId", "in": "path", "description": "Pet id to delete", "required": true, "type": "integer", "format": "int64" }], . . . Attack point HTTP method, how does it handle unspecified methods? OAUTH 2: which implementation?, known vulnerabilities? How does it validate tokens? Scopes? Is access validated? Link between user and petId? Are IDs random? Injection? XSS? What if we do not set the โ€œpetIdโ€? What if we do not give an int? Or > int64 max size?
  • 10. โ€œClassic Discoveryโ€ in case the API is secret 10 What about just keeping your API secret? ๏ฝ Local Proxy or network sniffer ๏ฝ Guess / brute-force APIs ๏ฝ http://api.*.com/api/v?/*.json
  • 11. Public API with a secret API keyโ€ฆ 11 March 2014 Issue was already reported to them in 2010...
  • 12. Story 12 ๏ฝ Install the official Android App ๏ฝ Extract the APK file and install on an emulator ๏ฝ Use TCPDUMP to listen to traffic from App ๏ฝ Start App, enter garbage at login page ๏ฝ GET /handler.php?CritickerKey=xxxxx&Function=UserSignin&UserName=asdf asdf&Password=6d2dedb5b9e02d466a8d98b4c4398b1d ๏ฝ The Criticker API has a call to get the list of users! ๏ฝ GET handler.php?CritickerKey=xxxxx&Function=AccountUsers ๏ฝ And a call to request the current password! In plaintext!! ๏ฝ GET handler.php?CritickerKey=xxxxx&Function=LookupPassword&UserId=xxx xx
  • 13. What did they do wrong? 13 ๏ฝ They created an API with โ€œuselessโ€, dangerous and documented features ๏ฝ Call to get list of all users? ๏ฝ Call to get password of a any user? ๏ฝ Passwords are stored in plain text on the server ๏ฝ They use plain HTTP (no SSL) ๏ฝ The โ€œkeyโ€ is sent over the network with every call
  • 14. Secret API with docs in error message 14 ๏ฝ Basic authentication (over SSL, no cert pinning) ๏ฝ With static fixed username/password for all users (embedded in App) ๏ฝ Only โ€˜authenticationโ€™ is the userID ๏ฝ This userID is sequential (not random) ๏ฝ Returns a help file if you send a wrong API request
  • 15. Assume your API is publicโ€ฆ
  • 16. Fuzzing and invalid input 16 http://api.openweathermap.org/data/2.5/weather?id=2172797 ๏ฝ Attack vector: ๏ฝ Replace the id parameter with โ€œrandomlyโ€ generated value ๏ฝ Purpose: ๏ฝ Get information through error message ๏ฝ Prevention ๏ฝ Ensure generic, consistent and correct error messages that do not reveal any additional information
  • 17. Malicious Input 17 ๏ฝ Attack vector ๏ฝ Craft malicious input that targets specific message parser, implementation weakness, etc. ๏ฝ Vulnerable parser will recursively replace &lol9; ๏ฝ Resulting in a billion โ€˜lolโ€™s; taking up 3GByte of RAM <?xml version="1.0"?> <!DOCTYPE lolz [ <!ENTITY lol "lol"> <!ELEMENT lolz (#PCDATA)> <!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;"> <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;"> <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;"> <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;"> <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;"> <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;"> <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;"> <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;"> ]> <lolz>&lol9;</lolz>
  • 18. Malicious Input 18 ๏ฝ Purpose ๏ฝ Attempt to put server in insecure state (if lucky) ๏ฝ Crash server ๏ฝ Prevention ๏ฝ Only use proven parsers ๏ฝ Patch your system ๏ฝ Input validation and sanitation
  • 19. (SQL) Injection 19 http://api.openweathermap.org/weather?id=2172797 โ€œSELECT * FROM forecast WHERE locID='โ€ + id +โ€โ€˜โ€; ๏ฝ Attack Vector ๏ฝ /weather?id=5โ€™%20or%20โ€™1โ€™=โ€™1 ๏ฝ SELECT * FROM forecast WHERE locID=โ€˜5โ€™ or โ€˜1โ€™=โ€˜1โ€™ [xkcd]
  • 20. (SQL) Injection 20 ๏ฝ Purpose ๏ฝ If used for authentication: get access without credentials ๏ฝ Dump database ๏ฝ Clear database ๏ฝ Prevention ๏ฝ Never use String operations to create โ€˜semi-structuredโ€ data objects such as SQL queries, JSON, XML, Xpath, etc. ๏ฝ Use a parameterized API to construct the object instead ๏ฝ If not available: carefully ensure escaping all special characters depending on the syntax of the interpreter
  • 21. Cross Site Scripting (XSS) 21 Persistent XSS API Server 1. Inject malicious script ๏ฝ Prevention ๏ฝ Use context-aware auto-escaping ๏ฝ When?
  • 22. Cross Site Request Forgery (CSRF) 22 MyFace.com Authenticated Session Victim lured to visit attackerโ€™s site <a href=โ€œhttps://www.myface.com/ update.php?relationship=Single%2 0and%20Desperate>Free beer</a> POST
  • 23. Cross Site Request Forgery (CSRF) 23 ๏ฝ Purpose ๏ฝ Force end-user to execute a state-changing request (as attacker never sees response). ๏ฝ Change userโ€™s email address, reset password, transfer funds, โ€ฆ ๏ฝ Prevention ๏ฝ Include a per request random authentication code that is verified on the server (once!)
  • 24. CSRF does not apply to APIsโ€ฆ 24 ๏ฝ Normally SOAP and REST API authentication is not done through a session (cookie) ๏ฝ Instead, every API call contains authentication information ๏ฝ In a URL parameter ๏ฝ In the HTTP header (Oauth) ๏ฝ Part of the XML body (SOAP) ๏ฝ If you stick to these principles and use proper authentication/authorization model, CSRF does not apply.
  • 26. Authentication 26 ๏ฝ Basic/Digest authentication ๏ฝ Uses HTTP headers to identify users ๏ฝ WS-Security SAML and Username Tokens ๏ฝ SOAP/XML based authentication, passes credentials and assertions in SOAP message headers, optionally signed and encrypted ๏ฝ API Key based authentication ๏ฝ each request to an API contains a key uniquely identifying the client ๏ฝ OAuth 1.x/2 ๏ฝ HTTP-based interactions and flows that authorize usage of HTTP resources (API, Web, etc). OAuth indirectly includes a step for authentication but makes no claims on how that authentication should be done. ๏ฝ JSON web tokens
  • 27. Username / password ? 27 Apple Celebrity photo hack ๏ฝ Hidden API to find your phone ๏ฝ https://fmipmobile.icloud.com/fmipservice/device/ <apple_id>/initClient ๏ฝ Basic Authentication through SSL tunnel <apple_id> : <password> ๏ฝ So far so goodโ€ฆ ๏ฝ Server does not limit the number of attemptsโ€ฆ ๏ฝ Same password for all you i-things on Apple (iCloud)
  • 28. SSLโ€™s Role 28 SSL โ€“ The Good ๏ฝ Secures the actual client authentication; as majority of web authentication is based on passwords/tokens ๏ฝ Compatible with vast amount of clients and servers ๏ฝ โ€˜Easyโ€™ to set up (hard to do right) ๏ฝ Removes crypto burden from application developers
  • 29. SSLโ€™s Role 29 SSL โ€“ The Bad ๏ฝ Compatibility -> Complexity -> Vulnerabilities ๏ฝ For APIs it is also mostly the only crypto layer ๏ฝ If broken -> huge impact ๏ฝ โ€œBut we are using SSLโ€ฆโ€: it does not magically make your site secureโ€ฆ ๏ฝ If used with server side certs only, client side authentication is not in scope ๏ฝ Transport layer security -> does not prevent many application layer problems (injection, XSS, etc.)
  • 30. How did we get here?
  • 31. OWASP Top 10 โ€“ A History 31 2004 2007 2010 2013 A1 Unvalidated Input A1 Cross Site Scripting (XSS) A1 Injection A1 Injection A2 Broken Access Control A2 Injection Flaws A2 Cross Site Scripting (XSS) A2 Broken Authentication and Session Management A3 Broken Authentication and Session Management A3 Malicious File Execution A3 Broken Authentication and Session Management A3 Cross-Site Scripting (XSS) A4 Cross Site Scripting A4 Insecure Direct Object Reference A4 Insecure Direct Object References A4 Insecure Direct Object References A5 Buffer Overflow A5 Cross Site Request Forgery (CSRF) A5 Cross Site Request Forgery (CSRF) A5 Security Misconfiguration A6 Injection Flaws A6 Information Leakage and Improper Error Handling A6 Security Misconfiguration A6 Sensitive Data Exposure A7 Improper Error Handling A7 Broken Authentication and Session Management A7 Insecure Cryptographic Storage A7 Missing Function Level Access Control A8 Insecure Storage A8 Insecure Cryptographic Storage A8 Failure to Restrict URL Access A8 Cross-Site Request Forgery (CSRF) A9 Application Denial of Service A9 Insecure Communications A9 Insufficient Transport Layer Protection A9 Using Components with Known Vulnerabilities A10 Insecure Configuration Management A10 Failure to Restrict URL Access A10 Unvalidated Redirects and Forwards A10 Unvalidated Redirects and Forwards [Jim DelGrosso]
  • 33. Messages to take home 33 ๏ฝ Security is very difficult to get right ๏ฝ Do not reinvent or worse, โ€œimproveโ€ the wheel yourself ๏ฝ Web APIโ€™s suffer more or less from the same general โ€˜issuesโ€™ as web applications ๏ฝ However, API โ€˜structureโ€™ allows for dedicated security enforcement point ๏ฝ Messaging (Request/Response) ๏ฝ Authentication ๏ฝ Authorization ๏ฝ Tailor (authentication mechanism) to your consumer ๏ฝ Take your SSL setup seriously
  • 35. 35
  • 36. 36
  • 37. Whatโ€™s Up with SSL? 37 ๏ฝ BEAST (2011, CBC padding crypto attack, <TLS1.1) ๏ฝ RC4 (2013, 223 encryptions required, RC4) ๏ฝ BREACH (2013, clever crypto attack, universal) ๏ฝ Heartbleed (2014, openssl buffer overread, 1.0.1 to 1.0.1f) ๏ฝ POODLE (2014, ~BEAST, SSL3.0, TLS?) ๏ฝ FREAK (2015, RSA_EXPORT factoring, various) ๏ฝ Who says you can trust root certificates in your browser? ๏ฝ 177 root certs in Firefox
  • 38. Cross Site Scripting (XSS) 38 Reflective XSS API Server ๏ฝ Prevention ๏ฝ Use context-aware auto-escaping ๏ฝ When?