[英]TypeError: must be string without null bytes, not str in os.system()
I am trying to write a python code which executes a C executable using the following line 我正在尝试编写使用以下行执行C可执行文件的python代码
os.system("./a.out \"%s\"" % payload)
where ./a.out is a C executable, and payload is a string (without spaces) given as command line argument. 其中./a.out是C可执行文件,有效负载是作为命令行参数给出的字符串(不带空格)。 (The link is this . I am trying to follow example under section chaining functions)
(链接是这个 。我试图按照节链接功能下的示例进行操作)
Now I have written another C code but it takes 3 command line arguments. 现在,我编写了另一个C代码,但是它需要3个命令行参数。 So my string should be arg[1] + " " + arg[2] + " " + payloadString.
所以我的字符串应该是arg [1] +“” + arg [2] +“” + payloadString。 (The c code is converting the arg[1] and arg[2] into integer to use it in its functions).
(C代码将arg [1]和arg [2]转换为整数以在其函数中使用)。 Here is the snippet of my python code:
这是我的python代码的片段:
p = "10 " #arg[1]
p += "10 " #arg[2]
p += "string without spaces which I need as payload" #arg[3]
os.system("./a.out \"%s\"" % p)
where ./a.out is executable of my C code which takes 3 command line arguments. 其中./a.out是我的C代码的可执行文件,它带有3个命令行参数。 When I run the python code I get error:
当我运行python代码时,出现错误:
Traceback (most recent call last):
File "this_file.py", line XX, in <module>
os.system("./a.out \"%s\"" % p)
TypeError: must be string without null bytes, not str
Can anyone help me? 谁能帮我?
PS I am new to python. PS我是python的新手。 Similar questions were there in stack overflow, but I am not sure how to use their answers to solve my problem.
堆栈溢出中也存在类似的问题,但是我不确定如何使用他们的答案来解决我的问题。
在os.system
调用中放入r
。
os.system(r"./a.out \"%s\"" % p)
Why don't you use call for this purpose. 您为什么不为此目的使用通话。 I guess it will do the work You can provide the arguments in the list Example:
我想它将完成工作。您可以在列表示例中提供参数:
from subprocess import call
call(["./a.out","10","10","string without spaces which I need as payload"])
here in your case it is equivalent to 在你的情况下,这相当于
call(["./a.out",arg[0],arg[1],arg[2]])
I think this should work 我认为这应该工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.