浏览代码

Uploading project files

Uploading all files that i have
父节点
当前提交
a01bf289ca
共有 5 个文件被更改,包括 322 次插入0 次删除
  1. 53
    0
      Scanner/install_docker.sh
  2. 66
    0
      Scanner/networkdiscovery.py
  3. 84
    0
      Scanner/portscanner.py
  4. 73
    0
      Scanner/scheduler.py
  5. 46
    0
      Scanner/setup_manual.sh

+ 53
- 0
Scanner/install_docker.sh 查看文件

@@ -0,0 +1,53 @@
1
+#!/bin/bash
2
+
3
+echo "🛠 Installing Docker and Docker Compose on Ubuntu..."
4
+
5
+# Step 1: Remove older Docker versions (if any)
6
+sudo apt remove -y docker docker-engine docker.io containerd runc
7
+
8
+# Step 2: Update package index
9
+sudo apt update
10
+
11
+# Step 3: Install dependencies
12
+sudo apt install -y \
13
+    ca-certificates \
14
+    curl \
15
+    gnupg \
16
+    lsb-release \
17
+    apt-transport-https \
18
+    software-properties-common
19
+
20
+# Step 4: Add Docker’s official GPG key
21
+sudo mkdir -p /etc/apt/keyrings
22
+curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
23
+    sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
24
+
25
+# Step 5: Set up Docker repository
26
+echo \
27
+  "deb [arch=$(dpkg --print-architecture) \
28
+  signed-by=/etc/apt/keyrings/docker.gpg] \
29
+  https://download.docker.com/linux/ubuntu \
30
+  $(lsb_release -cs) stable" | \
31
+  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
32
+
33
+# Step 6: Update and install Docker
34
+sudo apt update
35
+sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
36
+
37
+# Step 7: Enable and start Docker
38
+sudo systemctl enable docker
39
+sudo systemctl start docker
40
+
41
+# Step 8: (Optional) Add current user to docker group (to avoid needing sudo)
42
+if ! groups $USER | grep -q docker; then
43
+    echo " Adding $USER to docker group..."
44
+    sudo usermod -aG docker $USER
45
+    echo "⚠ Please log out and back in for group changes to take effect."
46
+fi
47
+
48
+# Step 9: Test
49
+echo " Docker installed. Testing..."
50
+docker --version
51
+docker compose version
52
+
53
+echo " Done!"

+ 66
- 0
Scanner/networkdiscovery.py 查看文件

@@ -0,0 +1,66 @@
1
+
2
+
3
+import nmap
4
+import psutil
5
+import socket
6
+import ipaddress
7
+import pandas as pd
8
+from datetime import datetime
9
+import os
10
+
11
+# Set up data directory
12
+BASE_DIR = os.path.dirname(os.path.abspath(__file__))
13
+DATA_DIR = os.path.abspath(os.path.join(BASE_DIR, "..", "data"))
14
+os.makedirs(DATA_DIR, exist_ok=True)
15
+excluded_prefixes = ("lo", "docker", "br-", "veth", "vmnet", "virbr")
16
+
17
+def get_ipv4_interfaces():
18
+    ipv4_interfaces = []
19
+    for name, addrs in psutil.net_if_addrs().items():
20
+        for addr in addrs:
21
+            if addr.family == socket.AF_INET:
22
+                # Skip loopback or docker interfaces
23
+                if name.startswith(excluded_prefixes):
24
+                    continue
25
+                ipv4_interfaces.append((name, addr.address, addr.netmask))
26
+    return ipv4_interfaces
27
+
28
+def network_discovery():
29
+    ipv4_interfaces = get_ipv4_interfaces()
30
+    if not ipv4_interfaces:
31
+        print("No active IPv4 network interfaces found.")
32
+        return
33
+
34
+    nm = nmap.PortScanner()
35
+    active_hosts = []
36
+
37
+    for name, ip, netmask in ipv4_interfaces:
38
+        network = ipaddress.IPv4Network((ip, netmask), strict=False)
39
+        print(f"Discovering hosts in IP range {network} using interface {name}...")
40
+
41
+        try:
42
+            nm.scan(hosts=str(network), arguments='-sn -T4')
43
+        except Exception as e:
44
+            print(f"Error scanning {network}: {e}")
45
+            continue
46
+
47
+        discovered = nm.all_hosts()
48
+        print(f"Found {len(discovered)} hosts on {network}")
49
+
50
+        for host in discovered:
51
+            active_hosts.append([host, datetime.now().strftime("%Y-%m-%d %H:%M:%S")])
52
+
53
+    if active_hosts:
54
+        columns = ['IP', 'Discovery Timestamp']
55
+        df = pd.DataFrame(active_hosts, columns=columns)
56
+        filename = "active_hosts.csv"
57
+        output_file = os.path.join(DATA_DIR, filename)
58
+        df.to_csv(output_file, index=False)
59
+        print(f"Discovery complete. Results saved to {filename}")
60
+        return df
61
+    else:
62
+        print("No active hosts found.")
63
+        return None
64
+
65
+if __name__ == "__main__":
66
+    network_discovery()

