西湖论剑 2023
搞了一天出了俩逆向,还有一个没交上…
1. Dual personality
类似天堂之门,
将cs段寄存器设为0x33,切换到64位模式;设为0x23,切换回32位模式。
32位、64位模式切换。有反调试,静态分析即可。
import struct
target = bytes.fromhex('AA4F0FE2E44199542C2B847EBC8F8B78D373885EAE47857031B309CE13F50DCA')
key0 = [4, 0x77, 0x82, 0x4a]
key1 = [0xc, 0x22, 0x38, 0x0E]
key2 = (0x5df966ae - 0x21524111) & 0xffffffff
flag = [target[_] ^ key0[_ % 4] for _ in range(32)]
for i in range(4):
v, = struct.unpack('<Q', bytes(flag[i * 8: (i + 1) * 8]))
nv = (v >> key1[i]) | (v << (64 - key1[i])) & 0xffffffffffffffff
vv = struct.pack('<Q', nv)
for j in range(8):
flag[i * 8 + j] = vv[j]
for i in range(8):
v, = struct.unpack('<L', bytes(flag[i * 4: (i + 1) * 4]))
nv = (v - key2) & 0xffffffff
key2 ^= v
vv = struct.pack('<L', nv)
for j in range(4):
flag[i * 4 + j] = vv[j]
print(''.join(chr(c) for c in flag))
3. Berkeley
bpf 逆向,参考 bpf,ebpf一些原理以及逆向基于libbpf-bootstrap编写的bpf文件
状态不太好,先是忽略了 BitVec
是有符号数,然后是迟迟没有想到去爆破。
cipher = [0xf3, 0x27, 0x47, 0x1b, 0x8f, 0x09, 0xfb, 0x17, 0x70, 0x48, 0xb0, 0x53, 0x32, 0xdb, 0xc0, 0xb8, 0x63, 0x2d,
0x40, 0x4b, 0xf5, 0x16, 0xf0, 0x35, 0xe7, 0xdf, 0xea, 0xa2, 0x9c, 0x41, 0xb3, 0x25, 0xd7, 0x0c, 0x33, 0x9c,
0x7b, 0x5a, 0xcd, 0x13, 0xbb, 0xee, 0x3e, 0x0e, 0xf2, 0xcf, 0x35, 0xda, 0xaf, 0xa2, 0x66, 0x7d, 0x38, 0x37,
0x67, 0x1e, 0x1f, 0x6b, 0x7b, 0x30, 0x0b, 0x7a, 0x02, 0xa9, 0xc8, 0x61, 0x27, 0x41, 0xdb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a4, 0x43, 0x40, 0xe1, 0x37, 0x9e, 0x36, 0x76, 0x71, 0x84,
0xbd, 0x06, 0x8d, 0x47, 0x7d, 0x53, 0xd7, 0xc8, 0xce, 0x15, 0x92, 0x95, 0x4c, 0x28, 0x6d, 0x75, 0xeb, 0x7c, 0xf3,
0xbe, 0xaa, 0xb8, 0xed, 0x03, 0x3c, 0x27, 0x3e, 0x19, 0xdd, 0xa6, 0x66, 0x25, 0x1e, 0xc4, 0x6e, 0xc0, 0xe2, 0xdb,
0x3a, 0xd9, 0x81, 0xa5, 0x1b, 0xf5, 0x04, 0xae, 0xba, 0xea, 0x97, 0x83, 0x35, 0x44, 0xa3, 0x7a, 0x1a, 0xf1, 0x86,
0xda, 0x7b, 0x14, 0x72, 0x9c, 0x6a, 0x0f, 0x5f, 0x0a]
cst32 = [0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01]
for i in range(256):
cipher[i] = key.index(cipher[i]) ^ key[i]
print(cipher)
import z3
for i in range(32):
c = z3.BitVec(f'x{i}', 8)
s = z3.Solver()
s.add(c < z3.BitVecVal(128, 32)) # 万恶之源 s.add(c < 128) 不可以, 要用 s.add(c > 0),因为 BitVec 是有符号数
for j in range(8):
s.add((~((cst32[j] + c) ^ c)) & 0xff == key.index(cipher[i * 8 + j]))
if s.check() == z3.sat:
print(chr(s.model()[c].as_long()), end='')
标签:西湖,2023,0xf3,range,cipher,32,论剑,add,z3
From: https://www.cnblogs.com/gaoyucan/p/17087358.html