1 of 38

SSRF / XSPA

Real world Attacks and Mitigations

@riyazwalikar

2 of 38

whoami | head

  • WebAppSec Consultant, Penetration Tester, Bug Bounty Hunter for Google, Facebook, Paypal, Mozilla and other bounty programs
  • null security community Bangalore chapter mod
  • Aspiring singer
  • fire juggler

3 of 38

file agenda.txt

So what are we going to discuss today?

4 of 38

dpkg -i investigate.deb

Found a facebook.com URL which fetched the <title> from a URL I could control

Tested for XSS, SQLi and LFI/RFI

Setup a HTTP server with port 8080 exposed to the Internet

Used http://myserver:8080 as an argument, mistyped the port number as 808

Facebook displayed an error that hinted on the port being closed

I tested this with other open and closed ports as well

5 of 38

uptime | cut –d " " –f2

Realized I could port scan Internet facing servers using verbose distinct errors from facebook

6 of 38

cat /etc/issue

Facebook was using underlying server side code to open socket connections to remote servers to download content

Friendly error messages were being sent to the client for failed socket connections at the web application level

There was no proper data handling for non HTTP streams, which was causing the application to behave unexpectedly

7 of 38

mail -s 'Bug!' sec@fb.com < /dev/null

Reported the issue to Facebook who responded saying that they did not see how this was a problem

8 of 38

mail -s 'Bug!' sec@fb.com < /dev/null

Sent facebook a Proof of Concept python port scanner

Scanned some random servers on the Internet using the script

Facebook replied and acknowledged that this was a problem

9 of 38

10 of 38

11 of 38

export vuln = 'XSPA / SSRF'

XSPA occur when a web application attempts to connect to user supplied URLs and does not validate backend responses received from the remote server

XSPA allows an attacker to port scan servers and attack services (Internet facing as well as internal devices) while proxying the attack from another web application

XSPA – Cross Site Port Attacks

12 of 38

export vuln = 'XSPA / SSRF'

XSPA – Cross Site Port Attacks

13 of 38

export vuln = 'XSPA / SSRF'

XSPA – Cross Site Port Attacks

Consider an application that allows users to specify an external image URL.

Image File URL

Server Status & Body Response

http://remote_server.com/image.png

200 OK – Image retrieved

http://remote_server.com:22/image.png

200 OK – “Invalid Image”

http://remote_server.com:3306/image.png

200 OK – “Invalid Image”

http://remote_server.com:8081

200 OK – “Connection refused!”

The remote server on which the image resides has ports 22,80 and 3306 open

14 of 38

export vuln = 'XSPA / SSRF'

Application displays verbose errors for failed socket connections, receives fixed length responses or delays response for a fixed length of time

Application does not verify received data from the remote server, if the connection was successful

Application does not blacklist internal IP addresses/URLs

XSPA – Cross Site Port Attacks

15 of 38

An attacker generates an HTTP request of the form

http://vulnerable/getimage.php?img=http://internet/image.png

HTTP GET

The vulnerable server then on behalf of the attacker makes a GET request to the internet server for the image.png

HTTP GET

The image is downloaded to the web server and then a local link to it is sent to the attacker

Image

(Response)

Page

(Response)

16 of 38

An attacker generates an HTTP request of the form

http://vulnerable/getimage.php?img=http://LANIP:22/img.png

HTTP GET

The vulnerable server then on behalf of the attacker makes a GET request to the locally accessible server for the img.png

HTTP GET

SSH Banner (Response)

Error

(Response)

Since a GET is made to a non HTTP service, the service returns any banners and/or errors

The web application may then generate specific errors or may display raw errors received – banners for example

17 of 38

find . -print | xargs grep 'logic'

18 of 38

cat popular_servers | ./poke

Found XSPA/SSRF in

19 of 38

cat facebook

The first finding

Application specific response for open port above 1024

20 of 38

cat facebook

The first finding

Application specific response for open port below 1024

21 of 38

cat facebook

The first finding

Application specific response for closed port

22 of 38

cat Google

Google Webmasters – XSPA/SSRF

Application specific response for open HTTP Port

23 of 38

cat Google

Google Webmasters – XSPA/SSRF

Application specific response for open non-HTTP Port

24 of 38

cat Google

Google Webmasters – XSPA/SSRF

Application specific response for closed port

25 of 38

cat mozilla_marketplace

Application specific response for open HTTP port

26 of 38

cat mozilla_marketplace

Application specific response for open non HTTP port

27 of 38

cat mozilla_marketplace

Application specific response for closed port

28 of 38

cat yahoo_developer_network

HTML Page content received from remote server on Open HTTP Port

29 of 38

cat yahoo_developer_network

Non HTTP Service responds with banner – Open non HTTP Port

30 of 38

cat yahoo_developer_network

Non HTTP Service responds with banner – Open non HTTP Port

31 of 38

ls adobe*.flv | xargs vlc

32 of 38

cat /xspa/other_attacks

Attackers can access internal applications and perform URL based attacks (SQLi, Parameter manipulation etc.)

Since the GET /<data> part is controlled by the attacker, it would be possible to attack services and execute code on internal systems

Denial of service attacks on internal services

33 of 38

sudo demo &

34 of 38

patch -p1 < /var/xspa/fixes

Response Handling - implement server side validation of responses received from remote resources

Error handling and messages - Display generic error messages to the client in case something goes wrong.

Restrict connectivity to HTTP based ports - restrict connections to HTTP ports on the server

Blacklist IP addresses - Internal IP addresses, localhost specifications and internal hostnames should be blacklisted

35 of 38

cat /xspa/reading

  • http://spl0it.wordpress.com/2010/12/02/internal-port-scanning-via-crystal-reports/
  • http://www.shmoocon.org/2008/presentations/Web%20portals,%20gateway%20to%20information.ppt
  • http://media.blackhat.com/bh-us-12/Briefings/Polyakov/BH_US_12_Polyakov_SSRF_Business_WP.pdf
  • https://www.corelan.be/index.php/2009/07/19/exploit-writing-tutorial-part-1-stack-based-overflows/
  • http://anantshri.info/articles/web_app_finger_printing.html
  • http://www.nruns.com/_downloads/Whitepaper-Hacking-jBoss-using-a-Browser.pdf
  • http://www.sectheory.com/intranet-hacking.htm
  • http://ha.ckers.org/weird/xhr-ping-sweep.html
  • http://www.w3.org/Protocols/rfc2616/rfc2616.html

All images are the property of their respective creators.

36 of 38

cat /xspa/special_thanks

A big thanks to Jeremiah, @makash, @w3bd3vil, @abh1sek, @nikchillz, Alexander Polyakov and everybody at the @null0x00 community for their help with testing, verifying, building exploits and just being so cool!

37 of 38

38 of 38

Riyaz Ahemed Walikar�@riyazwalikar�http://www.riyazwalikar.com