Python 如何使用pwntools正确捕获流程的输出

Python 如何使用pwntools正确捕获流程的输出,python,exploit,pwntools,Python,Exploit,Pwntools,我目前对如何使用pwntools库来开发python3程序感到困惑——主要是将输入发送到易受攻击的程序中。 这是我当前的python脚本 from pwn import * def executeVuln(): vulnBin = process("./buf2", stdin=PIPE, stdout=PIPE) vulnBin.sendlineafter(': ','A'*90) output = vulnBin.recvline(timeout=5) pr

我目前对如何使用pwntools库来开发python3程序感到困惑——主要是将输入发送到易受攻击的程序中。 这是我当前的python脚本

from pwn import *
def executeVuln():
    vulnBin = process("./buf2", stdin=PIPE, stdout=PIPE)
    vulnBin.sendlineafter(': ','A'*90)
    output = vulnBin.recvline(timeout=5)

    print(output)

executeVuln()
下面是我试图利用的程序-这不是关于如何利用该程序,更多的是关于使用脚本正确地自动化它

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>

#define BUFSIZE 176
#define FLAGSIZE 64

void flag(unsigned int arg1, unsigned int arg2) {
  char buf[FLAGSIZE];
  FILE *f = fopen("flag.txt","r");
  if (f == NULL) {
    printf("Flag File is Missing. Problem is Misconfigured, please contact an Admin if you are running this on the shell server.\n");
    exit(0);
  }

  fgets(buf,FLAGSIZE,f);
  if (arg1 != 0xDEADBEEF)
    return;
  if (arg2 != 0xC0DED00D)
    return;
  printf(buf);
}

void vuln(){
  char buf[BUFSIZE];
  gets(buf);
  puts(buf);
}

int main(int argc, char **argv){

  setvbuf(stdout, NULL, _IONBF, 0);

  gid_t gid = getegid();
  setresgid(gid, gid, gid);

  puts("Please enter your string: ");
  vuln();
  return 0;
}

#包括
#包括
#包括
#包括
#包括
#定义BUFSIZE 176
#定义标志大小64
无效标志(无符号整数arg1、无符号整数arg2){
char buf[FLAGSIZE];
文件*f=fopen(“flag.txt”、“r”);
如果(f==NULL){
printf(“缺少标志文件。问题配置错误,如果在shell服务器上运行此文件,请与管理员联系。\n”);
出口(0);
}
fgets(buf,旗标尺寸,f);
如果(arg1!=0xDEADBEEF)
返回;
如果(arg2!=0xC0DED00D)
返回;
printf(buf);
}
void vuln(){
字符buf[BUFSIZE];
获取(buf);
put(buf);
}
int main(int argc,字符**argv){
setvbuf(标准输出,空,0);
gid_t gid=getegid();
setresgid(gid,gid,gid);
puts(“请输入您的字符串:”);
vuln();
返回0;
}
这个过程是开放的。 sendlineafter会一直阻塞,直到它发送该行,因此如果它不匹配,它将无限期地等待。但是,它运行正常,因此应该发送输入。 由于以下原因,输出应接收来自recvLine的90 A

put(buffer)
输出输入的字符串

然而,所有返回的都是
b''
,这似乎表明易受攻击的程序没有接收输入并返回空字符串

有人知道这是什么原因吗