114 lines
3.8 KiB
Python
114 lines
3.8 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Verify TM jsonImport hash match + try CDP install of .user.js."""
|
|
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
CMD = r"""
|
|
echo 4669805 | sudo -S -p '' bash -lc '
|
|
# ensure userscript is served
|
|
ls -la /opt/douyinWEB/backend/neko/provisioning/
|
|
# on ops1: hash check + CDP open install URL
|
|
docker exec douyinweb-ops-neko-1 python3 - <<'"'"'PY'"'"'
|
|
import json, hashlib, urllib.request, time
|
|
|
|
def tm_sha256(text: str) -> str:
|
|
return hashlib.sha256(text.encode("utf-8")).hexdigest()
|
|
|
|
def tm_hash(value, seen=None):
|
|
if seen is None:
|
|
seen = []
|
|
if value is None:
|
|
return tm_sha256("object:null")
|
|
if isinstance(value, dict):
|
|
ident = id(value)
|
|
if ident in seen:
|
|
raise ValueError("circular")
|
|
seen.append(ident)
|
|
try:
|
|
parts = [tm_hash(value[k], seen) for k in sorted(value)]
|
|
finally:
|
|
seen.pop()
|
|
return tm_sha256("".join(parts))
|
|
if isinstance(value, list):
|
|
ident = id(value)
|
|
if ident in seen:
|
|
raise ValueError("circular")
|
|
seen.append(ident)
|
|
try:
|
|
parts = [tm_hash(item, seen) for item in value]
|
|
finally:
|
|
seen.pop()
|
|
return tm_sha256("".join(parts))
|
|
if isinstance(value, bool):
|
|
return tm_sha256(f"boolean:{str(value).lower()}")
|
|
if isinstance(value, (int, float)) and not isinstance(value, bool):
|
|
return tm_sha256(f"number:{value}")
|
|
if isinstance(value, str):
|
|
return tm_sha256(f"string:{value}")
|
|
raise TypeError(type(value))
|
|
|
|
payload = json.loads(urllib.request.urlopen("http://127.0.0.1:18080/tampermonkey-provisioning.json", timeout=5).read())
|
|
h = "1:" + tm_hash(payload)
|
|
pol = json.load(open("/etc/opt/chrome/policies/managed/policies.json"))
|
|
ph = pol["3rdparty"]["extensions"]["dhdgffkkebhmkfjojejmpbldmpobfkfo"]["jsonImport"][0]["hash"]
|
|
print("computed", h)
|
|
print("policy ", ph)
|
|
print("match", h == ph)
|
|
print("installAsSystemScripts", pol["3rdparty"]["extensions"]["dhdgffkkebhmkfjojejmpbldmpobfkfo"]["jsonImport"][0].get("installAsSystemScripts"))
|
|
|
|
# list tabs / open install
|
|
tabs = json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=4).read())
|
|
print("tabs_before", len(tabs))
|
|
for t in tabs:
|
|
print("-", (t.get("url") or "")[:100])
|
|
|
|
# Open local userscript URL — TM should intercept
|
|
# First check if file is served
|
|
for url in [
|
|
"http://127.0.0.1:18080/youtube-studio-auto-dismiss.user.js",
|
|
"http://127.0.0.1:18080/tampermonkey-provisioning.json",
|
|
]:
|
|
try:
|
|
r = urllib.request.urlopen(url, timeout=4)
|
|
print("GET", url, r.status, "len", len(r.read()))
|
|
except Exception as e:
|
|
print("GET fail", url, e)
|
|
|
|
# new tab via CDP
|
|
try:
|
|
raw = urllib.request.urlopen("http://127.0.0.1:9222/json/new?http://127.0.0.1:18080/youtube-studio-auto-dismiss.user.js", timeout=5).read()
|
|
print("new_tab", raw[:300])
|
|
except Exception as e:
|
|
print("new_tab_fail", e)
|
|
# fallback put
|
|
try:
|
|
req = urllib.request.Request("http://127.0.0.1:9222/json/new", method="PUT")
|
|
print("put_new", urllib.request.urlopen(req, timeout=5).read()[:200])
|
|
except Exception as e2:
|
|
print("put_fail", e2)
|
|
|
|
time.sleep(3)
|
|
tabs = json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list", timeout=4).read())
|
|
print("tabs_after", len(tabs))
|
|
for t in tabs:
|
|
print("-", (t.get("title") or "")[:50], "|", (t.get("url") or "")[:120])
|
|
PY
|
|
'
|
|
"""
|
|
|
|
|
|
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)
|
|
_i, o, e = c.exec_command(CMD, timeout=90)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|