108 lines
4.0 KiB
Python
108 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Diagnose Tampermonkey on VPS assign Nekos (esp #8)."""
|
|
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
REMOTE = r"""
|
|
set -e
|
|
EXT=dhdgffkkebhmkfjojejmpbldmpobfkfo
|
|
echo '=== policies ==='
|
|
python3 - <<'PY'
|
|
import json
|
|
from pathlib import Path
|
|
for p in [
|
|
Path('/opt/douyinWEB/backend/neko/policies/policies.json'),
|
|
Path('/etc/neko/policies/policies.json'),
|
|
]:
|
|
if p.exists():
|
|
d=json.loads(p.read_text())
|
|
print(p, 'forcelist', d.get('ExtensionInstallForcelist'))
|
|
print(' jsonImport', ((d.get('3rdparty') or {}).get('extensions') or {}).get('dhdgffkkebhmkfjojejmpbldmpobfkfo'))
|
|
PY
|
|
echo '=== browser-launch tm flags ==='
|
|
grep -nE 'Offline Tampermonkey|tm_load_dir|load-extension|ExtensionInstall' /opt/douyinWEB/backend/neko/browser-launch.sh | head -30
|
|
echo '=== containers ==='
|
|
docker ps -a --format '{{.Names}} {{.Status}}' | grep 'douyinweb-neko-' | sort
|
|
for i in 1 2 3 4 5 6 7 8; do
|
|
name=douyinweb-neko-$i
|
|
if ! docker ps --format '{{.Names}}' | grep -qx "$name"; then
|
|
echo "===== $name NOT_RUNNING ====="
|
|
continue
|
|
fi
|
|
echo "===== $name ====="
|
|
docker exec "$name" bash -lc '
|
|
EXT=dhdgffkkebhmkfjojejmpbldmpobfkfo
|
|
P=/home/neko/.config/google-chrome/Default
|
|
echo -n "ext_dir "; ls -d "$P/Extensions/$EXT"/*/ 2>/dev/null | head -1 || echo MISSING
|
|
echo -n "les "; ls "$P/Local Extension Settings/$EXT" 2>/dev/null | wc -l
|
|
python3 - <<PY
|
|
import json,urllib.request
|
|
from pathlib import Path
|
|
ext="dhdgffkkebhmkfjojejmpbldmpobfkfo"
|
|
p=Path("/home/neko/.config/google-chrome/Default/Preferences")
|
|
e={}
|
|
if p.exists():
|
|
e=((json.loads(p.read_text()).get("extensions") or {}).get("settings") or {}).get(ext) or {}
|
|
print("state", e.get("state"), "loc", e.get("location"), "webstore", e.get("from_webstore"), "disable", e.get("disable_reasons"))
|
|
# cmdline load-extension
|
|
import os,re
|
|
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("utf-8","replace")
|
|
except Exception:
|
|
continue
|
|
if "google-chrome" in cmd and "--type=" not in cmd:
|
|
m=re.search(r"--load-extension=([^ ]+)", cmd)
|
|
print("chrome_load_ext", m.group(1) if m else "NONE")
|
|
found=True
|
|
break
|
|
if not found: print("chrome_load_ext NO_PROC")
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=3).read())
|
|
except Exception as ex:
|
|
print("cdp_err", ex); tabs=[]
|
|
sw=[t for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or "")]
|
|
print("tm_sw", len(sw))
|
|
# LES script hits
|
|
import subprocess
|
|
hits=subprocess.getoutput("grep -aR \\"YouTube Studio Auto Dismiss\\" /home/neko/.config/google-chrome/Default/Local\\ Extension\\ Settings/dhdgffkkebhmkfjojejmpbldmpobfkfo 2>/dev/null | wc -l")
|
|
print("script_hits", hits.strip())
|
|
# policy inside
|
|
try:
|
|
pol=json.loads(Path("/etc/opt/chrome/policies/managed/policies.json").read_text())
|
|
print("in_forcelist", pol.get("ExtensionInstallForcelist"))
|
|
except Exception as e:
|
|
print("pol_err", e)
|
|
PY
|
|
' || echo EXEC_FAIL
|
|
done
|
|
# google update reachable?
|
|
echo '=== clients2.google.com from neko-8 ==='
|
|
docker exec douyinweb-neko-8 bash -lc 'curl -sS -m 5 -o /dev/null -w "%{http_code}\n" https://clients2.google.com/service/update2/crx || echo FAIL'
|
|
echo '=== provisioning hash ==='
|
|
ls -la /opt/douyinWEB/backend/neko/provisioning/ | head
|
|
grep -E 'hash|Auto Dismiss|version' /opt/douyinWEB/backend/neko/provisioning/tampermonkey-provisioning.json 2>/dev/null | head -10
|
|
"""
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_diag_vps_tm.sh", "wb") as f:
|
|
f.write(REMOTE.encode())
|
|
sftp.close()
|
|
_i, o, e = c.exec_command("bash /tmp/_diag_vps_tm.sh", timeout=180)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|