2021西湖论剑 Reverse(Re) Writeup(WP)

ROR

二进制位线性变换,直接上z3。(不知道为什么,python脚本被压缩去掉空格了,各位将就看图片吧。)

from z3 import *
box = [
  0x65, 0x08, 0xF7, 0x12, 0xBC, 0xC3, 0xCF, 0xB8, 0x83, 0x7B,
  0x02, 0xD5, 0x34, 0xBD, 0x9F, 0x33, 0x77, 0x76, 0xD4, 0xD7,
  0xEB, 0x90, 0x89, 0x5E, 0x54, 0x01, 0x7D, 0xF4, 0x11, 0xFF,
  0x99, 0x49, 0xAD, 0x57, 0x46, 0x67, 0x2A, 0x9D, 0x7F, 0xD2,
  0xE1, 0x21, 0x8B, 0x1D, 0x5A, 0x91, 0x38, 0x94, 0xF9, 0x0C,
  0x00, 0xCA, 0xE8, 0xCB, 0x5F, 0x19, 0xF6, 0xF0, 0x3C, 0xDE,
  0xDA, 0xEA, 0x9C, 0x14, 0x75, 0xA4, 0x0D, 0x25, 0x58, 0xFC,
  0x44, 0x86, 0x05, 0x6B, 0x43, 0x9A, 0x6D, 0xD1, 0x63, 0x98,
  0x68, 0x2D, 0x52, 0x3D, 0xDD, 0x88, 0xD6, 0xD0, 0xA2, 0xED,
  0xA5, 0x3B, 0x45, 0x3E, 0xF2, 0x22, 0x06, 0xF3, 0x1A, 0xA8,
  0x09, 0xDC, 0x7C, 0x4B, 0x5C, 0x1E, 0xA1, 0xB0, 0x71, 0x04,
  0xE2, 0x9B, 0xB7, 0x10, 0x4E, 0x16, 0x23, 0x82, 0x56, 0xD8,
  0x61, 0xB4, 0x24, 0x7E, 0x87, 0xF8, 0x0A, 0x13, 0xE3, 0xE4,
  0xE6, 0x1C, 0x35, 0x2C, 0xB1, 0xEC, 0x93, 0x66, 0x03, 0xA9,
  0x95, 0xBB, 0xD3, 0x51, 0x39, 0xE7, 0xC9, 0xCE, 0x29, 0x72,
  0x47, 0x6C, 0x70, 0x15, 0xDF, 0xD9, 0x17, 0x74, 0x3F, 0x62,
  0xCD, 0x41, 0x07, 0x73, 0x53, 0x85, 0x31, 0x8A, 0x30, 0xAA,
  0xAC, 0x2E, 0xA3, 0x50, 0x7A, 0xB5, 0x8E, 0x69, 0x1F, 0x6A,
  0x97, 0x55, 0x3A, 0xB2, 0x59, 0xAB, 0xE0, 0x28, 0xC0, 0xB3,
  0xBE, 0xCC, 0xC6, 0x2B, 0x5B, 0x92, 0xEE, 0x60, 0x20, 0x84,
  0x4D, 0x0F, 0x26, 0x4A, 0x48, 0x0B, 0x36, 0x80, 0x5D, 0x6F,
  0x4C, 0xB9, 0x81, 0x96, 0x32, 0xFD, 0x40, 0x8D, 0x27, 0xC1,
  0x78, 0x4F, 0x79, 0xC8, 0x0E, 0x8C, 0xE5, 0x9E, 0xAE, 0xBF,
  0xEF, 0x42, 0xC5, 0xAF, 0xA0, 0xC2, 0xFA, 0xC7, 0xB6, 0xDB,
  0x18, 0xC4, 0xA6, 0xFE, 0xE9, 0xF5, 0x6E, 0x64, 0x2F, 0xF1,
  0x1B, 0xFB, 0xBA, 0xA7, 0x37, 0x8F
]
enc = [
  0x65, 0x55, 0x24, 0x36, 0x9D, 0x71, 0xB8, 0xC8, 0x65, 0xFB,
  0x87, 0x7F, 0x9A, 0x9C, 0xB1, 0xDF, 0x65, 0x8F, 0x9D, 0x39,
  0x8F, 0x11, 0xF6, 0x8E, 0x65, 0x42, 0xDA, 0xB4, 0x8C, 0x39,
  0xFB, 0x99, 0x65, 0x48, 0x6A, 0xCA, 0x63, 0xE7, 0xA4, 0x79
]
v5 = [0]*8
v5[0] = 128
v5[1] = 64
v5[2] = 32
v5[3] = 16
v5[4] = 8
v5[5] = 4
v5[6] = 2
v5[7] = 1
flag = []

for i in range(len(enc)):
    for n in range(len(box)):
        if enc[i] == box[n]:
            flag.append(n)
print(flag)

