提交 7b38f3dd 编写于 作者: Z zzz

readme

上级 92ba12a2
...@@ -180,6 +180,28 @@ sudo lsof -p $autopsy_pid | grep "\.so" | grep "tsk" ...@@ -180,6 +180,28 @@ sudo lsof -p $autopsy_pid | grep "\.so" | grep "tsk"
``` ```
##### autopsy 中 jni.so依赖 (linux)
```bash
cd /app/autopsy-home/autopsy-4.20.0/
find . -name *.jar | xargs -I% sh -c "jar -tvf % |grep NATIV && echo %"
# NATIVELIBS/amd64/linux/libtsk_jni.so
#./autopsy/modules/ext/sleuthkit-4.12.0.jar
unzip ./autopsy/modules/ext/sleuthkit-4.12.0.jar -d /tmp/t/
readelf -d /tmp/t/NATIVELIBS/x86_64/linux/libtsk_jni.so | grep tsk
# 0x0000000000000001 (NEEDED) 共享库:[libtsk.so.19]
ldconfig -p | grep tsk
#libtsk_jni.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libtsk_jni.so.0
#libtsk_jni.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libtsk_jni.so
#libtsk.so.19 (libc6,x86-64) => /lib/x86_64-linux-gnu/libtsk.so.19
#libtsk.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libtsk.so #关注这一条
```
> /lib/x86_64-linux-gnu/libtsk.so 是被 [autopsy下载页面](https://www.autopsy.com/download/) 中的 [安装包 sleuthkit-java_4.12.0-1_amd64.deb](https://github.com/sleuthkit/sleuthkit/releases/download/sleuthkit-4.12.0/sleuthkit-java_4.12.0-1_amd64.deb) 安装到ubuntu22.04中的
> 所以 linux下的libtsk.so 对应 windows下的什么?
## 调试autospy(java) ## 调试autospy(java)
...@@ -188,11 +210,13 @@ sudo lsof -p $autopsy_pid | grep "\.so" | grep "tsk" ...@@ -188,11 +210,13 @@ sudo lsof -p $autopsy_pid | grep "\.so" | grep "tsk"
# 以调试模式启动autopsy , # 以调试模式启动autopsy ,
# 注意 跟上面的启动命令相比 只是在后面加了 -J-agentlib:jdwp=.... # 注意 跟上面的启动命令相比 只是在后面加了 -J-agentlib:jdwp=....
sudo /app/autopsy-home/autopsy-4.20.0/platform/lib/nbexec --jdkhome /usr/lib/jvm/bellsoft-java8-full-amd64/ --clusters /app/autopsy-home/autopsy-4.20.0/autopsy:/app/autopsy-home/autopsy-4.20.0/CoreTestLibs:/app/autopsy-home/autopsy-4.20.0/harness:/app/autopsy-home/autopsy-4.20.0/java: --userdir /home/zz/.autopsy/dev --branding autopsy -J-Xms24m -J-Xmx4G -J-Xverify:none -J-XX:+UseG1GC -J-XX:+UseStringDeduplication -J-Dprism.order=sw -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005
sudo /app/autopsy-home/autopsy-4.20.0/bin/../platform/lib/nbexec --jdkhome /usr/lib/jvm/bellsoft-java8-full-amd64/ --clusters /app/autopsy-home/autopsy-4.20.0/autopsy:/app/autopsy-home/autopsy-4.20.0/CoreTestLibs:/app/autopsy-home/autopsy-4.20.0/harness:/app/autopsy-home/autopsy-4.20.0/java: --userdir /root/.autopsy/dev --branding autopsy -J-Xms24m -J-Xmx4G -J-Xverify:none -J-XX:+UseG1GC -J-XX:+UseStringDeduplication -J-Dprism.order=sw -J-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:5005
#注意 -agentlib:jdwp=... 前面加了 -J 显然 这是表示 当前的程序nbexec 传递给jvm的参数 #注意 -agentlib:jdwp=... 前面加了 -J 显然 这是表示 当前的程序nbexec 传递给jvm的参数
#注意 sudo ... /root/.autopsy 正常启动 , 而 sudo ... /home/zz/.autopsy 会启动到一半并卡住不动 即启动失败
#autopsy正常启动 #autopsy正常启动
``` ```
### 以jdb或netbeans或idea等连接到上面的调试端口 ### 以jdb或netbeans或idea等连接到上面的调试端口
...@@ -403,14 +427,14 @@ for pid in `pidof java `; do grep openide /proc/$pid/cmdline && autopsy_pid=$pi ...@@ -403,14 +427,14 @@ for pid in `pidof java `; do grep openide /proc/$pid/cmdline && autopsy_pid=$pi
``` ```
###### 3. gdb带调试脚本附加到该autopsy的jvm进程 ###### 3. gdb带调试脚本附加到该autopsy的jvm进程
```bash ```bash
sudo gdb -p $autopsy_pid -command=./gdb_debug_script/autopsy_jvm_libtsk_so.gs sudo gdb -p $autopsy_pid -command=/pubx/disk-recovery/idea_debug_autopsy/gdb_debug_script/autopsy_jvm_libtsk_so.gs
``` ```
###### 4. 调试脚本产生的日志输出文件 ###### 4. 调试脚本产生的日志输出文件
> 调试脚本产生的日志输出文件: /pubx/disk-recovery/idea_debug_autopsy/autopsy_gdb.log > 调试脚本产生的日志输出文件: /pubx/disk-recovery/idea_debug_autopsy/autopsy_gdb.log
# 基于sleuthkit的数据恢复程序 # 数据恢复sleuthkit+GUI(msWin10X64)
## 基于sleuthkit的磁盘或分区列出、文件写db ## 基于sleuthkit的磁盘或分区列出、文件写db
### 自己基于autopsy的sleuthkit_jni整理的 ### 自己基于autopsy的sleuthkit_jni整理的
> 手工写好的:[idea_debug_autopsy的标签tag_diskOrPartition_list_then_save_file_list_to_sqlite3db_by_jni_sleuthkit](https://gitcode.net/pubz/disk-recovery/sleuthkit.org/idea_debug_autopsy/-/tree/tag_diskOrPartition_list_then_save_file_list_to_sqlite3db_by_jni_sleuthkit) > 手工写好的:[idea_debug_autopsy的标签tag_diskOrPartition_list_then_save_file_list_to_sqlite3db_by_jni_sleuthkit](https://gitcode.net/pubz/disk-recovery/sleuthkit.org/idea_debug_autopsy/-/tree/tag_diskOrPartition_list_then_save_file_list_to_sqlite3db_by_jni_sleuthkit)
...@@ -443,7 +467,7 @@ sl-vc140-vc141-x86_64.1.1.5\build\native\openssl-vc140-vc141-x86_64.targets. ...@@ -443,7 +467,7 @@ sl-vc140-vc141-x86_64.1.1.5\build\native\openssl-vc140-vc141-x86_64.targets.
2. vs2017 右击 "Solution 'tsk-win' " --> Rebuild 2. vs2017 右击 "Solution 'tsk-win' " --> Rebuild
3. vs2017 tsk_loaddb右击-->"Set as Startup Project" 3. vs2017 tsk_loaddb右击-->"Set as Startup Project"
4. 调试目标:```tsk_loaddb.exe -d e:\tmp\g.db \\.\G:```, 注意 -d e:\tmp\g.db 和 \\.\G: 位置不能换,否则tsk_loadb.exe解析不出来。 4. 调试目标:```tsk_loaddb.exe -d e:\tmp\g.db \\.\G:```, 注意 -d e:\tmp\g.db 和 \\.\G: 位置不能换,否则tsk_loadb.exe解析不出来。
5. vs2017 tsk_loaddb右击-->Property-->Debugging-->Command Arguments: ```tsk_loaddb.exe -d e:\tmp\g.db \\.\G:``` 5. vs2017 tsk_loaddb右击-->Property-->Debugging-->Command Arguments: ```-d e:\tmp\g.db \\.\G:```
6. 用sqlite-db-browser打开e:\tmp\g.db, 其中表tsk_files中若干行记录,每条记录表示一个文件 6. 用sqlite-db-browser打开e:\tmp\g.db, 其中表tsk_files中若干行记录,每条记录表示一个文件
...@@ -453,16 +477,319 @@ sl-vc140-vc141-x86_64.1.1.5\build\native\openssl-vc140-vc141-x86_64.targets. ...@@ -453,16 +477,319 @@ sl-vc140-vc141-x86_64.1.1.5\build\native\openssl-vc140-vc141-x86_64.targets.
3. vs2017 tsk_recover右击-->"Set as Startup Project" 3. vs2017 tsk_recover右击-->"Set as Startup Project"
4. 复制任一文件(这里为adv3.csv)到G:\, 再shift delete删除该文件 4. 复制任一文件(这里为adv3.csv)到G:\, 再shift delete删除该文件
5. 调试目标:```tsk_recover.exe \\.\G: d:\tmp\recover``` 5. 调试目标:```tsk_recover.exe \\.\G: d:\tmp\recover```
6. vs2017 tsk_recover右击-->Property-->Debugging-->Command Arguments: ```tsk_recover.exe \\.\G: d:\tmp\recover``` 6. vs2017 tsk_recover右击-->Property-->Debugging-->Command Arguments: ```\\.\G: d:\tmp\recover```
7. 目录 d:\tmp\recover\下有被恢复出的文件_dv3.csv,经比较,_dv3.csv和adv3.csv的内容是相同的。即正常恢复。 7. 目录 d:\tmp\recover\下有被恢复出的文件_dv3.csv,经比较,_dv3.csv和adv3.csv的内容是相同的。即正常恢复。
8. **可见,给sleuthkit\win32\tsk_recover\tsk_recover.vcxproj套上一层GUI 就是一个最简易的数据恢复软件。** 8. **可见,给sleuthkit\win32\tsk_recover\tsk_recover.vcxproj套上一层GUI 就是一个最简易的数据恢复软件。**
## tsk_recover.dll
0. 直接从tsk_recover.exe 改造为 tsk_recover.dll
## qt5
> qt 选vs2017 编译器,需要 win10sdk中的调试器 ,否则无法调试,详见下图:
> ![在这里插入图片描述](https://img-blog.csdnimg.cn/cf61c7bf3cd844bcbdaa2064e3be680e.png)
## pyside2(pyqt类似物)
0. [使用QtDesigner](https://github.com/se7enXF/pyside2/blob/master/Lesson_02.%E4%BD%BF%E7%94%A8QtDesigner/README.md)
```bash
#打开anaconda 命令行
pip install pyside2
%appdata%\Python\Python310\Scripts\pyside2-designer.exe
#即可打开qt界面设计器 qt designer
```
## 物理磁盘列表 (sleuthkit无此代码、autopsy不全且恶心)
### 简介:
1. sleuthkit 中只有 拿某磁盘的分区列表 的代码(就在本文中),没有 拿物理磁盘列表 的代码
2. autopsy中以java且很偷懒的样式 :windows下拿不到物理磁盘列表、只拿到分区列表;linux下枚举/dev/下文件以拿到磁盘列表、分区列表
### 结论: 拿物理磁盘列表 代码 得自己写了
> 拿物理磁盘列表 以及 某磁盘下分区列表的 代码 只能自己写了
#### 详细描述 sleuthkit、autopsy关于 拿物理磁盘列表 :
#### 1. sleuthkit中 没有拿物理磁盘列表 的代码,
#### 2. autopsy中用java且偷懒且windows不全、linux全
> 但autopsy以java: win32下拿分区列表(没有物理磁盘列表)、linux下拿物理磁盘列表和分区列表,但样式很偷懒,基本没法用。具体如下:[\Core\src\org\sleuthkit\autopsy\coreutils\PlatformUtil.java]()
```java
//PlatformUtil.java
public static List<LocalDisk> getPhysicalDrives() {//第384行
List<LocalDisk> drives = new ArrayList<>();
// Windows drives
if (PlatformUtil.isWindowsOS()) {
//如果是windows操作系统, 直接依次读文件 \\.\PhysicalDrive0 , \\.\PhysicalDrive1, \\.\PhysicalDrive2, ...
//人为拍脑袋认为,当发生4次读异常,则所有分区都读出来了。
// windows下 文件路径 \\.\PhysicalDriveK 表示 第K个分区(第K个逻辑盘),如果读该路径能读出内容,则间接表示有该分区,这是很偷懒的办法
//应该调用某个api完成才是正道
int n = 0;
int breakCount = 0;
while (true) {
String path = "\\\\.\\PhysicalDrive" + n; //NON-NLS 第K个分区 \\.\PhysicalDriveK
if (canReadDrive(path)) {
try {
drives.add(new LocalDisk("Drive " + n, path, SleuthkitJNI.findDeviceSize(path))); //NON-NLS
} catch (TskCoreException ex) {
// Don't add the drive because we can't read the size
}
n++;
} else {
if (breakCount > 4) { // Give up after 4 non-existent drives
break;
}
breakCount++;
n++;
}
}
// Linux drives
} else {
//如果是Linux操作系统,直接列出设备目录 /dev/下所有文件,找hd、sd、disk开头的 且可读的 且 长度小于5的,
//这些是 磁盘或分区, 磁盘 比如 /dev/hda ,分区比如 /dev/hda1 ,
//Linux下这样是可以拿到磁盘列表、分区列表的,但这显然很偷懒,应该调用某个api完成才是正道。
File dev = new File("/dev/");
File[] files = dev.listFiles();
for (File f : files) {
String name = f.getName();
if ((name.contains("hd") || name.contains("sd") || name.contains("disk")) && f.canRead() && name.length() <= 5) { //NON-NLS
String path = "/dev/" + name; //NON-NLS
if (canReadDrive(path)) {
try {
drives.add(new LocalDisk(path, path, SleuthkitJNI.findDeviceSize(path)));
} catch (TskCoreException ex) {
// Don't add the drive because we can't read the size
}
}
}
}
}
return drives;
}
```
## 自己写的 物理磁盘列表、分区列表
1. [正常列出物理磁盘: sleuthkit/win32/win32PhyDiskList/win32PhyDiskList.cpp](https://gitcode.net/pubz/disk-recovery/sleuthkit.org/sleuthkit/-/commit/8dfcdf87d2406fb11fa19e55b1b0d1feebee1b24)
2. 参考
> [参考](https://stackoverflow.com/a/7584873),
[how-to-get-a-list-of-physical-storage-devices](https://stackoverflow.com/questions/7584627/how-to-get-a-list-of-physical-storage-devices)
## 某磁盘的分区表
> [\tsk\vs\tsk_vs.h](https://gitcode.net/pubz/disk-recovery/sleuthkit.org/sleuthkit/-/blob/z/sleuthkit-4.12.0/tsk/vs/tsk_vs.h)
```cpp
struct TSK_VS_INFO {//第65行
//...
TSK_VS_PART_INFO *part_list; //第75行 ///< Linked list of partitions //分区链表
//...
};
```
> [tools/vstools/mmcat.cpp](https://gitcode.net/pubz/disk-recovery/sleuthkit.org/sleuthkit/-/blob/z/sleuthkit-4.12.0/tools/vstools/mmcat.cpp)
```cpp
//...
int
main(int argc, char **argv1)//第42行
{
TSK_VS_INFO *vs; //第44行 //vs->part_list 是 分区链表
TSK_PNUM_T pnum; //第50行 //uint32_t pnum; //pnum 分区编号
const TSK_VS_PART_INFO *vs_part; //第52行
if (tsk_parse_pnum(argv[argc - 1], &pnum)) {//第150行 pnum是命令行中给定的
exit(1);
}
/* process the partition tables */
if ((vs = tsk_vs_open(img, imgaddr * img->sector_size, vstype)) == NULL) {//第156行 //拿分区表
//...
exit(1);
}
if (pnum >= vs->part_count) {//pnum是命令行中给定的
//...
exit(1);
}
vs_part = tsk_vs_part_get(vs, pnum); //第171行 //拿分区
if (vs_part == NULL) {
tsk_fprintf(stderr, "Error looking up partition\n");
exit(1);
}
//...
tsk_vs_close(vs);
tsk_img_close(img);
//...
}//第209行 //main结尾
```
## 目录遍历、文件遍历(带动作)
### [samples\callback-style.cpp](https://gitcode.net/pubz/disk-recovery/sleuthkit.org/sleuthkit/-/blob/z/sleuthkit-4.12.0/samples/callback-style.cpp)
1. tsk_fs_dir_walk : 遍历目录 ,对每个目录执行动作函数
2. tsk_fs_file_walk : 遍历文件, 对每个文件执行动作函数
> sleuth/win32/下基本是应用程序,都有main函数,其中许多应用程序的main基本是近距离调用 目录遍历tsk_fs_dir_walk 、文件遍历tsk_fs_file_walk ,即这些应用可以看作是 目录遍历时的动作、文件遍历的动作 组成的。
> 具体如下:
```cpp
static uint8_t
proc_fs(TSK_IMG_INFO * img_info, TSK_OFF_T start)
{
//...
/* Walk the files, starting at the root directory */
if (tsk_fs_dir_walk(fs_info, fs_info->root_inum,
(TSK_FS_DIR_WALK_FLAG_ENUM) (TSK_FS_DIR_WALK_FLAG_RECURSE),
dir_act, NULL)) {//从根目录root_inum开始遍历文件系统fs_info的目录,对每个目录执行动作函数dir_act
//错误处理
return 1;
}
//...
}//proc_fs结尾
```
> 目录的动作函数dir_act
```cpp
static TSK_WALK_RET_ENUM
dir_act(TSK_FS_FILE * fs_file, const char *path, void * /*ptr*/)
{//目录的动作函数dir_act
/* Ignore NTFS System files */
/* If the name has corresponding metadata, then walk it */
if (fs_file->meta) {
proc_file(fs_file, path);//内部调用了遍历文件
}
return TSK_WALK_CONT;
}
static uint8_t
proc_file(TSK_FS_FILE * fs_file, const char *path)
{
/* Note that we could also cycle through all of the attributes in the
* file by using one of the tsk_fs_attr_get() functions and walking it
* with tsk_fs_attr_walk(). See the File Systems section of the Library
* User's Guide for more details:
* http://www.sleuthkit.org/sleuthkit/docs/api-docs/ */
if (tsk_fs_file_walk
(fs_file, (TSK_FS_FILE_WALK_FLAG_ENUM) myflags, file_act,
//遍历目录fs_file下的文件,对每个文件执行动作函数file_act
(void *) &md)) {
//...
}
return 0;
}
```
## sleuthkit代码理解 ## sleuthkit代码理解
> [Design_Documents](http://wiki.sleuthkit.org/index.php?title=Design_Documents) > [Design_Documents](http://wiki.sleuthkit.org/index.php?title=Design_Documents)
> [Developer's_Guide](http://wiki.sleuthkit.org/index.php?title=Developer%27s_Guide) > [Developer's_Guide](http://wiki.sleuthkit.org/index.php?title=Developer%27s_Guide)
### Nat==native (jni方法名)
[bindings\java\jni\dataModel_SleuthkitJNI.cpp](https://gitcode.net/pubz/disk-recovery/sleuthkit.org/sleuthkit/-/blob/z/sleuthkit-4.12.0/bindings/java/jni/dataModel_SleuthkitJNI.cpp)
```cpp
//...
JNIEXPORT jlong JNICALL
Java_org_sleuthkit_datamodel_SleuthkitJNI_openVolNat(JNIEnv * env, //第1394行, 末尾的Nat是native的缩写。
//native是java的关键字 ,java中native表示本地方法,即c++写的jni方法。
jclass obj, jlong a_vs_info, jlong vol_id)
{
//...
}
//...
```
### jopen==JournalOpen
> [\sleuthkit\tools\fstools\jls.cpp](https://gitcode.net/pubz/disk-recovery/sleuthkit.org/sleuthkit/-/blob/z/sleuthkit-4.12.0/tools/fstools/jls.cpp)
```cpp
//...
int
main(int argc, char **argv1)
{
//...
if (fs->jopen == NULL) {//第178行
tsk_fprintf(stderr,
"Journal support does not exist for this file system\n"); //从这里可以看出jopen中的j意思是Journal
//...
}
//...
}//main结束
//...
```
### pool volumes
> pvol_block == pool_volume_block,
```bash
cd /d D:\disk-recovery\sleuthkit\win32\Release\
blkstat
#...
#usage: blkstat [-vV] [-f fstype] [-i imgtype] [-b dev_sector_size] [-o imgoffset] [-P pooltype] [-B pool_volume_block] image [images] addr
#...
-P pooltype: Pool container type (use '-P list' for supported types)
-B pool_volume_block: Starting block (for pool volumes only)
#...
blkstat -P list
#Supported file system types:
# auto (auto-detect)
# apfs (APFS container)
# lvm (Linux LVM volume group)
```
> **由此可见 所谓 pool volumes ,就是指 volume group 即 volume 列表,只有LVM和apfs能支持 volume列表**
# 数据恢复sleuthkit+GUI(macos-10.13.6)
> "# 数据恢复sleuthkit+GUI(msWin10X64)" 表述过的,这里不再重复表述
## vbox安装macos-high-sierra-10.13.6.iso
1. 下载并安装:[VirtualBox-7.0.8-156879-Win.exe](https://download.virtualbox.org/virtualbox/7.0.8/VirtualBox-7.0.8-156879-Win.exe)
2. 下载:[macOS/macos-high-sierra-10.13.6.iso](https://pan.baidu.com/disk/main?from=homeSave#/index?category=all&path=%2FmacOS)
```bash
md5sum.exe macos-high-sierra-10.13.6.iso
#af8d962f691cc615d28e1f2498aaf882 *macos-high-sierra-10.13.6.iso
```
> 注意 : macOS High Sierra 10.13.6 是2017年发行的
3. macOS安装过程中报错"应用程序副本已损坏",解决:
> 修改真机win10系统时间为2017年,且vbox中建立的虚拟机"macos-10.13.6"的网络要断开,否则
4. 参考 [Virtual Box 安装macOS High Sierra 10.13.6](https://www.shanyemangfu.com/virtual-box-macos.html)
```bash
#vbox启动macos-high-sierra-10.13.6.iso 卡在"end randomseed"解决:
D:\VirtualBox\VBoxManage modifyvm "macos-10.13.6" --cpu-profile "Intel Core i7-6700K"
#启动iso,大致停在 "Mac /Libaray/LauchAgents error=2 no such file or directory",后循环重启:
D:\VirtualBox\VBoxManage setextradata "macos-10.13.6" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "iMac11,3"
D:\VirtualBox\VBoxManage setextradata "macos-10.13.6" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
D:\VirtualBox\VBoxManage setextradata "macos-10.13.6" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Iloveapple"
D:\VirtualBox\VBoxManage setextradata "macos-10.13.6" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
D:\VirtualBox\VBoxManage setextradata "macos-10.13.6" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1
```
5. 启动虚拟机,选中文,分区工具 --> 磁盘抹除,关掉分区工具,安装OS, 正常进入apple 安装界面,自己重启后,继续安装,结束
6. 注册apple id: prg,rmz,prgrmz07@163.com, (PWD*xxx)0
7. 安装xcode
> 适合mac-10.13.6的xcode版本: [xcode10.1](https://xcodereleases.com/)
> [搜索Xcode 10](https://developer.apple.com/download/all/?q=Xcode%2010), 往下拉,找到 下载地址[Xcode_10.1.xip](https://download.developer.apple.com/Developer_Tools/Xcode_10.1/Xcode_10.1.xip)
## 识别不了的.iso
> vbox直接拒绝启动:
1. ISO 格式原版可引导镜像Install-macOS-Catalina-10.15.7_19H15.iso
2. [macOS镜像列表页面](https://sysin.org/blog/macOS/) , [macOS High Sierra 10.13.6 (17G66) 下载 ](https://sysin.org/blog/macOS-High-Sierra/)
# 其他 # 其他
#### 正式编译 调试版 libtsk.so #### 正式编译 调试版 libtsk.so
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册