问题
Ok, the situation is a bit hard to explain. I have a user in an SSH chroot jail. I copied some binaries and all the necessary libraries, and it works. However, when I try to use os.system or subprocess.call inside python (or system in C for that matter) It refuses to work. (both in absolute and relative path).
For example:
>> import os
>> os.system('/usr/bin/ls')
32515 # Means that it can't find the file
>> os.listdir() # To make sure i'm in the jail
['etc', 'usr', 'lib64', 'home', 'dev', 'lib', 'bin'] # The expected output of the jail's root directory
>> os.listdir('/usr/bin')
['id', 'cat', 'scp', 'less', 'ls', 'whoami', 'vim', 'nohup', 'python', 'bash'] # Clearly ls is here
outside of python (and inside the jail) the ls command works just great.
If anyone has any insight to what's going on I would be grateful.
Edit:
The nice people in the comments noted that using subprocess without shell=True works. I would like an explanation of why that works, and maybe an alternative for c/c++. Thank you very much!
来源:https://stackoverflow.com/questions/42347022/using-pythons-subprocess-call-or-os-system-inside-a-chroot-jail