题目是个64位的exe,IDA打开发现很多反调试、反vm的内容,熟悉的检测mac、检测productid等操作:
绕过反调试后,最终只有几步:
以为是vmp,动态跟了下发现关键点不在这里,往回找发现一个可疑函数:
在判断不是virtualbox运行环境后,调用了一个函数,跟进去,发现在经过一些检查还有打开文件等操作后,有一段算法:
搜索特征值0x61C88647发现一篇文章介绍说作者为了避免程序被通过搜索特征值0x9e3779b9识别出xtea算法,通常会使用0x61C88647(-0x9e3779b9)代替,同时wiki找到xtea的算法实现,也一一吻合:
提取对应的key值:
写解密程序即可:
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <windows.h> #define XTEA_KEY_SIZE 16 #define XTEA_BLOCK_SIZE 16 #define BLOCKS_TO_ENCRYPT 8 void xtea_encrypt(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4]) { unsigned int i; uint32_t v0 = v[0], v1 = v[1], sum = 0, delta = 0x9E3779B9; for (i = 0; i < num_rounds; i++) { v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); sum += delta; v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum >> 11) & 3]); } v[0] = v0; v[1] = v1; } void xtea_decrypt(unsigned int num_rounds, uint32_t v[2], uint32_t const key[4]) { unsigned int i; uint32_t v0 = v[0], v1 = v[1], delta = 0x9E3779B9, sum = de
题目是一个apk,功能是对图片进行加密,而在这题中要做的就是对加密(lock)的图片进行解密。
打开发现主要的加密部分在libnative.so里,
函数为enc(),参数有输入文件名,输出文件名以及密钥key,key为签名md5值,动态调试得到“f8c49056e4ccf9a11e090eaf471f418d”;
跟踪发现enc函数用了AES的s_box,猜测与aes有关,但仔细查看发现有区别。关键函数有如下几个:
主要需要对以上几个函数逆向,bytexor()直接再次加密就可以逆回去,singletable()与aes的单表置换有关,使用aes的inv_s_box表逆回去,
substitution()也是置换,反置换回去。做的时候遇到些问题主要卡在sub_162c上了,但是之后发现对这个函数逆向只要再加密3次就还原了(1+3
共4次加密回到原输入)。
所以对这几个函数逆向有:
解密lock图片有:
贴上代码如下:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "cdefs.h" BYTE byte_36E4[] = { 0x63,0x7C,0x77,0x7B,0xF2,0x6B,0x6F,0xC5,0x30,0x01,0x67,0x2B ,0xFE,0xD7,0xAB,0x76,0xCA,0x82,0xC9,0x7D,0xFA,0x59,0x47,0xF0,0xAD,0xD4,0xA2,0xAF ,0x9C,0xA4,0x72,0xC0,0xB7,0xFD,0x93,0x26,0x36,0x3F,0xF7,0xCC,0x34,0xA5,0xE5,0xF1 ,0x71,0xD8,0x31,0x15,0x04,0xC7,0x23,0xC3,0x18,0x96,0x05,0x9A,0x07,0x12,0x80,0xE2 ,0xEB,0x27,0xB2,0x75,0x09,0x83,0x2C,0x1A,0x1B,0x6E,0x5A,0xA0,0x52,0x3B,0xD6,0xB3 ,0x29,0xE3,0x2F,0x84,0x53,0xD1,0x00,0xED,0x20,0xFC,0xB1,0x5B,0x6A,0xCB,0xBE,0x39 ,0x4A,0x4C,0x58,0xCF,
题目是一个apk,对输入字符串进行验证,使用jeb打开可以发现验证逻辑为:
逻辑很清晰,可爆破验证得到flag为"flag{MAth_i&_GOOd_DON7_90V_7hInK?"(需添加‘}’)。
贴上代码如下:
#include <stdio.h> int main() { int a[] = { 0, 146527998, 205327308, 94243885, 138810487, 408218567, 77866117, 71548549, 563255818, 559010506, 449018203, 576200653, 307283021, 467607947, 314806739, 341420795, 341420795, 469998524, 417733494, 342206934, 392460324, 382290309, 185532945, 364788505, 210058699, 198137551, 360748557, 440064477, 319861317, 676258995, 389214123, 829768461, 534844356, 427514172, 864054312 }; int b[] = { 13710, 46393, 49151, 36900, 59564, 35883, 3517, 52957, 1509, 61207, 63274, 27694, 20932, 37997, 22069, 8438, 33995, 53298, 16908, 30902, 64602, 64028, 29629, 26537, 12026, 31610, 48639, 19968, 45654, 51972, 64956, 45293, 64752, 37108 }; int c[] = { 38129, 57355, 22538, 47767, 8940, 4975, 27050, 56102, 21796, 41174, 63445, 53454, 28762, 59215, 16407, 64340, 37644, 59896, 41276, 25896, 27