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
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. (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. So my string should be arg[1] + " " + arg[2] + " " + payloadString. (The c code is converting the arg[1] and arg[2] into integer to use it in its functions). Here is the snippet of my python code:
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. When I run the python code I get error:
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. Similar questions were there in stack overflow, but I am not sure how to use their answers to solve my problem.
把一个r
放在os.system
调用中。
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
链接地址: http://www.djcxy.com/p/87214.html