文章目录
前言
在渗透测试过程中,当我们get shell后,常需要上传工具到目标机器,进一步的扩大战果。上传工具到靶机,就避免不了与目标机器的文件系统进行交互,这个过程就像是在雪地上行走,难免会留下各种痕迹,这些痕迹信息如果处理不好,将会被作为管理员取证溯源的重要依据。因此,在渗透测试过程中,我们要尽量减少与文件系统的交互,著名的渗透测试工具meterpreter就是依照这一思想设计的,它将各种模块加载到靶机的内存中,而不将文件写在磁盘上,这样做极大的减少了在系统上留下操作痕迹的几率。那么,当我们必须要上传某些工具到目标靶机时,如何能够躲避或者干扰管理员对文件系统信息的取证溯源呢,meterpreter又给了我们一个较好的解决方案,就是其priv模块下的timestop命令。
一、timestomp的使用前提
timestomp命令目前只支持windows操作系统,linux操作系统中暂无此命令支持,也就是说在使用windows/meterpreter/reverse_tcp这个payload时,才会有这个命令,这个命令是在meterpreter的priv模块中,如果没有加载模块,可以先用use或load命令,查看和加载相应模块。
load命令-l选项列出已经加载的模块
meterpreter > load -l
espia
extapi
incognito
kiwi
lanattacks
mimikatz
peinjector
powershell
priv
python
sniffer
stdapi
unhook
winpmem
使用load命令加载priv模块
meterpreter > load priv
[-] The 'priv' extension has already been loaded.
二、MACE时间
1、文件系统简述
我们可以将磁盘看成一个图书馆大楼,磁盘上的各种文件就是图书馆大楼内的各种图书,文件系统就是一个类似于图书管理系统的一套软件或图书管理流程。图书管理系统确保每本书从入馆到出馆,每一个环节都有据可查,同样,文件系统也是实现了类似的功能,对每个文件的读写删除以及各种属性更改等操作都做了详细的记录,因此有了前言里那句话,我们在与文件系统进行交互的时候,就像在雪地上行走,势必会留下脚印。
2、linux操作系统
linux操作系统一般使用ext3、ext4这类文件系统,可以使用stat命令查看文件的MAC时间,如下图。
root@kali2020:~# touch 1.txt
root@kali2020:~# stat 1.txt
File: 1.txt
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 801h/2049d Inode: 4196637 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-08-26 07:42:03.367678468 -0400
Modify: 2020-08-26 07:42:03.367678468 -0400
Change: 2020-08-26 07:42:03.367678468 -0400
Birth: -
access即访问时间,当我们用vim等编辑器打开文件,access时间会改变,同样我们使用cp命令拷贝文件时候也会改变access时间。如果有c语言基础,我们会知道,access这个动作实质上就是将文件读入内存中。
root@kali2020:~# vim 1.txt
root@kali2020:~# stat 1.txt
File: 1.txt
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 801h/2049d Inode: 4196637 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-08-26 07:43:58.051677030 -0400
Modify: 2020-08-26 07:42:03.367678468 -0400
Change: 2020-08-26 07:42:03.367678468 -0400
Birth: -
change对应的是文件属性的修改,如我们将1.txt加上可执行的属性,change time会改变,稍微对文件系统有深入了解的同学可以清楚,实质上change time的元数据是记录在文件系统的inode节点中的。下图以增加文件的可执行权限为例。
root@kali2020:~# chmod +x 1.txt
root@kali2020:~# stat 1.txt
File: 1.txt
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: 801h/2049d Inode: 4196637 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-08-26 07:43:58.051677030 -0400
Modify: 2020-08-26 07:42:03.367678468 -0400
Change: 2020-08-26 07:47:06.347674669 -0400
Birth: -
modify对应的是文件内容的改变,由于文件内容势必改变文件大小的属性,因此在修改modify时间的同时,change时间也经常随之改变,例如:
root@kali2020:~# echo 123 > 1.txt
root@kali2020:~# stat 1.txt
File: 1.txt
Size: 4 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 4196637 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-08-26 07:49:39.015672755 -0400
Modify: 2020-08-26 07:51:16.263671535 -0400
Change: 2020-08-26 07:51:16.263671535 -0400
Birth: -
对于linux操作系统,我们可以使用touch命令人为的修改文件的Access、Modify时间,而无法修改Change时间,同时meterpreter也对应的linux版本也没有对应的timestomp命令,因此,在取证过程中,Change时间还是具有很强的参考价值。
3、windows操作系统
windows操作系统一般使用ntfs文件系统,对于ntfs文件系统,其有MACE时间,我们可以使用meterpreter的-v选项查看。
meterpreter > timestomp 1.txt -v
[*] Showing MACE attributes for 1.txt
Modified : 2020-08-30 21:33:44 -0400
Accessed : 2020-08-30 21:33:44 -0400
Created : 2020-08-30 21:33:44 -0400
Entry Modified: 2020-08-30 21:33:45 -0400
这里的modify和access时间同linux操作系统中基本是相同的,就不再做阐述。主要说说Create和Entry Modified时间。Create时间很好理解,即文件的创建时间,它不同于linux操作系统中的change时间。而Entry Modified时间是在ntfs文件系统的主文件分区表MTF(master table file)存放,entry信息包含文件大小、名称、目录、磁盘位置、创建位置等信息。举个例子,当我们做磁盘整理时,某文件存储的磁盘块发生了改变,那么Entry Modified时间也会随之改变。同样,如果我们只做文件名的修改,Entry Modified时间也会发生改变。再例如,我们将文件名改变,MAC时间都不变,只有Entry Modified时间会改变。
meterpreter > timestomp 1.txt -v
[*] Showing MACE attributes for 1.txt
Modified : 2020-02-08 20:49:09 -0500
Accessed : 2020-02-08 20:49:09 -0500
Created : 2020-02-08 20:49:09 -0500
Entry Modified: 2020-08-31 20:19:17 -0400
三、timestomp使用详解
1.查看帮助文档
meterpreter > timestomp help
Usage: timestomp <file(s)> OPTIONS
OPTIONS:
-a <opt> Set the "last accessed" time of the file
-b Set the MACE timestamps so that EnCase shows blanks
-c <opt> Set the "creation" time of the file
-e <opt> Set the "mft entry modified" time of the file
-f <opt> Set the MACE of attributes equal to the supplied file
-h Help banner
-m <opt> Set the "last written" time of the file
-r Set the MACE timestamps recursively on a directory
-v Display the UTC MACE values of the file
-z <opt> Set all four attributes (MACE) of the file
2.使用-v选项查看文件信息
meterpreter > timestomp shell.exe -v
[*] Showing MACE attributes for shell.exe
Modified : 2020-03-20 20:08:06 -0400
Accessed : 2020-03-20 20:08:06 -0400
Created : 2020-03-20 20:08:06 -0400
Entry Modified: 2020-03-20 20:08:06 -0400
3.使用-f选项拷贝文件MACE时间
meterpreter > edit 2.txt
meterpreter > timestomp 2.txt -v
[*] Showing MACE attributes for 2.txt
Modified : 2020-08-31 20:30:53 -0400
Accessed : 2020-08-31 20:30:23 -0400
Created : 2020-08-31 20:30:23 -0400
Entry Modified: 2020-08-31 20:30:53 -0400
meterpreter > timestomp 1.txt -v
[*] Showing MACE attributes for 1.txt
Modified : 2020-02-08 20:49:09 -0500
Accessed : 2020-02-08 20:49:09 -0500
Created : 2020-02-08 20:49:09 -0500
Entry Modified: 2020-08-31 20:19:17 -0400
meterpreter > timestomp 2.txt -f 1.txt
[*] Pulling MACE attributes from 1.txt
[*] Setting specific MACE attributes on 2.txt
meterpreter > timestomp 2.txt -v
[*] Showing MACE attributes for 2.txt
Modified : 2020-02-08 20:49:09 -0500
Accessed : 2020-02-08 20:49:09 -0500
Created : 2020-02-08 20:49:09 -0500
Entry Modified: 2020-08-31 20:19:17 -0400
4.使用-m/-a/-c/-e修改文件MACE时间
-a修改accessed时间,其他参数同理。
meterpreter > timestomp 1.txt -a '03/12/2015 23:21:18'
[*] Setting specific MACE attributes on 1.txt
meterpreter > timestomp 1.txt -v
[*] Showing MACE attributes for 1.txt
Modified : 2020-02-08 20:49:09 -0500
Accessed : 2015-03-12 23:21:18 -0400
Created : 2020-02-08 20:49:09 -0500
Entry Modified: 2020-08-31 20:19:17 -0400
5.使用-b/-r使MACE时间显示清空
该功能暂时无法使用。官网给出的功能如下
使用-b命令后文件的时间显示丢失或混乱。-r同理。
总结
以上就是今天要讲的内容,本文仅仅简单介绍了timestomp命令的使用,而命令虽然简单,但其技术思想值得我们细细品究,以便将来在实战中熟练应用这些战术。