72 lines
2.7 KiB
Python
72 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
INNER = r'''
|
|
import json, os, re, urllib.request, time
|
|
from pathlib import Path
|
|
ext="dhdgffkkebhmkfjojejmpbldmpobfkfo"
|
|
# wait cdp
|
|
tabs=[]
|
|
for _ in range(12):
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=3).read())
|
|
break
|
|
except Exception:
|
|
time.sleep(2)
|
|
pref=Path("/home/neko/.config/google-chrome/Default/Preferences")
|
|
e={}
|
|
if pref.exists():
|
|
e=((json.loads(pref.read_text()).get("extensions") or {}).get("settings") or {}).get(ext) or {}
|
|
print("tm", e.get("state"), e.get("location"), e.get("from_webstore"))
|
|
print("ext", Path(f"/home/neko/.config/google-chrome/Default/Extensions/{ext}/5.5.0_0/manifest.json").exists())
|
|
les=Path(f"/home/neko/.config/google-chrome/Default/Local Extension Settings/{ext}")
|
|
print("les_dir", les.is_dir(), "files", len(list(les.glob("*"))) if les.is_dir() else 0)
|
|
sp=Path("/home/neko/.config/google-chrome/Default/Secure Preferences")
|
|
print("secure_bytes", sp.stat().st_size if sp.exists() else -1)
|
|
found=False
|
|
for pid in os.listdir("/proc"):
|
|
if not pid.isdigit(): continue
|
|
try: cmd=open(f"/proc/{pid}/cmdline","rb").read().replace(b"\x00",b" ").decode()
|
|
except Exception: continue
|
|
if "google-chrome" in cmd and "--type=" not in cmd and "load-extension" in cmd:
|
|
m=re.search(r"--load-extension=([^ ]+)", cmd)
|
|
print("load_ext", m.group(1) if m else None); found=True; break
|
|
if not found: print("load_ext NONE")
|
|
print("tm_sw", sum(1 for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or "")))
|
|
print("tab_n", len(tabs))
|
|
'''
|
|
|
|
REMOTE = r'''
|
|
NAMES=$(docker ps --format '{{.Names}}' | grep -E '^douyinweb-neko-[0-9]+$' | sort)
|
|
echo "running: $NAMES"
|
|
for name in $NAMES; do
|
|
echo "===== $name ====="
|
|
docker exec -i "$name" python3 < /tmp/_verify_tm_inner.py
|
|
done
|
|
'''
|
|
|
|
|
|
def run(label, host, port, user, pw, sudo):
|
|
print(f"\n########## {label} ##########", flush=True)
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pw, timeout=40, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_verify_tm_inner.py", "wb") as f:
|
|
f.write(INNER.encode())
|
|
with sftp.file("/tmp/_verify_tm_all.sh", "wb") as f:
|
|
f.write(REMOTE.encode())
|
|
sftp.close()
|
|
cmd = f"echo {pw} | sudo -S -p '' bash /tmp/_verify_tm_all.sh" if sudo else "bash /tmp/_verify_tm_all.sh"
|
|
_, o, e = c.exec_command(cmd, timeout=300)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
|
|
|
|
run("PHYSICAL", "107.173.30.245", 4014, "eric", "4669805", True)
|
|
run("VPS", "107.173.30.245", 22, "root", "Xiao4669805", False)
|