如何从命令行提供标准输入输入?
我正在尝试对班级作业的程序执行缓冲区溢出攻击。攻击程序和漏洞程序都是我写的。
易受攻击的代码使用 scanf
从 stdin 读取数据。
<代码>./易受攻击< male_payload_file.txt 工作正常。 更多恶意有效负载 | ./vulnerable 和 echo JUNK_JUNK_JUNK_JUNK | ./vulnerable
也按预期工作。
但是,我想使用攻击程序继续提供越来越长的有效负载,直到程序崩溃。因此,我需要动态生成更大的垃圾有效负载。我正在使用 system ("./vulnerable");
来重复调用并测试异常退出。
我如何指定这样的有效负载?
有没有办法运行 ./vulnerable < male_payload_binary
或以某种方式使我不必将恶意有效负载放入文件中,但可以在命令行中指定它?
I am trying to perform a buffer overflow attack on a program for a class assignment. Both the attack program as well as the vulnerable programme is written by me.
The vulnerable code uses scanf
to read data from stdin.
./vulnerable < malicious_payload_file.txt
works fine.more malicious_payload | ./vulnerable
and echo JUNK_JUNK_JUNK_JUNK | ./vulnerable
also works as expected.
However, i would like to use the attack programme to keep supplying incrementally longer payloads till the programme crashes. So, I need to dynamically generate larger payloads of junks. I am using system ("./vulnerable");
to repeatedly call and test for an abnormal exit.
How do I specify such a payload?
Is there a way to run ./vulnerable < malicious_payload_binary
or in some manner such that I do not have to put the malicious payload in a file, but can specify it in the command line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这个怎么样?
您可以将
echo
命令替换为任何能够生成您想要的 ./vulnerable 输入的命令。一个这样的例子是持续不断的垃圾流作为输入,您可以这样做:How about this?
You can replace the
echo
command with any command that generates the input to ./vulnerable you want. One such example is a constant flow of junk as input, you can do this:您可以尝试使用
popen
而不是system
,而不是尝试使用命令行:从
pclose
获得的退出代码与如果您使用另一个进程来创建数据并通过 shell 将其通过管道传输到 ./vulnerable,您将从system
获得数据Rather than trying to use the command line, you might try using
popen
instead ofsystem
:The exitcode you get from
pclose
is the same as what you would have got fromsystem
, had you used another process to create the data and piped it via the shell to ./vulnerable尝试管道而不是重定向:
Try piping instead of redirecting:
编辑:我想我终于明白你的问题了(也许),你想阅读命令行参数吗?如果
将其编译为名为
stdintest
的二进制文件并像这样运行它:./stdintest somefile.txt
它将输出:
OLD:
正如 dolphy 提到的,只需写入
malicious_payload_binary
中的标准输出,从vulnerable
中的标准输入读取,然后用管道连接它们:./malicious_payload_binary | ./易受攻击
EDIT: I think I finally understand your question (maybe), you want to read command line arguments? Something like
If you compile it to a binary named
stdintest
and run it like so:./stdintest somefile.txt
it will output:
OLD:
As dolphy mentioned, just write to stdout in
malicious_payload_binary
, read from stdin invulnerable
, and connect them with a pipe:./malicious_payload_binary | ./vulnerable