Win10中的USB日志
2023-8-28 10:55:1 Author: blog.nsfocus.net(查看原文) 阅读量:23 收藏

阅读: 21

一、USBDriveLog

参[1]

USBDriveLog是第三方工具,将Win10、Win11内置USB日志以更人性化的方式展示出来。该工具可查看U盘插入时间、拔出时间、容量、文件系统类型等等,还有许多可用作U盘指纹的数据。一般关心这几列数据:

Serial Number // U盘序列号
Plug Time // U盘插入时间
Unplug Time // U盘拔出时间
Capacity // U盘容量(大小)
File System // U盘文件系统类型

涉及USB设备取证场景时,USBDriveLog是一种选择。该工具只有一个EXE,无需安装,便携。为了显示Vendor Name、Product Name,需要额外下载usb.ids,与EXE置于同一目录。

缺省在线查看USB日志,但可以离线查看USB日志,只要找得着日志,比如这种位置:

X:\Windows\System32\winevt\Logs\Microsoft-Windows-Partition%4Diagnostic.evtx
X:\Windows\System32\winevt\Logs\Microsoft-Windows-Storsvc%4Diagnostic.evtx

若日志位于C盘,需要管理员权限访问这两个文件,离线查看时无所谓。具体操作如下:

File->Choose Data Source (F7)->Load from->External Folder

二、USB日志

USBDriveLog只支持Win10及以上版本OS,更低版本Windows不被支持,因为只有高版本Windows才有下列USB日志:

Microsoft-Windows-Partition/Diagnostic
Microsoft-Windows-Storsvc/Diagnostic

它们有各自的.evtx文件

$ wevtutil.exe gl Microsoft-Windows-Partition/Diagnostic
name: Microsoft-Windows-Partition/Diagnostic
enabled: true

logging:
logFileName: %SystemRoot%\System32\Winevt\Logs\Microsoft-Windows-Partition%4Diagnostic.evtx
retention: false

$ wevtutil.exe gl Microsoft-Windows-Storsvc/Diagnostic
name: Microsoft-Windows-Storsvc/Diagnostic
enabled: true

logging:
logFileName: %SystemRoot%\System32\Winevt\Logs\Microsoft-Windows-Storsvc%4Diagnostic.evtx
retention: false

1) 手工启用/禁用USB日志

这两种日志缺省启用中,反取证时,可以考虑禁用USB日志:

wevtutil.exe sl Microsoft-Windows-Partition/Diagnostic /e:false
wevtutil.exe sl Microsoft-Windows-Storsvc/Diagnostic /e:false

2) PowerShell查看USB日志

参[2]、[3]

2.1) Microsoft-Windows-Partition/Diagnostic

EventID为1006时对应U盘插入、拔出,要靠其他字段区分是哪种操作

————————————————————————–
$Filter =
@{
LogName = ‘Microsoft-Windows-Partition/Diagnostic’
ID = 1006
StartTime = [datetime]::Today.AddDays(-30)
EndTime = [datetime]::Today.AddDays(1)
}
$events = Get-WinEvent -FilterHashtable $Filter -ErrorAction SilentlyContinue |
Where-Object { $_.Properties[8].Value -ne 0 }
$final = “”
ForEach ( $event in $events )
{
$final += “$($event.TimeCreated) $($event.Properties[13].Value) $([math]::Round($event.Properties[8].Value/1GB))GB $($event.Properties[68].Value) $($event.Properties[71].Value) ”
$final += $event.Properties[72].Value[0..2] | ForEach-Object { $_.ToString(“X2”) }
$final += “`r`n”
}
$final | Out-String
————————————————————————–

上述脚本查看最近30天内U盘拔插日志,显示下列字段:

TimeCreated SerialNumber Capacity PartitionCount MbrBytes Mbr

比如:

08/23/2023 17:34:34 0123456789ABCDE 59GB 0 0 // 拔出U盘
08/23/2023 15:41:49 0123456789ABCDE 59GB 4 512 FA 33 C0 // 插入U盘
08/23/2023 14:51:05 0123456789ABCDE 59GB 0 0
08/23/2023 14:48:36 0123456789ABCDE 59GB 4 512 FA 33 C0

Mbr字段有值时,只显示前3字节。部分MBR前3字节如下:

$ rasm2 -a x86 -b 32 -s intel -D “FA 33 C0”
0x00000000 1 fa cli
0x00000001 2 33c0 xor eax, eax

