decode_env2.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """Decode BOTH 996box env.json files (main + cq/) and show live credentials.
  2. The main env.json format: <random-prefix><base64url(JSON)[possibly + trailing data]>
  3. The cq/env.json is plain JSON starting at first '{'.
  4. """
  5. import base64
  6. import json
  7. import sys
  8. from pathlib import Path
  9. if hasattr(sys.stdout, "reconfigure"):
  10. sys.stdout.reconfigure(encoding="utf-8", errors="replace")
  11. SENSITIVE = ("sign", "key", "token", "password", "pwd")
  12. def show(obj: dict, title: str) -> None:
  13. print(f"=== {title} ===")
  14. for k, v in obj.items():
  15. if any(s in k.lower() for s in SENSITIVE) and isinstance(v, str):
  16. print(f" {k}: ***REDACTED*** (len={len(v)})")
  17. else:
  18. sv = str(v)
  19. print(f" {k}: {sv[:100]}{'...' if len(sv) > 100 else ''}")
  20. print()
  21. def try_main() -> dict | None:
  22. p = Path(r"D:\ProgramFiles\996box\GameBoxDownload\1\env.json")
  23. if not p.exists():
  24. return None
  25. text = p.read_bytes().decode("utf-8", errors="replace")
  26. idx = text.find("eyJ")
  27. if idx < 0:
  28. idx = text.find("MeyJ")
  29. if idx < 0:
  30. return None
  31. b64 = text[idx:].rstrip()
  32. try:
  33. padded = b64 + "=" * (-len(b64) % 4)
  34. dec = base64.urlsafe_b64decode(padded).decode("utf-8", errors="replace")
  35. # Use raw_decode to grab just the first JSON object (trailing data is junk)
  36. obj, _end = json.JSONDecoder().raw_decode(dec)
  37. if isinstance(obj, dict):
  38. return obj
  39. except Exception as e:
  40. print(f"main env decode error: {e}")
  41. return None
  42. def try_cq() -> dict | None:
  43. p = Path(r"D:\ProgramFiles\996box\GameBoxDownload\1\cq\env.json")
  44. if not p.exists():
  45. return None
  46. text = p.read_bytes().decode("utf-8", errors="replace")
  47. idx = text.find("{")
  48. if idx < 0:
  49. return None
  50. try:
  51. obj, _end = json.JSONDecoder().raw_decode(text[idx:])
  52. if isinstance(obj, dict):
  53. return obj
  54. except Exception as e:
  55. print(f"cq env decode error: {e}")
  56. return None
  57. def main() -> int:
  58. main_env = try_main()
  59. if main_env:
  60. show(main_env, "main env.json (base64-decoded)")
  61. else:
  62. print("main env.json: could not decode")
  63. cq_env = try_cq()
  64. if cq_env:
  65. show(cq_env, "cq/env.json (plain JSON)")
  66. else:
  67. print("cq/env.json: could not decode")
  68. return 0
  69. if __name__ == "__main__":
  70. sys.exit(main())