+ 84
- 0
Scanner/portscanner.py 查看文件

@@ -0,0 +1,84 @@
1
+
2
+import nmap
3
+import pandas as pd
4
+from datetime import datetime
5
+import os
6
+
7
+# Set up data directory
8
+BASE_DIR = os.path.dirname(os.path.abspath(__file__))
9
+DATA_DIR = os.path.abspath(os.path.join(BASE_DIR, "..", "data"))
10
+os.makedirs(DATA_DIR, exist_ok=True)
11
+
12
+
13
+def detailed_scan():
14
+    active_hosts_path = os.path.join(DATA_DIR, "active_hosts.csv")
15
+    try:
16
+        active_hosts_df = pd.read_csv(active_hosts_path)
17
+    except FileNotFoundError:
18
+        print("File active_hosts.csv not found. Please run the network discovery script first.")
19
+        return
20
+
21
+    nm = nmap.PortScanner()
22
+    scan_results = []
23
+
24
+    start_time = datetime.now()
25
+    print(f"Scan started at: {start_time.strftime('%Y-%m-%d %H:%M:%S')}")
26
+
27
+    for index, row in active_hosts_df.iterrows():
28
+        ip = row['IP']
29
+        print(f"Scanning {ip} for detailed information...")
30
+        try:
31
+            nm.scan(ip, arguments='-p- -T5')
32
+        except Exception as e:
33
+            print(f"Error scanning {ip}: {e}")
34
+            continue
35
+
36
+        for host in nm.all_hosts():
37
+            hostnames = [x['name'] for x in nm[host].get('hostnames', [])]
38
+            mac_address = nm[host]['addresses'].get('mac', 'N/A')
39
+            scan_timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
40
+
41
+            for proto in nm[host].all_protocols():
42
+                for port in nm[host][proto]:
43
+                    port_data = nm[host][proto][port]
44
+                    if port_data.get('state') != 'open':
45
+                        continue
46
+
47
+                    row = [
48
+                        ip,
49
+                        ', '.join(hostnames),
50
+                        mac_address,
51
+                        proto,
52
+                        port,
53
+                        port_data.get('name', ''),
54
+                        port_data.get('state', ''),
55
+                        port_data.get('product', ''),
56
+                        port_data.get('version', ''),
57
+                        port_data.get('extrainfo', ''),
58
+                        scan_timestamp
59
+                    ]
60
+                    scan_results.append(row)
61
+
62
+    end_time = datetime.now()
63
+    print(f"Scan finished at: {end_time.strftime('%Y-%m-%d %H:%M:%S')}")
64
+    print(f"Total scan duration: {end_time - start_time}")
65
+
66
+    if not scan_results:
67
+        print("No open ports found.")
68
+        return
69
+
70
+    columns = [
71
+        'IP', 'Hostname', 'MAC Address', 'Protocol', 'Port', 'Name',
72
+        'State', 'Product', 'Version', 'Extra Info', 'Timestamp'
73
+    ]
74
+    detailed_df = pd.DataFrame(scan_results, columns=columns)
75
+
76
+    filename = "detailed_scan_results.csv"
77
+    output_file = os.path.join(DATA_DIR, filename)
78
+    write_header = not os.path.exists(output_file)
79
+    detailed_df.to_csv(output_file, mode='a', header=write_header, index=False)
80
+    print(f"Scan results saved to {output_file}")
81
+    print(detailed_df)
82
+
83
+if __name__ == "__main__":
84
+    detailed_scan()

+ 73
- 0
Scanner/scheduler.py 查看文件

