Daemon Of Hacking
  • WELCOME!
    • 👋/home/usr/KruKnight
  • METHODOLOGIES & RESOURCES
    • Passwords & Attacks
    • Post Exploitation
      • 👀Situational Awareness
      • 🖥️Privilege Escalation
        • Linux Privilege Escalation
        • Windows Privilege Escalation
  • Writeups
    • CyCtf 2024
      • Vending Machine
      • Aerospace
      • OhMyCell
    • Portswigger Labs
      • Authentication
        • Username enumeration via different responses
        • 2FA simple bypass
        • Password reset broken logic
        • Username enumeration via subtly different responses
        • Username enumeration via response timing
        • Broken Brute-Force Protection, IP Block
        • Username enumeration via account lock
        • 2FA broken logic
        • Brute-forcing a stay-logged-in cookie
        • Offline password cracking
        • Password reset poisoning via middleware
        • Password brute-force via password change
        • Broken brute-force protection, multiple credentials per request
      • Os Command Injection
        • OS command injection, simple case
        • Blind OS command injection with time delays
        • Blind OS command injection with output redirection
        • Blind OS command injection with out-of-band interaction
        • Blind OS command injection with out-of-band data exfiltration
      • Cross-Origin Resource Sharing (CORS)
        • CORS vulnerability with basic origin reflection
        • CORS vulnerability with trusted null origin
        • CORS vulnerability with trusted insecure protocols
      • Server-side template injection
        • Basic server-side template injection
        • Basic server-side template injection (code context)
      • Server-Side Request Forgery (SSRF)
        • Basic SSRF against the local server
        • Basic SSRF against another back-end
        • Blind SSRF with out-of-band detection
        • SSRF with blacklist-based input filter
        • SSRF with filter bypass via open redirection vulnerability
      • Path Traversal
  • 🟩HTB Writeups
    • Heal
Powered by GitBook
On this page
  • Lab Description
  • Walkthrough
  • Step 1: Analyzing the Application
  • Step 2: Testing for Template Injection
  • Step 3: Establishing Remote Code Execution (RCE)
  • Step 4: Locating the Target File

Was this helpful?

  1. Writeups
  2. Portswigger Labs
  3. Server-side template injection

Basic server-side template injection

PreviousServer-side template injectionNextBasic server-side template injection (code context)

Last updated 5 months ago

Was this helpful?

Lab Description

Walkthrough

Homepage

Step 1: Analyzing the Application

Before testing for vulnerabilities, it’s essential to understand the application’s functionality. The homepage displays a shopping interface with products. When clicking on a product, a message stating, "Unfortunately, this product is out of stock," is displayed.

Using Burp send the request to the repeater and examine the parameters passed when interacting with a product.

  • The message parameter is present in the request. This parameter might be used to dynamically render content on the webpage.

Step 2: Testing for Template Injection

Server-side template injection occurs when user inputs are passed directly into the server's template engine without proper sanitization. By crafting specific payloads, we can test if the message parameter is vulnerable.

  1. Inject a basic payload: {{7*7}}.

    • Expected Output: If vulnerable, the result should display 49 (calculated value).

    • Observation: The output displays {{7*7}}, meaning this specific syntax did not trigger the vulnerability.

  2. Exploring other template engines.

    • Attempted payload: <%= 7*7 %> (Ruby's Embedded Ruby, ERB syntax).

    • Result: Successfully evaluated to 49. This confirms the application uses the ERB engine, making it vulnerable to Ruby-based template injection.

Step 3: Establishing Remote Code Execution (RCE)

Thought Process:

After confirming template injection, the next step is to assess whether arbitrary code can be executed.

<%= system('id') %>

The response contains system information (uid=12002(carlos) gid=12002(carlos)), confirming RCE.

Step 4: Locating the Target File

Thought Process:

The goal is to delete the morale.txt file from Carlos's home directory. First, we need to confirm its presence in the current directory.

  • The output lists morale.txt as a file in the current directory.

Step 5: Deleting the File

Now that the target file is identified, the next step is to delete it using the rm command.

<%= system('rm morale.txt') %>

After executing the payload, the lab confirms successful completion.