type
status
date
slug
summary
tags
category
icon
password
关于2024CISCN的题解
asm_re
直接手撕汇编

exp
androidso_re

flag的加密在inspect这个类里面
经过了DES(CBC模式)加密+base64加密
那么我们需要得到DES加密的IV和key
在libSecret_entrance.so里面

分别在getiv和getkey里面把a1的类型变一下改成JNIEnv*


然后我们直接利用jnitrace



whereThel1b
出题人自己编写的动态链接库

真正对明文进行处理的函数时whereThelib这个库里面的trytry函数
我们可以先搜索init,发现有一个PyInit_whereThel1b这个函数

然后我们就可以找到初始化这些模块的地方__pyx_moduledef

这里定义了一个随机数种子
然后后面又调用了whereistheflag1

说明对字符的处理在whereistheflag1里面
在whereistheflag1里面先调用了一个base64,说明先进行了base64加密

还是生成一个随机数,生成的范围时是(0,len(arr))


这里还调用了一下xor

这里整理一下加密的逻辑
由于随机数种子的参数我们不知道
gdb_debug
加密逻辑非常清楚
有三处异或
在生成的随机数那里,有一个办法
在它调用rand这个函数之后,后面下一个条件断点

我们需要下三处条件断点,然后得出三处生成的随机数数组

rust_baby
首先我们要先找到这个函数
sub_7FF7B37F298A
这个函数相当于就是我们的主函数

然后我们把memcpy的内容放到cyberchef里面解密,发现它一个字典的格式,这里面的信息对我们后面有用
这个函数就是输入函数

我们注意到后面只处理八个字符,所以我就先输入8个字符
我们直接下个硬件断点,然后我们可以跟踪对字符串的处理

由于这里的加密函数太复杂了,我们直接黑盒分析
我们可以得到这个规律,后面还有个异或操作
后面还有一个异或操作

然后我们可以在这里提取出来我们需要异或的数值,但是我们怎么提取出真正的密钥呢,我们可以看到v91那里一共有104个字节,我们可以把这里全部设置成0
然后在后面可以提取出密钥,由于中间全部进行了base64加密操作,base64解密之后的就是真正的密钥

GoReverse
程序分析
这里借鉴的思路是panda0s师傅的思路

发现没有符号表,我们可以先恢复一下符号表
https://github.com/0xjiayu/go_parser
克隆仓库,IDA加载go_parser.py即可,不需要把脚本放到plugin里面

初始化在runtime_main里面,然后我们的主函数在main__B2bUPq_Execute里面
里面一共有两个反调试的地方

在调用这个runtime_systemstack之后就会退出,我们可以把这个nop掉

第二个反调试就很明显了,在地址0x004D64A0 这里
把他patch掉就行了

后面的zQyveE为xxtea加密,我们可以把ToUint32s复制下来

我们可以发现xxtea进行了魔改,魔改的地方为MX和delta
然后我们可以在以下几个地方设置断点


然后我们可以先在进行异或操作之前下个断点

因为我是之前先异或了,所以再异或一下就回去了,这样便于我们更好分析
以下是我们异或的值

我们经过xxtea加密之后我们看一下它的返回值

一共十六个字节,很明显是我们的输入之后的加密结果,但是我们便于分析统一变成11,这个时候我们就可以直接按F9
跳到了

然后这个时候我们可以得到SM4的密钥
继续往下面调
这是生成的随机数

我们统一把它设成22
再继续往下面调,一直到了
然后我们在rsi寄存器得到了我们一开始经过xxtea加密的密文
这个时候要和sm4生成的密文(CTR模式)进行异或
但是这个iv是随机生成的(后面会解释这个怎么得到)
继续往下面调我们可以到到aes的密钥

再往下面走,我们可以得到aes的iv是key的前16位
我们在最后retn这里下个断点,我们把前16位的全都替换成33,最后在Linux里面会输出一段base32的字符串



就是我们最后输入的33,那么说明我们在经过base32和aes解密之后,得到的前16个字节就是sm4随机生成的iv
逆向分析
这里为了复现我直接借用了其它师傅在比赛中得到的flag

根据flag长度为40或42可知counter还需要分别+1和+2,总共3*16bytes

我们将SM4加密的密文与AES解出来的明文的从第16位开始进行异或,解出来的就是xxtea的密文
之后进行xxtea加密

有关复现上的问题,欢迎您在底部评论区留言,一起交流~
- Author:5m10v3
- URL:https://5m10v3.top/article/6c54e1cb-35a0-46fa-8874-83cc331610b3
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!
Relate Posts