【发布时间】:2020-08-02 11:02:30
【问题描述】:
我使用subprocess.Popen(cmd, shell=True) 在python 中创建了一个简单的反向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)
【问题讨论】:
-
你能介绍一下你的python代码吗?
-
@YiZhao 更新
-
代码对我有用。如果您在该目录的终端中调用“ls”怎么办?您可能已删除该目录?添加 import os print(os.getcwd()) 并检查该目录是否真的存在。
-
我绝对没有删除目录。在常规终端中调用
ls可以正常工作 -
stackoverflow.com/questions/29396928/…这和你的问题有关吗?
标签: python python-3.x shell subprocess reverse-shell