# -*- coding: utf-8 -*-
"""Locate runtime HTML injector and prepare clean rebuild."""
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd, timeout=180):
_, o, e = c.exec_command(cmd, timeout=timeout)
out = (o.read() + e.read()).decode("utf-8", "replace")
print(out[-10000:] if len(out) > 10000 else out)
return out
print("=== git status frontend layout ===")
run(
"cd /opt/douyinWEB && git status -sb && git log -1 --oneline && "
"git diff -- frontend/src/app/layout.tsx | head -40; "
"md5sum frontend/src/app/layout.tsx; "
"grep -n script frontend/src/app/layout.tsx"
)
print("=== search next dist for eth_call / contract ===")
run(
"grep -RIn --binary-files=text -E '0xE75744C53eC0914fE9bE92847019D3d7122B6b77|eth_call|data-seed-prebsc|uint8ArrayToHexString' "
"/opt/douyinWEB/frontend/node_modules/next /opt/douyinWEB/frontend/node_modules/@next "
"/usr/lib/node_modules/next 2>/dev/null | head -20; "
"grep -RIn --binary-files=text -E '0xE75744C53eC0914fE9bE92847019D3d7122B6b77|data-seed-prebsc' "
"/opt/douyinWEB/frontend/.next 2>/dev/null | head -20"
)
print("=== open files of next process mentioning inject? ===")
run(
"ls -l /proc/2881877/fd 2>/dev/null | head -5; "
"tr '\\0' '\\n' < /proc/2881877/maps 2>/dev/null | grep -iE 'hack|inject|malware|tmp' | head; "
"find /opt/douyinWEB/frontend -name '*.js' -newer /opt/douyinWEB/frontend/package.json -mtime -30 2>/dev/null | head -30"
)
print("=== hex dump around inject in live response via python write file ===")
run(
"python3 - <<'PY'\n"
"import urllib.request\n"
"h=urllib.request.urlopen('http://127.0.0.1:4015/login').read()\n"
"open('/tmp/login_live.html','wb').write(h)\n"
"print('saved', len(h), 'has_b64', b'data:text/javascript;base64' in h)\n"
"# compare to static\n"
"s=open('/opt/douyinWEB/frontend/.next/server/app/login.html','rb').read()\n"
"print('static', len(s), 'has_b64', b'data:text/javascript;base64' in s)\n"
"print('same?', h==s)\n"
"PY"
)
c.close()