当前位置:网站首页>Windows 事件查看器记录到 MYSQL
Windows 事件查看器记录到 MYSQL
2022-08-03 15:58:00 【allway2】
在我们的小型办公环境中,我们使用 Windows 2008 R2 Active Directory 进行用户管理/身份验证和控制。由于一些标准操作程序,我被要求在 Linux 基础 mySQL DB 中记录用户帐户创建/删除事件。由于 windows 不提供直接将事件导出到 linux base mysql 的选项,因此我使用带有任务调度程序方法标记的特定 windows 事件为其制定了解决方法。更不用说,这种将任务调度程序与事件一起使用的方法并不是什么新鲜事物,但是对于像我这样的麻木 来说,如何仅获取根据我们的口味修剪的非常特定的字段并将其远程登录,这肯定有点令人困惑linux mysql数据库。但是 Alhamdulillah 我设法在几个小时内努力做到了。
我在这篇文章中使用的项目是……
- 带有 Active Directory 的 Windows 2008 R2 服务器
- c:\temp 文件夹保存触发事件的临时信息
- e:\userlog\ 文件夹保存所有日志
- 将记录在本地日志文件和 mySQL 数据库中的事件 ID [根据需要]:
4720
新用户帐户已创建
4726
用户帐户已删除 - 当特定事件发生时将执行的两个批处理文件。
- Mysql(我使用mysql-5.7.17-winx64.zip)包在mysql DB名称中添加条目
events
您可以从 fmy Google Drive 下载 mysql-5.7.17-winx64.zip
Syed Jahanzaib 的 mysql-5.7.17-winx64
LOG 的新帐户批处理文件 [ac-new-log.bat]
@echo off
set MYSQL_HOST=10.0.0.1
set MYSQL_ID=your_mysqlid
set MYSQL_PASS=your_password
set MYSQL_DB=your_events
set MYSQL_TB=your_table
set ACTION=Account Created
set HOLDER=c:\temp\acnew-temp.txt
set LOGFILE=e:\userlog\users-created-log.log
type nul > %HOLDER%
wevtutil qe security /rd:true /f:text /c:1 /q:"*[System/EventID=4720]" > %HOLDER%
for /f "tokens=4" %%a in ('type %HOLDER% ^| find /i "Account Name"') do set accname=%%a
for /f "tokens=3" %%a in ('type %HOLDER% ^| find /i "Event ID"') do set eventid=%%a
for /f "tokens=2" %%a in ('type %HOLDER% ^| find /i "Date"') do set dt=%%a
set HEADER=%eventid% : %accname% / %ACTION% @ ... %dt%
echo %HEADER%
echo %HEADER% >> %LOGFILE%
c:\mysql\bin\mysql -h %MYSQL_HOST% -u%MYSQL_ID% -p%MYSQL_PASS% -e "use %MYSQL_DB%; INSERT INTO %MYSQL_TB% (eventid,type,account,msg) VALUES ('%eventid%','%ACTION
%','%accname%','%HEADER%');"LOG 的帐户删除批处理文件 [ac-del-log.bat]
@echo off
set MYSQL_HOST=10.0.0.1
set MYSQL_ID=MY_ID
set MYSQL_PASS=MY_PASS
set MYSQL_DB=DB
set MYSQL_TB=TABLE
set ACTION=Account Deleted
set HOLDER=c:\temp\acdel-temp.txt
set LOGFILE=e:\userlog\users-deleted-log.log
type nul > %HOLDER%
wevtutil qe security /rd:true /f:text /c:1 /q:"*[System/EventID=4726]" > %HOLDER%
for /f "tokens=3" %%a in ('type %HOLDER% ^| find /i "Account Name"') do set accname=%%a
for /f "tokens=3" %%a in ('type %HOLDER% ^| find /i "Event ID"') do set eventid=%%a
for /f "tokens=2" %%a in ('type %HOLDER% ^| find /i "Date"') do set dt=%%a
set HEADER=%eventid% : %accname% / %ACTION% @ ... %dt%
echo %HEADER%
echo %HEADER% >> %LOGFILE%
c:\mysql\bin\mysql -h %MYSQL_HOST% -u%MYSQL_ID% -p%MYSQL_PASS% -e "use %MYSQL_DB%; INSERT INTO %MYSQL_TB% (eventid,type,account,msg) VALUES ('%eventid%','%ACTION%','%accname%','%HEADER%');"附加具有特定事件 ID 的批处理文件
在域控制器上,打开事件查看器,转到 4720 事件,右键单击并选择“将任务附加到此事件”,然后在触发器中选择您的批处理文件。(用于创建帐户)
如下图所示 ……



