🖥️
Offensive security concepts
  • Introduction
  • 💿Virtualbox network setup
    • What is VirtualBox?
    • NAT
    • NAT network
    • Bridged adapter
    • Internal network
    • pfSense
    • vboxmanage
    • Overview
  • 🕵️OSINT
    • What is OSINT?
    • Google dorks
    • Metadata
    • Social media
      • osintagram
  • Tools
    • waybackurls
    • recon-ng
    • sherlock
    • maltego
    • theHarvester
    • photon
  • 😨Social Engineering
    • What is social engineering?
    • 7 tricks of social engineering
    • Email phishing
    • Typosquatting
    • Compiled resources
  • 😈MitM attack
    • What is MitM attack?
    • ARP spoof/poison
    • DNS spoof/poison
    • HTTP MitM attack
    • ICMP redirect attack
    • DHCP spoofing
    • Evil twin attack
    • Experiment (guest network)
    • Compiled resources
  • 🔌UPnP exploitation
    • What is UPnP?
    • What is SSDP?
    • IGD functions
    • LAN devices
    • Compiled resources
  • Network Reconnaissance & Attacks
    • What is network recon & attacks?
  • 1️⃣Network live host discovery
    • What is network live host discovery?
    • nmap
    • arp-scan
    • masscan
  • 2️⃣Network port scan/services enumeration
    • What is network port scan/services enumeration?
    • nmap
    • netcat
  • 3️⃣Network services vulnerability scanning & exploitation
    • What is network vulnerability scanning/exploitation?
    • 20/21 ~ FTP
    • 22 ~ SSH
    • 25 ~ SMTP
    • 53 ~ DNS
    • 80/443 ~ HTTP/HTTPS
    • 110 ~ POP3
    • 111/2049 ~ RPC/NFS
    • 139/445 ~ SMB
    • 143 ~ IMAP
    • 3389 ~ RDP
  • Vulnerability & exploitation
    • Database
    • Metasploit
    • Msfvenom
  • Misconfigurations
    • .DS_Store
  • Web Application Penetration Testing
    • Introduction
    • Web Content Discovery
      • Directories/URLs gathering
      • Subdomain enumeration
    • File inclusion & Path traversal
    • Insecure Direct Object Reference (IDOR)
    • Upload vulnerabilities
      • File extension cheat-sheet
    • SSRF
    • CSRF
    • XSS
    • SSTI
    • SQL injection
      • Filter evasion techniques
      • Practical challenge examples
        • TryHackMe
          • TryHackMe Burp suite: Repeater room
          • TryHackMe Advanced SQL Injection
  • Authentication/session management
    • OWASP WSTG-SESS-10 ~ JSON Web Token (JWT)
    • OWASP WSTG-ATHZ-05 ~ OAuth weaknesses
  • Webshell
  • Web API pentesting
    • Resources
    • Methodology
    • jq
    • httpx
    • ParamSpider
  • Web app pentesting methodology
  • OWASP
    • OWASP top 10
    • OWASP API top 10
    • Web Security Testing Guide (WSTG)
      • WSTG-ATHZ
        • WSTG-ATHZ-05 ~ OAuth weaknesses
      • WSTG-SESS
        • WSTG-SESS-10 ~ JWT
  • General web knowledge
    • URI standard (RFC 3986)
    • HTTP headers
  • 🛣️Attacks on routing protocols
    • What are attacks on routing protocols?
    • BGP hijacking
  • 🏕️To explore
    • MQTT
    • Routersploit
    • DNS rebinding attack
    • LLMNR/mDNS poisoning
  • 👤Anonymity
    • VPN
    • Proxychains
    • TOR
    • Obfuscation
  • Credentials brute-force/cracking
    • Introduction
    • Windows SAM database
    • Dictionary attack
    • Rainbow attack
      • Hash database
    • Tools
      • Hydra
      • John the ripper
      • Hashcat
      • hash-identifier
  • Post-exploitation
    • Gaining shell
      • netcat
      • socat
      • powershell
      • bash
      • PHP
    • Repository
  • Privilege escalation
    • Linux
      • Repositories
      • Enumeration
      • Vulnerabilities exploit
        • General
        • Kernel exploit
        • Sudo
        • SUID
        • Capabilities
        • Cronjobs
        • $PATH
        • NFS (target-machine)
        • Filesystem sharing
          • NFS (attacker-machine)
    • Windows
      • Password harvesting
      • Vulnerabilities exploit
        • Scheduled tasks
        • AlwaysInstallElevated
        • Service misconfigurations
          • Insecure permissions on service executable
          • Unquoted service path
          • Insecure service permission
        • Abusing privileges
  • Ⓜ️MITRE ATT&CK
    • Introduction
  • 🧰Tools/services
    • Introduction
    • Web application pentesting
      • Web discovery/fuzzing
        • paramspider
        • arjun
        • katana
      • uro
      • Password brute-forcing
      • Burp Suite (Community)
      • scanners
        • ZAP (Zed Attack Proxy)
        • nikto
        • nuclei
    • Information gathering/reconnaissance
    • Network recon & attacks
      • nmap (general overview)
      • scapy
      • bettercap
    • General
      • impacket
    • Wordlists
      • cewl
  • Professional report writing
    • Report template
      • Web applicaton pentesting
        • OWASP report layout
  • Tasks on-the-go
    • Note taking on-the-go
    • Other tips
  • Practice
    • Web Application Pentesting
      • OWASP
        • OWASP Juice Shop
        • OWASP Mutillidae II
        • OWASP Hackademic
      • Vulnhub
        • ...
      • Damn Vulnerable Web Application (DVWA)
    • Metasploitable 2
  • Operational Security (OpSec)
    • Hardening
      • General
      • Oracle VirtualBox
      • Web Browser
      • VPN/Proxy
  • Safe document viewer
    • PDF
    • .docx
  • Write-ups
    • TryHackMe
      • Silver Platter
      • Light
      • Pickle Rick
      • Hammer
        • Enumeration (active recon)
          • /hmr
          • Further directory discovery
          • /phpmyadmin
          • burp suite sitemap
        • Brute forcing 4-digit code
        • Retrieving the flag
      • OWASP Top 10 - 2021 (task 22)
      • sqlmap
    • OverTheWire
      • Untitled
    • OWASP
      • OWASP Juice Shop
      • OWASP WebGoat
  • AI prompt
    • ChatGPT
