Using python's subprocess.call or os.system inside a chroot jail

会有一股神秘感。 提交于 2020-05-15 08:08:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!