decrypt_did888.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. # -*- coding: utf-8 -*-
  2. """
  3. did888.txt AES-192-ECB 解密脚本
  4. 依据: 分析报告_did黑产池.md / G线线报(G_代理池基建线.md §2.2)
  5. 下载源: https://sexfuck.oss-cn-shanghai.aliyuncs.com/did888.txt
  6. 算法: AES-192-ECB, 密钥 = FnHGbGQADToD3SjKgAf0GvNuxU (24字节, 镜像 0x4e9990)
  7. 用法:
  8. python decrypt_did888.py <本地已下载的did888.txt路径>
  9. # 或不带参数, 默认读当前目录 did888.txt
  10. 说明: 纯本地解密, 不发起网络请求。文件需自行获取(浏览器/curl 均可)。
  11. 输出:
  12. did888_decrypted.txt 解密后明文
  13. did888_keys.txt 从明文提取的 did 列表(逐行)
  14. """
  15. import sys
  16. import re
  17. import base64
  18. import binascii
  19. sys.stdout.reconfigure(encoding='utf-8', errors='replace')
  20. # ---- 镜像摘出的常量 ----
  21. AES_KEY = b'FnHGbGQADToD3SjKgAf0GvNuxU' # 24 字节 = AES-192
  22. OSS_URL = 'https://sexfuck.oss-cn-shanghai.aliyuncs.com/did888.txt'
  23. # did 期望形态(依镜像内证据):
  24. # UUID: B6D6329A-CC09-4006-8978-42CC797640D5 (openShare/profile 参数)
  25. # 纯hex: 32位十六进制(快手 web did 常见形态)
  26. UUID_RE = re.compile(r'[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}')
  27. HEX32_RE = re.compile(r'\b[0-9a-f]{32}\b')
  28. DEC_RE = re.compile(r'\b\d{15,20}\b') # 快手 did 也有长十进制形态
  29. def load_cipher(path):
  30. raw = open(path, 'rb').read()
  31. print(f'密文文件: {path} ({len(raw)} 字节)')
  32. return raw
  33. def try_decrypt(raw):
  34. """尝试多种载荷形态: 原始字节 / base64 / hex。返回明文字节或 None。"""
  35. from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  36. def ecb(data):
  37. if len(data) % 16 != 0:
  38. return None # ECB 要求 16 字节对齐
  39. c = Cipher(algorithms.AES(AES_KEY), modes.ECB())
  40. d = c.decryptor()
  41. return d.update(data) + d.finalize()
  42. # 形态1: 文件本身就是 AES 密文块
  43. out = ecb(raw)
  44. if looks_plain(out):
  45. return out, '原始密文块'
  46. # 形态2: base64 编码后传输
  47. for stripper in [lambda b: b, lambda b: b.replace(b'\r', b''), lambda b: b.replace(b'\n', b''), lambda b: b.replace(b'\n', b'').replace(b'\r', b'')]:
  48. t = stripper(raw).strip()
  49. try:
  50. b64 = base64.b64decode(t, validate=True)
  51. out = ecb(b64)
  52. if looks_plain(out):
  53. return out, 'base64 包装'
  54. except (binascii.Error, ValueError):
  55. continue
  56. # 形态3: hex 编码
  57. t = raw.strip()
  58. if re.fullmatch(rb'[0-9a-fA-F\s]+', t):
  59. try:
  60. hx = binascii.unhexlify(re.sub(rb'\s', b'', t))
  61. out = ecb(hx)
  62. if looks_plain(out) or out:
  63. return out, 'hex 包装'
  64. except (binascii.Error, ValueError):
  65. pass
  66. return None, None
  67. def looks_plain(data):
  68. """解密结果是否像文本(GBK/ASCII 可读、含换行)。"""
  69. if not data:
  70. return False
  71. printable = sum(1 for b in data if 0x20 <= b <= 0x7e or b in (0x0a, 0x0d, 0x09))
  72. return printable / len(data) > 0.85
  73. def strip_pkcs7(data):
  74. """去 PKCS7 填充(若使用)。"""
  75. if not data:
  76. return data
  77. pad = data[-1]
  78. if 1 <= pad <= 16 and data[-pad:] == bytes([pad]) * pad:
  79. return data[:-pad]
  80. return data
  81. def extract_dids(text):
  82. """从明文提取 did 列表。"""
  83. dids = []
  84. seen = set()
  85. for m in UUID_RE.finditer(text):
  86. v = m.group().upper()
  87. if v not in seen:
  88. seen.add(v); dids.append(v)
  89. for m in HEX32_RE.finditer(text):
  90. v = m.group()
  91. if v not in seen:
  92. seen.add(v); dids.append(v)
  93. for m in DEC_RE.finditer(text):
  94. v = m.group()
  95. if v not in seen:
  96. seen.add(v); dids.append(v)
  97. return dids
  98. def main():
  99. path = sys.argv[1] if len(sys.argv) > 1 else 'did888.txt'
  100. try:
  101. raw = load_cipher(path)
  102. except FileNotFoundError:
  103. print(f'文件不存在: {path}')
  104. print(f'请先自行下载: {OSS_URL}')
  105. print('(本脚本不发起网络请求)')
  106. return 1
  107. print('密文头 32 字节:', raw[:32].hex())
  108. result, mode = try_decrypt(raw)
  109. if result is None:
  110. print()
  111. print('=== 解密失败 ===')
  112. print('AES-192-ECB + FnHG 密钥未产出可读明文。可能原因:')
  113. print(' 1. 文件已下线/内容改变(404 XML 错误页等)')
  114. print(' 2. 载荷有额外包装(base64/hex 之外)')
  115. print(' 3. 密钥已轮换')
  116. return 2
  117. plain = strip_pkcs7(result)
  118. print()
  119. print(f'=== 解密成功 (形态: {mode}) ===')
  120. print(f'明文 {len(plain)} 字节')
  121. text = plain.decode('gbk', errors='replace')
  122. print('--- 明文前 500 字符 ---')
  123. print(text[:500])
  124. print('--- 明文末 200 字符 ---')
  125. print(text[-200:])
  126. with open('did888_decrypted.txt', 'wb') as f:
  127. f.write(plain)
  128. dids = extract_dids(text)
  129. with open('did888_keys.txt', 'w', encoding='utf-8') as f:
  130. f.write(f'# did 池 (did888.txt 解密产物)\n')
  131. f.write(f'# 来源: {OSS_URL}\n')
  132. f.write(f'# AES-192-ECB key: FnHGbGQADToD3SjKgAf0GvNuxU\n')
  133. f.write(f'# 提取 did 数: {len(dids)}\n\n')
  134. for v in dids:
  135. f.write(v + '\n')
  136. print()
  137. print(f'=== did 提取结果 ===')
  138. print(f'提取 did 数: {len(dids)}')
  139. for v in dids[:10]:
  140. print(f' {v}')
  141. if len(dids) > 10:
  142. print(f' ... ({len(dids) - 10} more)')
  143. print()
  144. print(f'已写出: did888_decrypted.txt / did888_keys.txt')
  145. return 0
  146. if __name__ == '__main__':
  147. sys.exit(main())