如何将 \x00 作为参数传递给程序?
我有一个小程序,我希望将 shellcode 作为参数传递。在shellcode中,需要传递\x00。我尝试了以下命令:
./program `python -c 'print "\x01\x00\x00\x00\x9c\xd8\xff\xbf"'`
但是 \x00 根本没有注册!传递给程序的参数是“\x01\x9c\xff\xbf”。
我不认为这是 python 的问题,而是传递参数的 shell 的问题。我正在使用 bash shell。
现在,如何强制 shell 传递参数“\x00”?
谢谢和问候,
赫里希凯什穆拉里
I have a small program where I wish to pass shellcode as argument. In the shellcode, there is a necessity to pass \x00. I tried the following command:
./program `python -c 'print "\x01\x00\x00\x00\x9c\xd8\xff\xbf"'`
But the \x00 doesn't get registered at all! The arguments passed to the program are "\x01\x9c\xff\xbf".
I don't think it's a problem with python, but rather with the shell which passes the argument. I am using the bash shell.
Now, how do I force the shell to pass the argument '\x00'?
Thanks and Regards,
Hrishikesh Murali
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
一点也不。 Unix 使用 C 样式字符串作为调用命令的参数,并且它们是以 NUL 结尾的字符序列。
您可以做的是重写您的程序(或找到调用变体)以接受其标准输入中的参数。 NUL 字节在那里工作得很好,而且事实上被广泛使用,通常用作文件名的分隔符,因为它们几乎是文件名中唯一不能包含的内容。有关可以说是最流行的示例,请参阅
find
的-print0
开关和xarg
的开关-0
。Not at all. Unix uses C-style strings for the arguments a command is invoked with, and they are NUL-terminated character sequences.
What you can do is to rewrite your program (or find an invocation variant) to accept the parameter in its standard input. NUL bytes work just fine there and are, in fact, widely used, typically as separators for file names, since they are pretty much the only thing a file name can never contain. See
find
's-print0
switch andxarg
's switch-0
for the arguably most popular examples.如果您检查
wc
,您会发现确实传递了 NUL 字符:为了摆脱末尾的换行符:
此数据被传递给脚本,但问题是NUL 不能成为变量值的一部分。
要了解如何操作,请尝试将其传递给脚本:
Gone。但有一种方法可以挽救局面 - 使用重定向或管道从标准输入读取:
If you check with
wc
, you'll find that the NUL character is indeed passed:To get rid of the newline at the end:
This data is passed to the script, but the problem is that NUL can not be part of a variable value.
To see how, try to pass this to a script:
Gone. But there's a way to save the day - Read from standard input, using either redirection or a pipe:
带有 --null 选项的 xargs 命令可以提供帮助:
我尝试过,它有效。
the xargs command with --null option can help:
I tried that, and it worked.
我相信这是因为 Bash 丢弃空字符。
为了测试这一点,我使用 od 命令以八进制格式转储参数,使用以下脚本:
并使用以下命令运行它:
不打印空字符。
要解决此问题,请传入 hexdump,然后在程序中反转它。示例:
现在您看到打印了空字符。
I believe this is because Bash discards null characters.
To test this I used the
od
command to dump out the parameters in octal format, using the following script:and ran it using:
The null characters are not printed.
To get around this issue pass in a hexdump and then reverse it in your program. Example:
Now you see that the null characters are printed.
您可以尝试将 shellcode 放入文件中,然后读回并将其传递给可执行文件。
类似于:
使用上面的 perl cmdline 作为程序的参数
You can try putting the shellcode in a file and then read it back and pass it to the executable.
something like:
use the above perl cmdline as argument to the program
你可以试试这个,
它
证明\x00已经通过了。
顺便说一下,我在测试中发现c程序在argv中肯定会stip \00。您可以检查 argv,例如,
所以我猜 shell 或 c 程序可以自动删除 \x00 字符。也许有人可以解释为什么会发生这种情况。
但我们还有其他技术来避免 shellcode 中的 \x00。
你可以参考一下文章。
https://www.exploit-db。 com/docs/english/13019-shell-code-for-beginners.pdf
You can try this,
and
It proves \x00 is passed.
By the way, I find c program surely stip \00 in argv in my test. You can examine the argv such as,
So I guess shell or c program can stip \x00 chararcter automatically.Maybe someone can explain why it happens.
But we have other technique to avoid \x00 in shellcode.
You can refer to the article.
https://www.exploit-db.com/docs/english/13019-shell-code-for-beginners.pdf