Microservices Revenge
Category: Web
Description
I've upgraded the security of this website and added a new feature. Can you still break it?
- Junhua
Attachments: dist.zip
Write-up
- This challenge appears to be a continuation of the previous Microservices challenge.
- The flag can now only be obtained from the
/flag
endpoint of a new microservice atrflagpage
. - Unfortunately, direct access to
rflagpage
is not possible, and we must go through thegateway
. - However, specifying
flagpage
as theservice
query parameter to thegateway
will redirect us to the/construction
endpoint ofrflagpage
, as indicated by the specified routes. - We need to identify potential attack vectors that can be exploited to forward our request to
http://rflagpage/flag
. - It seems that
http://rhomepage/
is vulnerable to Server-Side Template Injection (SSTI), as we can manipulate ouruser
cookie to render malicious markup content, which is treated as safe HTML input.
- Another attack vector we discovered is SSTI in
http://radminpage/
, where we can inject malicious markup content by manipulating theuser
cookie, as there is no input sanitization before rendering.
- It is more promising to focus on the second attack vector, as we can attempt to leverage SSTI to achieve Server-Side Request Forgery (SSRF). The first attack vector primarily allows us to execute malicious client-side payloads, but it is unlikely to enable us to forward our request to
rflagpage
. - Since
radminpage
andrflagpage
are in the same network, we aim to exploit the second SSTI vulnerability to make a request tohttp://rflagpage/flag
viaradminpage
, retrieve its content, and then send it to our webhook by appending it. - However, there is a custom Web Application Firewall (WAF) method in the gateway called
is_sus()
that checks theservice
query parameter and theuser
cookie against a list of forbidden words. - To bypass these checks, we can cleverly construct a payload that utilizes Jinja2 filters and additional query parameters.
- By specifying banned strings in the query parameters and utilizing Jinja2 filters in our SSTI payload, we can slowly build our payload by retrieving banned content from our query parameters.
- We can use
subprocess.Popen
which can be accessed via"".__class__.__subclasses__
with SSTI and execute inline Python code usingpython3 -c "<python code>"
. - The Python code we aim to execute is as follows:
- The following
curl
request contains the necessary logic to exfiltrate the flag fromhttp://rflagpage/flag
and send it to our webhook URL:
Flag: grey{55t1_bl4ck1ist_byp455_t0_S5rf_538ad457e9a85747631b250e834ac12d}