77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Check Chrome version, locales, TM service worker, store reachability on ops-neko."""
|
|
import base64
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
PROBE = r'''
|
|
import json, urllib.request, subprocess, os
|
|
from pathlib import Path
|
|
|
|
print("chrome_ver", subprocess.getoutput("google-chrome --version || google-chrome-stable --version"))
|
|
ext="dhdgffkkebhmkfjojejmpbldmpobfkfo"
|
|
root=Path(f"/home/neko/.config/google-chrome/Default/Extensions/{ext}/5.5.0_0")
|
|
print("locales", (root/"_locales").exists(), "count", len(list((root/"_locales").iterdir())) if (root/"_locales").exists() else 0)
|
|
print("en_messages", (root/"_locales/en/messages.json").exists())
|
|
print("metadata", list((root/"_metadata").iterdir()) if (root/"_metadata").exists() else None)
|
|
# store reach
|
|
for url in [
|
|
"https://clients2.google.com/service/update2/crx",
|
|
"https://clients2.googleusercontent.com/",
|
|
]:
|
|
try:
|
|
req=urllib.request.Request(url, method="GET")
|
|
with urllib.request.urlopen(req, timeout=8) as r:
|
|
print("reach", url, r.status)
|
|
except Exception as e:
|
|
print("reach_fail", url, type(e).__name__, str(e)[:120])
|
|
# CDP service workers / extension pages
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=4).read())
|
|
except Exception as e:
|
|
print("cdp_fail", e); raise SystemExit
|
|
print("tabs", len(tabs))
|
|
for t in tabs:
|
|
u=t.get("url") or ""
|
|
typ=t.get("type")
|
|
if typ=="service_worker" or "dhdgff" in u or "chrome://extensions" in u or "chrome-extension://" in u:
|
|
print("HIT", typ, (t.get("title") or "")[:50], u[:160])
|
|
# open extensions page if missing
|
|
has_ext_page=any("chrome://extensions" in (t.get("url") or "") for t in tabs)
|
|
if not has_ext_page:
|
|
try:
|
|
urllib.request.urlopen("http://127.0.0.1:9222/json/new?chrome://extensions/", timeout=5)
|
|
print("opened_extensions_page")
|
|
except Exception as e:
|
|
print("open_ext_fail", e)
|
|
'''
|
|
|
|
B64 = base64.b64encode(PROBE.encode()).decode()
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
remote = f"""
|
|
echo 4669805 | sudo -S -p '' bash -lc '
|
|
B64="{B64}"
|
|
for i in 1 2; do
|
|
echo "===== OPS$i ====="
|
|
printf %s "$B64" | docker exec -i douyinweb-ops-neko-$i bash -lc "base64 -d > /tmp/_tm_probe.py && python3 /tmp/_tm_probe.py"
|
|
done
|
|
'
|
|
"""
|
|
_i, o, e = c.exec_command(remote, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|