TSGCTF optimized 中用到的 UPX 壳的反解压
判断是否加壳
- 不标准的段名,静态链接
- 找不到输出字符串
- entry point 在其他地方
一些通过 upx 压缩的文件可能不会被识别为 upx 压缩过的,基本上是通过更改文件头中的一些数据实现的(可根据 upx -d 的报错判断)
upx 文件头结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| struct b_info // 12-byte header before each compressed block {
uint32_t sz_unc; uint32_t sz_cpr; unsigned char b_method; unsigned char b_ftid; unsigned char b_cto8; unsigned char b_unused;
};
struct l_info // 12-byte trailer in header for loader (offset 116) {
uint32_t l_checksum; uint32_t l_magic; uint16_t l_lsize; uint8_t l_version; uint8_t l_format;
};
struct p_info // 12-byte packed program header follows stub loader {
uint32_t p_progid; uint32_t p_filesize; uint32_t p_blocksize;
};
|
现在主要伪造的是 p_info ,l_info 里的内容,在b_info 暂时还没有伪造方法
复原
都改成 UPX! 就能 upx -d 解压了
无法用以上方法复原的情况
可以考虑用 gdb 调试,gcore 命令获取内存状况
也可以尝试用 radare2 解压内存
因为 upx 是开源的,所以有时候压缩方式会遭到更改
参考链接