思路
-
解题大致思路
首先放进DIE分析程序,发现是PyInstaller打包的,我们就拿,pyinstxtractor去解决包

-
这里注意程序是python3.7的,所以要提前用python3.7去解包,解包发现加密了,PyInstaller加密的key会一起打包,所以是不安全的,我们可以pyimod00_crypto_key.pyc里面看到key的值
key = 'f8c0870eba862579' -
然后我们就可以写一个解密的程序
from Crypto.Cipher import AES from Crypto.Util import Counter import zlib CRYPT_BLOCK_SIZE = 16 # key obtained from pyimod00_crypto_key key = bytes('f8c0870eba862579', 'utf-8') inf = open('baby_python.baby_core.pyc.encrypted', 'rb') # encrypted file input outf = open('baby_python.baby_core.pyc', 'wb') # output file # Initialization vector iv = inf.read(CRYPT_BLOCK_SIZE) ctr = Counter.new(128, initial_value=int.from_bytes(iv, byteorder='big')) cipher = AES.new(key, AES.MODE_CTR, counter=ctr) # Decrypt and decompress plaintext = zlib.decompress(cipher.decrypt(inf.read())) # Write pyc header # The header below is for Python 3.8 outf.write(b'\x42\x0d\x0d\x0a\x00\x00\x00\x00\x70\x79\x69\x30\x10\x01\x00\x00') # Write decrypted data outf.write(plaintext) inf.close() outf.close()解密后生成baby_python.baby_core.pyc,拿去反编译然后发现是一个简单的矩阵乘法嗷,乘法结果md5加密就是答案,我们写一个z3去解决
EXP
-
具体攻击代码
-
from z3 import * co = [ [ 158, 195, 205, 229, 213, 238, 211, 198, 190, 226, 135, 119, 145, 205, 113, 122], [ 234, 256, 185, 253, 244, 134, 102, 117, 190, 106, 131, 205, 198, 234, 162, 218], [ 164, 164, 209, 200, 168, 226, 189, 151, 253, 241, 232, 151, 193, 119, 226, 193], [ 213, 117, 151, 103, 249, 148, 103, 213, 218, 222, 104, 228, 100, 206, 218, 177], [ 217, 202, 126, 214, 195, 125, 144, 105, 152, 118, 167, 137, 171, 173, 206, 240], [ 160, 134, 131, 135, 186, 213, 146, 129, 125, 139, 174, 205, 177, 240, 194, 181], [ 183, 213, 127, 136, 136, 209, 199, 191, 150, 218, 160, 111, 191, 226, 154, 191], [ 247, 188, 210, 219, 179, 204, 155, 220, 215, 127, 225, 214, 195, 162, 214, 239], [ 108, 112, 104, 133, 178, 138, 110, 176, 232, 124, 193, 239, 131, 138, 161, 218], [ 140, 213, 142, 181, 179, 173, 203, 208, 184, 129, 129, 119, 122, 152, 186, 124], [ 105, 205, 124, 142, 175, 184, 234, 119, 195, 218, 141, 122, 202, 202, 190, 178], [ 183, 178, 256, 124, 241, 132, 163, 209, 204, 104, 175, 211, 196, 136, 158, 210], [ 224, 144, 189, 106, 177, 251, 206, 163, 167, 144, 208, 254, 117, 253, 100, 106], [ 251, 251, 136, 170, 145, 177, 175, 124, 193, 188, 193, 198, 208, 171, 151, 230], [ 143, 200, 143, 150, 243, 148, 136, 213, 161, 224, 170, 208, 185, 117, 189, 242], [ 234, 188, 226, 194, 248, 168, 250, 244, 166, 106, 113, 218, 209, 220, 158, 228]] r = [ 472214, 480121, 506256, 449505, 433390, 435414, 453899, 536361, 423332, 427624, 440268, 488759, 469049, 484574, 480266, 522818] s = Solver() v = [Int('v[%d]'%i) for i in range(16)] for i in range(16): s.add(v[i]>0) for i in range(16): s.add(v[i]<1000) for i in range(16): vv = 0 for j in range(16): vv += co[i][j] * v[j] s.add(vv=r[i]) print(s.check()) print(s.solver()) m = s.model() for i in range(16): print(m[v[i]],end = '')
总结
-
对该题的考点总结
学会对一般的Pyinstaller加密打包程序的破解
会z3解密矩阵乘法