Str = [BitVec('instr%d' % i, 8) for i in range(40)]
v4 = BitVec('v4', 8)
s = Solver()
for i in range(0, 40, 8):
    for j in range(8):
        v4 = ((v5[j] & Str[i + 3]) << (8 - (3 - j) % 8)) | ((v5[j] & Str[i + 3]) >> ((3 - j) % 8)) | (
                    (v5[j] & Str[i + 2]) << (8 - (2 - j) % 8)) | ((v5[j] & Str[i + 2]) >> ((2 - j) % 8)) | (
                        (v5[j] & Str[i + 1]) << (8 - (1 - j) % 8)) | ((v5[j] & Str[i + 1]) >> ((1 - j) % 8)) | (
                        (v5[j] & Str[i]) << (8 - -j % 8)) | ((v5[j] & Str[i]) >> (-j % 8))
        s.add(((((v5[j] & Str[i + 7]) << (8 - (7 - j) % 8)) | ((v5[j] & Str[i + 7]) >> ((7 - j) % 8)) | ((v5[j] & Str[i + 6]) << (8 - (6 - j) % 8)) | ((v5[j] & Str[i + 6]) >> ((6 - j) % 8)) | ((v5[j] & Str[i + 5]) << (8 - (5 - j) % 8)) | ((v5[j] & Str[i + 5]) >> ((5 - j) % 8)) | ((v5[j] & Str[i + 4]) << (8 - (4 - j) % 8)) | ((v5[j] & Str[i + 4]) >> ((4 - j) % 8)) | v4)) == flag[i+j])

if s.check() == sat:
    m = s.model()
    s = []
    for i in range(len(m)):
        s.append(m[Str[i]].as_long())
    print(bytes(s).decode()) # Q5la5_3KChtem6_HYHk_NlHhNZz73aCZeK05II96

2021西湖论剑 Reverse(Re) Writeup(WP)

TacticalArmed

单指令SMC解密执行。程序将一个一个完整的40字节TEA加密流程的指令放入了数据区,在运行时动态的解密单指令并执行,下一次执行的单指令将覆盖上一次执行的单指令。

可以利用OD或者x64dbg的脚本,将所有指令dump下来。od脚本如下:

VAR opcode_size
VAR dump_address

BP 00401504 
Dump:
BP 0040140
RUN
MOV opcode_size, [ebp-10]
MOV dump_address,  [405640]
DMA dump_address, opcode_size, "my_code.bin"     

CMP eip, 00401504
JNE Dump

MSG "运行完毕"
RET

由于原程序没有基质随机,不用修复重定位偏移,所以可以直接将dump下来的指令在作为一个新增的节添加进题目程序中,并稍微修复使IDA可以反汇编。

2021西湖论剑 Reverse(Re) Writeup(WP)

2021西湖论剑 Reverse(Re) Writeup(WP)

2021西湖论剑 Reverse(Re) Writeup(WP)

很显然是一个tea加密,只不过轮数变为33论,并且key在tls中会检测调试器,只有调试器不存在的时候才会给予正确的key。

2021西湖论剑 Reverse(Re) Writeup(WP)

需要注意的是,在整个40字节的加密过程中,sum只初始化了一次,所以与正常调用tea是有所不同的,那么解密函数如下。

#include <stdio.h>
#include <stdint.h>

void TeaDecrypt(uint32_t* v, uint32_t* k) {
    uint32_t v0 = v[0], v1 = v[1], sum = 0, i; // B6528EEE
    uint32_t delta = 0x81A5692E;
    uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3];
    uint32_t sums[] = { 0xb6528eee ,0x6ca51ddc ,0x22f7acca ,0xd94a3bb8,0x8f9ccaa6 };
    for (int n = 0; n < 10; n += 2)
    {
        sum = sums[n / 2];
        v0 = v[0 + n], v1 = v[1 + n];
        for (i = 0; i < 33; i++) {
            v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
            v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
            sum -= delta;
        }
        v[0 + n] = v0; v[1 + n] = v1;
    }
}


int main()
{
    uint8_t enc[] = { 
          0xED, 0x1D, 0x2F, 0x42, 0x72, 0xE4, 0x85, 0x14, 0xD5, 0x78,
          0x55, 0x03, 0xA2, 0x80, 0x6B, 0xBF, 0x45, 0x72, 0xD7, 0x97,
          0xD1, 0x75, 0xAE, 0x2D, 0x63, 0xA9, 0x5F, 0x66, 0x74, 0x6D,
          0x2E, 0x29, 0xC1, 0xFC, 0x95, 0x97, 0xE9, 0xC8, 0xB5, 0x0B,
          0
    };

    uint32_t key[] = { 0x7CE45630,0X58334908,0X66398867,0XC35195B1 };

    TeaDecrypt((uint32_t*)enc, key);
    puts((char*)enc); // kgD1ogB2yGa2roiAeXiG8_aqnLzCJ_rFHSPrn55K
	return 0;
}

虚假的粉丝

一个脑洞题。

开始需要输入3个部分通过check,第一个check是有U和S字符的文件,第二个check是这些字符在文件的偏移,第三个是读取多少个字符,grep一下所以文件内容,可以获得三个信息。

2021西湖论剑 Reverse(Re) Writeup(WP)

分别是:

4457 1118 40

输入后,会打印一个UzNDcmU3X0szeSUyMCUzRCUyMEFsNE5fd0FsSzNS,base64一下是最后一个key

S3Cre7_K3y = Al4N_wAlK3R

输入最后一个keyAl4N_wAlK3R,程序会解密5135号文件,该文件的字符图里面的字母就是flag。

2021西湖论剑 Reverse(Re) Writeup(WP)

flag: A_TrUe_AW_f4ns

上一篇:【Vulnhub-LAMPSecurity】CTF 6


下一篇:CTF web安全45天入门学习路线