Powered by GitBook
On this page
  • Enumeration
  • Payload to the server query parameter
  1. Write-ups
  2. TryHackMe

OWASP Top 10 - 2021 (task 22)

This challenge deals with a Server-Side Request Forgery (SSRF) vulnerability that is present in the server query parameter.

PreviousRetrieving the flagNextsqlmap

Last updated 3 months ago

Extra practice challenge: "Going the extra mile"

There's a way to use SSRF to gain access to the site's admin area. Can you find it?

A GET request is sent to the following href to download the resume:

/download?server=secure-file-storage.com:8087&id=75482342

General format of the HTTP URL:

http://<url>:8087/download?server=<server_addr>&id=<file_id>

Enumeration

  1. Visiting the following URL http://10.10.106.252:8087/admin (GET request), presented me with a webpage displaying the following message:

Admin interface only available from localhost!!!

This tells us that the admin page can only be accessed from within the machine itself. The goal now will be to find a SSRF vulnerability to redirect the request to the localhost admin URL instead.

  1. I have noticed that an error messages with snippets of the code-base (sensitive information) is shown when a non-integer value is provided to the id query parameter via a GET request.

For example, when the value t is provided, the following info and code snippet is shown in the error message.

A GET request to http://<url>:8087/download?server=&id=t gives the following error details:

ValueError: invalid literal for int() with base 10: 't'

def download():
    file_id = request.args.get('id','')
    server = request.args.get('server','')

    if file_id!='':
        filename = str(int(file_id)) + '.pdf'
        
        response_buf = BytesIO()
        crl = pycurl.Curl()
        crl.setopt(crl.URL, server + '/public-docs-k057230990384293/' + filename)
        crl.setopt(crl.WRITEDATA, response_buf)

From the code snippet in the error message, I have discovered that the final HTTP URL where the request is being sent is generated in the following format:

server + '/public-docs-k057230990384293/' + filename

Where the server query parameter is taken directly from the server query parameter value. The id query parameter value is used directly to generate the final URL value, however, it does not have a direct exploitable impact. This tells us that we can potentially control the final URL where the GET request is being sent.

Thus, the goal is to craft a payload to the server query parameter to forge a request to the localhost admin URL: http://localhost:8087/admin - allowing us to retrieve the admin page content.

Payload to the server query parameter

The placeholder <url>will be used as a general value. As detailed from part 1 in the Enumeration section, the goal will be to redirect the GET request to the localhost admin page at port 8087 - placeholder value should be replaced with localhost:8087/admin.

  1. Null terminator/byte (%00)

http://<url>:8087/download?server=<url>%2500&id=1

The input to the id parameter will be a random integer value. While the value to the server query parameter will be the target URL with the %00character at the end. The goal is to forcefully terminate the string value, to have the server ignore the part after the input.

<url>%00/public-docs-k057230990384293/<filename> -> <url>

However, this method does not work, and produces the following error message:

ValueError: embedded null byte

  1. ? (query symbol) (✔ Working method)

Inserting a ? character at the end of the server query parameter value will trick the server to treat the rest of the input ('/public-docs-k057230990384293/' + filename) as a query. Thus, effectively ignoring its values, allowing an attacker to fully control the server address.

A GET request to the following payload allows us to send a request to the /admin path from within the server localhost, bypassing the restrictions.

http://<target_url>:8087/download?server=localhost:8087/admin?&id=1

  1. #(URI fragment) (✔ Working method)

Similar to the query symbol, inserting an URI fragment symbol (#) at the end of the server query parameter value will trick the server to treat the rest of the input as a fragment.

First attempt of payload:

http://<target_url>:8087/download?server=localhost:8087/admin#&id=1

**Tested on Google Chrome and Firefox

Some browsers may remove the section after the hash symbol (#):

.../.../admin#&id=1 -> .../.../admin

The final URL causes the id query parameter to be removed, which gives the following error:

No file selected...

A fix will be to encode the hash symbol (%23):

.../.../admin%23&id=1 -> .../.../admin#&id=1

Hence, the final GET request URL is:

http://<target_url>:8087/download?server=localhost:8087/admin%23&id=1

TryHackMe | OWASP Top 10 - 2021TryHackMe
Use a hash (#) in a landing page URL - Studio Help
Logo
Logo
URI fragment - URIs | MDNMDN Web Docs
Logo