Types of API and their Uses
- REST and SOAP API use predominantly use HTTP as their protocol
- Arguments are sent as part of the URL, as HTTP Header or in the request body
- Message payload is predominantly JSON for REST and XML for SOAP
Why Hack an API ?
- Provoke error messages or response that give us system details
- Database names
- File Paths
- Component versions
- Find Security holes that give us access to system resources
- Put the API in an unavailable or unstable state (DOS)
Security Standards for Web API
- SSL commonly used for transport-level encryption
- Message level encryption and signatures :
- SOAP/XML: WS-Security and related standards
- REST:JSON Web Algorithms
- Authentication
- SOAP: WS-Security/SAML
- REST: Oauth 1 + 2, OpenID Connect, SAML, custom
API Attack Surface Detection
- We want to know as much as possible about an APIs endpoints, messages, parameters behaviour
- The more we know - the better we can target our attack
- Unfortunately though - an API has no ‘UI’ that can show is the attack surface
-apis: {
-{
path:”/pet/{petID}”,
-operations: [
-{
method: “DELETE”,u
summary: “Delete a pet”,
notes: “ ”
type: “void”,
nickname: “deletepet”,
- authorizations: {
- Oauth2: {
-{
scope: “write:pets”,
description: “modify pets in your account”
}
]
},
- Parameters: [
- {
name: “petID”,
description: “Pet id to delete”,
required: true,
type:”string”,
paranType: “path”,
allowMultiple:false
}
},
Attack Surface Detection : API Metadata
- api-docs.json
- WSDL/XML Schema
- Swagger, RAML, API-Blueprint, ioDocs, etc
- Hypermedia (JSON-LD, Siren, etc)
- Documentation / Developer Portals
Attack Surface Detection: Other Methods
- Discovery
- Record traffic via proxy or network sniffer to record and “learn” an API
- Brute Force
- Try common used endpoints (/api, /api/v1, etc)
- Use error messages to uncover possible paths
API Security Checklist
* Authentication
- Don't use Basic Auth Use standard authentication (e.g. JWT, OAuth).
- Don't reinvent the wheel in Authentication, token generation, password storage. Use the standards.
- Use Max Retry and jail features in Login.
- Use encryption on all sensitive data.
* JWT (JSON Web Token)
- Use a random complicated key (JWT Secret) to make brute forcing the token very hard.
- Don't extract the algorithm from the payload. Force the algorithm in the backend (HS256 or RS256).
- Make token expiration (TTL, RTTL) as short as possible.
- Don't store sensitive data in the JWT payload, it can be decoded easily.
* OAuth
- Always validate redirect_uri server-side to allow only whitelisted URLs.
- Always try to exchange for code and not tokens (don't allow response_type=token).
- Use state parameter with a random hash to prevent CSRF on the OAuth authentication process.
- Define the default scope, and validate scope parameters for each application.
* Access
- Limit requests (Throttling) to avoid DDoS / brute-force attacks.
- Use HTTPS on server side to avoid MITM (Man In The Middle Attack).
- Use HSTS header with SSL to avoid SSL Strip attack.
* Input
- Use the proper HTTP method according to the operation: GET (read), POST (create), PUT/PATCH (replace/update), and DELETE (to delete a record), and respond with 405 Method Not Allowed if the requested method isn't appropriate for the requested resource.
- Validate content-type on request Accept header (Content Negotiation) to allow only your supported format (e.g. application/xml, application/json, etc) and respond with 406 Not Acceptable response if not matched.
- Validate content-type of posted data as you accept (e.g. application/x-www-form-urlencoded, multipart/form-data, application/json, etc).
- Validate User input to avoid common vulnerabilities (e.g. XSS, SQL-Injection, Remote Code Execution, etc).
- Don't use any sensitive data (credentials, Passwords, security tokens, or API keys) in the URL, but use standard Authorization header.
- Use an API Gateway service to enable caching, Rate Limit policies (e.g. Quota, Spike Arrest, Concurrent Rate Limit) and deploy APIs resources dynamically.
* Processing
- Check if all the endpoints are protected behind authentication to avoid broken authentication process.
- User own resource ID should be avoided. Use /me/orders instead of /user/654321/orders.
- Don't auto-increment IDs. Use UUID instead.
- If you are parsing XML files, make sure entity parsing is not enabled to avoid XXE (XML external entity attack).
- If you are parsing XML files, make sure entity expansion is not enabled to avoid Billion Laughs/XML bomb via exponential entity expansion attack.
- Use a CDN for file uploads.
- If you are dealing with huge amount of data, use Workers and Queues to process as much as possible in background and return response fast to avoid HTTP Blocking.
- Do not forget to turn the DEBUG mode OFF.
Output
- Send X-Content-Type-Options: nosniff header.
- Send X-Frame-Options: deny header.
- Send Content-Security-Policy: default-src 'none' header.
- Remove fingerprinting headers - X-Powered-By, Server, X-AspNet-Version etc.
- Force content-type for your response, if you return application/json then your response content-type is application/json.
- Don't return sensitive data like credentials, Passwords, security tokens.
- Return the proper status code according to the operation completed. (e.g. 200 OK, 400 Bad Request, 401 Unauthorized, 405 Method Not Allowed, etc).
CI & CD
- Audit your design and implementation with unit/integration tests coverage.
- Use a code review process and disregard self-approval. Ensure that all components of your services are statically scanned by AV software before push to production, including vendor libraries and other dependencies.
Useful terminology:
Vulnerability: A weakness in the target system, through which penetration can successfully occur.
Exploit: Once a vulnerability is known, an attacker takes advantage of it, and breaks into the system using a code/script known as an exploit.
Payload: This is a set of tasks initiated by the attacker subsequent to an exploit, in order to maintain access to the compromised system
Image Source : Google |
Metasploit has good provisions for information gathering and vulnerability scanning, due to its integration with the dradis framework and configuration with various database drivers such as mysql, sqlite and postgresql
Post Written by author : B Siddarth QA
About blogger : about me
Very valuable post...! This information shared is helpful to improve my knowledge skill. Thank you...!
ReplyDeleteOffshore software testing services
software testing services company
software testing services
Software Qa Services
quality assurance service providers
Performance testing services
Security testing services
software testing Companies
regression testing services
Hey Guys !
ReplyDeleteUSA Fresh & Verified SSN Leads AVAILABLE with best connectivity
All Leads have genuine & valid information
**HEADERS IN LEADS**
First Name | Last Name | SSN | Dob | DL Number |Address | State | City | Zip | Phone Number | Account Number | Bank NAME
*Price for SSN lead $2
*You can ask for sample before any deal
*If anyone buy in bulk, we can negotiate
*Sampling is just for serious buyers
==>ACTIVE & FRESH CC FULLZ ALSO AVAILABLE<==
->$5 PER EACH
->Hope for the long term deal
->Interested buyers will be welcome
**Contact 24/7**
Whatsapp > +923172721122
Email > leads.sellers1212@gmail.com
Telegram > @leadsupplier
ICQ > 752822040
Thanks for the valuable information. Are you looking for a one-stop solution to your Information/Cybersecurity needs? IARM, one of the few companies to focus exclusively on End-End Information/Cybersecurity solutions and services providers to organizations across all verticals.
ReplyDeletePenetration Testing Service Provider
Mobile Application Penetration Testing Company
<a href="https://www.iarminfo.com/api-penetration-testing/”> Web application Penetration testing company</a>
Very valuable information shared in this blog . I was looking for something like that and found it here.
ReplyDeleteTop QA Companies
Top Automation Testing Companies
Top Mobile App Testing Companies
Top Performance Testing Companies
Thank you so much for your wonderful information…great work keep going…Looking for the best network penetration testing services in Hyderabad in your budget contact Cyanous software solutions now.
ReplyDeleteBest network penetration testing services in Hyderabad
Best software & web development company in Hyderabad
This was a stunning and valuable content. thanks for sharing this informative post.
ReplyDeleteEthical Hacking Training in Chennai
Ethical Hacking Course Near Me
Ethical Hacking Course in Coimbatore
Hi. So much thoughtful information you have provided here. Really a nice blog to read through. Thanks for sharing. Also please follow this Expert Web Security Testing Services by 5Data Inc in the USA
ReplyDeleteNice blog
ReplyDeleteEnsure Cybersecurity with Expert Web Security Testing Services
Interesting article Thank you for sharing Penetration testing
ReplyDelete