SERVER-SIDE REQUEST FORGERY

Server-side Request Forgery (SSRF) is a vulnerability that allows and attacker to cause the webserver to make an additional or edited HTTP request to the resource of the attackers choosing. There are two types of SSRF, the first is a regular SSRF where data is returned to the attacker and the second is a blind SSRF, but no information is returned to the attackers screen.


A successful SSRF can result in any of the following:
  • Access to unauthorised areas.
  • Access to confidential data.
  • Ability to Scale to internal networks.
  • Reveal authentication tokens/credentials.

Examples of SSRF:

In the below example, the attacker has complete control over the page requested by the web server. The attacker has requested the URL of some data for a user and it has been returned by the web server.



The below example shows that an attacker can combine a SSRF attack with a directory traversal vulnerability. More information on directory traversal can be found here.



In the below example the attacker can control the server's subdomain to which the request is made. Take note of the payload ending in &x= being used to stop the remaining path from being appended to the end of the attacker's URL and instead turns it into a parameter ?x= on the query string.



Going back to the original request, the attacker can instead force the web server to request a server of the attackers choice. By doing so, we can capture request headers that are sent to the attacker's specified domain. These headers could contain authentication credentials or API keys sent by website.thm



Here I am able to find the flag of http://server.website.thm by requesting server=server.website.thm/flag?id=9&x=



Finding an SSRF 

Potential SSRF vulnerabilities can be spotted in web applications in many different ways, here are four common examples:


Some of these examples are easier to exploit than others and a lot of trial and error will be required to find a working payload. For blind SSRF exploits, an external HTTP logging tool such as Burp Suite or https://requestbin.com/ will need to be used to monitor requests.


Defeating Common SSRF Defences

The two most common ways of defending against SSRF are Deny and Allow lists.

A Deny List is where all requests are accepted apart from resources specified in a list or a matching a particular pattern. The Deny list could include sensitive data, endpoints, IP addresses or domains. For example, names such as localhost and 127.0.0.1 may be included in a Deny List however an attacker may be able to bypass this by using alternative localhost references such code 0 , 0.0.0.0 or subdomains that have a DNS record which resolves to the IP Adress 12.7.0.0.1 such as 127.0.0.1.nip.io

Also, in a cloud environment, it would be beneficial to block access to the IP address 169.254.169.254 , which contains metadata for the deployed cloud server, including possibly sensitive information. An attacker can bypass this by registering a subdomain on their own domain with a DNS record that points to the IP Address 169.254.169.254.

An Allow List is where all requests are denied unless they appear on a list or match a particular pattern. For example, if the Allow list only accepts URLs that begin with https://example.com, an attacker can create a subdomain on the attackers domain name, such as https://example.com.attackers-domain.com. The application logic would now allow this input and let an attacker control the internal HTTP request

An Open Redirect is an endpoint on the server where the website visitor gets automatically redirected to another website address. Take for example the link code https://example.com/link?url=https://example-shop.com
. This endpoint was created to record the number of times visitors have clicked this link for advertising/marketing purposes. Imagine instead that there was an SSRF vulnerability with rules that only allowed URLs beginning with https://example.com/. an Attacker could utilise the above feature and redirect the internal HTTP request to a domain of the attackers choosing.

SSRF Practical

There is a detailed walkthrough of a SSRF exploit on a website at https://tryhackme.com/room/ssrfqi, please refer to this for steps taken.

Comments

Popular posts from this blog

STARTUP

NMAP POST PORT SCANS

BURPSUITE IN-DEPTH