我在python中使用subprocess.Popen(cmd, shell=True)
创建了一个简单的反向shell,用于客户端运行命令。然而,当我在用户目录中使用命令时,我会得到一个shell init错误。这是我尝试使用ls
时得到的结果
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
ls: .: Operation not permitted
以sudo的身份运行ls
命令不起作用。
值得一提的是,命令在用户目录之外的目录中按预期工作。
这是调用命令的代码:
output = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
来自中国博客
[root@smart hello]# cat /root/Desktop/hello.sh
#!/bin/bash
echo "hello"
[root@smart hello]# /root/Desktop/hello.sh
shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
hello
[root@smart hello]# cd /
[root@smart /]# /root/Desktop/hello.sh
hello
[root@smart /]#
它说,如果你去掉剧本的第一行,它也会很好。
[root@smart hello]# cat /root/Desktop/hello.sh
echo "hello"
[root@smart hello]# /root/Desktop/hello.sh
hello
如果这对你来说也是真的。那么这就不是子流程的问题。