From e9924f465a7eb8237017d84bdff14037aefb60c8 Mon Sep 17 00:00:00 2001 From: babylard Date: Sun, 7 Jul 2024 10:33:27 -0500 Subject: [PATCH] 1.0 Commit --- Documentation/docs.ipynb | 6 +- GUI/main.py | 116 +++++++++++++++++++++++++++++++++++---- GUI/requirements.txt | 2 +- README.md | 10 ++-- 4 files changed, 114 insertions(+), 20 deletions(-) diff --git a/Documentation/docs.ipynb b/Documentation/docs.ipynb index 1444c39..b387b61 100644 --- a/Documentation/docs.ipynb +++ b/Documentation/docs.ipynb @@ -5,12 +5,12 @@ "metadata": {}, "source": [ "# Setup\n", - "First of all, you will need to install Packet capturing software for the program to function properly. Here are some good options:\n", + "First of all, you will need to install Packet capturing software for the program to function properly. Here are some good options you can choose from:\n", "1. [NpCap](https://npcap.com/#download)\n", "2. [WinPcap](https://www.winpcap.org/install/default.htm)\n", "3. [Nmap](https://nmap.org/download.html)\n", "\n", - "If wouldn't use WinPcap, as it has ceased development quite a long time ago and is vunreble to DLL Injections and such, however if you're not worried about security then it should work just fine. For more information on vunrebilities of using WinPcap you can visit their [website](https://www.winpcap.org/). For Mac users, I reccomend using Nmap.\n", + "I wouldn't use WinPcap, as it has ceased development a long time ago, but if you're not worried about security then it should work just fine. For more information you can visit their [website](https://www.winpcap.org/).\n", "\n", "Please note that you are only required to have one of these, or other software with the same functionality.\n", "\n", @@ -18,7 +18,7 @@ "\n", "# Basic Usage\n", "\n", - "To begin, Input the IP Address of your Router/AP, along with the range. If you dont know what an IP range is, you can just leave it as is and it will function just fine. Both fields will be set properly as of 0.0.3, so they can be left as is unless you would like to make changes. The TUI version currently does not have this functionality. There is also a checkbox labeled \"Show short OUIs\" which when checked, will show an 8 character long version of listed manufacturers to preserve space since these can often be quite long, espesially from foriegn manufacturers. When left unchecked, the full length will be outputted. The TUI version now has this ability as of 0.8\n", + "To begin, Input the IP Address of your Router/AP, along with the range. If you dont know what an IP range is, you can just leave it as is and it will function just fine. Both fields will be set properly by default, so they can be left as is unless you would like to make changes. There is also a checkbox labeled \"Show short OUIs\" which when checked, will show an 8 character long version of listed manufacturers to reserve space since these can often be quite long, espesially from foriegn manufacturers. When left unchecked, the full length will be outputted. The TUI version now has this ability as of 0.8\n", "\n", "Once everything is set to your preference, press `Scan Network`. The program will list devices it finds in realtime, and when finished you should have list of every devices IP, MAC Address, OS, etc.\n", "\n", diff --git a/GUI/main.py b/GUI/main.py index 176c115..a781899 100644 --- a/GUI/main.py +++ b/GUI/main.py @@ -1,6 +1,6 @@ -# Imports import customtkinter as ctk -from tkinter import messagebox +from tkinter import * +from tkinter import filedialog from scapy.all import * import scapy.all as scapy from scapy.layers.dot11 import RadioTap, Dot11, Dot11Deauth @@ -10,6 +10,8 @@ import threading import sys import webbrowser +import json +import os # Variables hostname = conf.route.route("0.0.0.0")[2] @@ -43,10 +45,19 @@ def deauth_function(target_mac, bssid, count=1): scapy.send(deauth_packet, verbose=False) time.sleep(10) - print("Deauthed for 10 Seconds, repeating...") except: print("Invalid input.") +def portscan_function(ip): + for port in range(65535): + try: + serv = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + serv.bind((ip,port)) + except: + print('\033[1;32;40m [OPEN]: ', port) + + serv.close() #close connection + def start_deauth(target_mac, bssid, count=1): global deauth_thread @@ -62,6 +73,15 @@ def stop_deauth_thread(): stop_deauth_event.set() print("Stopped Deauth.") +def start_portscan(ip): + global portscan_thread + + if portscan_thread and portscan_thread.is_alive(): + stop_portscan_thread() + + portscan_thread = threading.Thread(target=portscan_function, args=(ip)) + portscan_thread.start() + def get_device_type(mac_address): global show_short_oui p = manuf.MacParser() @@ -129,7 +149,6 @@ def scan_thread(ip): scanning_thread.start() # GUI - ctk.set_appearance_mode("system") ctk.set_default_color_theme("green") @@ -142,7 +161,7 @@ def on_deauth(): router_mac = router_entry.get() if target_mac and router_mac: start_deauth(target_mac=target_mac, bssid=router_mac) - deauth_output.insert(ctk.END, f"Deauthing {target_mac}, this lasts about 10 seconds and will be looped every 10 seconds.\n--------------------------------------------------------------------\n") + deauth_output.insert(ctk.END, f"Deauth loop started.\n--------------------------------------------------------------------\n") else: deauth_output.insert(ctk.END, "Values not set. Please enter details in both Target MAC and Router MAC. If you need any help, feel free to read the documentation.\n") @@ -171,10 +190,10 @@ def validate_numeric_input(value): return all(char.isdigit() or char == "." for char in value) or value == "" def main_window(): - global root, output_text + global root, output_text, ip_entry, range_entry root = ctk.CTk() root.title("NetScan") - root.geometry("753x600") + root.geometry("753x558") validate_command = root.register(validate_numeric_input) @@ -186,6 +205,58 @@ def on_scan_network(): def on_clear_output(): output_text.delete(1.0, ctk.END) + + def donothing(): + print("Unimplemented") + + def save(): + # Open a file dialog to choose the save location + file_path = filedialog.asksaveasfilename(defaultextension=".json", filetypes=[("JSON files", "*.json"), ("All files", "*.*")]) + if file_path: + # Sanitize file name by removing invalid characters + file_name = os.path.basename(file_path) + sanitized_file_name = "".join(c for c in file_name if c.isalnum() or c in "_-.") + + # Add "NetScan_" to the beginning of the file name + if not sanitized_file_name.endswith(".json"): + sanitized_file_name += ".json" + if not sanitized_file_name.startswith("NetScan_"): + sanitized_file_name = "NetScan_" + sanitized_file_name + + # Construct full file path with sanitized file name + save_file_path = os.path.join(os.path.dirname(file_path), sanitized_file_name) + + # Save the current state to a JSON file + data = { + "router_ip": ip_entry.get(), + "ip_range": range_entry.get(), + "output": output_text.get(1.0, ctk.END), + "short_oui": oui_var.get() + } + with open(save_file_path, 'w') as file: + json.dump(data, file, indent=4) + print(f"File saved to {save_file_path}") + + def open_file(): + # Open a file dialog to choose the file to open + file_path = filedialog.askopenfilename(filetypes=[("JSON files", "*.json"), ("All files", "*.*")]) + if file_path: + # Check if the file is valid for your program + if not file_path.endswith(".json") or not os.path.basename(file_path).startswith("NetScan_"): + print(f"Invalid file selected: {file_path}") + return + + # Load the state from the JSON file + with open(file_path, 'r') as file: + data = json.load(file) + ip_entry.delete(0, ctk.END) + ip_entry.insert(0, data["router_ip"]) + range_entry.delete(0, ctk.END) + range_entry.insert(0, data["ip_range"]) + output_text.delete(1.0, ctk.END) + output_text.insert(ctk.END, data["output"]) + oui_var.set(data.get("short_oui", False)) + print(f"File loaded from {file_path}") ctk.CTkLabel(root, text="Router IP").grid(row=0, column=0, padx=1, pady=1, sticky="w") ctk.CTkLabel(root, text="IP Range").grid(row=0, column=1, padx=1, pady=1, sticky="w") @@ -210,10 +281,35 @@ def on_clear_output(): sys.stdout = TextRedirector(output_text) ctk.CTkButton(root, text="Scan Network", command=on_scan_network).grid(row=3, column=0, padx=5, pady=5, sticky="w") - ctk.CTkButton(root, text="Deauth a device", command=deauth_window).grid(row=3, column=1, padx=5, pady=5, sticky="w") - ctk.CTkButton(root, text="Help", command=docs).grid(row=3, column=2, padx=5, pady=5, sticky="w") - ctk.CTkButton(root, text="Clear Output", command=on_clear_output).grid(row=4, column=0, columnspan=3, padx=5, pady=5, sticky="w") + def newfile(): + on_clear_output() + range_entry.delete(0, ctk.END) + range_entry.insert(0, "24") + ip_entry.delete(0, ctk.END) + ip_entry.insert(0, hostname) + oui_var.set(False) + + menubar = Menu(root) + filemenu = Menu(menubar, tearoff=0) + filemenu.add_command(label="New", command=newfile) + filemenu.add_command(label="Open", command=open_file) + filemenu.add_command(label="Save", command=save) + filemenu.add_separator() + filemenu.add_command(label="Exit", command=root.quit) + menubar.add_cascade(label="File", menu=filemenu) + + helpmenu = Menu(menubar, tearoff=0) + helpmenu.add_command(label="Documentation", command=docs) + menubar.add_cascade(label="Help", menu=helpmenu) + + viewmenu = Menu(menubar, tearoff=0) + viewmenu.add_command(label="Clear", command=on_clear_output) + viewmenu.add_command(label="Deauth", command=deauth_window) + viewmenu.add_command(label="Port scan", command=donothing) + menubar.add_cascade(label="View", menu=viewmenu) + + root.config(menu=menubar) root.mainloop() if __name__ == "__main__": diff --git a/GUI/requirements.txt b/GUI/requirements.txt index 7695117..31957d8 100644 --- a/GUI/requirements.txt +++ b/GUI/requirements.txt @@ -1,3 +1,3 @@ manuf==1.1.5 -PySimpleGUI==4.60.5 scapy==2.5.0 +customtkinter==5.2.2 \ No newline at end of file diff --git a/README.md b/README.md index 770d9b8..483c5bd 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # NetScan -A lightweight Network scanner which lists IPs, MAC Addresses of devices on a specified network, which is also capable of deauthing devices. +A Network scanner which lists IPs, MAC Addresses, and other information about devices on a network, which can also Deuath devices. -![image](https://github.com/babylard/NetScan/assets/75695872/5ec60a6f-acdf-4ef7-a6ea-ec1ee3adf62e) +![image](https://github.com/babylard/NetScan/assets/75695872/40ad710c-4471-4910-91e3-2e29567890dc) # Dependencies -You may require WinPcap, Npcap, or other Packet Capturing software for the program to work properly. I highly reccomend Npcap over WinPcap, as WinPcap has ceased development a very long time ago. But if you dont care for security, WinPcap will work just fine. +You may require WinPcap, Npcap, or other Packet Capturing software for the program to work properly. These will be listed below. Be sure to run `pip install -r requirements.txt` to install all needed modules to function. @@ -21,6 +21,4 @@ To begin, input the IP of the router you would like to scan for connected device Both fields will be properly set by default as of 0.0.3, then press "Scan". The output will begin listing devices it finds in realtime, and should let you know when it is done. Afterwards you should have a neat looking list of IP's, MAC Addresses, OS information, etc. - - -Please view the [Documentation](https://github.com/babylard/NetScan/blob/main/Documentation/docs.ipynb) for more in depth information. +Please view the [Documentation](https://github.com/babylard/NetScan/blob/main/Documentation/docs.ipynb) for more in depth information. \ No newline at end of file