【HW系列】—Windows日志与Linux日志分析
文章目录
- 一、Windows日志
- 1. Windows事件日志
- 2. 核心日志类型
- 3. 事件日志分析实战
- 详细分析步骤
- 二、Linux日志
- 1. 常见日志文件
- 2. 关键日志解析
- 3. 登录爆破检测方法
- 日志分析核心要点
一、Windows日志
1. Windows事件日志
- 介绍:记录系统、应用程序及安全事件,用于故障排查、安全审计与行为追踪。
- 打开方式:
- 运行 eventvwr 或 eventvwr.msc
- 控制面板 → 管理工具 → 事件查看器
- PowerShell:Get-WinEvent
2. 核心日志类型
💡 权限要求:安全日志需管理员权限查看。
3. 事件日志分析实战
(1) RDP协议远程登录分析
- 关键事件ID:
- 4624:登录成功(类型10表示RDP)
- 4778:会话重连
- 4647:用户手动注销
- 分析步骤:
- 筛选事件ID 4624,检查Logon Type=10
- 提取Source Network Address字段获取客户端IP
- 结合Account Name确认登录账户
(2) 登录爆破检测
- 特征事件:
- 4625:登录失败(频繁出现)
- 同一IP短时间内多次尝试不同用户名
详细分析步骤
步骤1:筛选RDP登录成功事件
# PowerShell查询过去24小时成功的RDP登录
Get-WinEvent -FilterHashtable @{LogName='Security'ID=4624StartTime=(Get-Date).AddHours(-24)
} | Where-Object { $_.Properties[8].Value -eq 10 } | Format-List *
关键字段解析:
- Properties[5]:登录账户名(TargetUserName)
- Properties[18]:源IP地址(IpAddress)
- Properties[8]:登录类型(LogonType=10表示RDP)
- TimeCreated:登录时间
步骤2:追踪完整RDP会话
# 查询特定IP的完整RDP活动(登录+注销)
$IP = "192.168.1.100"
Get-WinEvent -FilterHashtable @{LogName='Security'ID=@(4624,4634,4647)StartTime=(Get-Date).AddDays(-7)
} | Where-Object { ($_.Id -eq 4624 -and $_.Properties[8].Value -eq 10 -and $_.Properties[18].Value -eq $IP) -or($_.Id -in @(4634,4647) -and $_.Properties[1].Value -like "*$IP*")
} | Sort-Object TimeCreated | Format-Table TimeCreated,Id,Message -AutoSize
步骤3:计算会话持续时间
# 计算各RDP会话的持续时间(需配合日志导出分析)
$sessions = @{}
Get-WinEvent -LogName Security | Where-Object { $_.Id -in @(4624,4634,4647) -and $_.Properties[8].Value -eq 10
} | ForEach-Object {if ($_.Id -eq 4624) {$sessions[$_.Properties[3].Value] = @{Start = $_.TimeCreatedUser = $_.Properties[5].ValueIP = $_.Properties[18].Value}}elseif ($_.Id -in @(4634,4647)) {if ($sessions.ContainsKey($_.Properties[3].Value)) {$duration = $_.TimeCreated - $sessions[$_.Properties[3].Value].Start[PSCustomObject]@{User = $sessions[$_.Properties[3].Value].UserIP = $sessions[$_.Properties[3].Value].IPStartTime = $sessions[$_.Properties[3].Value].StartEndTime = $_.TimeCreatedDuration = "$($duration.Hours)h $($duration.Minutes)m"}$sessions.Remove($_.Properties[3].Value)}}
}
- 操作流程:
1. 统计失败登录TOP 10 IP
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4625} | Group-Object -Property @{e={$_.Properties[18].Value}} | Sort-Object Count -Descending | Select -First 102. 查看某IP的爆破详情(如192.168.1.20)
Get-WinEvent -FilterHashtable @{LogName='Security'; ID=4625} | Where-Object {$_.Properties[18].Value -eq '192.168.1.20'} |Format-List TimeCreated, Message
> ⚠️ 注意:高频4625事件(如每分钟>5次)可能为暴力破解。
二、Linux日志
1. 常见日志文件
2. 关键日志解析
- lastlog:二进制文件,需用lastlog -u 用户名查看指定用户最后登录时间。
- wtmp:记录登录/注销行为,last -f /var/log/wtmp显示完整历史。
- secure/auth.log:核心安全日志,记录SSH登录成功/失败、sudo授权等。
3. 登录爆破检测方法
1. 统计爆破root的IP及次数(CentOS)
grep "Failed password for root" /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr2. 提取爆破使用的用户名(Ubuntu)
grep "Failed password" /var/log/auth.log | perl -ne '/for (.+?) from/ && print "$1\n"' | sort | uniq -c3. 定位爆破时间范围
grep "Failed password" /var/log/secure | head -1 # 首次尝试
grep "Failed password" /var/log/secure | tail -1 # 末次尝试
🔍 技巧:结合fail2ban工具自动封锁高频攻击IP。
日志分析核心要点
更深入的日志保护策略(如日志加密、远程存储)可参考。