InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties…

Follow publication

SSRF steals EC2 tokens

What is SSRF (Server-Side Request Forgery)? Server-Side Request Forgery (SSRF) is a critical vulnerability that allows an attacker to manipulate a server into making unintended requests. This can lead to leakage of sensitive data, access to internal systems, or even remote code execution. Let’s go deeper into how SSRF can be used to steal source code, access internal services, and exfiltrate sensitive data.

  • Many applications run internal services that shouldn’t be exposed to the public (e.g., http://localhost, http://127.0.0.1, http://internal-service.local).
  • If an attacker can manipulate the URL, they can scan internal services.

Example payload:

http://example.com/get-image?url=http://localhost:6379/ If the response is different for an open port, the attacker knows which services are running.

AWS SSRF Payload:

http://example.com/get-image?url=http://169.254.169.254/latest/meta-data/

If successful, the attacker can read IAM role credentials, allowing them to take over cloud resources.

Now let’s we reproduce the vulnerability . I found the target by https://www.youtube.com/@lostsecc this youtube channel you can support him and learn from him . His is bug hunter also and some of vulnerability i learn from him i’m very grateful . So let’s we talking about how to reproduce this vulnerability . I’ve tried to reproduce the vulnerability to more critical and i see something it’s using AWS server . So based on my research i can steal the IAM credentials and takeover S3 cloud bucket from the server and also i’ve identify the website is using a php languages so i can use a symlink to get the current path to arbitary read file on the server .

I will not be responsible if you use this lesson incorrectly. I am only conveying knowledge.

TBH this vulnerability has been patched by a few weeks and i think i want to disclosure this vulnerablity

1. https://www.somaiya.edu/download.php?pdf_path=https://XXX.com/blabla.pdf

It’s will downloading a pdf file so i tried to manipulation the url and it’s work , so that’s mean the download.php allows downloads from external url and not internal only , So the conclusion is i can get any source from the server like arbitary file read , I can get IAM credentials by change pdf_path value into AWS internal and also can do file:///etc/passwd

So after i try to manipulation the external url with file:///etc/passwd it's valid now let's we leak the mysql credentials using a symlink

What is Symlink?

First of all we need to knows how symlink was work. A symbolic link (symlink) is a special type of file in a filesystem that points to another file or directory. It acts as a shortcut, allowing users to access the target file or directory from a different location without duplicating the actual data

Now let’s find the current path of server using symlink . After i research i’ve found this /proc/self/cwd/index.php so this is symlink to read current path on server

Then after i put this file:///proc/self/cwd/index.php it’s work i’ve leaked the index.php. In index.php after i analyze the code i got the location of database on arigel/config/database.php

Here the credentials of mysql . As you can see here the host mysql is using amazon cloud so i think it’s possibility i can access the cloud AWS from the server and steal the credentials

1.Change the pdf_path value with internal aws http://169.254.169.254/latest/user-data

As you can see there is list of directory for internal aws so to steal the credentials just do this

http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance

So for full video you can watch in my youtube channel here

Impact Of SSRF

  1. Attacker can takeover s3 bucket or any sensitive credentials on cloud server
  2. Possibility leakage source code

Best Regards,

Muhammad Nizar

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in InfoSec Write-ups

A collection of write-ups from the best hackers in the world on topics ranging from bug bounties and CTFs to vulnhub machines, hardware challenges and real life encounters. Subscribe to our weekly newsletter for the coolest infosec updates: https://weekly.infosecwriteups.com/

Written by Muhammad Nizar

Hi i'm 15 y/o now my dreams is want to be successfull people and could be proud of my parents . I hope i can be Bug hunter and Security Researcher one day .

No responses yet

Write a response