[Reverse] babyre - sherlly
题目是个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 = delta*num_rounds; for (i = 0; i < num_rounds; i++) { v1 -= (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + key[(sum >> 11) & 3]); sum -= delta; v0 -= (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + key[sum & 3]); } v[0] = v0; v[1] = v1; } int main() { HANDLE hEncryptedFile, hOriginalFile; DWORD dwBytesRead = 0, dwBytesWritten = 0; int i; uint32_t key[] = {0xface, 0xdead, 0xbabe, 0xd00d}; uint32_t buffer[36]; char *filename="encrypt"; char *tmpFileName="flag.txt"; hEncryptedFile = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hEncryptedFile == INVALID_HANDLE_VALUE) return -1; // Create temporary file for decrypted data hOriginalFile = CreateFile(tmpFileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hOriginalFile == INVALID_HANDLE_VALUE) { CloseHandle(hEncryptedFile); CloseHandle(hOriginalFile); return -1; } ReadFile(hEncryptedFile, buffer, 36, &dwBytesRead, NULL); for (i = 0; i < BLOCKS_TO_ENCRYPT; i+=2) { xtea_decrypt(32, &buffer[i], (uint32_t *)key); WriteFile(hOriginalFile, &buffer[i], 8, &dwBytesWritten, NULL); } // remain WriteFile(hOriginalFile, &buffer[i], 4, &dwBytesWritten, NULL); return 0; }
Flag:qwbctf{this_is_not_that_hard_right?}
打赏还是打残,这是个问题
没有帐号? 立即注册