[英]How do I provide stdin inputs from command line?
我试图对类分配的程序执行缓冲区溢出攻击。 攻击程序以及易受攻击的程序都是由我编写的。
易受攻击的代码使用scanf
从stdin读取数据。
./vulnerable < malicious_payload_file.txt
工作正常。 more malicious_payload | ./vulnerable
more malicious_payload | ./vulnerable
和echo JUNK_JUNK_JUNK_JUNK | ./vulnerable
echo JUNK_JUNK_JUNK_JUNK | ./vulnerable
也按预期工作。
但是,我想使用攻击程序继续提供更长的有效负载,直到程序崩溃。 所以,我需要动态生成更大的有效载荷。 我正在使用system ("./vulnerable");
反复呼叫和测试异常退出。
如何指定这样的有效负载?
有没有办法运行./vulnerable < malicious_payload_binary
或以某种方式运行,以便我不必将恶意负载放在文件中,但可以在命令行中指定它?
这个怎么样?
echo "your payload goes here" | ./vulnerable
您可以使用任何生成所需./vulnerable输入的命令替换echo
命令。 一个这样的例子是作为输入的不断的垃圾流,你可以这样做:
cat /dev/urandom | ./vulnerable
您可以尝试使用popen
而不是system
来尝试使用命令行,而不是尝试使用命令行:
FILE *fp = popen("./vulnerable", "w");
// write stuff to fp -- it goes to vulnerable's stdin
int exitcode = pclose(fp);
你从pclose
获得的pclose
与你从system
获得的pclose
是一样的,如果你使用另一个进程来创建数据并通过shell将它传输到./vulnerable
尝试管道而不是重定向:
./malicious_payload_binary | ./vulnerable
编辑:我想我终于明白你的问题(也许),你想读取命令行参数? 就像是
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("the name of this program is %s\n", argv[0]);
printf("%d command line arguments were provided\n", argc);
printf("the input file is %s\n", argv[1]);
// could do something like: fopen(argv[1]) here
return 0;
}
如果将它编译为名为stdintest
的二进制文件stdintest
运行它:
./stdintest somefile.txt
它将输出:
the name of this program is ./stdintest
2 command line arguments were provided
the input file is somefile.txt
旧:
正如dolphy所提到的,只需在malicious_payload_binary
写入stdout,从vulnerable
stdin读取,并用管道连接它们: ./malicious_payload_binary | ./vulnerable
./malicious_payload_binary | ./vulnerable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.