XYZ E Municipality

Description

Can you find the secret track?

Challenge Files: https://master-platform-bucket.s3.amazonaws.com/challenges/f7bab6f2-dd2d-40fc-9cb3-a4b8dd452a0c/public.ziparrow-up-right

Source

import os
import requests
from flask import Flask, render_template, render_template_string, request

app = Flask(__name__)
app.static_folder = "static"
basedir = os.path.abspath(os.path.dirname(__file__))

def sanitize_string(template):
    global_vars = ["self", "request", "session", "g", "app"]
    for var in global_vars:
        template = "{% set " + var + " = None %}\n" + template
    return template

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/generate_certificate", methods=["POST"])
def generate_certificate():
    social_id = request.form["social_id"]
    certificate_template = requests.get("http://localhost:8000/certificate-template").text

    with open(f"{basedir}/templates/generate.html", "r") as f:
        content = f.read()
        content = content.replace("{{CERTIFICATE}}", certificate_template.replace("{{ social_id }}", social_id))

    return render_template_string(sanitize_string(content), social_id=social_id)


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000)

Solution

render_template_string functions is clear indicator for SSTI. There's sanitize_string function for content which we will need to bypass.

XYZ E-Municipality.png
XYZ E-Municipality-1.png

SSTI confirmed with {{7*7}}

XYZ E-Municipality-2.png

https://book.hacktricks.wiki/en/pentesting-web/ssti-server-side-template-injection/index.html#jinja2-pythonarrow-up-right

There's many payloads to choose, but my favorite is

XYZ E-Municipality-3.png

/flag.txt is only readable by root and we are ctf-player...

XYZ E-Municipality-4.png

Root is running the other application we can potentially hijack

It's running in Debug mode and we could leak PIN code to access it (?) Not sure how without frontend yet.

https://book.hacktricks.wiki/en/network-services-pentesting/pentesting-web/werkzeug.htmlarrow-up-right

I think for node address we need eth1

After gathering information use the script in HackTricks to get pin code, first I tried using eth0 interface to generate it.

During testing I got {"auth": false, "exhausted": true} status, exhausted means that PIN is perma blocked 💀

Not sure why but eth0 was required instead of eth1 to make the PIN work...

First to authenticate we need a SECRET value, it's stored in HTML so just http request and grab it.

Now we can authenticate and grab cookies

Flag: flag{gYDTW6Avx6q6HCc7pEBKRW3AoWDYa8xu}

Last updated