Hacking and Defending APIs 1.1
Hacking and Defending APIs 1.1
1
#whoami
Robert Wagner
@mr_minion
• Hak4Kidz Co-Founder
• ISSA-Chicago Board
• Apisec.ai Evangelist
• API7:Security Misconfiguration
• API8: Injection
BOLA vulns are present when an API provider allows consumers access to resources that they should not
be authorized to access. Two things are key to finding BOLA: resource ID and a lack of security controls.
Request
GET /api/resource/1
GET /user/account/find?user_id=15
POST /company/account/Apple/balance
POST /admin/pwreset/account/9001
Attack
GET /api/resource/5
GET /user/account/find?user_id=10
POST /company/account/Google/balance
POST /admin/pwreset/account/1337
Design access the same way a Domain Admin would – put users into access groups, and assign
permissions to the groups – for EVERY Attribute
Require ALL access be based on authorized requests to an ATTRIBUTE, and DENY everything else.
Testing isn't "hard". You're typically just replacing one value for another. But it can be time consuming,
when you have 1000s of endpoints
API authentication is only unique, in the fact that it takes place beyond the GUI. Somehow, it is often
overlooked and lacks security.
API2: Mitigations
• This vector is all about attackers abusing your authentication flows. Credential stuffing works
really well here.
• Get MFA already!!
• Just like encryption, don't roll your own Auth! This work has already been done for you.
• Remember that your "I Forgot My Password" mechanism can be abused just as easily.
Excessive data exposure occurs when a consumer makes an API request for data and the provide r
responds with more information than requested
Excessive data exposure typically takes place because the API developers are expecting/trusting their
consumers to parse out the data.
This vulnerability is the equivalent of asking someone for their name and they start telling you their DOB,
home address, email address, SSN, and whether they use MFA
Example:
API3: Watch Those Streams
- Sequential IDs
• If your API returns PII, you'll need to classify that data and apply policy to it.
• Apply concepts of least privilege, just like all other data access.
The API is not sufficiently protected against excessive amounts of requests or payload sizes.
Rate limiting is how some organizations monetize their APIs, bypassing this restriction can have serious
financial impacts.
If the affected infrastructure does not have enough resources then a certain amount of requests will
lead to a denial of service.
Request
POST /admin/pwreset/account/9001
Attack
POST /admin/pwreset/AccoUnt/9001
POST /admin/pwreset/account/9001?
POST /admin/pwreset/AccoUnt/9001%00
There are multiple ways to throttle requests, responses, and the resources allocated
Valid Request
PUT /api/v1/account/update
Token:UserA-Token
--snip--
Attack
DELETE /api/v1/account/UserB
Token:UserA-Token
--snip--
Response
HTTP/1.1 200 OK
Just like with BOLA (API1) you need an access policy designed to stop imposters
Access needs to be controlled down to the attribute level, based on the users session. DENY everything
else
Logs FTW again! Every indexing tool has some sort of "Rare" value call. Use it to surface rare methods to
an endpoint. You won't prevent the attack, but at least you'll have visibility.
• If documentation is shared between public users, partners, and administrators then mass
assignment weaknesses will be even easier to discover/exploit
POST /api/v1/register
--snip--
{"username":"hAPI_hacker","email":"[email protected]","admin": true,"admin":1,"isadmin":
true,"role":"admin","role":"administrator","user_priv": "admin","password":"Password1!"}
API6: Looking for Clues
Your attacker is for any clue about properties or fields they can manipulate
Restrict and define the exact parameters the endpoint will accept (yay)
API7: Security Misconfiguration
Fortunately(?) Infosec and IT have been dealing with this for decades.
Change management and compliance frameworks already cover almost all these issues.
Enforce them.
API8: Injection
Injection flaws include: SQL Injection, NoSQL Injection, XXS, and system command injection.
API8: Still the Bane of Our Existence
Test early, test often. It's too easy for these flaws to get missed.
A common practice for APIs is to include versioning within the URL path: /v1, /v2, /v3, /test, /uat etc.
If an API provider allows access to an unsupported or incomplete version of the API then they run the
risk of having additional weaknesses within the affected version.
Weaknesses can often be found in patch notes and all over Github. If an API provider had a weakness in
a previous version, then the access to that version should be removed across the entire API.
API9: Where are those Crown Jewels, again??
Document your APIs. Yes, all of them.
Enumerate your APIs. You shouldn't have to use Kiterunner, but you probably will. See Katie!
• Essentially a false negative is when vulnerabilities are present, but are not detected.
• Vulnerability testing that results in false negative findings provides a risky sense of being secure.
• APIs that are not tested with the right tools and techniques often result in false negatives. False
negatives leave API providers the idea that they are safe and secure, when they are not.
Case Study: USPS Informed Visibility (2018)
• One of the features that drove the innovation behind the USPS Informed Visibility program was
the API.
• The USPS Office of Inspector General performed a vulnerability assessment and the report was
released on October 12, 2018. This report is public and can be found here
https://www.uspsoig.gov/document/informed-visibility-vulnerability-assessment
• The OIG Vulnerability Assessment was released on October 12, 2018. The Krebs article exposing
the data exposure was released on November 21, 2018.
• This is not to drag the Inspector General through the mud, but instead to emphasize that they
were using classic tools and techniques that provided them with false negative results. These
results were passed on to the USPS.
• If you use the wrong vulnerability assessment tools then you will receive false-negatives.
• The OIG stated that they used Nessus and HP WebInspect. (Instead of HP WebInspect: Nikto,
OWASP ZAP, Burp Suite Pro)
1 - crAPI Burp Suite Automated Scan
Penetration testing: Is currently a point in time adversarial test of your web apps and APIs.
- When the right tools and techniques are used, penetration testing will not only reveal
vulnerabilities, but can provide proof-of-concept for what can be achieved when those
vulnerabilities are exploited.
Bug Bounty programs: Typically, bug bounties are a continuous test of your API. This is another valuable
layer of testing.
- Bug bounty communities often contain a mix of awesome hackers at various levels of
expertise.
- A bounty program will often provide your API security testing with a variety of skillsets
testing them.
- You can lure API hackers to target your APIs with additional incentives ($$$).
Both of these types of testing offer advantages:
- Business Logic Testing: Using features of an API against the API provider.
- Both provide you with an additional layer of assurance by delivering results your
organization can use for remediation.
Securely test your current API vulnerability management program against deliberately vulnerable APIs.
If your current program does not detect any vulnerabilities against these deliberately vulnerable
applications then your API vulnerability management program needs improvement!
The most likely problem is that you are not using the correct tools or techniques in order to detect API
vulnerabilities.
crAPI
https://github.com/OWASP/crAPI
VAmPI
https://github.com/erev0s/VAmPI
vAPI
https://github.com/roottusk/vapi
Pixi
https://github.com/DevSlop/Pixi
- Configure tools and use techniques that test the API from the standpoint of an
authorized user.
- Do not trust automated scans that show that your API is secure (they are probably lying,
configured incorrectly, or just currently incapable).
- Add layers to your API security testing by including penetration testing, bug bounty
programs, and make sure that you are using the right tools configured appropriately.
- Use the OWASP API Security Top 10 (2019) to guide your vulnerability assessment testing.
• If you’re not allowed to use Kiterunner to scan, you can still leverage it’s “word lists” with a log
indexing tool.
- Create code to replace 4xx and 5xx with a fake 200 if more than x number of errors, with
new (but unproductive) paths to follow.
Want to Learn More?
hAPI Hacking!
[email protected]
@mr_minion
www.linkedin.com/in/robertwagner2
@hAPI_hacker
www.linkedin.com/in/coreyball