_verify_demoadmin_password.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # -*- coding: utf-8 -*-
  2. """Verify DemoAdmin stored password against candidates via SM2 decrypt."""
  3. from __future__ import annotations
  4. import sys
  5. import pymysql
  6. from gmssl import sm2
  7. sys.stdout.reconfigure(encoding='utf-8')
  8. CONN = dict(
  9. host='123.60.180.165', port=3306,
  10. user='aidopremote', password='1234567890aiDOP#',
  11. database='aidopdev', charset='utf8mb4', autocommit=True,
  12. )
  13. PUBLIC_KEY = "0484C7466D950E120E5ECE5DD85D0C90EAA85081A3A2BD7C57AE6DC822EFCCBD66620C67B0103FC8DD280E36C3B282977B722AAEC3C56518EDCEBAFB72C5A05312"
  14. PRIVATE_KEY = "8EDB615B1D48B8BE188FC0F18EC08A41DF50EA731FA28BF409E6552809E3A111"
  15. CANDIDATES = ["1234567890dop", "Admin.NET++010101"]
  16. def try_decrypt(cipher_hex: str):
  17. """Try several permutations for Admin.NET / BouncyCastle SM2 ciphertext."""
  18. results = []
  19. # Strip possible 04 prefix (SEC1 uncompressed marker)
  20. variants = [cipher_hex]
  21. if cipher_hex.lower().startswith("04"):
  22. variants.append(cipher_hex[2:])
  23. for mode_name, mode_val in [("C1C3C2", 1), ("C1C2C3", 0)]:
  24. sm2_crypt = sm2.CryptSM2(public_key=PUBLIC_KEY, private_key=PRIVATE_KEY, mode=mode_val)
  25. for v in variants:
  26. try:
  27. plain = sm2_crypt.decrypt(bytes.fromhex(v))
  28. if plain:
  29. txt = plain.decode('utf-8', errors='replace')
  30. results.append((mode_name, v is variants[0] and "with-04" or "no-04", txt))
  31. except Exception as ex:
  32. results.append((mode_name, "err", str(ex)))
  33. return results
  34. def main() -> None:
  35. conn = pymysql.connect(**CONN)
  36. with conn.cursor(pymysql.cursors.DictCursor) as cur:
  37. cur.execute(
  38. "SELECT Id, Account, Password, TenantId FROM SysUser WHERE Account='DemoAdmin' LIMIT 1"
  39. )
  40. row = cur.fetchone()
  41. if not row:
  42. print("DemoAdmin not found")
  43. return
  44. print(f"Account : {row['Account']}")
  45. print(f"TenantId: {row['TenantId']}")
  46. print(f"Ciphertext head (first 64 chars): {row['Password'][:64]}...")
  47. print(f"Ciphertext length : {len(row['Password'])}")
  48. print("\n=== 尝试多种 SM2 解密组合 ===")
  49. plains = try_decrypt(row['Password'])
  50. for m, v, p in plains:
  51. print(f" [{m} | {v}] => {p!r}")
  52. print("\n=== 比对候选密码 ===")
  53. for c in CANDIDATES:
  54. hits = [x for x in plains if x[2] == c]
  55. print(f" {c!r:<30} => {'MATCH: ' + str([(h[0], h[1]) for h in hits]) if hits else 'no match'}")
  56. conn.close()
  57. if __name__ == "__main__":
  58. main()