#!/usr/bin/env python3
"""
NullFrame OS - NullAttack GUI
Security Testing Dashboard - Thunderbolt 4 USB + WiFi/BLE/RF/Network
"""

import tkinter as tk
from tkinter import ttk, messagebox
import subprocess
import os

# Cyberpunk RGB Theme
BG_DARK = "#0a0a0f"
BG_PANEL = "#12121a"
BG_BUTTON = "#1a1a2e"
ACCENT_CYAN = "#00fff2"
ACCENT_MAGENTA = "#ff00aa"
ACCENT_GREEN = "#00ff88"
ACCENT_YELLOW = "#ffee00"
ACCENT_RED = "#ff3366"
TEXT_WHITE = "#ffffff"

class NullAttackGUI:
    def __init__(self, root):
        self.root = root
        self.root.title("NullAttack - NullFrame OS Security Suite")
        self.root.geometry("1400x900")
        self.root.configure(bg=BG_DARK)
        self.create_header()
        self.create_notebook()
        self.create_footer()
        
    def create_header(self):
        header = tk.Frame(self.root, bg=BG_DARK, height=80)
        header.pack(fill='x', padx=10, pady=5)
        
        title = tk.Label(header, text="[ NULLATTACK ]", font=('Consolas', 36, 'bold'),
                        bg=BG_DARK, fg=ACCENT_CYAN)
        title.pack(pady=10)
        
        subtitle = tk.Label(header, 
                           text="NullFrame OS | Security Testing Lab | Thunderbolt 4 Required for USB Attacks",
                           font=('Consolas', 11), bg=BG_DARK, fg="#888899")
        subtitle.pack()
        
        warning = tk.Label(header, 
                          text="!! AUTHORIZED USE ONLY - SECURITY TESTING LAB !!",
                          font=('Consolas', 11, 'bold'), bg=BG_DARK, fg=ACCENT_RED)
        warning.pack(pady=5)
        
    def create_footer(self):
        footer = tk.Frame(self.root, bg=BG_PANEL, height=35)
        footer.pack(fill='x', side='bottom', padx=10, pady=5)
        self.status_label = tk.Label(footer, text="Ready", font=('Consolas', 10),
                                    bg=BG_PANEL, fg=ACCENT_GREEN)
        self.status_label.pack(side='left', pady=8)
        
    def create_notebook(self):
        self.notebook = ttk.Notebook(self.root)
        self.notebook.pack(fill='both', expand=True, padx=10, pady=5)
        
        self.usb_tab = ttk.Frame(self.notebook)
        self.thunderbolt_tab = ttk.Frame(self.notebook)
        self.wifi_tab = ttk.Frame(self.notebook)
        self.ble_tab = ttk.Frame(self.notebook)
        self.rf_tab = ttk.Frame(self.notebook)
        self.network_tab = ttk.Frame(self.notebook)
        self.lab_tab = ttk.Frame(self.notebook)
        
        self.notebook.add(self.usb_tab, text="[USB]")
        self.notebook.add(self.thunderbolt_tab, text="[Thunderbolt4]")
        self.notebook.add(self.wifi_tab, text="[WiFi]")
        self.notebook.add(self.ble_tab, text="[BLE/Bluetooth]")
        self.notebook.add(self.rf_tab, text="[RF/Glitch]")
        self.notebook.add(self.network_tab, text="[Network]")
        self.notebook.add(self.lab_tab, text="[Lab Control]")
        
        self.create_usb_tab()
        self.create_thunderbolt_tab()
        self.create_wifi_tab()
        self.create_ble_tab()
        self.create_rf_tab()
        self.create_network_tab()
        self.create_lab_tab()

    def create_usb_tab(self):
        warn = tk.Label(self.usb_tab, text="USB Attacks - Physical Access Required",
                       font=('Consolas', 12, 'bold'), bg=BG_DARK, fg=ACCENT_YELLOW)
        warn.pack(pady=10)
        
        frame = ttk.Frame(self.usb_tab)
        frame.pack(fill='x', padx=20, pady=5)
        
        tk.Label(frame, text="USB Devices:", font=('Consolas', 12, 'bold'),
                bg=BG_DARK, fg=ACCENT_CYAN).pack(anchor='w')
        
        self.usb_listbox = tk.Listbox(frame, height=6, bg=BG_PANEL, fg=TEXT_WHITE,
                                     font=('Consolas', 10))
        self.usb_listbox.pack(fill='x', pady=5)
        
        btn_frame = ttk.Frame(frame)
        btn_frame.pack(fill='x')
        
        ttk.Button(btn_frame, text="Scan USB", command=self.scan_usb).pack(side='left', padx=5)
        ttk.Button(btn_frame, text="BadUSB Payloads", command=self.badusb_menu).pack(side='left', padx=5)
        
        payload_frame = ttk.LabelFrame(self.usb_tab, text="BadUSB Attack Scripts", padding=10)
        payload_frame.pack(fill='both', expand=True, padx=20, pady=10)
        
        payloads = [
            ("RubberDucky DuckyScript", "usb_ducky"),
            ("Teensy Payload", "usb_teensy"),
            ("USB Death (Port Kill)", "usb_death"),
            ("Keystroke Injection", "usb_keystroke"),
            ("Credential Harvester", "usb_harvest"),
            ("Reverse Shell Dropper", "usb_shell"),
        ]
        
        for i, (name, key) in enumerate(payloads):
            row = i // 2
            col = i % 2
            btn = tk.Button(payload_frame, text=name, font=('Consolas', 11),
                          bg=BG_BUTTON, fg=ACCENT_MAGENTA, relief='flat', padx=15, pady=12,
                          command=lambda k=key: self.execute_payload(k))
            btn.grid(row=row, column=col, padx=10, pady=5, sticky='ew')

    def create_thunderbolt_tab(self):
        warn = tk.Label(self.thunderbolt_tab, 
                       text="!! THUNDERBOLT 4 REQUIRED !! DMA Attack Framework",
                       font=('Consolas', 14, 'bold'), bg=BG_DARK, fg=ACCENT_YELLOW)
        warn.pack(pady=10)
        
        frame = ttk.Frame(self.thunderbolt_tab)
        frame.pack(fill='both', expand=True, padx=20, pady=10)
        
        info = tk.Label(frame, text=
                       "Thunderbolt 4 enables:\n"
                       "- Direct Memory Access (DMA) attacks\n"
                       "- PCIe device emulation\n"
                       "- USB-C port redirection\n"
                       "- Firmware recovery attacks\n"
                       "- PCIe JTAG debugging",
                       font=('Consolas', 11), bg=BG_DARK, fg=TEXT_WHITE, justify='left')
        info.pack(anchor='w')
        
        attack_frame = ttk.LabelFrame(frame, text="Thunderbolt Attacks", padding=10)
        attack_frame.pack(fill='both', expand=True, pady=10)
        
        tb_attacks = [
            ("DMA Memory Dump", "tb_dma_dump"),
            ("PCILeech Live Injection", "tb_pcileech"),
            ("USB-C Impersonation", "tb_usbc_impersonate"),
            ("PCIe Device Emulation", "tb_pcie_emulate"),
            ("IOMMU Bypass", "tb_iommu_bypass"),
            ("Firmware Dump", "tb_firmware_dump"),
            ("Thunderstrike SMM", "tb_thunderstrike"),
            ("DMA Rootkit Injection", "tb_dma_rootkit"),
        ]
        
        for i, (name, key) in enumerate(tb_attacks):
            row = i // 2
            col = i % 2
            btn = tk.Button(attack_frame, text=name, font=('Consolas', 11),
                          bg=BG_BUTTON, fg=ACCENT_MAGENTA, relief='flat', padx=15, pady=12,
                          command=lambda k=key: self.execute_tb_attack(k))
            btn.grid(row=row, column=col, padx=10, pady=5, sticky='ew')

    def create_wifi_tab(self):
        frame = ttk.Frame(self.wifi_tab)
        frame.pack(fill='both', expand=True, padx=20, pady=10)
        
        tk.Label(frame, text="WiFi Attack Suite", font=('Consolas', 18, 'bold'),
                bg=BG_DARK, fg=ACCENT_CYAN).pack(pady=10)
        
        wifi_attacks = [
            ("Start Monitor Mode", "wifi_monitor"),
            ("Scan Networks", "wifi_scan"),
            ("Deauth Attack", "wifi_deauth"),
            ("Capture Handshake", "wifi_capture"),
            ("WPA2 Cracker", "wifi_crack"),
            ("WPS Brute Force", "wifi_wps"),
            ("Evil Twin AP", "wifi_eviltwin"),
            ("PMKID Attack", "wifi_pmkid"),
            ("Rogue AP Portal", "wifi_rogue"),
            ("Deauth Flood", "wifi_deauth_flood"),
        ]
        
        grid = ttk.Frame(frame)
        grid.pack(fill='both', expand=True)
        
        for i, (name, key) in enumerate(wifi_attacks):
            row = i // 2
            col = i % 2
            btn = tk.Button(grid, text=name, font=('Consolas', 11),
                          bg=BG_BUTTON, fg=ACCENT_CYAN, relief='flat', padx=15, pady=12,
                          command=lambda k=key: self.run_wifi_attack(k))
            btn.grid(row=row, column=col, padx=10, pady=5, sticky='ew')

    def create_ble_tab(self):
        frame = ttk.Frame(self.ble_tab)
        frame.pack(fill='both', expand=True, padx=20, pady=10)
        
        tk.Label(frame, text="BLE/Bluetooth Attack Suite", font=('Consolas', 18, 'bold'),
                bg=BG_DARK, fg=ACCENT_MAGENTA).pack(pady=10)
        
        ble_attacks = [
            ("Scan BLE Devices", "ble_scan"),
            ("GATT Service Enum", "ble_gatt"),
            ("BLE Sniff Ubertooth", "ble_sniff"),
            ("BLE Jam", "ble_jam"),
            ("Cursed BLE Glitch", "ble_glitch"),
            ("BLE Replay Attack", "ble_replay"),
            ("BLE MITM Proxy", "ble_mitm"),
            ("BLE Firmware Dump", "ble_firmware"),
            ("Bluetooth DoS", "ble_dos"),
            ("BLE Keyboard Injection", "ble_keyboard"),
        ]
        
        grid = ttk.Frame(frame)
        grid.pack(fill='both', expand=True)
        
        for i, (name, key) in enumerate(ble_attacks):
            row = i // 2
            col = i % 2
            btn = tk.Button(grid, text=name, font=('Consolas', 11),
                          bg=BG_BUTTON, fg=ACCENT_MAGENTA, relief='flat', padx=15, pady=12,
                          command=lambda k=key: self.run_ble_attack(k))
            btn.grid(row=row, column=col, padx=10, pady=5, sticky='ew')

    def create_rf_tab(self):
        frame = ttk.Frame(self.rf_tab)
        frame.pack(fill='both', expand=True, padx=20, pady=10)
        
        tk.Label(frame, text="RF/Glitching Suite", font=('Consolas', 18, 'bold'),
                bg=BG_DARK, fg=ACCENT_GREEN).pack(pady=10)
        
        rf_attacks = [
            ("RF Spectrum Scan RTL-SDR", "rf_spectrum"),
            ("RF Sniff 433MHz", "rf_433_sniff"),
            ("RF Sniff 915MHz", "rf_915_sniff"),
            ("RF Replay Attack", "rf_replay"),
            ("RF Jammer", "rf_jam"),
            ("Sub-GHz Fuzz", "rf_fuzz"),
            ("RF Glitch Cursed", "rf_glitch"),
            ("RTL-SDR Record", "rf_record"),
        ]
        
        grid = ttk.Frame(frame)
        grid.pack(fill='both', expand=True)
        
        for i, (name, key) in enumerate(rf_attacks):
            row = i // 2
            col = i % 2
            btn = tk.Button(grid, text=name, font=('Consolas', 11),
                          bg=BG_BUTTON, fg=ACCENT_GREEN, relief='flat', padx=15, pady=12,
                          command=lambda k=key: self.run_rf_attack(k))
            btn.grid(row=row, column=col, padx=10, pady=5, sticky='ew')

    def create_network_tab(self):
        frame = ttk.Frame(self.network_tab)
        frame.pack(fill='both', expand=True, padx=20, pady=10)
        
        tk.Label(frame, text="Network Attack Suite", font=('Consolas', 18, 'bold'),
                bg=BG_DARK, fg=ACCENT_YELLOW).pack(pady=10)
        
        net_attacks = [
            ("Port Scan nmap", "net_scan"),
            ("ARP Spoof MITM", "net_arp_spoof"),
            ("DNS Spoof", "net_dns_spoof"),
            ("SSL Strip", "net_ssl_strip"),
            ("Responder LLMNR", "net_responder"),
            ("Ettercap Filter", "net_ettercap"),
            ("VPN Downgrade", "net_vpn_down"),
            ("Network DoS", "net_dos"),
        ]
        
        grid = ttk.Frame(frame)
        grid.pack(fill='both', expand=True)
        
        for i, (name, key) in enumerate(net_attacks):
            row = i // 2
            col = i % 2
            btn = tk.Button(grid, text=name, font=('Consolas', 11),
                          bg=BG_BUTTON, fg=ACCENT_YELLOW, relief='flat', padx=15, pady=12,
                          command=lambda k=key: self.run_net_attack(k))
            btn.grid(row=row, column=col, padx=10, pady=5, sticky='ew')

    def create_lab_tab(self):
        frame = ttk.Frame(self.lab_tab)
        frame.pack(fill='both', expand=True, padx=20, pady=10)
        
        tk.Label(frame, text="Lab Control Center", font=('Consolas', 18, 'bold'),
                bg=BG_DARK, fg=TEXT_WHITE).pack(pady=10)
        
        lab_frame = ttk.LabelFrame(frame, text="Lab Status", padding=10)
        lab_frame.pack(fill='both', expand=True)
        
        tk.Label(lab_frame, text="Target Devices: Unknown", font=('Consolas', 12),
                bg=BG_DARK, fg=ACCENT_GREEN).pack(anchor='w', pady=5)
        tk.Label(lab_frame, text="Thunderbolt: Not Connected", font=('Consolas', 12),
                bg=BG_DARK, fg=ACCENT_RED).pack(anchor='w', pady=5)
        tk.Label(lab_frame, text="WiFi Adapter: Checking...", font=('Consolas', 12),
                bg=BG_DARK, fg=ACCENT_YELLOW).pack(anchor='w', pady=5)
        
        ttk.Button(lab_frame, text="Refresh Lab Status", 
                  command=lambda: self.status_update("Lab status refreshed")).pack(pady=10)

    def scan_usb(self):
        self.usb_listbox.delete(0, 'end')
        try:
            result = subprocess.run(['lsusb'], capture_output=True, text=True, timeout=10)
            for line in result.stdout.split('\n'):
                if line.strip():
                    self.usb_listbox.insert('end', line)
        except Exception as e:
            self.usb_listbox.insert('end', f"Error: {e}")

    def badusb_menu(self):
        messagebox.showinfo("BadUSB", "Select payload from list")
        
    def execute_payload(self, key):
        self.status_update(f"Executing {key}")
        messagebox.showwarning("Payload", f"Would execute: {key}")
        
    def execute_tb_attack(self, key):
        self.status_update(f"Thunderbolt: {key}")
        messagebox.showwarning("TB Attack", f"Thunderbolt 4 required for: {key}")
        
    def run_wifi_attack(self, key):
        self.status_update(f"WiFi: {key}")
        
    def run_ble_attack(self, key):
        self.status_update(f"BLE: {key}")
        
    def run_rf_attack(self, key):
        self.status_update(f"RF: {key}")
        
    def run_net_attack(self, key):
        self.status_update(f"Network: {key}")
        
    def status_update(self, msg, color=ACCENT_GREEN):
        self.status_label.config(text=msg, fg=color)

if __name__ == "__main__":
    root = tk.Tk()
    app = NullAttackGUI(root)
    root.mainloop()
