1、查询系统是否已安装sudo、syslog程序
创新互联专注于企业营销型网站、网站重做改版、安仁网站定制设计、自适应品牌网站建设、HTML5建站、商城网站建设、集团公司官网建设、外贸网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为安仁等各大城市提供网站开发制作服务。[root@shangke ~]# rpm -qa|egrep "sudo|syslog" rsyslog-5.8.10-10.el6_6.x86_64 sudo-1.8.6p3-19.el6.x86_64 如果没有安装,则用yum安装,yum install -y sudo syslog
2、配置/etc/sudoers
增加配置“Defaults logfile=/var/log/sudo.log”到/etc/sudoers中
[root@shangke ~]# echo "Defaults logfile=/var/log/sudo.log" >>/etc/sudoers [root@shangke ~]# tail -1 /etc/sudoers ##检查操作是否成功 Defaults logfile=/var/log/sudo.log [root@shangke ~]# visudo -c ##检查sudoers文件语法 /etc/sudoers: parsed OK
3、配置系统日志
增加配置local2.debug到/etc/syslog.conf中(Centos5.8中)
增加配置local2.debug到/etc/rsyslog.conf中(Centos6.4中)
[root@shangke ~]# echo "local2.debug /var/log/sudo.log" >>/etc/rsyslog.conf [root@shangke ~]# tail -1 /etc/rsyslog.conf ##检查配置 local2.debug /var/log/sudo.log
4、重启syslog或rsyslog内核日志记录器
[root@shangke ~]# /etc/init.d/rsyslog restart Shutting down system logger: [ OK ] Starting system logger: [ OK ]
5、查看日志目录的权限
[root@shangke ~]# ll /var/log/sudo.log -rw------- 1 root root 1148 Jan 31 16:05 /var/log/sudo.log
6、测试sudo日志审计配置结果
[root@shangke ~]# whoami root [root@shangke ~]# pwd /root [root@shangke ~]# useradd mzq [root@shangke ~]# vi /etc/sudoers mzq ALL=(ALL) ALL [root@shangke ~]# su - mzq [mzq@shangke ~]$ sudo -l Matching Defaults entries for mzq on this host: requiretty, !visiblepw, always_set_home, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin, logfile=/var/log/sudo.log User mzq may run the following commands on this host: (ALL) NOPASSWD: /bin/su, (ALL) /usr/bin/sudo, (ALL) ALL [mzq@shangke ~]$ su - Password: [root@shangke ~]# cat /var/log/sudo.log Jan 31 16:05:27 : mzq : TTY=pts/0 ; PWD=/home/mzq ; USER=root ; COMMAND=/bin/cat /var/log/sudo.log Jan 31 16:24:11 : mzq : TTY=pts/0 ; PWD=/home/mzq ; USER=root ; COMMAND=list Jan 31 16:25:09 : mzq : TTY=pts/0 ; PWD=/home/mzq ; USER=root ; COMMAND=/bin/cat /var/log/sudo.log
7、记录登录用户的数据
/var/log/useraudit.log文件记录登录用户的时间,来源IP,以及在系统中运行了什么命令。
[root@shangke ~]# vim /etc/profile 在最后添加下面内容:export HISTORY_FILE=/var/log/useraudit.logexport PROMPT_COMMAND='{ h=`history 1`;w=`who am i`;echo -e $(date "+%Y-%m-%d %H:%M:%S") --- $w ---$h;} >> $HISTORY_FILE'然后执行命令: [root@shangke ~]# touch /var/log/useraudit.log [root@shangke ~]# chmod 777 /var/log/useraudit.log [root@shangke ~]# chattr +a /var/log/useraudit.log [root@shangke ~]# cat /var/log/useraudit.log 2016-01-31 16:30:16 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 15 su - 2016-01-31 16:30:18 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 16 ls 2016-01-31 16:30:22 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 17 sudo ls 2016-01-31 16:30:34 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 18 cat /var/log/sudo.log 2016-01-31 16:30:46 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 19 sudo cat /var/log/so 2016-01-31 16:30:50 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 20 sudo cat /var/log/sudo.log 2016-01-31 16:31:09 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 21 rm -f oldboy1 2016-01-31 16:31:12 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 22 sudo cat /var/log/sudo.log 2016-01-31 16:32:04 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 23 sodu cat /var/log/useraudit.log 2016-01-31 16:32:41 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 24 cd /var/log/ 2016-01-31 16:32:43 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 25 ls 2016-01-31 16:33:05 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 25 ls 2016-01-31 16:33:08 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 26 cd 2016-01-31 16:33:10 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 27 ls 2016-01-31 16:33:18 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 28 rm -f oldboy2 2016-01-31 16:33:23 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 141 su - mzq 2016-01-31 16:33:40 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 142 cat /var/log/sudo.log 2016-01-31 16:33:54 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 143 cat /var/log/sudo.log|grep rm 2016-01-31 16:34:01 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 144 cat /var/log/sudo.log|grep rm -f 2016-01-31 16:34:10 --- root pts/0 2016-01-31 16:21 (10.0.0.1) --- 145 cat /var/log/sudo.log|grep "rm -f"
8、日志集中管理
1)rsync+inotify或定时任务+rsync,推到日志管理服务器上,IP_date.sudo.log
2)syslog服务来处理
[root@shangke ~]#echo "IP logserver">>/etc/hosts #日志服务器地址 [root@shangke ~]#echo "*.info @logserver">>/etc/syslog.conf<<====适合所有日志推走
3)日志收集解决方案scribe、Flume、logstash、stom
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。