Skip to content

Create an actual .env / Make a python venv / Update Readme #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: Cli
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__
.DS_Store
venv
.env
34 changes: 33 additions & 1 deletion Code/netscan.py → CLI/netscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from quick_scanner import quick_scan # Importing the quick_scan function from the quick_scanner module
import os # Importing os module. Used to check if the user is running the script as root.
from port_scan import scan_ports
from os_detection import detect_os

from datetime import datetime # Importing datetime module for date and time manipulation

Expand Down Expand Up @@ -57,7 +58,8 @@ def main():
print("4. sniff\t- Sniff packets in the network")
print("5. check\t- Run a port scan on a device discovered during a scan")
print("6. help\t\t- Display help information about commands or general usage")
print("7. exit\t\t- Exit the program")
print("7. osdetect\t- Detect the potential OS a Host is using.")
print("8. exit\t\t- Exit the program")
print("For more inforamtion on a command use: [COMMAND] -h")
print("\n") # Printing a new line

Expand All @@ -75,6 +77,35 @@ def main():
if "exit" in prompt: # If user wants to exit
print("\033[91mQuitting...\033[0m ") # Display quitting message
sys.exit() # Exit the program
elif "osdetect" in prompt:
if "-h" in prompt:
print("\033[91mOS Detection Help:\033[0m")
print("Usage: osdetect [IP] or [ID]")
print("Description: Attempt to detect the operating system of a host using TTL and TCP fingerprinting.")
print("Examples:")
print(" osdetect 192.168.1.1")
print(" osdetect 3 (ID from previous scan)")
continue

try:
target = prompt[1]
if target.isdigit() and scan_result and int(target) in scan_result:
ip = scan_result[int(target)]["ip"]
else:
ip = target

print(f"Detecting OS for {ip}...")
result = detect_os(ip)
if "error" in result:
print(f"Error: {result['error']}")
else:
print(f"IP: {result['ip']}")
print(f"TTL: {result['ttl']}")
print(f"TCP Window Size: {result['tcp_window']}")
print(f"Guessed OS: {result['os_guess']}")
except Exception as e:
print("Usage: osdetect [IP] or [ID from scan result]")
print("Error:", str(e))
elif "help" in prompt: # If user wants help
if "-h" in prompt: # If user wants specific help
# Printing help message for help command
Expand All @@ -91,6 +122,7 @@ def main():
print("3. results\t- Display the results of the network scan")
print("4. sniff\t- Sniff packets in the network")
print("5. help\t\t- Display help information about commands or general usage")
print("7. osdetect\t- Detect the potential OS a Host is using.")
print("6. exit\t\t- Exit the program")
print("For more inforamtion on a command use: [COMMAND] -h")
elif "sniff" in prompt:
Expand Down
38 changes: 38 additions & 0 deletions CLI/os_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from scapy.all import IP, TCP, sr1, ICMP

def detect_os(ip):
try:
# Try TCP SYN to port 80
pkt = IP(dst=ip)/TCP(dport=80, flags="S")
ans = sr1(pkt, timeout=2, verbose=0)

if not ans:
# Fallback to ICMP
icmp_pkt = IP(dst=ip)/ICMP()
ans = sr1(icmp_pkt, timeout=2, verbose=0)

if ans:
ttl = int(ans.ttl)
window = ans.getlayer(TCP).window if ans.haslayer(TCP) else None

# Rough OS guess based on TTL
if ttl <= 64:
os = "Linux/Unix"
elif ttl <= 128:
os = "Windows"
elif ttl <= 255:
os = "Cisco/Network Device"
else:
os = "Unknown"

return {
"ip": ip,
"ttl": ttl,
"tcp_window": window,
"os_guess": os
}
else:
return {"ip": ip, "error": "No response from host"}

except Exception as e:
return {"ip": ip, "error": str(e)}
File renamed without changes.
File renamed without changes.
9 changes: 8 additions & 1 deletion Code/scanner.py → CLI/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@
import json
import socket
import sys
import os
from dotenv import load_dotenv

load_dotenv()

# Function to get the current time formatted as a string
def time_format():
return time.strftime("%d-%m-%Y_%H:%M:%S")

# Function to make an API request and return a device's manufacturer by MAC address
def api_lookup(mac_address: str, vV_switch: bool) -> str:

api_key = os.getenv("MAC_VENDORS_APIKEY")

url = f"https://api.macvendors.com/v1/lookup/{mac_address}"
headers = {"Authorization": "Bearer API_KEY"}
headers = {"Authorization": f"Bearer {api_key}"}
if vV_switch:
print("Header for API lookup created")
api = requests.get(url=url, headers=headers)
Expand Down
File renamed without changes.
Binary file added GUI/.DS_Store
Binary file not shown.
Loading