对事件 id 4726 重复相同的操作。
好的,完成它。
在 mySQL 中创建数据库
现在在 mySQL 中创建一个具有所需名称和表的新数据库……
一个例子如下。
mysql.sql
;-- MySQL dump 10.13 Distrib 5.5.54, for debian-linux-gnu (i686)
--
-- Host: localhost Database: events
-- ------------------------------------------------------
-- Server version 5.5.54-0ubuntu0.12.04.1
/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @[email protected]@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @[email protected]@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @[email protected]@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `mymaindb`
--
DROP TABLE IF EXISTS `mymaindb`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mymaindb` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`eventid` varchar(40) DEFAULT NULL,
`type` varchar(255) NOT NULL,
`account` varchar(255) NOT NULL,
`msg` varchar(10000) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=462 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `mymaindb`
--
LOCK TABLES `mymaindb` WRITE;
/*!40000 ALTER TABLE `mymaindb` DISABLE KEYS */;
INSERT INTO `mymaindb` VALUES (459,'2017-02-13 08:39:45','4720','Account Created','testing.act','4720 : testing.act / Account Created @ ... 2017-02-13T12:02:05.777'),(461,'2017-02-13 08:49:46','4726','Account Deleted','testing.act','4726 : testing.act / Account Deleted @ ... 2017-02-13T12:02:38.521');
/*!40000 ALTER TABLE `mymaindb` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET [email protected]_TIME_ZONE */;
/*!40101 SET [email protected]_SQL_MODE */;
/*!40014 SET [email protected]_FOREIGN_KEY_CHECKS */;
/*!40014 SET [email protected]_UNIQUE_CHECKS */;
/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */;
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */;
/*!40101 SET [email protected]_COLLATION_CONNECTION */;
/*!40111 SET [email protected]_SQL_NOTES */;
-- Dump completed on 2017-02-13 14:47:11要导入以上 DB,请使用以下命令……
mysql -uroot -pROOTPASS < mydb.sql
CMD 中的脚本结果:
现在尝试在活动目录中创建/删除用户帐户,您将在 mysql db 中看到结果。
我建议先调试,确保一切正常,手动执行bat文件查看结果
ac-new-log.bat
.
mySQL DB 中的脚本结果:
[以上所有的大惊小怪只是为了获取根据口味修剪的特定数据,并将其登录到远程 linux mySQL 中,否则任务通常很容易]
phpmyadmin 快照

mysql cmd 行快照
mysql> select * from MY_DB;
+-----+---------------------+---------+-----------------+-------------+--------------------------------------------------------------------+
| id | datetime | eventid | type | account | msg |
+-----+---------------------+---------+-----------------+-------------+--------------------------------------------------------------------+
| 459 | 2017-02-13 13:39:45 | 4720 | Account Created | testing.act | 4720 : testing.act / Account Created @ ... 2017-02-13 13:39:45 |
| 461 | 2017-02-13 13:49:46 | 4726 | Account Deleted | testing.act | 4726 : testing.act / Account Deleted @ ... 2017-02-13 13:39:45 |
+-----+---------------------+---------+-----------------+-------------+--------------------------------------------------------------------+
2 rows in set (0.00 sec)这只是一个小例子,关于如何使用方法构建自己的定制解决
out of the box方案!
边栏推荐
猜你喜欢

AI也有健忘症?英国41岁教授专访:解决灾难性遗忘

How to get the 2 d space prior to ViT?UMA & Hong Kong institute of technology & ali SP - ViT, study for visual Transformer 2 d space prior knowledge!.

DAYU200 OpenHarmony标准系统HDMI全屏显示

Interpretation of the 2021 Cost of Data Breach Report

30W 2C(JD6606S + FP6652X2)BOM

红蓝对抗经验分享:CS免杀姿势

A new round of competition for speech recognition has started. Will natural dialogue be the next commanding height?

【899. 有序队列】

常见分布式理论(CAP、BASE)和一致性协议(Gosssip、Raft)

用友YonSuite与旺店通数据集成对接-技术篇2
随机推荐
使用VS Code搭建ESP-IDF环境
美国国防部更“青睐”光量子系统研究路线
ECCV 2022 | 基于关系查询的时序动作检测方法
CopyOnWriteArrayList details
我在滴滴做开源
小熊派——无线联网开发
新一代网状网协议T-Mesh无线通信技术优势介绍
我写了个”不贪吃蛇“小游戏
Spark entry learning-2
AI+BI+可视化,Sugar BI架构深度剖析
Yii2安装遇到Loading composer repositories with package information
Small Tools (4) integrated Seata1.5.2 distributed transactions
Convex Optimization of Optimal Power Flow (OPF) in Microgrids and DC Grids (Matlab Code Implementation)
下午见!2022京东云数据库新品发布会
AI也有健忘症?英国41岁教授专访:解决灾难性遗忘
Research on power flow in DC microgrid based on Newton's method (Matlab code implementation)
mysql delete 执行报错:You can‘t specify target table ‘doctor_info‘ for update in FROM clause
【Unity入门计划】基本概念(7)-Input Manager&Input类
产品以及研发团队有使用专业的办公软件,如禅道、蓝湖等,他们应该如何使用 Tita 系统?
Interpretation of the 2021 Cost of Data Breach Report