1. 主要工具
- binwalk
- scalpel
2. 解压并且查看文件类型
首先我们解压这个文件用gunzip disk-image.gz,然后我们看看这是什么文件:
file c297795634cb4f6e8e1d88be044ec0c4
3. 使用binwalk查看文件
binwalk c297795634cb4f6e8e1d88be044ec0c4
很奇怪,没有显示与writeup一致的信息,通过binwalk我们可以看到里面有个ELF文件,里面可能就有FLAG
ELF文件(Executable Linkable Format)是一种文件存储格式。Linux下的目标文件和可执行文件都按照该格式进行存储
writeup:
$ binwalk disk-image
# 终端显示:
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 Linux EXT filesystem, rev 1.0 ext3 filesystem data, UUID=bc6c2b24-106a-4570-bc4f-ae09abbdabbd
65536 0x10000 Linux EXT filesystem, rev 1.0 ext3 filesystem data, UUID=bc6c2b24-106a-4570-bc4f-ae09abbdabbd
72704 0x11C00 Linux EXT filesystem, rev 1.0 ext3 filesystem data, UUID=bc6c2b24-106a-4570-bc4f-ae09abbdabbd
1113088 0x10FC00 ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV)
1116896 0x110AE0 LZMA compressed data, properties: 0x89, dictionary size: 16777216 bytes, uncompressed size: 100663296 bytes
1117024 0x110B60 LZMA compressed data, properties: 0x9A, dictionary size: 16777216 bytes, uncompressed size: 100663296 bytes
1117216 0x110C20 LZMA compressed data, properties: 0xB6, dictionary >size: 16777216 bytes, uncompressed size: 33554432 bytes
1117408 0x110CE0 LZMA compressed data, properties: 0xD8, dictionary >size: 16777216 bytes, uncompressed size: 50331648 bytes
4. 配置scalpel文件
使用 scalpel 工具之前,首先要修改配置文件: /etc/scalpel/scalpel.conf。
scalpel.conf的格式是
case size header footer
例如用户要恢复所有删除 pdf 文件,那么要编辑配置文件将 pdf 两行之前注释去掉。
vim /etc/scalpel/scalpel.conf。
[...]
pdf y 5000000 %PDF %EOFx0d REVERSE
pdf y 5000000 %PDF %EOFx0a REVERSE
[...]
现在我们要恢复所有删除的ELF文件
所以在配置文件中添加
elf y 1000000 x7Fx45x4Cx46
可以使用命令:
echo "elf y 1000000 \x7F\x45\x4C\x46" >> /etc/scalpel/scalpel.conf
5. 使用scalpel恢复文件
配置完成后使用下面命令修复文件:
scapel c297795634cb4f6e8e1d88be044ec0c4
生成文件的目录树
tree scalpel-output
scalpel-output/
├── audit.txt
└── elf-0-0
└── 00000000.elf
6. 获得FLAG
那么这个可执行文件是做什么的呢?让我们来看看:
$ chmod u+x ./scalpel-output/elf-0-0/00000000.elf && ./scalpel-output/elf-0-0/00000000.elf
your flag is:
de6838252f95d3b9e803b28df33b4baa
7 参考资料
[1] Sharif University Quals CTF 2014: Recover Deleted File
[2] 恢复Linux误删除文件系列之scalpel工具
[3] ELF文件详解—初步认识
[4] ELF文件格式