> 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-easy/cap-hackthebox-writeup.md).

# Запись HackTheBox Cap

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

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

* Небезопасная ссылка на объект каталога (IDOR)
* Утечка информации
* Злоупотребление возможностями (Python3.8) (повышение привилегий)
  {% endhint %}

## Разведка

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

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

<figure><img src="/files/227492fc9b5537a2fb9c853c9a0b1ce98a476633" alt="" width="563"><figcaption></figcaption></figure>

**Проверка подключения VPN**

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

<figure><img src="/files/fd25ed8c2523a388bb72940e5631bdf6cef734e0" alt="" width="563"><figcaption></figcaption></figure>

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

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

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

<figure><img src="/files/958be2981f8f8752ae37d5f04c0a347b9ea89ea3" alt=""><figcaption></figcaption></figure>

**Анализ открытых портов с помощью extractPorts:**

Используйте функцию extractPorts, чтобы отобразить открытые порты в кратком формате и скопировать их в буфер обмена (21,22,80)

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

#### Сканирование версий портов с помощью Nmap:

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

```bash
nmap -sCV -p21,22,80 10.10.10.245 -oN targeted
```

<figure><img src="/files/03aa0a61b5166570482ea5c05d6b981856b88614" alt=""><figcaption></figcaption></figure>

### Порт 80 - HTTP

<figure><img src="/files/4e3e59fb7e5b4eb6c2f48f81d0b83b81782a1a00" alt=""><figcaption></figcaption></figure>

Мы обращаемся к HTTP-сервису и обнаруживаем раздел под названием **Security Snapshot**. Этот раздел позволяет создавать и загружать **pcap** файлы, содержащие системные журналы.

<figure><img src="/files/190d1556abe20464e80dc301746280f5070215c9" alt=""><figcaption></figcaption></figure>

## Уязвимость IDOR

**Первоначальное наблюдение**

После анализа **pcap** файлов с помощью Wireshark не было найдено никакого непосредственно пригодного содержимого.

<figure><img src="/files/9604d7a2182e84eb2a08146a4b3dc08c4a563b37" alt=""><figcaption></figcaption></figure>

Однако мы замечаем, что каждый раз, когда файл загружается, создается **снимок** . Соответствующий URL содержит параметр, указывающий идентификатор снимка, например: `snapshot_data=2`.

<figure><img src="/files/1c07e8649390be8ea0c36b93934aef222fccc964" alt=""><figcaption></figcaption></figure>

Вручную изменив параметр URL, чтобы получить доступ к снимку 0, мы получаем файл, содержащий конфиденциальную информацию.

### **Анализ с помощью Wireshark**

Изучив кадры в **pcap** файле, мы определяем учетные данные пользователя:

* имя пользователя: `nathan`
* пароль: `Buck3tH4TF0RM3!`

<figure><img src="/files/333599b74dca454c4357d4e0c3b9c7570233153d" alt=""><figcaption></figcaption></figure>

#### Использование учетных данных

**Доступ по FTP**

Мы используем учетные данные для подключения к FTP-сервису:

Подключение успешно. Мы получаем **user.txt** файл, содержащий первый флаг.

<figure><img src="/files/5b623a5929357b602fe3efbefc334b7d4163c810" alt=""><figcaption></figcaption></figure>

**Доступ по SSH**

Проверив те же учетные данные для подключения по SSH, мы получаем полный доступ:

```bash
ssh nathan@10.10.10.245
Buck3tH4TF0RM3!
```

<figure><img src="/files/146b962c26e6c8a2c6826ec02696b85cbfb357e1" alt=""><figcaption></figcaption></figure>

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

### Уязвимость Capabilites Python3.8

#### Фильтрация **capabilities**:

Если отфильтровать по capabilities, появляется Python 3.8:

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

<figure><img src="/files/ba6013006dd24b8fb9873ca5966338247e90192c" alt="" width="554"><figcaption></figcaption></figure>

Используйте [GTFOBins](https://gtfobins.github.io/) в качестве справки.

```bash
python3.8 -c 'import os; os.setuid(0); os.system("/bin/sh")'
```

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

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

<figure><img src="/files/40223873763bfcc22f49fcaa8bb5a96c78d0d8ed" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/21aab2d3f19962e5cc7f19af3231e8978d0cd14d" alt="" width="482"><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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