@@ -0,0 +1,73 @@
1
+import schedule
2
+import subprocess
3
+import time
4
+import os
5
+from datetime import datetime
6
+
7
+BASE_DIR = os.path.dirname(os.path.abspath(__file__))
8
+ENV_DIR= os.path.join(BASE_DIR, "venv", "bin", "python3")
9
+
10
+def log(message):
11
+    print(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {message}")
12
+
13
+def run_host_discovery():
14
+    log(" Running Host Discovery...")
15
+    try:
16
+        subprocess.run([ENV_DIR, os.path.join(BASE_DIR, "Host_Discovery", "networkdiscovery.py")], check=True)
17
+        log(" Host Discovery completed")
18
+    except subprocess.CalledProcessError as e:
19
+        log(f" Host Discovery failed: {e}")
20
+
21
+def run_port_scan():
22
+    active_hosts_file = os.path.join(BASE_DIR, "data", "active_hosts.csv")
23
+    if not os.path.exists(active_hosts_file) or os.path.getsize(active_hosts_file) == 0:
24
+        log(" Skipping Port Scan: active_hosts.csv not found or is empty.")
25
+        return
26
+
27
+    log(" Running Port Scan...")
28
+    try:
29
+        subprocess.run(["sudo", ENV_DIR, os.path.join(BASE_DIR, "Host_Discovery", "portscanner.py")], check=True)
30
+        log("Port Scan completed")
31
+    except subprocess.CalledProcessError as e:
32
+        log(f" Port Scan failed: {e}")
33
+
34
+def run_vulnerability_scan():
35
+    active_hosts_file = os.path.join(BASE_DIR, "data", "active_hosts.csv")
36
+    if not os.path.exists(active_hosts_file) or os.path.getsize(active_hosts_file) == 0:
37
+        log("Skipping Vulnerability Scan: active_hosts.csv not found or is empty.")
38
+        return
39
+
40
+    log(" Running Vulnerability Scan Sequence...")
41
+    scripts = [
42
+        "createTargets.py",
43
+        "taskmaker.py",
44
+        "starttask.py",
45
+        "getreports.py",
46
+        "generate_reports.py"
47
+    ]
48
+    for script in scripts:
49
+        path = os.path.join(BASE_DIR, "Vunerability_Scanner/", script)
50
+        try:
51
+            subprocess.run([ENV_DIR, path], check=True)
52
+            log(f" Finished {script}")
53
+        except subprocess.CalledProcessError as e:
54
+            log(f" Error in {script}: {e}")
55
+            break
56
+
57
+# Schedule tasks
58
+schedule.every().hour.at(":00").do(run_host_discovery)
59
+schedule.every().hour.at(":05").do(run_port_scan)
60
+schedule.every(11).hours.at(":10").do(run_vulnerability_scan)
61
+
62
+log(" Scheduler is running...")
63
+
64
+
65
+# Run initial discovery and scan
66
+log(" Running initial startup scan sequence...")
67
+run_host_discovery()
68
+run_port_scan()
69
+run_vulnerability_scan()
70
+
71
+while True:
72
+    schedule.run_pending()
73
+    time.sleep(30)

+ 46
- 0
Scanner/setup_manual.sh 查看文件

@@ -0,0 +1,46 @@
1
+#!/bin/bash
2
+
3
+echo "Starting manual setup for OpenVAS dashboard..."
4
+
5
+# Ensure we're running on Ubuntu with sudo
6
+if [[ $EUID -ne 0 ]]; then
7
+   echo "This script must be run with sudo: sudo ./setup_manual.sh"
8
+   exit 1
9
+fi
10
+
11
+# ---- 1. System Dependencies ----
12
+echo "Installing system dependencies..."
13
+apt update && apt install -y \
14
+    nmap \
15
+    python3 \
16
+    python3-pip \
17
+    python3-venv \
18
+    libxslt1-dev \
19
+    libxml2-dev \
20
+    libffi-dev \
21
+    build-essential \
22
+    virtualenv \
23
+    unzip \
24
+    net-tools \
25
+    curl
26
+
27
+# ---- 2. Python Virtual Environment ----
28
+PROJECT_DIR=$(pwd)
29
+echo "Creating virtual environment in: $PROJECT_DIR/venv"
30
+python3 -m venv venv
31
+source venv/bin/activate
32
+
33
+# ---- 3. Install Python Packages ----
34
+echo "Installing Python dependencies in virtual environment..."
35
+pip install --upgrade pip
36
+pip install dash dash-bootstrap-components pandas plotly psutil python-nmap lxml tabulate python-dotenv schedule gvm-tools
37
+
38
+echo "Manual setup complete!"
39
+echo "To activate your virtual environment later, run:"
40
+echo "source $PROJECT_DIR/venv/bin/activate"
41
+
42
+
43
+echo ""
44
+echo "To run the scheduler:"
45
+echo " sudo $PROJECT_DIR/venv/bin/python3 $PROJECT_DIR/scheduler.py"
46
+