利用mysql log 找到恶意删除的真凶
网站的一个大栏目不知道什么原因突然删掉了,栏目里面的新闻数据全部丢失,后果很严重,好在我们的技术人员备份了数据,恢复了网站的数据,使得网站的损失降到最低,为了寻找原因,想知道具体的删除时间,于是想到MySQL的日志。
我们网站MySQL数据库是安装在 FreeBSD上面的。
日志文件保存在 /var/db/mysql的目录中的。
# cd /var/db/mysql
# ls
日志文件是以mysql-bin.000001-mysql-bin.000007的一系列文件
二进制日志的查看,可使用mysql自带的mysqlbinlog命令.方法:
在系统的命令窗口(不是mysql命令窗口),转到mysql的bin目录后,运行mysqlbinlog dblogbin.000001。我们也可以其输出重定向到文本文件中查看,mysqlbinlog mysql-bin.000001 > dblog.txt。
根据生成的dblog.txt文件,搜索相关日期的操作,或是具体删除的操作,可以获取精确的mysql执行删除命令的时间,部分日志如下:
#080920 20:00:02 server id 1 end_log_pos 866462017 Query thread_id=1162715 exec_time=1 error_code=0
use rixin/*!*/;
SET TIMESTAMP=1221912002/*!*/;
/*!\C gbk *//*!*/;
SET @@session.character_set_client=28,@@session.collation_connection=28,@@session.collation_server=28/*!*/;
Delete From arctype where ID=’1′/*!*/;
# at 866462017
#080920 20:00:03 server id 1 end_log_pos 866462118 Query thread_id=1162715 exec_time=0 error_code=0
SET TIMESTAMP=1221912003/*!*/;
Delete From archives where typeid=’1′/*!*/;
# at 866462118
#080920 20:00:03 server id 1 end_log_pos 866462229 Query thread_id=1162715 exec_time=0 error_code=0
SET TIMESTAMP=1221912003/*!*/;
update archives set typeid2=0 where typeid2=’1′/*!*/;
# at 866462229
#080920 20:00:03 server id 1 end_log_pos 866462330 Query thread_id=1162715 exec_time=0 error_code=0
SET TIMESTAMP=1221912003/*!*/;
Delete From feedback where typeid=’1′/*!*/;
# at 866462330
从上面的日志分析出精确的删除时间,再根据这个时间调出Apache的访问日志,查看具体的IP执行的操作,部分apache访问日志如下:
172.16.26.41 - - [20/Sep/2008:20:00:00 +0800] “GET /upimg/080920/30_130404949.jpg HTTP/1.1″ 304 -
172.16.26.41 - - [20/Sep/2008:20:00:00 +0800] “GET /templets/default/images/ecjtuli.gif HTTP/1.1″ 304 -
59.52.215.109 - - [20/Sep/2008:20:00:00 +0800] “GET /2.swf HTTP/1.1″ 304 -
172.16.24.250 - - [20/Sep/2008:20:00:00 +0800] “GET /adminrixin/catalog_del.php?ID=1&typeoldname=%D0%C2%CE%C5 HTTP/1.1″ 200 1890
172.16.26.41 - - [20/Sep/2008:20:00:00 +0800] “GET /upimg/080920/47_124249A5.JPG HTTP/1.1″ 304 -
172.16.24.250 - - [20/Sep/2008:20:00:00 +0800] “GET /adminrixin/menu.js HTTP/1.1″ 404 216
172.16.26.41 - - [20/Sep/2008:20:00:00 +0800] “GET //templets/default/images/tit_live_bg1.gif HTTP/1.1″ 304 -
59.52.215.109 - - [20/Sep/2008:20:00:00 +0800] “POST /ajax_chuanmei.php HTTP/1.1″ 200 406
PS:最终的IP地址和操作让我们很惊讶,是我们的一个管理员误操作删除了整个新闻栏目,排除了黑客入侵的可能性。
Tags: mysql log










学习了,涛哥