我有一个程序A,它打印一些文本数据,然后从stdin中读取一个gets()。我想创建一个程序/脚本,该程序将读取A(文本数据)的标准输出,并基于输出到其stdin的传递数据(二进制)。
该程序是一个简单的利用演示(格式字符串漏洞到转储栈,然后基于转储值的技术利用有效载荷,然后通过获取传递该有效载荷以触发缓冲区溢出并执行精心制作的shellcode)。
int main(int argc, char** argv) { char buffer[20]; BOOL(__stdcall *getName)(LPSTR lpBuffer, LPDWORD nSize) = GetComputerNameA; printf("The argument is: "); printf(argv[1]); printf("\r\n"); printf("Enter a message: "); gets(buffer); printf("Your message is: %s", buffer); TCHAR name[20]; DWORD len = 19; getName(name, &len); printf("Your computer is called %s", name); printf("\r\n"); }
我已经尝试通过target.stdout.readline()和target.stdin.write()在python中执行此操作,但是readline会挂起并且永远不会返回。我还通过OutputDataReceived事件在C#中进行了尝试,但只有在没有传递任何输入的情况下,我才能够读取输出。重定向标准输入后,我将无法读取任何内容。也发生挂起。
我的问题是我该如何实现?
编辑:执行程序的python代码示例
from subprocess import Popen, PIPE, STDOUT x = Popen(['test.exe', '"%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x"', 'start'], stdout=PIPE, stdin=PIPE, stderr=STDOUT) out = x.stdout.readline() print(out) input("{press enter}") data = bytearray(...payload...) payload = buffer(data) x.stdin.write(payload) input("{press enter}")