fix-xinting-token.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env python3
  2. """芯葶真key恢复: SSH隧道→查DB→直写容器(不打印完整token)"""
  3. import subprocess, threading, socketserver, time, json, base64, sys
  4. sys.path.insert(0, "/opt/data/venv-ops/lib/python3.13/site-packages")
  5. import paramiko
  6. ssh = paramiko.SSHClient()
  7. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  8. ssh.connect("server.fmode.cn", port=22, username="root", password="bofang666.", timeout=30)
  9. transport = ssh.get_transport()
  10. class H(socketserver.BaseRequestHandler):
  11. def handle(self):
  12. try:
  13. chan = transport.open_channel("direct-tcpip", ("127.0.0.1", 25432), self.request.getpeername())
  14. except Exception:
  15. return
  16. if chan is None:
  17. return
  18. try:
  19. while True:
  20. d = self.request.recv(4096)
  21. if not d:
  22. break
  23. chan.sendall(d)
  24. finally:
  25. try:
  26. chan.close()
  27. except Exception:
  28. pass
  29. class S(socketserver.ThreadingTCPServer):
  30. allow_reuse_address = True
  31. srv = S(("127.0.0.1", 15433), H)
  32. threading.Thread(target=srv.serve_forever, daemon=True).start()
  33. time.sleep(1)
  34. import psycopg2
  35. from urllib.parse import urlparse, unquote
  36. r = subprocess.run(["bash", "-c",
  37. "python3 -c \"import json;d=json.load(open('/opt/data/git-repos/future-server/config/config.nova.json'));print(d['fmodeApi']['databaseURI'])\""],
  38. capture_output=True, text=True)
  39. p = urlparse(r.stdout.strip())
  40. conn = psycopg2.connect(host="127.0.0.1", port=15433, dbname=p.path[1:],
  41. user=p.username, password=unquote(p.password), connect_timeout=15)
  42. cur = conn.cursor()
  43. cur.execute("SELECT u.username, 'sk-'||t.\"key\" FROM tokens t JOIN users u ON t.user_id=u.id WHERE u.username IN ('fmode18170957536','fmode13133826287','fmode18691770343')")
  44. rows = cur.fetchall()
  45. for name, tok in rows:
  46. print(f"{name}: len={len(tok)} {tok[:6]}...{tok[-4:]}")
  47. xinting_tok = [t for n, t in rows if n == "fmode18170957536"][0]
  48. b64t = base64.b64encode(xinting_tok.encode()).decode()
  49. cmd = f'''docker exec agent-node-xinting bash -c 'echo {b64t} | base64 -d > /tmp/t && python3 -c "
  50. import json
  51. p=\\"/opt/data/fmode-identity.json\\"
  52. d=json.load(open(p)); d[\\"newapi_token\\"]=open(\\"/tmp/t\\").read().strip()
  53. json.dump(d,open(p,\\"w\\"),ensure_ascii=False,indent=2)
  54. print(\\"xinting identity len:\\", len(d[\\"newapi_token\\"]))
  55. " && rm /tmp/t' '''
  56. r2 = subprocess.run(["/opt/data/venv-ops/bin/python", "/opt/data/scripts/r730_root.py", cmd],
  57. capture_output=True, text=True, timeout=120)
  58. print(r2.stdout[:150])
  59. conn.close()
  60. srv.shutdown()
  61. ssh.close()