Files
felhom.eu/documentation/audits/login-gate-2026-09-29/B/b2.py
T
2026-09-29 08:20:42 +02:00

71 lines
4.2 KiB
Python

# Part B2/B3 — stranger vs household, both apps, through the gate. Passwords generated here, kept in memory only.
import json, secrets, sys, time
sys.path.insert(0, '.')
from browser import Browser, hopstr
D = "enkisfelhom.hu"
PW = open('../.ctlpw').read().strip()
N8N, IMM = f"https://g-n8n.{D}", f"https://g-immich.{D}"
def gatepage(body):
return ("waiting for its first setup" in body, "Felhom vez" in body)
print("== B2a STRANGER, browser, no dashboard session")
for base in (N8N, IMM):
s = Browser("stranger")
st, body, hops = s.req(base + "/")
print(f" {base}/ : final {st} | {hopstr(hops)} | gate page (en, hu-ascii): {gatepage(body)} | app html seen: {'n8n' in body.lower()[:3000] and 'waiting' not in body or '<title>Immich' in body}")
print(f" cookies the stranger holds: {s.hosts_with_cookies()}")
print("== B2b STRANGER, API style (what a script would do)")
s = Browser("stranger")
for url, meth, body in ((N8N + "/rest/settings", "GET", None),
(N8N + "/rest/owner/setup", "POST", {"email": "x@x.hu", "firstName": "x", "lastName": "x", "password": "Xx" + secrets.token_hex(8)}),
(IMM + "/api/server/config", "GET", None),
(IMM + "/api/auth/admin-sign-up", "POST", {"email": "x@x.hu", "password": secrets.token_hex(8), "name": "x"})):
st, b, hops = s.req(url, meth, body=body, accept="application/json")
print(f" {meth} {url} -> {st} {b[:70]!r}")
print("== B2c STRANGER tricks")
st, b, h = s.req(f"https://felhom.{D}/__gate/start?rd=https://evil.example/", follow=False)
print(f" open-redirect try rd=evil -> {st} {b[:40]!r}")
st, b, h = s.req(N8N + "/__felhom_gate/cb?t=%5B%22g-n8n.enkisfelhom.hu%22%2C%229999999999%22%2C%22n%22%2C%22https%3A//g-n8n.enkisfelhom.hu/%22%2C%22forged%22%5D", follow=False)
print(f" forged token -> {st} {b[:40]!r}")
print("== B2d HOUSEHOLD, logged in to the dashboard first (the usual path: open the app from the dashboard)")
hh = Browser("household")
st, b, hops = hh.login_dashboard(D, PW)
print(f" dashboard login -> {st} | {hopstr(hops)}")
for base in (N8N, IMM):
t0 = time.time(); st, body, hops = hh.req(base + "/"); dt = time.time() - t0
print(f" {base}/ -> final {st} in {dt:.2f}s | {hopstr(hops)} | gate page: {gatepage(body)[0]} | len {len(body)}")
print(f" cookies per host: {hh.hosts_with_cookies()}")
print(" dashboard cookie on an app host?", any('felhom_session' in v for h, v in hh.hosts_with_cookies().items() if not h.startswith('felhom.')))
print("== B2e HOUSEHOLD on a phone, NOT logged in: opens the app link first")
ph = Browser("phone")
st, body, hops = ph.req(N8N + "/")
print(f" step 1 -> {st} gate page {gatepage(body)} | {hopstr(hops)}")
import re, html as H
link = H.unescape(re.search(r'href="([^"]+)"', body).group(1))
st, body, hops = ph.req(f"https://felhom.{D}{link}", follow=True)
print(f" step 2 sign-in link -> {st} | login form shown: {'password' in body.lower()}")
import urllib.parse
nxt = urllib.parse.parse_qs(urllib.parse.urlsplit(link).query)['next'][0]
st, body, hops = ph.req(f"https://felhom.{D}/login?next=" + urllib.parse.quote(nxt), "POST",
body="password=" + urllib.parse.quote(PW) + "&next=" + urllib.parse.quote(nxt),
headers={"Content-Type": "application/x-www-form-urlencoded"})
print(f" step 3 sign in -> final {st} | {hopstr(hops)} | gate page: {gatepage(body)[0]}")
print("== B2f token replay + cookie reuse on another app")
hh2 = Browser("household2"); hh2.login_dashboard(D, PW)
st, b, hops = hh2.req(f"https://felhom.{D}/__gate/start?rd=" + urllib.parse.quote(N8N + "/"), follow=False)
cb = dict((k.lower(), v) for k, v in []) # placeholder
loc_hops = hops
import http.client
# follow once by hand to capture the callback URL
st2, b2, h2 = hh2.req(f"https://felhom.{D}/__gate/start?rd=" + urllib.parse.quote(N8N + "/"), follow=True)
print(f" household2 reached n8n: {st2} {hopstr(h2)}")
gc = hh2.jar.get(f"g-n8n.{D}", {}).get("felhom_gate")
x = Browser("thief"); x.jar[f"g-immich.{D}"] = {"felhom_gate": gc}
st, b, hops = x.req(IMM + "/api/server/config", accept="application/json")
print(f" n8n's gate cookie presented to immich -> {st} {b[:50]!r}")
json.dump({"hh": hh.jar, "ph": ph.jar}, open('jars.json', 'w'))