首页 > 解决方案 > pwntools 中的 p64() 无法正常工作

问题描述

我想将输入发送到包含不可打印字符(如“\x90”)的进程。当我尝试像这样发送它时p.sendline(p64(0x414190)),我的程序将它打印回来,返回AA\x90。它将 "\x90" 作为一个字符串,而不是一个字节。有人可以帮我如何发送原始字节吗?

我的程序(容易格式化字符串,我不需要被告知):

#include <stdio.h>

int main() {
  char name[512];
  char passwd[512];

  printf("Enter your name: ");
  fgets(name, sizeof(name), stdin);
  printf(name);

  printf("Enter your password: ");
  fgets(passwd, sizeof(passwd), stdin);
  printf(passwd);

  exit(1);
}

标签: cpython-2.7format-stringpwntools

解决方案


Usingp64()确实将输入作为原始字节发送。DEBUG您可以通过在运行脚本时添加 pwntools 标志来检查它。调试输出然后打印发送和接收的所有内容。例如:

python2 solve.py DEBUG
[+] Starting local process './script': pid 23732
[DEBUG] Received 0x11 bytes:
    'Enter your name: '
[DEBUG] Sent 0x9 bytes:
    00000000  90 41 41 00  00 00 00 00  0a                        │·AA·│····│·│
    00000009
[*] Switching to interactive mode
[DEBUG] Received 0x18 bytes:
    00000000  90 41 41 45  6e 74 65 72  20 79 6f 75  72 20 70 61  │·AAE│nter│ you│r pa│
    00000010  73 73 77 6f  72 64 3a 20                            │sswo│rd: │
    00000018
\x90AAEnter your password: $ 

在上面的示例中,您会看到字节90 41 41 00 00 00 00 00 0a被发送到程序,而不是字符串\x90


推荐阅读