Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3013196
  • 博文数量: 535
  • 博客积分: 15788
  • 博客等级: 上将
  • 技术积分: 6507
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 09:11
文章分类

全部博文(535)

文章存档

2016年(1)

2015年(1)

2014年(10)

2013年(26)

2012年(43)

2011年(86)

2010年(76)

2009年(136)

2008年(97)

2007年(59)

分类: LINUX

2011-01-06 16:09:19

maldetect主要功能:
1 扫描文件是否包含恶意代码  
2 根据user或path记录对文件实时监控creation/modify/move operations(默认包含这几个操作,也可以监控其他文件操作,需要的话自行修改/usr/local/maldetect/maldet).(需要inotify支持,kernels 2.6.13+ and CentOS/RHEL 5 by default
官网:
下载:
安装很简单,解压后修改cron.daily文件,安装后该文件会复制到/etc/cron.daily/目录下,并改名为maldet,每天4点运行。
根据需要,可以添加到crontab,每小时运行。
修改文件里的内容:
  1. #!/bin/bash
  2. # clear quarantine/session/tmp data every 14 days
  3. /usr/sbin/tmpwatch 336 /usr/local/maldetect/tmp >> /dev/null 2>&1
  4. /usr/sbin/tmpwatch 336 /usr/local/maldetect/sess >> /dev/null 2>&1
  5. /usr/sbin/tmpwatch 336 /usr/local/maldetect/quarantine >> /dev/null 2>&1
  6. # check for new definition set
  7. /usr/local/maldetect/maldet -u >> /dev/null 2>&1
  8. # if were running inotify monitoring, send daily hit summary
  9. if [ "$(ps -A --user root -o "comm" | grep inotifywait)" ]; then
  10. /usr/local/maldetect/maldet --alert-daily >> /dev/null 2>&1
  11. #注意这里,如果你开着monitor,将不会运行下面的命令
  12. else
  13. /usr/local/maldetect/maldet -r /opt/html 2 >> /dev/null 2>&1
  14. fi

主要修改红色部分,-r 要扫描的目录  2 2天内修改过的文件,详细参数查看
/usr/local/maldetect/maldet --help

-a, --scan-all PATH       -a 扫描所有文件,不考虑修改时间
       Scan all files in path
建议先对所有文件扫描,然后再对2天以内文件进行定期扫描。

可以编辑该脚本进行定制 /usr/local/maldetect/maldet

另外,修改配置文件/usr/local/maldetect/conf.maldet
email_alert=1 打开邮件报警,扫描到恶意代码时发送邮件报警
quar_hits=1 隔离扫描到的包含恶意代码的文件。
quar_clean=1 清除恶意代码

以下为手动运行扫描进行测试:
  1. /usr/local/maldetect/maldet -r /opt/ 2
  2. Linux Malware Detect v1.3.7
  3. (C) 2002-2010, R-fx Networks
  4. (C) 2010, Ryan MacDonald
  5. inotifywait (C) 2007, Rohan McGovern
  6. This program may be freely redistributed under the terms of the GNU GPL v2
  7. maldet(19159): {scan} signatures loaded: 5269 (3624 MD5 / 1645 HEX)
  8. maldet(19159): {scan} building file list for /opt/ of new/modified files from last 2 days, this might take awhile...
  9. maldet(19159): {scan} file list completed, scanning 5 files...
  10. maldet(19159): {scan} 5/5 files scanned: 2 hits 0 cleaned
  11. maldet(19159): {scan} scan completed on /opt/: files 5, malware hits 3, cleaned hits 0
  12. maldet(19159): {scan} scan report saved 'maldet --report 010611-1604.19159'
  13. maldet(19159): {scan} quarantine disabled; set quar_hits=1 in conf.maldet or run 'maldet -q 010611-1604.19159' to quarantine results
可以看到扫描到了3个包含恶意代码的文件。

另:关于实时监控:
The inotify monitoring feature is designed to monitor paths/users in real-time for file creation/modify/move operations. This option requires a kernel that supports inotify_watch (CONFIG_INOTIFY) which is found in kernels 2.6.13+ and CentOS/RHEL 5 by default. If you are running CentOS 4 you should consider an inbox upgrade with:

关于在64位服务器上:
{mon} no inotify process found, check /usr/local/maldetect/inotify/inotify_log for errors.
下载inotify-tool,编译安装
cd /usr/local/maldetect/inotify
tar -xvzf inotify-tools-3.14.tar.gz
./configure
make
make install

删除maldetect自带的inotifywait
将编译安装的inotifywait做软连接到这里
  1. ln -s /usr/local/bin/inotifywait /usr/local/maldetect/inotify/
ldd  /usr/local/maldetect/inotify/inotifywait
找不到libinotifytools.so.0
 ln -s /usr/local/lib/libinotifytools.so.0 /usr/lib64/
OK,该问题解决


  1. 以下为我监控/opt目录的测试
  2. /opt/123 CREATE 06 Jan 15:49:45
  3. /opt/lighttpd-1.4.28/m4/111111 CREATE 06 Jan 15:50:35
阅读(4662) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~