Thamizhiniyan C S
HomeWriteupsResourcesCheatsheets
HackTheBox
HackTheBox
  • HackTheBox
  • Machines
    • Easy
      • Devvortex
      • Sau
      • CozyHosting
      • Cat
      • Crafty
      • Analytics
      • Squashed
      • Keeper
      • Pilgrimage
      • NodeBlog
      • PC
  • Tracks
    • Beginner Track
      • Lame
      • Find the Easy Pass
      • Weak RSA
      • Jerry
      • You Know 0xDiablos
      • Netmon
      • Under Construction
      • Blue
    • Intro To Android Exploitation
      • Pinned
      • Manager
      • Anchored
      • APKrypt
      • Explore
      • Don't Overreact
      • APKey
    • Pwn With Metasploit
      • Optimum
      • Devel
  • Challenges
    • Web
      • Easy
        • Templated
  • Sherlocks
    • DFIR
      • Easy
        • Recollection
    • SOC
      • Easy
        • Meerkat
    • Malware Analysis
      • Easy
        • Heartbreaker-Continuum
        • Lockpick
        • Lockpick 2.0
Powered by GitBook
On this page
  • Overview
  • Information Gathering - Website
  • Testing Template Injection
  • Generating the Payload and Exploiting the Vulnerability

Was this helpful?

  1. Challenges
  2. Web
  3. Easy

Templated

Templated HackTheBox Web Challenge Writeup by Thamizhiniyan C S

PreviousEasyNextDFIR

Last updated 1 year ago

Was this helpful?

Overview

Greetings everyone,

In this write-up, we will tackle Templated from HackTheBox.

Challenge link:

Difficulty Level: Easy

Let's Begin 🙌

First start the instance and navigate to the given IP address.


Information Gathering - Website

We got the response back as site under construction, with a message Proudly powered by Flask/Jinja2. From this we can devise that the server is made up of Flask and it uses Jinja2 template engine.

If we try to access a route which is not available, the server responds with a page not found error.

If we take a look at the error, we can see that the error has reflected the route which we tried to access. This might be vulnerable to template injection.


Testing Template Injection

So I looked out for Jinja2 payloads and found the following website:

I tried the Detection payload from the above website to check whether it is vulnerable to template injection.

I used Postman to send requests because it will be easy to modify and send the request each time.

As mentioned in the Detection section, the server thrown a Error. So this site is vulnerable to template injection.


Generating the Payload and Exploiting the Vulnerability

Next I tried some random payloads from the site and found the following which worked:

When I tried one of the above mentioned payloads, It worked:

Next again I tried some of the payloads in the above section and found the following payload to be working:

Okay, now we are able to execute commands and get the output for those commands. So I modified the request to list the contents of the directory:

Modified Payload: {{ self.**init**.**globals**.**builtins**.**import**('os').popen('ls').read() }}

If we take a look at the response we can see the flag file flag.txt. This time I modified the payload to view the contents of the flag.txt file:

Modified Payload: {{ self.**init**.**globals**.**builtins**.**import**('os').popen('cat flag.txt').read() }}

And we got the flag…….

Templated
PayloadsAllTheThings/README.md at master · swisskyrepo/PayloadsAllTheThingsGitHub
Logo