98 lines
3.3 KiB
Python
98 lines
3.3 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, time
|
|
from pathlib import Path
|
|
|
|
# dual chrome?
|
|
mains=[]
|
|
for pid in os.listdir("/proc"):
|
|
if not pid.isdigit(): continue
|
|
try: raw=open(f"/proc/{pid}/cmdline","rb").read()
|
|
except: continue
|
|
if b"google-chrome" in raw and b"--type=" not in raw and b"crashpad" not in raw:
|
|
mains.append(pid)
|
|
print("chrome_mains", mains)
|
|
|
|
# LES size / seed LES
|
|
ext="dhdgffkkebhmkfjojejmpbldmpobfkfo"
|
|
les=Path(f"/home/neko/.config/google-chrome/Default/Local Extension Settings/{ext}")
|
|
seed=Path(f"/etc/neko/tampermonkey-seed/Default/Local Extension Settings/{ext}")
|
|
print("LES bytes", sum(p.stat().st_size for p in les.glob("*") if p.is_file()) if les.exists() else 0)
|
|
print("seed LES", list(seed.iterdir()) if seed.exists() else None)
|
|
print("seed LES bytes", sum(p.stat().st_size for p in seed.glob("*") if p.is_file()) if seed.exists() else 0)
|
|
|
|
# provisioning scripts on disk
|
|
prov=Path("/var/www/provisioning")
|
|
print("prov files", sorted(p.name for p in prov.iterdir()) if prov.exists() else None)
|
|
for p in sorted(prov.glob("*.user.js")) if prov.exists() else []:
|
|
print(" userscript", p.name, p.stat().st_size)
|
|
|
|
# CDP: ask TM SW for storage keys via Runtime
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read())
|
|
sw=[t for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or "")]
|
|
print("tm_sw", len(sw), sw[0].get("webSocketDebuggerUrl") if sw else None)
|
|
|
|
# list all pages urls
|
|
for t in tabs:
|
|
print("TAB", t.get("type"), (t.get("url") or "")[:140])
|
|
|
|
# Try chrome.management via evaluating in an extension page
|
|
off=[t for t in tabs if "offscreen.html" in (t.get("url") or "")]
|
|
target = (sw or off or [None])[0]
|
|
if not target:
|
|
print("no tm target")
|
|
else:
|
|
# Use /json/new to open options and dump script count via page
|
|
try:
|
|
newp = json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/new?chrome-extension://dhdgffkkebhmkfjojejmpbldmpobfkfo/options.html#nav=dashboard", timeout=5).read())
|
|
print("opened options", newp.get("id"), newp.get("url"))
|
|
time.sleep(2)
|
|
except Exception as e:
|
|
print("open options err", e)
|
|
newp=None
|
|
tabs2=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read())
|
|
for t in tabs2:
|
|
u=t.get("url") or ""
|
|
if "options.html" in u or "dashboard" in u:
|
|
print("OPT", t.get("title"), u[:160])
|
|
'''
|
|
|
|
|
|
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,
|
|
)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_probe_neko3_tm2.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_tm2.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()
|