douyinWEB/scripts/_probe_neko3_tm_cdp.py
2026-09-13 22:10:49 -05:00

93 lines
2.9 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import annotations
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PROBE = r'''
import json, os, urllib.request
from pathlib import Path
print("=== chrome/main procs ===")
for pid in sorted(os.listdir("/proc"), key=lambda x: int(x) if x.isdigit() else -1):
if not pid.isdigit():
continue
try:
raw = open(f"/proc/{pid}/cmdline", "rb").read()
except Exception:
continue
if not raw:
continue
low = raw.lower()
if b"chrome" not in low and b"browser-launch" not in low:
continue
if b"--type=" in raw:
continue
cmd = raw.replace(b"\0", b" ").decode("utf-8", "replace")
print(f"PID {pid}: {cmd[:700]}")
for part in raw.split(b"\0"):
if b"load-extension" in part or b"disable-extensions" in part:
print(" EXTFLAG", part.decode())
print("=== CDP ===")
try:
tabs = json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=5).read())
except Exception as e:
print("cdp_err", e)
tabs = []
print("tabs", len(tabs))
for t in tabs:
u = t.get("url") or ""
ty = t.get("type") or ""
title = (t.get("title") or "")[:60]
if ty == "service_worker" or "chrome-extension" in u or "dhdgff" in u or ty == "background_page":
print(ty, title, u[:160])
ext = "dhdgffkkebhmkfjojejmpbldmpobfkfo"
pref = Path("/home/neko/.config/google-chrome/Default/Preferences")
d = json.loads(pref.read_text())
e = ((d.get("extensions") or {}).get("settings") or {}).get(ext) or {}
print("=== TM prefs ===")
print("state", e.get("state"), "location", e.get("location"), "path", e.get("path"))
print("disable", e.get("disable_reasons"), "from_webstore", e.get("from_webstore"))
les = Path(f"/home/neko/.config/google-chrome/Default/Local Extension Settings/{ext}")
print("LES exists", les.exists(), "files", list(les.iterdir())[:8] if les.exists() else None)
pex = Path(f"/home/neko/.config/google-chrome/Default/Extensions/{ext}")
print("profile ext dir", list(pex.iterdir()) if pex.exists() else None)
'''
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
4014,
"eric",
"4669805",
timeout=45,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
# Write probe on host, pipe into container python via stdin
sftp = c.open_sftp()
with sftp.file("/tmp/_probe_neko3_tm.py", "w") as f:
f.write(PROBE)
sftp.close()
cmd = (
"echo '4669805' | sudo -S -p '' bash -lc "
"'docker exec -i douyinweb-neko-3 python3 - < /tmp/_probe_neko3_tm.py'"
)
_i, o, e = c.exec_command(cmd, timeout=60)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
main()