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

70 lines
1.8 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")
SCRIPT = r"""#!/bin/bash
set +e
for i in 1 2 3 4 5 6 7 8; do
N=douyinweb-neko-$i
docker inspect "$N" >/dev/null 2>&1 || { echo "$N MISSING"; continue; }
out=$(docker exec -i "$N" python3 - <<'PY'
import os, json, urllib.request
mains=[]
load=False
for pid in os.listdir("/proc"):
if not pid.isdigit(): continue
try: raw=open(f"/proc/{pid}/cmdline","rb").read()
except: continue
if not raw: continue
if b"google-chrome" in raw and b"--type=" not in raw and b"crashpad" not in raw and b"browser-launch" not in raw:
mains.append(pid)
if b"load-extension" in raw and b"dhdgff" in raw:
load=True
sw=0
try:
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=2).read())
sw=sum(1 for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or ""))
except Exception as e:
sw=-1
print(f"mains={len(mains)} load_ext={load} tm_sw={sw}")
PY
)
echo "neko-$i $out"
done
"""
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/_scan_neko_chrome.sh", "w") as f:
f.write(SCRIPT)
sftp.close()
_i, o, e = c.exec_command(
"echo '4669805' | sudo -S -p '' bash /tmp/_scan_neko_chrome.sh",
timeout=120,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
main()