Windowsセキュリティ監査とインシデント検出
はじめに
Windows環境でのセキュリティ監査とインシデント検出は、組織のセキュリティ体制を強化する上で重要です。この記事では、Windowsの監査機能と異常検出方法について解説します。
Windowsセキュリティ監査の基礎
監査ポリシーの設定
Windowsでは、セキュリティイベントの監視と記録を行うことができます。
グループポリシーでの設定:
コンピューターの構成 → Windows の設定 → セキュリティの設定 → ローカル ポリシー → 監査ポリシー
重要な監査イベント
| イベントID | 説明 |
|---|---|
| 4624 | ログオン成功 |
| 4625 | ログオン失敗 |
| 4648 | 明示的な資格情報の使用 |
| 4672 | 特権ログオン |
| 4720 | ユーザーアカウント作成 |
| 4724 | アカウントパスワードの変更試行 |
| 4768 | Kerberos認証チケット要求 |
| 4771 | Kerberos認証失敗 |
PowerShellによる監査
セキュリティイベントの監視
HLJSPOWERSHELL
# ログオン失敗の検出(過去24時間)
$StartTime = (Get-Date).AddHours(-24)
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4625
StartTime=$StartTime
} | Select-Object TimeCreated, Properties |
Format-Table -AutoSize
# 異常なログオンパターンの検出
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4624
} | Where-Object {
$_.Properties[8].Value -eq 10 # リモートデスクトップ
} | Group-Object -Property { $_.Properties[5].Value } |
Where-Object { $_.Count -gt 10 } |
Select-Object Name, Count
ファイルシステム監査
HLJSPOWERSHELL
# 重要なディレクトリの変更監査
$Path = "C:\ImportantData"
$AuditRule = New-Object System.Security.AccessControl.FileSystemAuditRule(
"Everyone",
"WriteData, Delete",
"ContainerInherit, ObjectInherit",
"None",
"Success, Failure"
)
$ACL = Get-Acl $Path
$ACL.AddAuditRule($AuditRule)
Set-Acl $Path $ACL
# 監査ログの確認
Get-WinEvent -FilterHashtable @{
LogName='Security'
ID=4663 # オブジェクトへのアクセス試行
} | Where-Object {
$_.Message -like "*$Path*"
}
Sysmonによる高度な監視
Sysmonの設定
HLJSXML
<!-- sysmon-config.xml -->
<Sysmon schemaversion="4.90">
<EventFiltering>
<!-- プロセス作成の監視 -->
<RuleGroup name="ProcessCreate" groupRelation="or">
<ProcessCreate onmatch="include">
<CommandLine condition="contains">powershell</CommandLine>
<CommandLine condition="contains">cmd.exe</CommandLine>
</ProcessCreate>
</RuleGroup>
<!-- ネットワーク接続の監視 -->
<RuleGroup name="NetworkConnect" groupRelation="or">
<NetworkConnect onmatch="include">
<DestinationPort condition="is">445</DestinationPort>
<DestinationPort condition="is">3389</DestinationPort>
</NetworkConnect>
</RuleGroup>
<!-- ドライバー/サービスの監視 -->
<DriverLoad onmatch="exclude"/>
<ImageLoad onmatch="exclude"/>
</EventFiltering>
</Sysmon>
インストール
HLJSPOWERSHELL
# Sysmonのインストール
.\Sysmon64.exe -accepteula -i sysmon-config.xml
# Sysmonイベントの確認
Get-WinEvent -LogName "Microsoft-Windows-Sysmon/Operational" -MaxEvents 100
異常検出スクリプト
不審なプロセス検出
HLJSPOWERSHELL
function Get-SuspiciousProcesses {
$SuspiciousPatterns = @(
'mimikatz',
'pwdump',
'procdump',
'gsecdump',
'lsadump'
)
Get-Process | Where-Object {
$processName = $_.ProcessName.ToLower()
$SuspiciousPatterns | Where-Object { $processName -like "*$_*" }
} | Select-Object ProcessName, Id, Path
}
# 実行
Get-SuspiciousProcesses
メモリ使用量の異常検出
HLJSPOWERSHELL
function Get-HighMemoryProcesses {
param(
[int]$ThresholdPercent = 10
)
$TotalMemory = (Get-CimInstance Win32_PhysicalMemory |
Measure-Object -Property Capacity -Sum).Sum / 1GB
Get-Process | Where-Object {
$memoryPercent = ($_.WorkingSet64 / 1GB) / $TotalMemory * 100
$memoryPercent -gt $ThresholdPercent
} | Select-Object ProcessName, Id,
@{Name="MemoryGB";Expression={[math]::Round($_.WorkingSet64/1GB, 2)}},
@{Name="MemoryPercent";Expression={[math]::Round((($_.WorkingSet64/1GB)/$TotalMemory*100), 2)}}
}
Windows Defenderと統合
脅威検出の監視
HLJSPOWERSHELL
# Defenderの検出履歴
Get-MpThreatDetection | Select-Object *
# リアルタイム保護の状態確認
Get-MpPreference | Select-Object DisableRealtimeMonitoring,
DisableBehaviorMonitoring,
DisableBlockAtFirstSeen
# 検疫された項目の確認
Get-MpThreat | Where-Object { $_.RemediationAction -eq 'Quarantine' }
ASR(Attack Surface Reduction)ルール
HLJSPOWERSHELL
# ASRルールの状態確認
Get-MpPreference | Select-Object -ExpandProperty AttackSurfaceReductionRules_Ids
Get-MpPreference | Select-Object -ExpandProperty AttackSurfaceReductionRules_Actions
# ASRルールの有効化(例:Officeマクロのブロック)
Set-MpPreference -AttackSurfaceReductionRules_Ids D3E037E1-3EB8-44C8-A917-57927947596D `
-AttackSurfaceReductionRules_Actions Enabled
セキュリティログの集中管理
Windows Event Forwarding(WEF)
HLJSPOWERSHELL
# サブスクリプションの作成(コレクター側)
wecutil cs subscription.xml
# サブスクリプションXMLの例
@"
<Subscription xmlns="http://schemas.microsoft.com/2006/03/windows/events/subscription">
<SubscriptionId>SecurityEvents</SubscriptionId>
<SubscriptionType>SourceInitiated</SubscriptionType>
<Description>セキュリティイベントの収集</Description>
<Enabled>true</Enabled>
<Uri>http://schemas.microsoft.com/wbem/wsman/1/windows/EventLog</Uri>
<ConfigurationMode>MinLatency</ConfigurationMode>
<Query><![CDATA[
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4624 or EventID=4625)]]</Select>
</Query>
</QueryList>
]]></Query>
<ReadExistingEvents>true</ReadExistingEvents>
<TransportName>http</TransportName>
<ContentFormat>RenderedText</ContentFormat>
<Locale Language="ja-JP"/>
<LogFile>ForwardedEvents</LogFile>
<PublisherName>Microsoft-Windows-EventCollector</PublisherName>
</Subscription>
"@ | Out-File subscription.xml
インシデント対応ワークフロー
自動化された対応スクリプト
HLJSPOWERSHELL
function Respond-ToThreat {
param(
[string]$ProcessId,
[string]$Reason
)
# ログ記録
$LogEntry = @{
Timestamp = Get-Date
ProcessId = $ProcessId
Reason = $Reason
Action = "Terminated"
}
$LogEntry | ConvertTo-Json | Out-File "C:\Security\incident-log.json" -Append
# プロセスの停止(必要に応じて)
try {
Stop-Process -Id $ProcessId -Force
Write-Host "プロセス $ProcessId を停止しました"
}
catch {
Write-Error "プロセス停止に失敗: $_"
}
# メモリダンプの作成(フォレンジック用)
# 注:これは正当なセキュリティ調査目的のみに使用
}
まとめ
効果的なセキュリティ監査には以下が必要です:
- 包括的なログ収集: 認証、プロセス、ファイルシステムの監査
- リアルタイム監視: SysmonやWindows Defenderとの連携
- 自動化: 異常検出とインシデント対応の自動化
- 定期的なレビュー: セキュリティログの分析と改善
これらの対策を実施することで、セキュリティインシデントの早期発見と対応が可能になります。