但MBR前3字节有许多其他变种。

Get-WinEvent支持-FilterXml,也即支持”XPath Filter”,靠Properties[i]过滤不易维护,应该用”XPath Filter”。

2.2) Microsoft-Windows-Storsvc/Diagnostic

EventID为1001时对应U盘插入。

————————————————————————–
$Filter =
@{
LogName = ‘Microsoft-Windows-Storsvc/Diagnostic’
ID = 1001
StartTime = [datetime]::Today.AddDays(-30)
EndTime = [datetime]::Today.AddDays(1)
}
$events = Get-WinEvent -FilterHashtable $Filter -ErrorAction SilentlyContinue |
Where-Object { $_.Properties[12].Value -gt 0 -and $_.Properties[7].Value -ne “” }
$final = “”
ForEach ( $event in $events )
{
$final += “$($event.TimeCreated) $($event.Properties[5].Value) $([math]::Round($event.Properties[12].Value/1GB))GB $($event.Properties[7].Value)`r`n”
}
$final | Out-String
————————————————————————–

上述脚本查看最近30天内U盘插入日志,显示下列字段:

TimeCreated SerialNumber Size FileSystem

比如:

08/23/2023 15:41:51 0123456789ABCDE 59GB NTFS
08/23/2023 14:48:37 0123456789ABCDE 59GB NTFS

USBDriveLog.exe合并Partition与Storsvc日志,将U盘插入、拔出时间、文件系统等信息在一行内显示,更直观。

3) eventvwr.msc查看USB日志

eventvwr.msc – Applications and Services Logs – Microsoft – Windows –
Partition – Diagnostic
Storsvc – Diagnostic

eventvwr.msc支持”XPath Filter”,比如:

————————————————————————–
Filter Current Log
XML
Edit query manually
————————————————————————–
<QueryList>
<Query Id=”0″ Path=”Microsoft-Windows-Storsvc/Diagnostic”>
<Select Path=”Microsoft-Windows-Storsvc/Diagnostic”>
*[System/EventID=1001]
</Select>
</Query>
</QueryList>
————————————————————————–

若”XPath Filter”有语法错,会提示”The specified query is invalid”。

假设<Query>中有多个<Select>,它们之间是逻辑或的关系。Windows Event Log只支持XPath 1.0的子集,只支持position、Band、timediff函数,其余函数不被支持,比如starts-with、contains函数。

上面只是简单示例,”XPath Filter”可以写得很复杂,比如对SerialNumber、Size、FileSystem组合过滤,感兴趣了可以放狗找相关资料,参[4]。

4) wevtutil.exe查看USB日志

只显示4条日志:

wevtutil.exe qe Microsoft-Windows-Partition/Diagnostic /rd:true /c:4 /f:text

wevtutil.exe可以离线使用:

wevtutil.exe qe “C:\Windows\System32\winevt\Logs\Microsoft-Windows-Partition%4Diagnostic.evtx” /lf:true /rd:true /c:4 /f:text

其/q参数支持”XPath Filter”。

参考资源

[1] USBDriveLog
https://www.nirsoft.net/utils/usb_drive_log.html
http://www.linux-usb.org/usb.ids

[2] USB storage forensics in Win10 #1 – Events – [2019-08-03]
https://www.senturean.com/posts/19_08_03_usb_storage_forensics_1/

[3] Get-WinEvent
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.diagnostics/get-winevent

Creating Get-WinEvent queries with FilterHashtable
https://learn.microsoft.com/en-us/powershell/scripting/samples/creating-get-winevent-queries-with-filterhashtable

[4] Consuming Events (Windows Event Log)
https://learn.microsoft.com/en-us/windows/win32/wes/consuming-events

[5] wevtutil
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/wevtutil

版权声明
本站“技术博客”所有内容的版权持有者为绿盟科技集团股份有限公司(“绿盟科技”)。作为分享技术资讯的平台,绿盟科技期待与广大用户互动交流,并欢迎在标明出处(绿盟科技-技术博客)及网址的情形下,全文转发。
上述情形之外的任何使用形式,均需提前向绿盟科技(010-68438880-5462)申请版权授权。如擅自使用,绿盟科技保留追责权利。同时,如因擅自使用博客内容引发法律纠纷,由使用者自行承担全部法律责任,与绿盟科技无关。


文章来源: https://blog.nsfocus.net/win10usb/
如有侵权请联系:admin#unsafe.sh