-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·168 lines (145 loc) · 4.94 KB
/
main.py
File metadata and controls
executable file
·168 lines (145 loc) · 4.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python3
"""
PP-MultiShield – core launcher
(the whole learning / lists / firewall block is delegated to learning_menu.py)
"""
import os
import sys
import subprocess
import time
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent
LOG_DIR = BASE_DIR / "logs"
REQUIRED_FILES = [
LOG_DIR / "alerts.log",
BASE_DIR / "whitelist.txt",
BASE_DIR / "blocks.txt",
BASE_DIR / "blacklist.txt",
]
def ensure_project_files() -> None:
LOG_DIR.mkdir(exist_ok=True)
for p in REQUIRED_FILES:
p.touch(exist_ok=True)
ensure_project_files()
# ───────── ui helpers ─────────
def print_menu(title: str, items: list[str]) -> None:
width = 72
print("=" * width)
print(title.center(width))
print("=" * width)
for idx, item in enumerate(items, 1):
print(f"[{idx}] {item}")
print("=" * width)
def safe_input(prompt: str):
try:
return input(prompt)
except KeyboardInterrupt:
print() # newline after ^C
return None
# ───────── protection launcher ─────────
def run_module(cmd: list[str], desc: str) -> None:
try:
proc = subprocess.Popen(cmd)
proc.wait()
except KeyboardInterrupt:
proc.terminate()
print(f"\n[{desc}] stopped.")
time.sleep(1)
def protection_menu() -> None:
items = [
"Start ARP Protection",
"Start DNS Protection",
"Start DHCP Protection",
"Start SSL-Strip Detection",
"Start Rogue-AP Detection",
"Start Broadcast-Poison Protection",
"Start ICMP Redirect Protection",
"Start HTTPS→HTTP Redirect Watcher",
"Start All Protections",
"Back"
]
scripts = {
"1": "arp_protect.py",
"2": "dns_protect.py",
"3": "dhcp_protect.py",
"4": "ssl_strip_detect.py",
"5": "rogue_ap.py",
"6": "broadcast_poison.py",
"7": "icmp_redirect_guard.py",
"8": "http_redirect_watch.py"
}
while True:
print_menu("Protection & Monitoring Modules", items)
sel = safe_input("Select option: ")
if sel is None:
return
sel = sel.strip()
if sel in scripts: # launch single module
iface = safe_input("Interface (empty = all): ")
if iface is None:
continue
iface = iface.strip()
cmd = ["sudo", "python3",
os.path.join(BASE_DIR, scripts[sel]), "--loop"]
# Optional ALL-UDP only for broadcast_poison.py
if scripts[sel] == "broadcast_poison.py":
all_udp = safe_input("Monitor ALL UDP ports? (y/n): ")
if all_udp and all_udp.lower() == "y":
cmd.append("--all-udp")
if iface:
cmd.extend(["--iface", iface])
run_module(cmd, items[int(sel) - 1][6:])
elif sel == "9": # start all protections
iface = safe_input("Interface for all (empty = all): ")
if iface is None:
continue
iface = iface.strip()
all_udp_choice = safe_input("Monitor ALL UDP ports in Broadcast-Poison? (y/n): ")
all_udp = bool(all_udp_choice and all_udp_choice.lower() == "y")
procs = []
try:
# start in menu order
for key in sorted(scripts.keys(), key=int):
script = scripts[key]
cmd = ["sudo", "python3",
os.path.join(BASE_DIR, script), "--loop"]
if script == "broadcast_poison.py" and all_udp:
cmd.append("--all-udp")
if iface:
cmd.extend(["--iface", iface])
procs.append(subprocess.Popen(cmd))
while True:
time.sleep(2)
except KeyboardInterrupt:
for p in procs:
p.terminate()
print("\nAll protections stopped.")
time.sleep(1)
elif sel == "10": # back
return
else:
print("Invalid input.")
# ───────── main menu ─────────
def main_menu() -> None:
import learning_menu as lm # lazy import
while True:
print_menu("PP-MultiShield – Main Menu",
["Learning / Lists / Firewall / Logs",
"Protection & Monitoring Modules",
"Exit"])
choice = safe_input("Select section: ")
if choice is None:
print("Goodbye.")
sys.exit(0)
choice = choice.strip()
if choice == "1":
lm.learning_menu()
elif choice == "2":
protection_menu()
elif choice == "3":
print("Goodbye.")
sys.exit(0)
else:
print("Invalid input.")
if __name__ == "__main__":
main_menu()