
在数字取证调查中,磁盘镜像分析是一项核心技术,它允许调查人员在不破坏原始证据的情况下,对存储设备进行全面检查。随着计算机和存储技术的快速发展,磁盘镜像分析技术也在不断演进,成为现代数字取证不可或缺的环节。
磁盘镜像分析不仅可以恢复已删除的文件,还能重建用户活动时间线,发现隐藏的数据和恶意软件痕迹,为法律诉讼提供关键证据。本实战指南将从基础概念入手,逐步深入到高级分析技术,帮助读者掌握完整的磁盘镜像分析流程。
磁盘镜像是存储设备内容的完整副本,包括所有文件、文件系统元数据以及未分配空间。在取证分析中,镜像的完整性和真实性至关重要,必须采取严格的取证措施来确保镜像数据的可靠性。
磁盘镜像的主要类型:
1. 原始镜像(Raw Image)
2. 取证镜像(Forensic Image)
3. 压缩镜像
4. 分区镜像
创建磁盘镜像的过程必须遵循严格的取证流程,以确保证据的法律效力。
1. 硬件写保护设备
使用专业的写保护设备可以防止在取证过程中意外修改原始证据。
2. 软件镜像工具
在无法使用硬件写保护的情况下,可以使用软件工具创建磁盘镜像。
DD命令(Linux/macOS)
# 创建完整磁盘镜像
sudo dd if=/dev/sdb of=/mnt/external/disk_image.dd bs=4M status=progress
# 同时计算SHA-256校验和
sudo dd if=/dev/sdb bs=4M status=progress | tee /mnt/external/disk_image.dd | sha256sum > /mnt/external/disk_image.sha256FTK Imager(Windows)
EnCase Forensic
3. 网络镜像技术
对于远程系统,可以使用网络镜像技术获取磁盘镜像。
# 目标系统上运行
sudo dd if=/dev/sda bs=4M | nc -l 1234
# 取证工作站上运行
nc target_ip 1234 > disk_image.dd4. 远程镜像注意事项
理解文件系统的工作原理是磁盘镜像分析的基础。不同的操作系统使用不同的文件系统,每种文件系统都有其独特的数据组织结构。
1. Windows文件系统(NTFS)
2. Linux文件系统(Ext4)
3. macOS文件系统(APFS)
4. 文件删除与恢复原理
无论何种文件系统,文件删除通常只是标记为删除,而不是立即擦除数据。
在开始创建磁盘镜像前,必须做好充分的硬件准备,确保取证过程的安全性和可靠性。
1. 必要硬件设备
2. 设备连接流程
3. 设备识别与管理
lsblk命令列出所有块设备fdisk -l查看分区信息FTK Imager是一款功能强大的商业取证工具,提供直观的图形界面,适合创建和分析磁盘镜像。
1. 安装与配置
2. 创建完整磁盘镜像
3. 创建分区镜像
当只需要分析特定分区时,可以创建分区镜像以节省时间和空间。
4. 使用命令行版本
FTK Imager还提供命令行版本(FTK Imager CLI),适合自动化操作。
ftkimager.exe /c /d /e01 /f "D:\evidence\disk_image.e01" /i /log:"D:\evidence\imaging.log" /m SHA-256 \.\PhysicalDrive1/c: 创建镜像/e01: 使用E01格式/f: 指定输出文件路径/m: 指定哈希算法/log: 指定日志文件路径dd命令是Linux和Unix系统中的一个强大工具,可以逐块复制数据,非常适合创建原始磁盘镜像。
1. 基本语法与参数
dd if=输入文件 of=输出文件 bs=块大小 [其他参数]if: 输入文件(源设备)of: 输出文件(目标文件)bs: 块大小(推荐4M或8M以提高速度)count: 复制的块数status=progress: 显示复制进度conv=noerror,sync: 出错时继续并同步写入2. 创建完整磁盘镜像
# 创建磁盘镜像并显示进度
sudo dd if=/dev/sdb of=/mnt/external/disk_image.dd bs=4M status=progress
# 同时计算MD5和SHA-256校验和
sudo dd if=/dev/sdb bs=4M status=progress | tee >(md5sum > /mnt/external/disk_image.md5) >(sha256sum > /mnt/external/disk_image.sha256) > /mnt/external/disk_image.dd3. 创建分区镜像
# 复制特定分区
sudo dd if=/dev/sdb1 of=/mnt/external/partition1.dd bs=4M status=progress4. 高级用法
sudo dd if=/dev/sdb bs=4M status=progress | gzip -c > /mnt/external/disk_image.dd.gz# 发送方
sudo dd if=/dev/sdb bs=4M | nc -l 1234
# 接收方
nc source_ip 1234 | sudo dd of=/mnt/external/disk_image.dd bs=4M status=progress# 发送方
sudo dd if=/dev/sdb bs=4M | gzip -c | nc -l 1234
# 接收方
nc source_ip 1234 | gunzip -c | sudo dd of=/mnt/external/disk_image.dd bs=4M status=progress5. 安全注意事项
split命令将镜像分割成多个文件skip参数跳过已复制的数据seek参数指定从何处开始写入EnCase Forensic是专业级数字取证工具,提供全面的镜像创建和分析功能。
1. 启动新案例
2. 添加证据设备
3. 配置镜像选项
4. 开始镜像过程
5. 验证与完成
Autopsy是一款功能强大的开源数字取证平台,由美国国家标准与技术研究院(NIST)开发,提供全面的磁盘镜像分析功能。
1. 安装与配置
# Debian/Ubuntu系统
sudo apt-get install autopsy sleuthkit
# CentOS/RHEL系统
sudo yum install autopsy sleuthkit# 使用Homebrew安装
brew install --cask autopsy2. 创建新案例
3. 添加数据源
4. 主要分析模块
5. 高级分析功能
Sleuth Kit是Autopsy的底层命令行工具集,提供了强大的磁盘镜像分析功能,适合自动化分析和高级取证任务。
1. 基本工具概述
2. 基本使用流程
# 查看磁盘分区表
mmls disk_image.dd# 分析特定分区的文件系统
fsstat -o 2048 disk_image.dd# 列出根目录内容(包括已删除文件)
fls -o 2048 -r disk_image.dd# 从inode提取文件内容
icat -o 2048 disk_image.dd 1234 > recovered_file.txt3. 高级使用技巧
# 查找并恢复所有已删除的文本文件
fls -o 2048 -d -r disk_image.dd | grep "txt" | awk '{print $2}' | xargs -I {} icat -o 2048 disk_image.dd {} > recovered_{}.txt# 在未分配空间中搜索关键词
blkls -o 2048 disk_image.dd | grep -i "password"# 创建基本时间线
fls -o 2048 -r -m / disk_image.dd > bodyfile.txt
mactime -b bodyfile.txt > timeline.html4. 自动化分析脚本
#!/bin/bash
# 自动化磁盘镜像分析脚本
IMAGE="disk_image.dd"
OUTPUT_DIR="analysis_results"
OFFSET=2048
# 创建输出目录
mkdir -p $OUTPUT_DIR
# 步骤1: 保存分区表信息
mmls $IMAGE > $OUTPUT_DIR/partition_table.txt
# 步骤2: 获取文件系统统计
fsstat -o $OFFSET $IMAGE > $OUTPUT_DIR/fs_stat.txt
# 步骤3: 列出所有文件(包括已删除)
fls -o $OFFSET -r -m / $IMAGE > $OUTPUT_DIR/all_files.txt
# 步骤4: 创建时间线
mactime -b $OUTPUT_DIR/all_files.txt > $OUTPUT_DIR/timeline.html
# 步骤5: 提取用户目录下的文件
mkdir -p $OUTPUT_DIR/user_files
fls -o $OFFSET -r -p -m / disk_image.dd | grep -i "home\|user" > $OUTPUT_DIR/user_files_list.txt
# 步骤6: 搜索关键词
blkls -o $OFFSET $IMAGE | grep -i "password\|secret\|key" > $OUTPUT_DIR/keywords_found.txt
echo "分析完成,结果保存在 $OUTPUT_DIR 目录"FTK Imager不仅可以创建镜像,还提供强大的分析功能,适合快速查看和提取证据。
1. 基本分析操作
2. 高级功能
不同的取证工具有各自的优势和适用场景,选择合适的工具对于高效完成取证分析至关重要。
1. 工具对比表
工具名称 | 类型 | 价格 | 优势 | 劣势 | 适用场景 |
|---|---|---|---|---|---|
Autopsy | 开源 | 免费 | 功能全面,插件丰富,活跃社区 | 界面较复杂,学习曲线陡峭 | 学术研究,预算有限的调查 |
FTK Imager | 商业 | 免费版+专业版 | 界面友好,稳定性高,镜像格式兼容性好 | 高级功能需付费,批量处理能力有限 | 快速初步分析,镜像创建 |
EnCase | 商业 | 付费 | 法庭认可,功能最全面,支持远程分析 | 价格昂贵,资源消耗大 | 专业法律调查,企业安全团队 |
Sleuth Kit | 开源 | 免费 | 命令行操作,自动化能力强,轻量级 | 无图形界面,操作复杂 | 脚本自动化,高级取证分析 |
X-Ways Forensics | 商业 | 付费 | 响应速度快,强大的恢复能力,支持损坏文件系统 | 界面不够现代化,学习曲线较陡 | 专业数据恢复,高级取证调查 |
Redline | 商业 | 免费版+企业版 | 内存分析强大,威胁狩猎功能 | 磁盘分析功能相对较弱 | 恶意软件分析,威胁检测 |
2. 选择工具的考虑因素
文件恢复是磁盘镜像分析的核心任务之一,通过各种技术可以恢复已删除、损坏或隐藏的文件。
1. 基本文件恢复技术
Foremost(Linux)
# 基本用法
foremost -t jpg,pdf,doc -i disk_image.dd -o recovery_output
# 常用参数
# -t: 指定要恢复的文件类型
# -i: 输入镜像文件
# -o: 输出目录PhotoRec(跨平台)
# 启动交互式界面
photorec disk_image.dd
# 或使用命令行模式
photorec /log /d recovery_output disk_image.ddRecuva(Windows)
2. 高级文件恢复技术
3. 数据挖掘技术
# 提取所有可打印字符串
strings disk_image.dd > extracted_strings.txt
# 过滤和搜索特定字符串
strings disk_image.dd | grep -i "password\|login\|secret" > keywords.txt
# 提取长字符串,可能包含有价值信息
strings -n 10 disk_image.dd > long_strings.txt文件系统元数据包含丰富的信息,对取证分析至关重要,可以揭示文件操作历史和用户活动。
1. NTFS元数据分析
2. Ext4元数据分析
3. APFS元数据分析
4. 元数据分析工具
MFTECmd
# 分析MFT文件
MFTECmd.exe -f \path\to\$MFT -o output_directoryLog2timeline
# 创建超级时间线
log2timeline.py timeline.plaso disk_image.dd
psort.py -o l2tcsv timeline.plaso > timeline.csvBulk Extractor
# 提取所有类型的元数据和特征
bulk_extractor -o output_dir disk_image.ddAutopsy元数据模块
时间线分析是将所有事件按照时间顺序排列,有助于理解用户活动和系统变化的过程,对于重建犯罪场景或安全事件至关重要。
1. 时间线类型与创建
使用Plaso工具
# 提取时间线数据
log2timeline.py timeline.plaso disk_image.dd
# 生成CSV格式时间线
psort.py -o l2tcsv timeline.plaso > timeline.csv
# 按时间顺序排序并过滤特定时间范围
psort.py -o l2tcsv -q "date >= '2025-01-01' AND date <= '2025-01-31'" timeline.plaso > filtered_timeline.csv使用mactime
# 从bodyfile生成HTML时间线
mactime -b bodyfile.txt -d > timeline.html
# 生成CSV格式时间线
mactime -b bodyfile.txt -y 2 > timeline.csv使用Autopsy
2. 时间线分析技巧
3. 事件重建方法
假设我们在分析一个数据泄露案例,通过时间线分析可以重建以下事件链:
通过这种时间线分析,我们可以清晰地看到攻击路径和数据泄露的完整过程,为调查和法律诉讼提供有力支持。
在磁盘镜像分析中,经常会遇到隐藏的数据,这些数据可能是用户有意隐藏,也可能是恶意软件留下的痕迹。
1. 常见的隐藏数据技术
2. 隐藏数据检测工具
# 在Windows中使用dir命令
dir /r
# 使用专用工具 streams
tools\streams.exe -s C:\evidence
# 在Linux中使用ntfsstreams
ntfsstreams -l /mnt/windows_volume# 使用bulk_extractor提取Slack空间
bulk_extractor -o output_dir -S slacker=yes disk_image.dd
# 使用Autopsy的Slack空间分析功能
# 在文件视图中启用Slack空间显示# 使用blkls提取未分配块
blkls -o 2048 disk_image.dd > unallocated_blocks.raw
# 使用strings搜索未分配空间中的字符串
strings unallocated_blocks.raw > unallocated_strings.txt3. 高级隐藏技术检测
4. 隐藏数据提取方法
# 在Windows中使用more命令
more < file.txt:secret_data > extracted_data.txt
# 使用专用工具提取
streams -s -d C:\evidence在现代数字取证调查中,单纯依靠磁盘镜像分析已经无法满足需求,网络取证与磁盘镜像分析的结合可以提供更全面的证据。
1. 网络痕迹在磁盘镜像中的位置
NetworkHistory)2. 网络证据提取技术
使用Browser History View
# 从镜像中提取浏览器历史
BrowserHistoryView.exe /LoadFromExternalDrive "E:\evidence" /scomma "output\browser_history.csv"使用Plaso分析浏览器数据
# 分析Chrome历史记录
log2timeline.py --parsers chrome_history timeline.plaso "E:\evidence\Users\username\AppData\Local\Google\Chrome\User Data\Default\History"Windows注册表分析
# 使用RECmd提取网络配置
RECmd.exe -f "E:\evidence\Windows\System32\config\SYSTEM" -o "output\network_config" --plugin "NetworkProfileList"Linux网络配置文件分析
# 提取Linux网络配置
icat -o 2048 disk_image.dd 1234 > /etc/network/interfaces
cat /etc/network/interfaces3. 网络取证工具与磁盘镜像分析的集成
#!/usr/bin/env python3
# 网络证据自动化提取脚本
import os
import subprocess
import datetime
output_dir = f"network_evidence_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}"
os.makedirs(output_dir, exist_ok=True)
# 配置参数
disk_image = "disk_image.dd"
offset = 2048
user_profile = "Users/username"
# 提取浏览器数据
print("提取浏览器数据...")
os.makedirs(f"{output_dir}/browser_data", exist_ok=True)
# 提取Chrome历史记录
browser_history_inode = "123456" # 需要根据实际情况调整
subprocess.run([
"icat", "-o", str(offset), disk_image, browser_history_inode,
">", f"{output_dir}/browser_data/chrome_history.db"
], shell=True)
# 提取Firefox历史记录
firefox_history_inode = "123457" # 需要根据实际情况调整
subprocess.run([
"icat", "-o", str(offset), disk_image, firefox_history_inode,
">", f"{output_dir}/browser_data/firefox_places.sqlite"
], shell=True)
# 提取网络配置文件
print("提取网络配置文件...")
os.makedirs(f"{output_dir}/network_config", exist_ok=True)
# 提取Windows网络配置
if os.path.exists("/mnt/windows"):
subprocess.run([
"cp", "/mnt/windows/Windows/System32/drivers/etc/hosts",
f"{output_dir}/network_config/hosts"
])
# 提取电子邮件数据
print("提取电子邮件数据...")
os.makedirs(f"{output_dir}/email_data", exist_ok=True)
# 执行Plaso分析
print("使用Plaso分析网络相关数据...")
plaso_output = f"{output_dir}/plaso_timeline.plaso"
subprocess.run([
"log2timeline.py", "--parsers", "chrome_history,firefox_history,webhist",
plaso_output, disk_image
])
# 生成网络相关事件时间线
subprocess.run([
"psort.py", "-o", "l2tcsv",
"-q", "source_short IN ('CHROME', 'FIREFOX', 'WEBHIST')",
plaso_output, ">", f"{output_dir}/network_events.csv"
], shell=True)
print(f"网络证据提取完成,结果保存在 {output_dir} 目录")内存取证和磁盘镜像分析的结合可以提供更全面的证据,特别是对于检测活跃的恶意软件和网络攻击。
1. 内存与磁盘关联分析的重要性
2. 内存与磁盘数据的关联技术
3. 实用工具与技术
malfind插件检测恶意代码,在磁盘中查找关联文件# 从内存中提取DLL文件哈希
volatility -f memory.dmp --profile=Win10x64 dlllist | grep -i "system32" | awk '{print $6}' > memory_dll_hashes.txt
# 计算磁盘上相应文件的哈希
find /mnt/windows/Windows/System32 -name "*.dll" -exec sha256sum {} \; > disk_dll_hashes.txt
# 比对哈希值查找差异
grep -v -f memory_dll_hashes.txt disk_dll_hashes.txt > differences.txt# 从内存中提取网络连接
volatility -f memory.dmp --profile=Win10x64 netscan > memory_netscan.txt
# 从磁盘镜像中提取网络日志
icat -o 2048 disk_image.dd 12345 > windows_event_log.evtx
# 使用工具分析并关联这两类数据#!/usr/bin/env python3
# 内存与磁盘关联分析脚本
import os
import subprocess
import re
from datetime import datetime
# 配置
memory_dump = "memory.dmp"
disk_image = "disk_image.dd"
offset = 2048
profile = "Win10x64"
output_dir = f"memory_disk_correlation_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
os.makedirs(output_dir, exist_ok=True)
print("提取内存中的进程信息...")
# 提取进程列表
subprocess.run([
"volatility", "-f", memory_dump, f"--profile={profile}", "pslist",
">", f"{output_dir}/memory_processes.txt"
])
print("提取内存中的网络连接...")
# 提取网络连接
subprocess.run([
"volatility", "-f", memory_dump, f"--profile={profile}", "netscan",
">", f"{output_dir}/memory_network_connections.txt"
])
print("在磁盘镜像中查找相关文件...")
# 获取系统目录中的可执行文件列表
subprocess.run([
"fls", "-o", str(offset), "-r", "-m", "/", disk_image,
"|", "grep", "\\\\\\\\\\\\.exe\\\\$\\\\|\\\\\\\\\\\\.dll\\\\$",
">", f"{output_dir}/disk_executables.txt"
], shell=True)
print("分析进程与文件关联...")
# 提取进程加载的DLL
subprocess.run([
"volatility", "-f", memory_dump, f"--profile={profile}", "dlllist",
">", f"{output_dir}/memory_dlllist.txt"
])
print("创建关联报告...")
# 这里可以添加更复杂的分析逻辑
# 例如:提取可疑进程,在磁盘中查找对应文件,计算哈希值等
print(f"分析完成,结果保存在 {output_dir} 目录")随着虚拟化技术的广泛应用,虚拟化环境中的磁盘取证变得越来越重要。
1. 虚拟磁盘格式与特点
2. 虚拟磁盘取证工具
VMware DiskMount
# 挂载VMDK文件
vmware-mount.exe X: "C:\path\to\disk.vmdk"
# 卸载
vmware-mount.exe /d X:qemu-img
# 转换虚拟磁盘格式
qemu-img convert -f vmdk -O raw disk.vmdk disk.raw
# 检查虚拟磁盘信息
qemu-img info disk.vmdkVirtualBox工具
# 克隆虚拟磁盘
VBoxManage clonehd disk.vdi disk_copy.vdi --format VDI
# 调整虚拟磁盘大小
VBoxManage modifyhd disk.vdi --resize 10240Redline for Virtual Environments
Mount Image Pro
FTK Imager Virtual
3. 虚拟化环境取证技术
4. 虚拟磁盘分析最佳实践
随着取证分析规模的扩大和复杂性的增加,自动化和脚本开发变得越来越重要。
1. 自动化取证的优势
2. 取证自动化工具与框架
3. 取证脚本开发实践
#!/usr/bin/env python3
# 高级磁盘镜像分析脚本
import os
import subprocess
import json
import hashlib
from datetime import datetime
class DiskForensicsAnalyzer:
def __init__(self, disk_image, offset=0, output_dir=None):
self.disk_image = disk_image
self.offset = offset
self.timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
self.output_dir = output_dir or f"forensics_output_{self.timestamp}"
os.makedirs(self.output_dir, exist_ok=True)
def extract_partition_table(self):
print("提取分区表信息...")
output_path = os.path.join(self.output_dir, "partition_table.txt")
cmd = f"mmls -o {self.offset} {self.disk_image} > {output_path}"
subprocess.run(cmd, shell=True)
return output_path
def analyze_file_system(self, partition_offset=None):
print("分析文件系统信息...")
effective_offset = partition_offset or self.offset
output_path = os.path.join(self.output_dir, f"fs_stat_offset_{effective_offset}.txt")
cmd = f"fsstat -o {effective_offset} {self.disk_image} > {output_path}"
subprocess.run(cmd, shell=True)
return output_path
def extract_file_list(self, partition_offset=None):
print("提取文件列表(包括已删除文件)...")
effective_offset = partition_offset or self.offset
output_path = os.path.join(self.output_dir, f"file_list_offset_{effective_offset}.txt")
cmd = f"fls -o {effective_offset} -r -m / {self.disk_image} > {output_path}"
subprocess.run(cmd, shell=True)
return output_path
def create_timeline(self, file_list_path):
print("创建时间线...")
output_path = os.path.join(self.output_dir, "timeline.html")
cmd = f"mactime -b {file_list_path} -d > {output_path}"
subprocess.run(cmd, shell=True)
return output_path
def extract_key_files(self, patterns, partition_offset=None):
print("提取关键文件...")
effective_offset = partition_offset or self.offset
key_files_dir = os.path.join(self.output_dir, "key_files")
os.makedirs(key_files_dir, exist_ok=True)
file_list_path = self.extract_file_list(effective_offset)
results = []
with open(file_list_path, 'r') as f:
for line in f:
for pattern in patterns:
if pattern.lower() in line.lower():
try:
parts = line.split('|')
if len(parts) >= 3:
inode = parts[0].strip().split()[0] if '(' in parts[0] else parts[0].strip()
filename = parts[2].strip()
# 提取文件
safe_filename = "_".join(filename.split(os.path.sep)).strip('_')[:100]
output_file = os.path.join(key_files_dir, f"inode_{inode}_{safe_filename}")
cmd = f"icat -o {effective_offset} {self.disk_image} {inode} > {output_file}"
subprocess.run(cmd, shell=True)
# 计算哈希
if os.path.exists(output_file):
with open(output_file, 'rb') as f_hash:
file_hash = hashlib.sha256(f_hash.read()).hexdigest()
results.append({
'inode': inode,
'filename': filename,
'extracted_path': output_file,
'sha256': file_hash
})
except Exception as e:
print(f"处理行时出错: {line}. 错误: {e}")
# 保存结果
results_json = os.path.join(self.output_dir, "key_files_results.json")
with open(results_json, 'w') as f:
json.dump(results, f, indent=2)
return results_json
def search_keywords(self, keywords, partition_offset=None):
print("搜索关键词...")
effective_offset = partition_offset or self.offset
output_path = os.path.join(self.output_dir, "keyword_search_results.txt")
# 提取未分配空间
unallocated_path = os.path.join(self.output_dir, "unallocated.raw")
cmd = f"blkls -o {effective_offset} {self.disk_image} > {unallocated_path}"
subprocess.run(cmd, shell=True)
# 搜索关键词
with open(output_path, 'w') as f:
for keyword in keywords:
f.write(f"\n=== 搜索关键词: {keyword} ===\n")
cmd = f"strings {unallocated_path} | grep -i '{keyword}'"
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
f.write(result.stdout)
return output_path
def generate_report(self):
print("生成分析报告...")
report_path = os.path.join(self.output_dir, "forensics_report.md")
with open(report_path, 'w') as f:
f.write(f"# 磁盘镜像取证分析报告\n\n")
f.write(f"生成时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n")
f.write(f"分析镜像: {self.disk_image}\n\n")
f.write(f"偏移量: {self.offset}\n\n")
f.write("## 分析结果\n\n")
# 列出所有生成的文件
f.write("### 生成的文件\n\n")
for root, _, files in os.walk(self.output_dir):
for file in files:
if file != "forensics_report.md":
rel_path = os.path.relpath(os.path.join(root, file), self.output_dir)
f.write(f"- [{rel_path}]({rel_path})\n")
# 可根据需要添加更多报告内容
f.write("\n## 结论\n\n")
f.write("本报告提供了磁盘镜像的初步分析结果。详细发现需要进一步人工审查。\n")
return report_path
# 使用示例
if __name__ == "__main__":
analyzer = DiskForensicsAnalyzer(
disk_image="disk_image.dd",
offset=2048
)
analyzer.extract_partition_table()
analyzer.analyze_file_system()
file_list = analyzer.extract_file_list()
analyzer.create_timeline(file_list)
# 提取关键文件
key_patterns = ["password", "config", "log", "database", "certificate"]
analyzer.extract_key_files(key_patterns)
# 搜索关键词
keywords = ["password", "secret", "admin", "login", "key"]
analyzer.search_keywords(keywords)
# 生成报告
report = analyzer.generate_report()
print(f"分析完成!报告保存在: {report}")# 磁盘镜像分析PowerShell脚本
param(
[string]$DiskImage,
[int]$Offset = 0,
[string]$OutputDir = $null
)
# 设置输出目录
if (-not $OutputDir) {
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$OutputDir = "forensics_output_$timestamp"
}
New-Item -ItemType Directory -Force -Path $OutputDir | Out-Null
Write-Host "输出目录: $OutputDir"
# 函数: 提取分区表
function Extract-PartitionTable {
param(
[string]$Image,
[int]$ImgOffset,
[string]$OutputPath
)
Write-Host "提取分区表信息..."
& mmls -o $ImgOffset $Image | Out-File -FilePath $OutputPath -Encoding utf8
return $OutputPath
}
# 函数: 提取文件列表
function Extract-FileList {
param(
[string]$Image,
[int]$ImgOffset,
[string]$OutputPath
)
Write-Host "提取文件列表..."
& fls -o $ImgOffset -r -m / $Image | Out-File -FilePath $OutputPath -Encoding utf8
return $OutputPath
}
# 函数: 搜索关键词
function Search-Keywords {
param(
[string]$Image,
[int]$ImgOffset,
[string[]]$Keywords,
[string]$OutputPath
)
Write-Host "搜索关键词..."
$unallocatedPath = Join-Path $OutputDir "unallocated.raw"
# 提取未分配空间
& blkls -o $ImgOffset $Image | Out-File -FilePath $unallocatedPath -Encoding ascii
# 搜索每个关键词
"" | Out-File -FilePath $OutputPath -Encoding utf8
foreach ($keyword in $Keywords) {
Write-Host " 搜索: $keyword"
"`n=== 搜索关键词: $keyword ===" | Out-File -FilePath $OutputPath -Encoding utf8 -Append
& strings $unallocatedPath | Select-String -Pattern $keyword -CaseSensitive:$false |
Out-File -FilePath $OutputPath -Encoding utf8 -Append
}
return $OutputPath
}
# 主流程
Write-Host "开始磁盘镜像分析..."
# 提取分区表
$partitionTablePath = Join-Path $OutputDir "partition_table.txt"
Extract-PartitionTable -Image $DiskImage -ImgOffset $Offset -OutputPath $partitionTablePath
# 分析文件系统
$fsStatPath = Join-Path $OutputDir "fs_stat.txt"
& fsstat -o $Offset $DiskImage | Out-File -FilePath $fsStatPath -Encoding utf8
# 提取文件列表
$fileListPath = Join-Path $OutputDir "file_list.txt"
Extract-FileList -Image $DiskImage -ImgOffset $Offset -OutputPath $fileListPath
# 创建时间线
$timelinePath = Join-Path $OutputDir "timeline.html"
Write-Host "创建时间线..."
& mactime -b $fileListPath -d | Out-File -FilePath $timelinePath -Encoding utf8
# 搜索关键词
$keywords = @("password", "secret", "admin", "login", "key")
$searchResultsPath = Join-Path $OutputDir "keyword_search_results.txt"
Search-Keywords -Image $DiskImage -ImgOffset $Offset -Keywords $keywords -OutputPath $searchResultsPath
# 生成报告
$reportPath = Join-Path $OutputDir "forensics_report.md"
Write-Host "生成分析报告..."
@"
# 磁盘镜像取证分析报告
生成时间: $(Get-Date -Format "yyyy-MM-dd HH:mm:ss")
分析镜像: $DiskImage
偏移量: $Offset
## 分析结果
### 生成的文件
"@ | Out-File -FilePath $reportPath -Encoding utf8
Get-ChildItem -Path $OutputDir -Recurse -File | Where-Object { $_.Name -ne "forensics_report.md" } |
ForEach-Object {
$relPath = Resolve-Path -Path $_.FullName -Relative
"- [$relPath]($relPath)" | Out-File -FilePath $reportPath -Encoding utf8 -Append
}
@"
## 结论
本报告提供了磁盘镜像的初步分析结果。详细发现需要进一步人工审查。
"@ | Out-File -FilePath $reportPath -Encoding utf8 -Append
Write-Host "分析完成!报告保存在: $reportPath"#!/bin/bash
# 磁盘镜像取证分析bash脚本
set -e
echo "磁盘镜像取证分析脚本"
echo "======================="
# 参数处理
DISK_IMAGE=""
OFFSET=0
OUTPUT_DIR=""
while getopts "i:o:f:h" opt; do
case $opt in
i) DISK_IMAGE="$OPTARG" ;;
o) OFFSET="$OPTARG" ;;
f) OUTPUT_DIR="$OPTARG" ;;
h) echo "用法: $0 -i <磁盘镜像> -o <偏移量> -f <输出目录>" && exit 0 ;;
*) echo "用法: $0 -i <磁盘镜像> -o <偏移量> -f <输出目录>" && exit 1 ;;
esac
done
# 检查必要参数
if [ -z "$DISK_IMAGE" ]; then
echo "错误: 必须指定磁盘镜像文件"
exit 1
fi
# 设置默认输出目录
if [ -z "$OUTPUT_DIR" ]; then
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
OUTPUT_DIR="forensics_output_$TIMESTAMP"
fi
# 创建输出目录
mkdir -p "$OUTPUT_DIR"
echo "输出目录: $OUTPUT_DIR"
# 函数: 提取分区表
extract_partition_table() {
local output_path="$OUTPUT_DIR/partition_table.txt"
echo "提取分区表信息..."
mmls -o "$OFFSET" "$DISK_IMAGE" > "$output_path"
return 0
}
# 函数: 提取文件列表
extract_file_list() {
local output_path="$OUTPUT_DIR/file_list.txt"
echo "提取文件列表..."
fls -o "$OFFSET" -r -m / "$DISK_IMAGE" > "$output_path"
return 0
}
# 函数: 搜索关键词
search_keywords() {
local keywords=($@)
local output_path="$OUTPUT_DIR/keyword_search_results.txt"
local unallocated_path="$OUTPUT_DIR/unallocated.raw"
echo "搜索关键词..."
# 提取未分配空间
blkls -o "$OFFSET" "$DISK_IMAGE" > "$unallocated_path"
# 清空输出文件
> "$output_path"
# 搜索每个关键词
for keyword in "${keywords[@]}"; do
echo " 搜索: $keyword"
echo -e "\n=== 搜索关键词: $keyword ===" >> "$output_path"
strings "$unallocated_path" | grep -i "$keyword" >> "$output_path"
done
return 0
}
# 主流程
echo "开始磁盘镜像分析..."
# 提取分区表
extract_partition_table
# 分析文件系统
echo "分析文件系统..."
fsstat -o "$OFFSET" "$DISK_IMAGE" > "$OUTPUT_DIR/fs_stat.txt"
# 提取文件列表
extract_file_list
# 创建时间线
echo "创建时间线..."
mactime -b "$OUTPUT_DIR/file_list.txt" -d > "$OUTPUT_DIR/timeline.html"
# 搜索关键词
search_keywords "password" "secret" "admin" "login" "key"
# 生成报告
echo "生成分析报告..."
cat > "$OUTPUT_DIR/forensics_report.md" << EOF
# 磁盘镜像取证分析报告
生成时间: $(date +"%Y-%m-%d %H:%M:%S")
分析镜像: $DISK_IMAGE
偏移量: $OFFSET
## 分析结果
### 生成的文件
EOF
# 添加文件列表
find "$OUTPUT_DIR" -type f -not -path "*forensics_report.md*" | sort | while read file; do
rel_path=$(realpath --relative-to="$OUTPUT_DIR" "$file")
echo "- [$rel_path]($rel_path)" >> "$OUTPUT_DIR/forensics_report.md"
done
# 添加结论
cat >> "$OUTPUT_DIR/forensics_report.md" << EOF
## 结论
本报告提供了磁盘镜像的初步分析结果。详细发现需要进一步人工审查。
EOF
echo "分析完成!报告保存在: $OUTPUT_DIR/forensics_report.md"4. 自动化分析框架整合
磁盘镜像分析是数字取证的核心能力。通过规范的镜像创建、系统化的文件系统与未分配空间分析、严格的证据链维护与隐私合规,可以在不破坏原始证据的前提下,高效重建用户活动与事件时间线,为调查与诉讼提供可靠支撑。