设为首页 收藏本站
查看: 891|回复: 0

[经验分享] Windows 2003下监控用户密码修改&服务启停

[复制链接]

尚未签到

发表于 2016-5-19 08:17:19 | 显示全部楼层 |阅读模式
1. 概述

1.1 本文目的
  本文旨在描述如何在Windows 2003上监控用户密码修改和系统服务的启停

1.2 约定
  本文部分功能需要可能需要启用相应的组策略编辑
  本文所涉及用户或目录是假定的目录,比如本文约定工作目录 E:\sytem、监控命令执行的用户是systemMonitor
  

2. 创建事件触发监控

REM 监控任何用户密码重置时,使用systemMonitor用户执行E:\system\pwdChangeTask.bat
EVENTTRIGGERS /Create /RU systemMonitor /RP systemMonitor的密码 /TR password_Set /L security /EID 628 /TK E:\system\pwdChangeTask.bat
REM 监控任何用户密码修改时,使用systemMonitor用户执行E:\system\pwdChangeTask.bat
EVENTTRIGGERS /Create /RU systemMonitor /RP systemMonitor的密码 /TR password_Change /L security /EID 627 /TK E:\system\pwdChangeTask.bat
REM 监控服务启停时,使用systemMonitor用户执行E:\system\startStopService.bat
EVENTTRIGGERS /Create /RU systemMonitor /RP systemMonitor的密码 /TR service_Change /L system /EID 7035 /TK E:\system\startStopService.bat

  
  
  

3. E:\system\pwdChangeTask.bat

REM 输出日志文件路径
set SYS_MONI_LOGFILE=E:\system\logs\systemMonitor%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%.log
REM 输出跳行标志,文件里面%SYS_MONI_LOGFILE%出现@@systemMonitor@@ SKIP LINES  解析时需要跳n行解析
echo @@systemMonitor@@ SKIP LINES  >> %SYS_MONI_LOGFILE%
REM 日志格式输出
CSCRIPT C:\Windows\system32\Eventquery.vbs /L Security /R 1 /FI "ID eq 627 OR ID eq 628" /V /FO CSV >> %SYS_MONI_LOGFILE%
  
  

4. E:\system\startStopService.bat

set SYS_MONI_LOGFILE=E:\system\logs\systemMonitor%DATE:~0,4%%DATE:~5,2%%DATE:~8,2%.log
echo @@systemMonitor@@ SKIP LINES >> %SYS_MONI_LOGFILE%
CSCRIPT C:\Windows\system32\Eventquery.vbs /L system /R 1 /FI "ID eq 7035" /V /FO CSV >> %SYS_MONI_LOGFILE%
  

5. 附java解析日志代码

  5.1 输出日志格式

@@systemMonitor@@ SKIP LINES  
Microsoft (R) Windows Script Host Version 5.6
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。
"类型","事件","时间日期","来源","计算机名","类别","用户","描述"
"审核成功","628","2010-5-6 14:22:41","Security","BBK","帐户管理","BBK\achievo","设置了用户帐户密码:  目标帐户名:Guest  目标域:BBK  目标帐户 ID:BBK\Guest  调用方用户名:achievo  调用方域:BBK  调用方登录 ID:(0x0,0xF9D361C)"

  

  5.2 java解析代码

package org.javaf.system.monitor;
import java.util.Calendar;
import org.javaf.common.utils.ReadTextFile;
import org.javaf.common.utils.WriteTextFile;
public class WindowsServerMonitor extends AbstractCommonMonitor {
protected void getReport(ReadTextFile rt ,WriteTextFile wtm,WriteTextFile wtd) {
String line;
while((line = rt.readLine()) != null) {
if(line.startsWith("@@systemMonitor@@ SKIP LINES")) {
this.skipLine(rt, 4);
continue;
}
if(line.indexOf(",") <=0 )
continue;
String contents[] = line.split(",");
if(contents.length < 8)
continue;
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_YEAR,c.get(Calendar.DAY_OF_YEAR)-1);
int day = c.get(Calendar.DATE);
int month = c.get( Calendar.MONTH ) + 1;
String outLine = "";
if(day<10 && month < 10){
outLine = getContent(contents,2).substring(0, 8) + "|" + ip;
}else if(day > 10 && month > 10 ){
outLine = getContent(contents,2).substring(0, 10) + "|" + ip;
}else {
outLine = getContent(contents,2).substring(0, 9) + "|" + ip;
}
long pid = getContentToLong(contents,1);
if(pid == 627 || pid == 628) {
String opUser = getContent(contents,7).split(":")[2].trim().split("\\s")[0].trim();
outLine += "|" + ( pid == 628 ? "设置":"更改") + opUser + "密码";
outLine += "|" + getContent(contents,6);
outLine += "|1";
wtm.println(outLine);
}
else if(pid == 7035) {
String tmpStr = getContent(contents,7);
tmpStr = tmpStr.substring(tmpStr.length()-6,tmpStr.length()-4) +"\"" +tmpStr.substring(0,tmpStr.indexOf("服务")).trim() + "\"服务";
outLine += "|" + tmpStr + "|" + getContent(contents,6);
outLine += "|1";
if( outLine.indexOf( "WinHTTP Web Proxy Auto-Discovery Service" ) == -1 ){
wtd.println(outLine);
wtm.println(outLine);
}
}
}
}
private String getContent(String []contents ,int i) {
return contents.substring(1,contents.length() - 1);
}
private Long getContentToLong(String []contents ,int i) {
return Long.parseLong(getContent(contents,i));
}
}

  
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-218871-1-1.html 上篇帖子: Windows 2003 上实现Sqlserver 2005 群集高可用性 下篇帖子: Active Directory服务和Windows 2000或Windows Server 2003域
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表