# Swamp CTF 2025

**Droppin' some fresh writeups from Swamp CTF 2025!** 🐊💥\
Teamed up with my crew, **sh3lldon3**, and we dove deep into the swampy madness.\
Let’s get straight into the hacks and hijinks—no fluff, just flags. 🚀

## Web

### Contamination

<figure><img src="/files/zBF0Mapz6T2miflGpA0Z" alt=""><figcaption></figcaption></figure>

Analysing the source code provided,  we get to know that&#x20;

1. Application has reverse proxy build using Ruby and has endpoint /api?action='getInfo'.
2. Backend is build using Python which has two endpoints "/api?action='getFlag'" and "/api?action='getInfo'".
3. We have to send POST requests with some json data.

<div><figure><img src="/files/QMi8cOLOCZPcRhonAIPE" alt=""><figcaption><p>Reverse Proxy Server</p></figcaption></figure> <figure><img src="/files/vFGD1EQ6iIcmNHKOhNbb" alt=""><figcaption><p>Backend code</p></figcaption></figure></div>

Now, in order to get flag we have to:

1. Hit the "/api?action='getFlag'" endpoint at backend, so somehow pass action='getFlag' as Reverse Proxy accepts only action='getInfo' and gives error otherwise.
2. Cause error in parsing json data so that environment variables containing flag get exposed.

### Exploit

Since the backend and reverse proxy is build using different languages, so there is difference in the handling parameters. Hence, we can do <mark style="color:blue;">**Parameter Pollution.**</mark>

<pre><code><strong>http://chals.swampctf.com:41234/api?action=getFlag&#x26;action=getInfo
</strong></code></pre>

This payload is able to bypass because whenever there are duplicate variables then Ruby will consider the last one while Python considers the first one.

Again, due to difference in the method of parsing JSON data, there are characters that are treated differently in two languages.

```
{ "data":"\q" }
```

&#x20;Now, "\q" is not a valid special character.&#x20;

1. When Ruby encounters it, then it simply consider it as  two characters '\\' and 'q'  and therefore, pass it to the backend and gives no error.
2. Since, it is not a valid escape sequence, therefore it will cause parsing error in backend (JSONcode error by Python).

In this way, We successfully expose the environment variables and get the Flag.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://h4ck-th3-wh47.gitbook.io/h4ck_th3_wh47/ctf-2025/swamp-ctf-2025.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
