如何将\x00作为参数传递给程序? [英] How to pass \x00 as argument to program?

查看:145
本文介绍了如何将\x00作为参数传递给程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小程序,希望将shellcode作为参数传递。在shellcode中,必须传递\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"'`

但是the x00根本没有注册!传递给程序的参数是 \x01\x9c\xff\xbf。

But the \x00 doesn't get registered at all! The arguments passed to the program are "\x01\x9c\xff\xbf".

我不认为这是python的问题,而是与传递参数的外壳。我正在使用bash外壳。

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.

现在,如何强制外壳传递参数'\x00'?

Now, how do I force the shell to pass the argument '\x00'?

感谢和问候,

赫里希克什·穆拉利(Hrishikesh Murali)

Thanks and Regards,
Hrishikesh Murali

推荐答案

如果使用<$ c进行检查$ c> wc ,您会发现确实传递了NUL字符:

If you check with wc, you'll find that the NUL character is indeed passed:

$ python -c 'print "\x00"' | wc -c
2

要摆脱结尾的换行符:

$ python -c 'import sys; sys.stdout.write("\x00")' | wc -c
1

该数据 传递给了脚本,但是问题是 NUL不能成为变量值的一部分。

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:

$ cat test.sh 
#!/usr/bin/env bash
echo ${#1}
$ ./test.sh "$(python -c 'import sys; sys.stdout.write("\x00")')"
0

已消失。但是有一种节省时间的方法-使用重定向或管道从标准输入中读取:

Gone. But there's a way to save the day - Read from standard input, using either redirection or a pipe:

$ cat test2.sh 
#!/usr/bin/env bash
wc -c
$ ./test2.sh < <(python -c 'import sys; sys.stdout.write("\x00")')
1
$ python -c 'import sys; sys.stdout.write("\x00")' | ./test2.sh
1

这篇关于如何将\x00作为参数传递给程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