Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/phishkit-core/src/evilginx_ctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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."
)));
}

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion crates/phishkit-core/src/readiness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn target_readiness(profile_id: String) -> AppResult<TargetReadiness> {
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",
);
Expand Down
15 changes: 14 additions & 1 deletion crates/phishkit-core/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,20 @@ pub fn evilginx_is_running(root: &std::path::Path) -> (bool, Option<u32>) {
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<u16> = Vec::new();
if let Ok(raw) = std::env::var("PHISHKIT_HTTPS_PORT") {
if let Ok(p) = raw.trim().parse::<u16>() {
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));
}
Expand Down
11 changes: 10 additions & 1 deletion docs/reference/data-and-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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.
36 changes: 25 additions & 11 deletions kit/evilginx/scripts/configure_lure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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.
Expand Down
47 changes: 38 additions & 9 deletions tests/python/test_configure_lure.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,44 @@ 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"
os.environ["EVILGINX_DNS_PORT"] = "5353"
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):
Expand Down Expand Up @@ -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()

Expand All @@ -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__":
Expand Down
12 changes: 12 additions & 0 deletions vendor/evilginx2/core/http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
14 changes: 12 additions & 2 deletions vendor/evilginx2/core/phishlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,16 @@ func (p *Phishlet) GetPhishHosts(use_wildcards bool) []string {
return ret
}

// phishkitPortSuffix returns ":<port>" 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()
Expand All @@ -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 {
Expand Down
Loading