|
| 1 | +import tkinter as tk |
| 2 | +from tkinter import ttk, messagebox |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +import re |
| 6 | +import shodan |
| 7 | +import nmap |
| 8 | +import logging |
| 9 | +import json |
| 10 | +import base64 |
| 11 | +from cryptography.fernet import Fernet |
| 12 | +from tkinter.simpledialog import askstring |
| 13 | +import requests |
| 14 | +from project_red_sword import Chatbot |
| 15 | + |
| 16 | +class C2Dashboard: |
| 17 | + def __init__(self, root): |
| 18 | + self.root = root |
| 19 | + self.root.title("C2 Dashboard") |
| 20 | + self.create_widgets() |
| 21 | + self.load_user_preferences() |
| 22 | + self.setup_logging() |
| 23 | + self.user_role = None |
| 24 | + self.session_active = False |
| 25 | + self.chatbot = Chatbot() |
| 26 | + |
| 27 | + def create_widgets(self): |
| 28 | + self.tab_control = ttk.Notebook(self.root) |
| 29 | + |
| 30 | + self.logs_tab = ttk.Frame(self.tab_control) |
| 31 | + self.exploits_tab = ttk.Frame(self.tab_control) |
| 32 | + self.communication_tab = ttk.Frame(self.tab_control) |
| 33 | + self.device_control_tab = ttk.Frame(self.tab_control) |
| 34 | + self.target_scanning_tab = ttk.Frame(self.tab_control) |
| 35 | + |
| 36 | + self.tab_control.add(self.logs_tab, text="Logs") |
| 37 | + self.tab_control.add(self.exploits_tab, text="Exploits") |
| 38 | + self.tab_control.add(self.communication_tab, text="Communication") |
| 39 | + self.tab_control.add(self.device_control_tab, text="Device Control") |
| 40 | + self.tab_control.add(self.target_scanning_tab, text="Target Scanning") |
| 41 | + |
| 42 | + self.tab_control.pack(expand=1, fill="both") |
| 43 | + |
| 44 | + self.create_logs_tab() |
| 45 | + self.create_exploits_tab() |
| 46 | + self.create_communication_tab() |
| 47 | + self.create_device_control_tab() |
| 48 | + self.create_target_scanning_tab() |
| 49 | + |
| 50 | + def create_logs_tab(self): |
| 51 | + self.logs_text = tk.Text(self.logs_tab, wrap="word") |
| 52 | + self.logs_text.pack(expand=1, fill="both") |
| 53 | + |
| 54 | + self.refresh_logs_button = ttk.Button(self.logs_tab, text="Refresh Logs", command=self.refresh_logs) |
| 55 | + self.refresh_logs_button.pack() |
| 56 | + |
| 57 | + def create_exploits_tab(self): |
| 58 | + self.exploits_listbox = tk.Listbox(self.exploits_tab) |
| 59 | + self.exploits_listbox.pack(expand=1, fill="both") |
| 60 | + |
| 61 | + self.load_exploits_button = ttk.Button(self.exploits_tab, text="Load Exploits", command=self.load_exploits) |
| 62 | + self.load_exploits_button.pack() |
| 63 | + |
| 64 | + self.run_exploit_button = ttk.Button(self.exploits_tab, text="Run Exploit", command=self.run_exploit) |
| 65 | + self.run_exploit_button.pack() |
| 66 | + |
| 67 | + def create_communication_tab(self): |
| 68 | + self.communication_text = tk.Text(self.communication_tab, wrap="word") |
| 69 | + self.communication_text.pack(expand=1, fill="both") |
| 70 | + |
| 71 | + self.send_message_button = ttk.Button(self.communication_tab, text="Send Message", command=self.send_message) |
| 72 | + self.send_message_button.pack() |
| 73 | + |
| 74 | + def create_device_control_tab(self): |
| 75 | + self.device_control_text = tk.Text(self.device_control_tab, wrap="word") |
| 76 | + self.device_control_text.pack(expand=1, fill="both") |
| 77 | + |
| 78 | + self.deploy_exploit_button = ttk.Button(self.device_control_tab, text="Deploy Exploit", command=self.deploy_exploit) |
| 79 | + self.deploy_exploit_button.pack() |
| 80 | + |
| 81 | + def create_target_scanning_tab(self): |
| 82 | + self.target_scanning_text = tk.Text(self.target_scanning_tab, wrap="word") |
| 83 | + self.target_scanning_text.pack(expand=1, fill="both") |
| 84 | + |
| 85 | + self.scan_targets_button = ttk.Button(self.target_scanning_tab, text="Scan Targets", command=self.scan_targets) |
| 86 | + self.scan_targets_button.pack() |
| 87 | + |
| 88 | + def refresh_logs(self): |
| 89 | + self.logs_text.delete(1.0, tk.END) |
| 90 | + with open("logs/deployment.log", "r") as f: |
| 91 | + logs = f.read() |
| 92 | + self.logs_text.insert(tk.END, logs) |
| 93 | + |
| 94 | + def load_exploits(self): |
| 95 | + self.exploits_listbox.delete(0, tk.END) |
| 96 | + exploits = os.listdir("exploits") |
| 97 | + for exploit in exploits: |
| 98 | + self.exploits_listbox.insert(tk.END, exploit) |
| 99 | + |
| 100 | + def run_exploit(self): |
| 101 | + selected_exploit = self.exploits_listbox.get(tk.ACTIVE) |
| 102 | + if selected_exploit: |
| 103 | + exploit_path = os.path.join("exploits", selected_exploit) |
| 104 | + result = subprocess.run([exploit_path], capture_output=True, text=True) |
| 105 | + messagebox.showinfo("Exploit Result", result.stdout) |
| 106 | + |
| 107 | + def send_message(self): |
| 108 | + message = self.communication_text.get(1.0, tk.END).strip() |
| 109 | + if message: |
| 110 | + # Implement secure communication logic here |
| 111 | + messagebox.showinfo("Message Sent", "Message sent successfully!") |
| 112 | + |
| 113 | + def deploy_exploit(self): |
| 114 | + device_info = self.device_control_text.get(1.0, tk.END).strip() |
| 115 | + if device_info: |
| 116 | + phone_regex = re.compile(r'\+?1?\d{9,15}') |
| 117 | + email_regex = re.compile(r'[\w\.-]+@[\w\.-]+') |
| 118 | + ip_port_regex = re.compile(r'(\d{1,3}\.){3}\d{1,3}:\d+') |
| 119 | + |
| 120 | + phone_numbers = phone_regex.findall(device_info) |
| 121 | + emails = email_regex.findall(device_info) |
| 122 | + ip_ports = ip_port_regex.findall(device_info) |
| 123 | + |
| 124 | + # Implement exploit deployment logic based on extracted information |
| 125 | + messagebox.showinfo("Exploit Deployment", "Exploits deployed successfully!") |
| 126 | + |
| 127 | + def scan_targets(self): |
| 128 | + shodan_api_key = os.getenv("SHODAN_API_KEY") |
| 129 | + nmap_api_key = os.getenv("NMAP_API_KEY") |
| 130 | + shodan_api = shodan.Shodan(shodan_api_key) |
| 131 | + nm = nmap.PortScanner() |
| 132 | + |
| 133 | + try: |
| 134 | + results = shodan_api.search('default password') |
| 135 | + for result in results['matches']: |
| 136 | + ip = result['ip_str'] |
| 137 | + nm.scan(ip, '22-443') |
| 138 | + self.target_scanning_text.insert(tk.END, f"IP: {ip}\n") |
| 139 | + for proto in nm[ip].all_protocols(): |
| 140 | + lport = nm[ip][proto].keys() |
| 141 | + for port in lport: |
| 142 | + self.target_scanning_text.insert(tk.END, f"Port: {port}\tState: {nm[ip][proto][port]['state']}\n") |
| 143 | + except shodan.APIError as e: |
| 144 | + messagebox.showerror("Shodan Error", str(e)) |
| 145 | + |
| 146 | + def setup_logging(self): |
| 147 | + logging.basicConfig(filename='logs/gui.log', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') |
| 148 | + |
| 149 | + def load_user_preferences(self): |
| 150 | + try: |
| 151 | + with open('config.json', 'r') as f: |
| 152 | + self.user_preferences = json.load(f) |
| 153 | + except FileNotFoundError: |
| 154 | + self.user_preferences = {} |
| 155 | + |
| 156 | + def save_user_preferences(self): |
| 157 | + with open('config.json', 'w') as f: |
| 158 | + json.dump(self.user_preferences, f) |
| 159 | + |
| 160 | + def login(self): |
| 161 | + username = askstring("Login", "Enter your username:") |
| 162 | + password = askstring("Login", "Enter your password:", show='*') |
| 163 | + if self.authenticate_user(username, password): |
| 164 | + self.user_role = self.get_user_role(username) |
| 165 | + self.session_active = True |
| 166 | + self.root.after(60000, self.check_session_timeout) |
| 167 | + else: |
| 168 | + messagebox.showerror("Login Failed", "Invalid credentials") |
| 169 | + |
| 170 | + def authenticate_user(self, username, password): |
| 171 | + # Implement user authentication logic here |
| 172 | + return True |
| 173 | + |
| 174 | + def get_user_role(self, username): |
| 175 | + # Implement user role retrieval logic here |
| 176 | + return "admin" |
| 177 | + |
| 178 | + def check_session_timeout(self): |
| 179 | + if self.session_active: |
| 180 | + self.session_active = False |
| 181 | + messagebox.showinfo("Session Timeout", "You have been logged out due to inactivity") |
| 182 | + self.login() |
| 183 | + |
| 184 | + def run_post_exploitation_module(self, module_name): |
| 185 | + # Implement post-exploitation module execution logic here |
| 186 | + messagebox.showinfo("Post-Exploitation Module", f"{module_name} executed successfully") |
| 187 | + |
| 188 | + def setup_ddns(self): |
| 189 | + no_ip_username = os.getenv("NO_IP_USERNAME") |
| 190 | + no_ip_password = os.getenv("NO_IP_PASSWORD") |
| 191 | + no_ip_hostname = os.getenv("NO_IP_HOSTNAME") |
| 192 | + |
| 193 | + if not no_ip_username or not no_ip_password or not no_ip_hostname: |
| 194 | + messagebox.showerror("DDNS Error", "No-IP DDNS credentials are missing") |
| 195 | + return |
| 196 | + |
| 197 | + update_url = f"https://{no_ip_username}:{no_ip_password}@dynupdate.no-ip.com/nic/update?hostname={no_ip_hostname}" |
| 198 | + response = requests.get(update_url) |
| 199 | + |
| 200 | + if response.status_code == 200: |
| 201 | + messagebox.showinfo("DDNS Update", "No-IP DDNS update successful") |
| 202 | + else: |
| 203 | + messagebox.showerror("DDNS Update", f"No-IP DDNS update failed: {response.text}") |
| 204 | + |
| 205 | + def setup_reverse_dns_tunneling(self): |
| 206 | + # Implement reverse DNS tunneling setup logic here |
| 207 | + pass |
| 208 | + |
| 209 | + def integrate_chatbot(self): |
| 210 | + self.chatbot_popup = tk.Toplevel(self.root) |
| 211 | + self.chatbot_popup.title("Chatbot") |
| 212 | + self.chatbot_text = tk.Text(self.chatbot_popup, wrap="word") |
| 213 | + self.chatbot_text.pack(expand=1, fill="both") |
| 214 | + self.chatbot_entry = tk.Entry(self.chatbot_popup) |
| 215 | + self.chatbot_entry.pack(fill="x") |
| 216 | + self.chatbot_entry.bind("<Return>", self.send_chatbot_command) |
| 217 | + |
| 218 | + def send_chatbot_command(self, event): |
| 219 | + command = self.chatbot_entry.get() |
| 220 | + if command: |
| 221 | + response = self.chatbot.process_command(command) |
| 222 | + self.chatbot_text.insert(tk.END, f"User: {command}\n") |
| 223 | + self.chatbot_text.insert(tk.END, f"Chatbot: {response}\n") |
| 224 | + self.chatbot_entry.delete(0, tk.END) |
| 225 | + |
| 226 | +if __name__ == "__main__": |
| 227 | + root = tk.Tk() |
| 228 | + app = C2Dashboard(root) |
| 229 | + app.login() |
| 230 | + app.setup_ddns() |
| 231 | + app.setup_reverse_dns_tunneling() |
| 232 | + app.integrate_chatbot() |
| 233 | + root.mainloop() |
0 commit comments