您的位置:首页 > 其它

使用wmi脚本对系统日志进行审计

2010-05-07 17:28 387 查看
运行all.vbs,弹出窗口:



输入要进行审计的日期,点"ok",脚本会自动审计你的服务器中相关的事件日志:



all.vbs代码如下:

On Error Resume Next
'=========================================================================
' System 日志摘要
'=========================================================================
logfile="System"
'输入参数处理
str=Inputbox("开始请输入日期yyyy-mm-dd(默认为昨天):","输入参数",FormatDateTime(DateAdd("d",-1,now),2))
'输入参数规范
a=split(str,"-")
for i=lbound(a)+1 to ubound(a)
if len(a(i))=1 Then '如果月和日少于两位,前面加0
a(i)="0" & a(i)
end if
next
str=Join(a,"")
'Wscript.Echo str
strComputer = "."

Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
'取主机名
computer=""
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
computer=objItem.Caption
Next
'筛选系统日志
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent where Logfile='"&logfile&"'",,48)
cnt0=0
cnt1=0
For Each objItem in colItems
dt=objItem.TimeWritten '取得日志时间
t=objItem.Type '取类型
If Mid(dt,1,8)=str Then
If t="错误" Then '---错误日志计数
cnt0=cnt0+1
End If
If t="警告" Then
cnt1=cnt1+1
End if
End if
Next
Wscript.Echo "主机 "&computer&" 【"&logfile&"】日志 "&str&" 摘要:" & " 错误 "&cnt0&" , 警告 "&cnt1
'==========================================================================
' application日志摘要
'==========================================================================
logfile="Application"
'筛选系统日志
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent where Logfile='"&logfile&"'",,48)
cnt0=0
cnt1=0
For Each objItem in colItems
dt=objItem.TimeWritten '取得日志时间
t=objItem.Type '取类型
If Mid(dt,1,8)=str Then
If t="错误" Then '---错误日志计数
cnt0=cnt0+1
End If
If t="警告" Then
cnt1=cnt1+1
End if
End if
Next
Wscript.Echo "主机 "&computer&" 【"&logfile&"】日志 "&str&" 摘要:" & " 错误 "&cnt0&" , 警告 "&cnt1
'==========================================================================
' Security日志摘要
'==========================================================================
logfile="Security"
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objItem in colItems
computer=objItem.Caption
Next
'筛选系统日志
Set colItems = objWMIService.ExecQuery("Select * from Win32_NTLogEvent where Logfile='"&logfile&"'",,48)
cnt0=0 '审核成功计数
cnt1=0 '审核失败计数
cnt2=0 '登陆成功计数
cnt3=0 '登陆失败计数
cnt4=0 '审核日志清除计数
cnt5=0 '审核策略变更计数
cnt6=0 '用户帐号变更计数
For Each objItem in colItems
dt=objItem.TimeWritten '取得日志时间
t=objItem.Type '取类型
code=objItem.EventCode '取事件id
If Mid(dt,1,8)=str Then
If t="审核成功" Then '---审核成功计数
cnt0=cnt0+1
End If
If t="审核失败" Then '---审核失败计数
cnt1=cnt1+1
End If
If code=528 Or code=540 Or code=552 then '---登陆成功计数
cnt2=cnt2+1
End If
If (code>=529 And code<=537) Or code=539 Or code=548 Or code=549 then '---登陆失败计数
cnt3=cnt3+1
End If
If code=517 then '---审核日志清除计数
cnt4=cnt4+1
End If
If code=612 then '---审核策略变更计数
cnt5=cnt5+1
End If
If code=624 Or code=627 Or code=628 Or code=630 Or code=642_
Or (code>=645 And code<=647) or code=685 then '---用户帐号变更计数
cnt6=cnt6+1
End If
End if
Next
Wscript.Echo "主机 "&computer&" 【"&logfile&"】日志 "&str&" 摘要:" & " 审核成功 "&cnt0&" , 审核失败 "_
&cnt1&" , 登陆成功 "&cnt2&" , 登陆失败 "&cnt3&" , 审核日志清除 "&cnt4&" , 审核策略变更 "&cnt5&_
" , 用户帐号变更 "&cnt6



对于有的服务器,这个过程可能会比较漫长,请千万要耐心.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: