1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
| import os import hashlib import base64 import gmpy2 from Crypto.Util.number import long_to_bytes, bytes_to_long
FILE_COUNT = 57 LOCKED_DIR = ".\\enced_files" TAIL_SIZE = 0x6f
RSA_PUBKEYS = [ "x9BqxsfHx8fH8ITNjeLxsfhdJuAF9rcTANS3sBybPV2g6KJndIeJhAVjq7vjbolzvXaKXqb46v+oAcw5m9mZ5bruu/wJtbeNqQ==", "wRiLwMHBwcHBWL3vc6UmwwavXoxp4X+uH8RAeWUgWC8/JS/m3FiIOCSaNsAnKQJPwCL5/rA8MyuRqdX1cxIZGnPzad9KlwEOiw==", "01T30tPT09PT7mfNwZfY9GDhNUBA2yz9uJTw2WPnH8CXIjmlwFfwhtWrgX0qnS2anIXOKskciqmkUj8lO8TZaq+YT1Nu1SDGUg==", "30RT3t/f39/flhsu7JRACZh83RDcbk/kX+xjgeQTv3DdncPxaCO+Y5I+GsVy3VS8nXX01QgLZCfEJsz9KZMRxNW7H0RQbDoWTw==", "+4z1+vv7+/v7YofVSZ8c+TyVZLZT20WUJf56Q18aYhUFHxXc5mKyAh6gDPodEzh1+hjDxIoGCRGrk+/PSSgjIEnJU+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90,0x68,0x07,0x53,0x31,0xDF,0xE0,0xA7,0x7B,0xF8, 0x87,0x9E,0xFE,0x77,0x0F,0xBF,0xE8,0xF2,0xFD,0x78,0xE1,0x8F,0xA8,0x33,0x4E,0xB9, 0xEA,0xC7,0xEF,0x6B,0xD9,0x80,0x24,0x0E,0x27,0xFF,0x4B,0x69,0xD6,0x32,0xDD,0x70 ])
INV_SBOX = bytes([SBOX.index(i) for i in range(256)])
def scan_locked_files(): groups = {0: [], 1: [], 2: [], 3: [], 4: []} for idx in range(FILE_COUNT): filepath = f"{LOCKED_DIR}\\file_{idx}.solar.locked" with open(filepath, "rb") as f: data = f.read() key_index = data[-TAIL_SIZE] if key_index in groups: groups[key_index].append((idx, data)) return groups
def parse_tail_metadata(raw_data): tail = raw_data[-TAIL_SIZE:] xor_key = tail[-0x26:-0x6] encrypted_meta = bytearray(tail[1:-6])
for i in range(len(encrypted_meta)): encrypted_meta[i] ^= xor_key[i % 32]
original_size = bytes_to_long(encrypted_meta[:8][::-1]) rsa_ciphertext = bytes_to_long(encrypted_meta[8:-0x20][::-1]) return original_size, rsa_ciphertext
def decode_pubkey(b64_str): raw = bytearray(base64.b64decode(b64_str)) mask = raw[0] for i in range(1, len(raw)): raw[i] ^= mask e = bytes_to_long(bytes(raw[1:9])[::-1]) n = bytes_to_long(bytes(raw[9:])[::-1]) return e, n
def common_modulus_attack(c1, c2, e1, e2, n): gcd, s1, s2 = gmpy2.gcdext(e1, e2) if gcd != 1: raise ValueError("共模攻击失败") m = (pow(c1, s1, n) * pow(c2, s2, n)) % n return m
def expand_aes_key(seed): expanded = b"" current = seed for _ in range(11): digest = hashlib.sha256(current).digest() chunk = bytes([digest[i*2] ^ digest[i*2+1] for i in range(16)]) expanded += chunk current = digest return list(expanded)
class ModifiedAES: def __init__(self, round_keys): self.rk = [] for i in range(0, 176, 16): matrix = [[round_keys[i + r*4 + c] for c in range(4)] for r in range(4)] self.rk.append(matrix) def decrypt_cbc(self, ciphertext, iv): plaintext = b"" prev_block = bytes(iv) for offset in range(0, len(ciphertext), 16): block = ciphertext[offset:offset+16] decrypted = self._decrypt_block(block) plaintext += bytes([decrypted[i] ^ prev_block[i] for i in range(16)]) prev_block = block return plaintext def _decrypt_block(self, block): state = [[block[r*4+c] for c in range(4)] for r in range(4)] self._add_round_key(state, self.rk[10]) self._inv_shift_rows(state) self._inv_sub_bytes(state)
for round_num in range(9, 0, -1): self._add_round_key(state, self.rk[round_num]) self._inv_mix_columns(state) self._inv_shift_rows(state) self._inv_sub_bytes(state) self._add_round_key(state, self.rk[0])
return bytes([state[r][c] for r in range(4) for c in range(4)]) def _add_round_key(self, state, key): for r in range(4): for c in range(4): state[r][c] ^= key[r][c] def _inv_sub_bytes(self, state): for r in range(4): for c in range(4): state[r][c] = INV_SBOX[state[r][c]] def _inv_shift_rows(self, state): state[0][1], state[1][1], state[2][1], state[3][1] = \ state[3][1], state[0][1], state[1][1], state[2][1] state[0][2], state[1][2], state[2][2], state[3][2] = \ state[2][2], state[3][2], state[0][2], state[1][2] state[0][3], state[1][3], state[2][3], state[3][3] = \ state[1][3], state[2][3], state[3][3], state[0][3] def _inv_mix_columns(self, state): for r in range(4): u = self._xtime(self._xtime(state[r][0] ^ state[r][2])) v = self._xtime(self._xtime(state[r][1] ^ state[r][3])) state[r][0] ^= u state[r][1] ^= v state[r][2] ^= u state[r][3] ^= v for r in range(4): t = state[r][0] ^ state[r][1] ^ state[r][2] ^ state[r][3] u = state[r][0] state[r][0] ^= t ^ self._xtime(state[r][0] ^ state[r][1]) state[r][1] ^= t ^ self._xtime(state[r][1] ^ state[r][2]) state[r][2] ^= t ^ self._xtime(state[r][2] ^ state[r][3]) state[r][3] ^= t ^ self._xtime(state[r][3] ^ u) @staticmethod def _xtime(a): return ((a << 1) ^ 0x1B) & 0xFF if a & 0x80 else a << 1
def decrypt_all_files(aes_cipher, iv): for idx in range(FILE_COUNT): src_path = f"{LOCKED_DIR}\\file_{idx}.solar.locked" dst_path = f"{LOCKED_DIR}\\file_{idx}.solar" with open(src_path, "rb") as f: raw = f.read() encrypted_content = raw[:-TAIL_SIZE] original_size, _ = parse_tail_metadata(raw) decrypted = aes_cipher.decrypt_cbc(encrypted_content, iv) with open(dst_path, "wb") as f: f.write(decrypted[:original_size]) os.remove(src_path) print(f"[+] 解密完成: file_{idx}.solar ({original_size} bytes)")
def main(): groups = scan_locked_files() print(f" 公钥1加密的文件数: {len(groups[1])}") print(f" 公钥4加密的文件数: {len(groups[4])}") _, data1 = groups[1][0] _, data4 = groups[4][0] _, c1 = parse_tail_metadata(data1) _, c2 = parse_tail_metadata(data4) print(f" 密文c1: {hex(c1)[:40]}...") print(f" 密文c2: {hex(c2)[:40]}...") e1, n1 = decode_pubkey(RSA_PUBKEYS[1]) e2, n2 = decode_pubkey(RSA_PUBKEYS[4]) print(f" e1 = {e1}") print(f" e2 = {e2}") print(f" n1 == n2: {n1 == n2}") aes_key_int = common_modulus_attack(c1, c2, e1, e2, n1) aes_key = long_to_bytes(aes_key_int)[::-1] print(f" 恢复的AES密钥: {aes_key.hex()}") iv = list(aes_key[:16]) round_keys = expand_aes_key(aes_key) print(f" IV: {bytes(iv).hex()}") print(f" 轮密钥长度: {len(round_keys)} bytes") cipher = ModifiedAES(round_keys) decrypt_all_files(cipher, iv) print("\n" + "=" * 50) print("解密完成!") print("=" * 50)
main()
|