Files
felhom.eu/documentation/audits/morning-after-2026-10-06/live-9202/tools/nc3.py
T

34 lines
2.5 KiB
Python

import sys, time
sys.path.insert(0, "/mnt/5_hdd/felhom.eu/git/app-catalog-felhom.eu/scripts")
import box_walk as w
EVF = open(f"{w.EV}/nextcloud.txt", "a", buffering=1)
def say(*a):
w.say(*a); EVF.write(" ".join(map(str, a)) + "\n")
H = "cloud.enkisfelhom.hu"
def tun(v, f, m, p, x=""):
q = lambda s: "'" + s.replace("'", "'\\''") + "'"
return w.guest(f"docker run --rm --network felhom-tunnel --ip 172.16.253.2 -v /root/tun.sh:/t.sh:ro curlimages/curl:8.11.1 "
f"sh /t.sh {H} {v} {f} {m} {q(p)} '' '' {q(x)}").strip().splitlines()[-1:]
occ = lambda a: w.guest(f"docker exec -u www-data nextcloud php occ {a} 2>&1 | tr '\\n' ' '").strip()
w.login()
D = "/opt/docker/stacks/nextcloud"
say(f"## CONTROL 2 — TRUSTED_PROXIES removed from the stack's compose (= the template before R-776) — {time.strftime('%FT%TZ', time.gmtime())}")
say(w.guest(f"cd {D} && cp -p docker-compose.yml /root/nc-compose.with && sed -i '/- TRUSTED_PROXIES=/d' docker-compose.yml && grep -c TRUSTED_PROXIES docker-compose.yml; docker exec -u www-data nextcloud php occ config:system:delete trusted_proxies").strip())
code, d = w.ctl("POST", "/api/stacks/nextcloud/restart"); say("restart through the product ->", code)
for _ in range(40):
if '"installed":true' in w.guest("docker exec nextcloud curl -s http://localhost/status.php"): break
time.sleep(5)
say("env now:", w.guest("docker exec nextcloud printenv TRUSTED_PROXIES || echo '(unset)'").strip(), "| trusted_proxies:", occ("config:system:get trusted_proxies"))
V2 = "198.51.100.88"
say(f"stranger {V2}, 3 wrong tries:", [tun(V2, f"10.7.0.{i}", "PROPFIND", "/remote.php/dav/files/nobody/", "Authorization: Basic bm9ib2R5Ondyb25n") for i in range(1, 4)])
time.sleep(3)
say(f"attempts {V2} (visitor):", occ(f"security:bruteforce:attempts {V2}"))
for ip in w.guest("docker inspect traefik --format '{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}'").split():
say(f"attempts {ip} (traefik):", occ(f"security:bruteforce:attempts {ip}"))
say("## put the template's compose back:", w.guest(f"cp -p /root/nc-compose.with {D}/docker-compose.yml && grep -c TRUSTED_PROXIES {D}/docker-compose.yml").strip())
code, d = w.ctl("POST", "/api/stacks/nextcloud/restart"); say("restart through the product ->", code)
for _ in range(40):
if '"installed":true' in w.guest("docker exec nextcloud curl -s http://localhost/status.php"): break
time.sleep(5)
say("env back:", w.guest("docker exec nextcloud printenv TRUSTED_PROXIES").strip())