Server-Side Request Forgery
Thilan Dissanayaka Application Security April 06, 2020

Server-Side Request Forgery

SSRF (Server-Side Request Forgery) is a type of security vulnerability where an attacker tricks a server into making a request to another internal or external system that the attacker shouldn’t have access to. Note the point that this request is not possible to make directly therefor the attacker is using the victim server to make that request on behalf of him.

In short,

The attacker doesn’t send the request directly to the target — they fool the server into sending it on their behalf.

How It Works

Imagine you call a hotel and say:

“Hey, can you call this other room for me and tell me what the person says?”

Now, what if you gave the front desk a number outside the hotel, like a secret government number? And the hotel doesn’t check and just dials it?

You’ve now abused the hotel’s phone system to call somewhere you couldn’t call directly.

That’s SSRF — using the server like a middleman to reach places you shouldn’t be allowed to.

A Common Example

Let’s say there’s a website that lets users give a URL to fetch a profile picture:

GET /fetch-image?url=http://example.com/pic.jpg

The server reads the url parameter and downloads the image from that link.

What if an attacker change the url parameter to the following?

http://127.0.0.1:8000/admin

Then the complete payload becomes,

GET /fetch-image?url=http://127.0.0.1:8000/admin

Now the server makes a request to itself or another internal service — and returns the result to the attacker. That internal page was never meant to be seen from the outside!

What Can Attackers Do with SSRF?

  • Access internal-only websites or APIs
  • Bypass firewalls or IP restrictions
  • Read cloud metadata (e.g., AWS http://169.254.169.254/)
  • Perform port scans from inside the network
  • Escalate to Remote Code Execution (RCE) if other bugs exist

Real-World Danger

In cloud environments like AWS, SSRF can be very dangerous.

Attackers may access:

http://169.254.169.254/latest/meta-data/

Which gives them access to:

  • Instance credentials
  • Tokens
  • Configuration secrets

That could lead to full cloud account takeover.

Types of SSRF

Type Description
Basic SSRF Directly manipulate a parameter to control server-side requests.
Blind SSRF The attacker can trigger a request, but does not see the response.
Recursive SSRF The SSRF leads to an internal request that in turn triggers more requests.
File-based SSRF SSRF used to access file system protocols (e.g., file://, gopher://)

How to Prevent SSRF

  • Don’t let users supply raw URLs to the server.
  • Use allow-lists: only let the server connect to specific safe domains.
  • Block requests to:

localhost, 127.0.0.1, 169.254.169.254, Internal IP ranges like 10.0.0.0/8, 192.168.0.0/16

  • Disable unnecessary outbound network access from servers.

  • Use network segmentation.

  • Sanitize and validate user input carefully.

SSRF Prevention Strategies

  • Input Validation Allowlist only specific, known URLs or domains.
const allowedDomains = ['https://api.myservice.com'];
  • Block Internal IP Ranges Block requests to:

127.0.0.1, 0.0.0.0, 169.254.169.254

Private IPs: 10.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12

  • DNS Resolution + IP Verification Resolve domain names and check that the resulting IP isn’t internal.

  • Disable unused protocols If your app doesn’t need gopher://, file://, etc., block them.

  • Network layer defenses Firewalls and service mesh rules (e.g., Istio) to restrict egress traffic.

  • Cloud-specific controls On AWS, disable metadata v1, use IMDSv2, and apply IAM policies.

SSRF Bypass Techniques

Attackers may use these to bypass input filters:

  • IP obfuscation

Decimal: http://2130706433 → 127.0.0.1

Octal: http://0177.0.0.1

Hex: http://0x7f000001

Mixed notation

  • DNS rebinding / redirects

http://evil.com/redirect?target=127.0.0.1

  • Protocol smuggling

gopher://127.0.0.1:3306/_DATA

file://, ftp://, or dict://

  • URL encoding

http://127.0.0.1%2Fetc%2Fpasswd

ALSO READ
Blockchain 0x000 – Understanding the Fundamentals
May 21, 2020 Web3 Development

Imagine a world where strangers can exchange money, share data, or execute agreements without ever needing to trust a central authority. No banks, no intermediaries, no single point of failure yet...

Identity and Access Management (IAM)
May 11, 2020 Identity & Access Management

Who are you — and what are you allowed to do? That's the fundamental question every secure system must answer. And it's exactly what Identity and Access Management (IAM) is built to solve.

How I built a web based CPU Simulator
May 07, 2020 Pet Projects

As someone passionate about computer engineering, reverse engineering, and system internals, I've always been fascinated by what happens "under the hood" of a computer. This curiosity led me to...

Writing a Shell Code for Linux
Apr 21, 2020 Exploit Development

Shellcode is a small piece of machine code used as the payload in exploit development. In this post, we write Linux shellcode from scratch — starting with a simple exit, building up to spawning a shell, and explaining every decision along the way.

Exploiting a Stack Buffer Overflow on Windows
Apr 12, 2020 Exploit Development

In a previous tutorial we discusses how we can exploit a buffer overflow vulnerability on a Linux machine. I wen through all theories in depth and explained each step. Now today we are going to jump...

Access Control Models
Apr 08, 2020 Identity & Access Management

Access control is one of the most fundamental concepts in security. Every time you set file permissions, assign user roles, or restrict access to a resource, you're implementing some form of access control. But not all access control is created equal...

Exploiting a  Stack Buffer Overflow  on Linux
Apr 01, 2020 Exploit Development

Have you ever wondered how attackers gain control over remote servers? How do they just run some exploit and compromise a computer? If we dive into the actual context, there is no magic happening....

Basic concepts of Cryptography
Mar 01, 2020 Cryptography

Ever notice that little padlock icon in your browser's address bar? That's cryptography working silently in the background, protecting everything you do online. Whether you're sending an email,...

Common Web Application Attacks
Feb 05, 2020 Application Security

Web applications are one of the most targeted surfaces by attackers. This is primarily because they are accessible over the internet, making them exposed and potentially vulnerable. Since these...

Remote Code Execution (RCE)
Jan 02, 2020 Application Security

Remote Code Execution (RCE) is the holy grail of application security vulnerabilities. It allows an attacker to execute arbitrary code on a remote server — and the consequences are as bad as it sounds. In this post, we'll go deep into RCE across multiple languages, including PHP, Java, Python, and Node.js.