-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
151 lines (117 loc) · 4.84 KB
/
Copy pathgui.py
File metadata and controls
151 lines (117 loc) · 4.84 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
import os
import sys
import json
import threading
import subprocess
import webview
import logging
logger = logging.getLogger('pywebview')
logger.setLevel(logging.CRITICAL)
class Api:
def __init__(self):
self.window = None
self.process = None
self.thread = None
def start_scan(self, form_data):
if self.process is not None and self.process.poll() is None:
return {"error": "A scan is already running"}
cmd = [sys.executable, "scanner.py", "--json-ui"]
if form_data.get("targets"):
cmd.extend(form_data["targets"].split())
if form_data.get("ports"):
cmd.extend(["-p", form_data["ports"]])
if form_data.get("snis"):
for sni in form_data["snis"].split(","):
cmd.extend(["--sni", sni.strip()])
if form_data.get("match"):
cmd.extend(["--match", form_data["match"]])
if form_data.get("ping"):
cmd.append("--ping")
if form_data.get("no_tcp"):
cmd.append("--no-tcp")
if form_data.get("no_tls"):
cmd.append("--no-tls")
if form_data.get("matched_only"):
cmd.append("--matched-only")
for key in ["file", "sni_file", "output", "ips_out", "snis_out", "config_in", "config_out"]:
if form_data.get(key):
cmd.extend([f"--{key.replace('_', '-')}", form_data[key].strip()])
for key in ["tcp_timeout", "tls_timeout", "ping_timeout", "retries", "retry_delay", "workers", "tls_workers"]:
if form_data.get(key):
cmd.extend([f"--{key.replace('_', '-')}", str(form_data[key])])
if sys.platform != "win32":
bash_cmd = "ulimit -n 1048576 2>/dev/null; "
settings_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "Settings.sh")
if os.path.exists(settings_path):
bash_cmd += f"source '{settings_path}' >/dev/null 2>&1; "
import shlex
bash_cmd += " ".join(shlex.quote(arg) for arg in cmd)
final_cmd = ["bash", "-c", bash_cmd]
else:
final_cmd = cmd
print("Running command:", " ".join(final_cmd) if sys.platform != "win32" else " ".join(final_cmd))
try:
kwargs = {}
if sys.platform != "win32":
kwargs["preexec_fn"] = os.setsid
self.process = subprocess.Popen(
final_cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
cwd=os.path.dirname(os.path.abspath(__file__)),
**kwargs
)
self.thread = threading.Thread(target=self._read_output, daemon=True)
self.thread.start()
return {"status": "started"}
except Exception as e:
return {"error": str(e)}
def _read_output(self):
if not self.process or not self.window:
return
for line in self.process.stdout:
line = line.strip()
if not line:
continue
if line.startswith("{") and line.endswith("}"):
js_code = f"if (window.onScannerEvent) window.onScannerEvent({line});"
self.window.evaluate_js(js_code)
else:
print("Scanner output:", line)
self.process.wait()
js_code = "if (window.onScannerEvent) window.onScannerEvent({'type': 'finished'});"
self.window.evaluate_js(js_code)
def stop_scan(self):
if self.process and self.process.poll() is None:
if sys.platform != "win32":
import signal
try:
os.killpg(os.getpgid(self.process.pid), signal.SIGTERM)
except Exception:
self.process.terminate()
else:
self.process.terminate()
self.process = None
return {"status": "stopped"}
return {"status": "not running"}
if __name__ == '__main__':
api = Api()
current_dir = os.path.dirname(os.path.abspath(__file__))
ui_dir = os.path.join(current_dir, "ui")
if not os.path.exists(ui_dir):
os.makedirs(ui_dir)
window = webview.create_window(
"TLSHunter Dashboard",
url=os.path.join(ui_dir, "index.html"),
js_api=api,
width=1100,
height=800,
background_color='#0B0F19'
)
api.window = window
def on_closed():
api.stop_scan()
window.events.closed += on_closed
webview.start()