freeBuf
主站

分类

漏洞 工具 极客 Web安全 系统安全 网络安全 无线安全 设备/客户端安全 数据安全 安全管理 企业安全 工控安全

特色

头条 人物志 活动 视频 观点 招聘 报告 资讯 区块链安全 标准与合规 容器安全 公开课

官方公众号企业安全新浪微博

FreeBuf.COM网络安全行业门户,每日发布专业的安全资讯、技术剖析。

FreeBuf+小程序

FreeBuf+小程序

等保测评2.0之Centos安全审计
2019-08-20 09:00:12

一、说明

在进行等级保护测评时,需要检查主机的安全审计功能,这里就以等级保护2.0来说一说centos6在这方面的检测,以下是安全计算环境的安全审计控制点中的测评项。

二、测评项a

图片.png

这里在初级教程中,让我们去查看系统日志服务安全审计服务是否正常运行,但是这两者有什么关系以及具体有什么功能书里没说清楚。

2.1. audit和syslog的关系

网上的资料:

audit 主要用来记录安全信息,用于对系统安全事件的追溯;而 syslog 日志系统用来记录系统中的各种信息,如硬件警报和软件日志等。但是 syslog 属于应用层,没办法记录太多信息。audit 来记录内核信息,包括文件的读写,权限的改变等。

举个例子来说,就是audit会记录系统情况,syslog也会记录,但是syslog记录的信息不如audit更详细,至于它俩具体能记录啥,下文会说。

在实际使用中,audit和syslog几乎就是独立的,比如audit进程没运行,syslog不会受到影响,会正常记录信息。而syslog没有开,audit也不会受到影响,会正常记录信息。

2.2. 安全审计内核模块与安全审计守护进程

这一段我也不是很清楚其原理,所以说错了请谅解。

大概意思就是auditd内核模块auditd守护进程,不是一回事。 auditd内核模块主要用来获取审计信息,而用户的auditd守护进程主要是从内核模块获取审计信息然后记录。 所以如果auditd内核模块没有起动,那么auditd守护进程启动了也没有任何用,用户定义的临时审计规则或永久审计规则都不会起效果,自然也不会记录任何信息(但注意,这个不会影响到syslog,syslog还是会正常记录信息的)。

我们可以通过auditctl -s命令查看auditd内核模块的状态:

[root@centos01 ~]# auditctl -s
AUDIT_STATUS: enabled=1 flag=1 pid=3232 rate_limit=0 backlog_limit=320 lost=0 backlog=0

里面的enabled的值即为auditd内核模块的状态,enabled为0则代表auditd内核模块没有启动,此时就像上文说的那样,系统不会记录任何信息。如果enabled为1,则代表auditd内核模块正常开启,此时可以正常收集信息。如果enabled为2,似乎是代表审计规则被锁定,不能修改升级规则。

而当enabled为1但auditd守护进程没有开启时,内核收集到的信息将会记录到写到/var/log/messages中。 

当然,一般情况下不会出现这种状态,使用service auditd startstop命令启动或停止auditd守护进程时,内核的状态和auditd守护进程的状态是一致的。 也就是start时,会开启auditd守护进程,同时auditd内核的enabled也会被设为1,stop时,也一样。

除非你使用auditctl -e命令特意去这么做:

[root@centos01 ~]# service auditd stop
停止 auditd:                                              [确定]
[root@centos01 ~]# auditctl -e 1
AUDIT_STATUS: enabled=1 flag=1 pid=0 rate_limit=0 backlog_limit=320 lost=0 backlog=0
[root@centos01 ~]# service auditd status
auditd 已停

此时,就出现了auditd内核模块未启动,但auditd守护进程启动的情况了。

2.3. 是否开启了安全审计功能

所以判断是否开启安全审计功能时,要顺带查看一下auditd内核模块的状态,至于syslog是否开启,我个人感觉还是以auditd为主,syslog开启了很好,没开启也无所谓。

2.4. 是否覆盖到每个用户和是否对重要行为、事件进行审计

我们可以通过auditctl -l查看现在运行着的审计规则(默认是无规则):

[root@centos01 ~]# auditctl -l
No rules

还可以通过查看/etc/audit/audit.rules文件,得到写在配置文件中的永久审计规则:

[root@centos01 ~]# cat /etc/audit/audit.rules
#This file contains the auditctl rules that are loaded
#whenever the audit daemon is started via the initscripts.
#The rules are simply the parameters that would be passed
#to auditctl.

#First rule - delete all
-D

#Increase the buffers to survive stress events.
#Make this bigger for busy systems
-b 320

#Feel free to add below this line. See auditctl man page

实际运行的规则和配置文件中写的规则有什么区别吗?对于实际运行的规则,你可以临时的增加、删除、修改(服务重启就恢复原样)。 而对于写在配置文件中的规则,如果你修改了配置文件却没有重启服务,那么你修改的也不会生效。

audit的审计规则大概有两类:一类是对文件的监控,一类是对系统调用的监控。

对于文件,可以定义审计规则监控对该文件的读、写、执行等操作,一旦发生,就会记录到日志文件中。 比如用以下命令对hosts文件的写和属性更改进行监控:

auditctl -w /etc/hosts -p wa

对于系统调用,可以定义审计规则对于命令的调用,比如用以下名监控对umask、chown命令的调用:

[root@centos01 ~]# auditctl -a exit,always -S umask -S chown
WARNING - 32/64 bit syscall mismatch, you should specify an arch
[root@centos01 ~]# auditctl -l
LIST_RULES: exit,always syscall=chown,umask

好,对于一个默认的、没有定义审计规则的系统,其实还是会记录一些东西的,我们可用aureport -i命令查看总览:

Summary Report
======================
Range of time in logs: 2019年03月12日 00:54:39.084 - 2019年07月26日 15:38:01.542
Selected time for report: 2019年03月12日 00:54:39 - 2019年07月26日 15:38:01.542
Number of changes in configuration: 67
Number of changes to accounts, groups, or roles: 172
Number of logins: 162
Number of failed logins: 75
Number of authentications: 471
Number of failed authentications: 442
Number of users: 6
Number of terminals: 33
Number of host names: 3
Number of executables: 32
Number of files: 3
Number of AVC's: 28
Number of MAC events: 152
Number of failed syscalls: 26
Number of anomaly events: 26
Number of responses to anomaly events: 36
Number of crypto events: 573
Number of keys: 1
Number of process IDs: 2036
Number of events: 11595

这里可以看到日志的开始和结束日期,以及各类记录的数量。
aureport命令有着很多参数,如-x、-l、-f、-c、-u等,可以查看各类记录的具体信息,默认情况下会对以下信息进行记录:

账号修改,如使用passwd、usermod等命令;
用户登陆,包括图形界面的登陆、远程登录,但应该不包括su;
配置修改,但是这个其实比较不清晰,大概用什么方式修改什么服务的配置文件会被记录下来,不清楚;
……

所以,默认情况下auditd也记录了一些东西,也勉强算是覆盖到每个用户和并对重要行为、事件进行审计了。

至于syslog,它大概记录的信息如下:
图片.png

三、 测评项b

图片.png

3.1. audit

这个,可以直接查看auditd的日志文件的具体内容:

[root@centos01 ~]# cat /var/log/audit/audit.log | head -n 2
type=DAEMON_START msg=audit(1552323279.084:9122): auditd start, ver=2.2 format=raw kernel=2.6.32-431.el6.x86_64 auid=4294967295 pid=1165 subj=system_u:system_r:auditd_t:s0 res=success
type=CONFIG_CHANGE msg=audit(1552323279.203:4): audit_backlog_limit=320 old=64 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditctl_t:s0 res=1

里面的信息还是很详细的,具体每个字段代表什么意思可看:https://blog.csdn.net/yongyong169/article/details/79035680 

反正符合要求应该是没啥问题的。

3.2. syslog

如果是syslog,有些日志比较详细,有些不够详细,last命令查询wtmp日志,就还算详细吧:

[root@centos01 ~]# last | head -n 20
root     pts/2        :0.0             Fri Jul 26 15:53   still logged in   
root     pts/1        :0.0             Fri Jul 26 14:51   still logged in   
root     pts/0        :0.0             Fri Jul 26 14:48   still logged in   
root     tty1         :0               Fri Jul 26 14:47   still logged in   
reboot   system boot  2.6.32-431.el6.x Fri Jul 26 14:47 - 15:56  (01:09)    
root     tty1         :0               Wed Jul 10 09:12 - 09:14  (00:01)    
reboot   system boot  2.6.32-431.el6.x Tue Jul  9 15:44 - 09:14  (17:29)    
root     pts/1        192.168.9.1      Wed Jul  3 13:36 - 11:59  (22:23)    
root     pts/0        :0.0             Wed Jul  3 13:35 - 22:34 (1+08:58)   
root     tty1         :0               Wed Jul  3 13:35 - 22:34 (1+08:59)   
reboot   system boot  2.6.32-431.el6.x Wed Jul  3 13:33 - 22:34 (1+09:00)   
root     pts/1        192.168.9.1      Wed Jul  3 13:06 - down   (00:26)    
root     pts/0        :0.0             Wed Jul  3 13:06 - 13:33  (00:26)    
root     tty1         :0               Wed Jul  3 13:04 - down   (00:28)    
reboot   system boot  2.6.32-431.el6.x Wed Jul  3 13:03 - 13:33  (00:29)    
oracle   pts/1        192.168.236.1    Sun Jun 30 19:46 - down   (09:53)    
root     pts/2        192.168.236.1    Sun Jun 30 19:05 - down   (10:34)    
oracle   pts/1        192.168.236.1    Sun Jun 30 16:52 - 19:46  (02:53)    
oracle   pts/0        :0.0             Sun Jun 30 16:48 - 05:40  (12:52)    
oracle   tty1         :0               Sat Jun 29 22:02 - 05:40 (1+07:38) 

四、测评项c

图片.png

这里有两个要求,一个是对记录进行保护,另外一个是备份。

4.1. 对记录进行保护

这个很简单,一个方面直接查看audit和syslog的日志文件的权限即可:

默认情况下都没有问题,other都不会具有写的权限。同时,存有日志的目录,other也没有写权限(即是否有权限删除该目录下的文件)。

[root@centos01 ~]# ls -ld /var/log/audit
drwxr-x---. 2 root root 4096 3月  12 00:54 /var/log/audit

[root@centos01 ~]# ls -l /var/log/audit;
总用量 2588
-rw-------. 1 root root 2643067 7月  26 15:50 audit.log


[root@centos01 ~]# ls -ld /var/log/
drwxr-xr-x. 14 root root 4096 7月  26 15:42 /var/log/

[root@centos01 ~]# ls -l /var/log;
总用量 3776
-rw-------. 1 root root   6550 3月  12 00:53 anaconda.ifcfg.log
-rw-------. 1 root root  25077 3月  12 00:53 anaconda.log
-rw-------. 1 root root  40223 3月  12 00:53 anaconda.program.log
-rw-------. 1 root root 171892 3月  12 00:53 anaconda.storage.log
-rw-------. 1 root root 132167 3月  12 00:53 anaconda.syslog
-rw-------. 1 root root  35064 3月  12 00:53 anaconda.xlog
-rw-------. 1 root root 115594 3月  12 00:53 anaconda.yum.log
drwxr-x---. 2 root root   4096 3月  12 00:54 audit
-rw-r--r--  1 root root   3211 7月  26 14:47 boot.log
-rw-------  1 root utmp      0 7月   1 03:38 btmp
-rw-------. 1 root utmp   1920 6月  29 19:47 btmp-20190701
drwxr-xr-x. 2 root root   4096 3月  12 00:58 ConsoleKit
-rw-------  1 root root   1021 7月  26 15:50 cron
-rw-------. 1 root root   5298 6月  28 15:19 cron-20190628
-rw-------. 1 root root  17806 6月  30 15:06 cron-20190630
-rw-------  1 root root  22711 7月   9 16:17 cron-20190709
-rw-------  1 root root   3407 7月  26 15:42 cron-20190726
drwxr-xr-x. 2 lp   sys    4096 8月  17 2013 cups
-rw-r--r--  1 root root  81565 7月  26 14:47 dmesg
-rw-r--r--  1 root root  81600 7月   9 15:44 dmesg.old
-rw-r--r--. 1 root root 393885 3月  12 20:46 dracut.log
drwxrwx--T. 2 root gdm    4096 7月  26 14:47 gdm
drwx------. 2 root root   4096 8月  14 2013 httpd
-rw-r--r--. 1 root root 147168 7月   3 13:36 lastlog
drwxr-xr-x. 2 root root   4096 3月  31 15:20 mail
-rw-------  1 root root      0 7月  26 15:42 maillog
-rw-------. 1 root root   2912 6月  28 14:30 maillog-20190628
-rw-------. 1 root root   7866 6月  29 21:51 maillog-20190630
-rw-------  1 root root   1596 7月   9 15:44 maillog-20190709
-rw-------  1 root root    353 7月  26 14:49 maillog-20190726
-rw-------  1 root root    923 7月  26 15:55 messages
-rw-------. 1 root root 172261 6月  28 15:06 messages-20190628
-rw-------. 1 root root 718061 6月  30 15:02 messages-20190630
-rw-------  1 root root 405081 7月   9 16:16 messages-20190709
-rw-------  1 root root 153160 7月  26 15:41 messages-20190726
drwxr-xr-x. 2 ntp  ntp    4096 11月 24 2013 ntpstats
-rw-r--r--. 1 root root     89 7月  26 14:47 pm-powersave.log
drwx------. 2 root root   4096 8月  23 2010 ppp
drwxr-xr-x. 2 root root   4096 3月  12 18:38 prelink
drwxr-xr-x. 2 root root   4096 7月  26 14:47 sa
drwx------. 3 root root   4096 3月  12 00:44 samba
-rw-------  1 root root      0 7月  26 15:42 secure
-rw-------. 1 root root   2700 6月  28 14:33 secure-20190628
-rw-------. 1 root root  20714 6月  29 22:02 secure-20190630
-rw-------  1 root root   7327 7月   9 15:44 secure-20190709
-rw-------  1 root root   3364 7月  26 14:51 secure-20190726
-rw-------. 1 root root      0 3月  12 00:54 spice-vdagent.log
-rw-------  1 root root      0 7月  26 15:42 spooler
-rw-------. 1 root root      0 6月  19 19:13 spooler-20190628
-rw-------. 1 root root      0 6月  28 15:19 spooler-20190630
-rw-------  1 root root      0 6月  30 15:06 spooler-20190709
-rw-------  1 root root      0 7月   9 16:17 spooler-20190726
drwxr-x---. 2 root root   4096 11月 23 2013 sssd
-rw-------. 1 root root  32256 7月   3 13:36 tallylog
-rw-r--r--. 1 root root      0 3月  12 00:55 wpa_supplicant.log
-rw-rw-r--. 1 root utmp 451200 7月  26 15:53 wtmp
-rw-r--r--  1 root root  53692 7月  26 15:53 Xorg.0.log
-rw-r--r--  1 root root  54094 7月  10 09:14 Xorg.0.log.old
-rw-r--r--. 1 root root  60193 6月  28 16:02 Xorg.1.log
-rw-r--r--. 1 root root  51164 4月   5 03:16 Xorg.1.log.old
-rw-r--r--. 1 root root  57801 6月  28 16:09 Xorg.2.log
-rw-r--r--. 1 root root  38398 4月   5 03:10 Xorg.2.log.old
-rw-r--r--. 1 root root  59160 6月  28 21:34 Xorg.3.log
-rw-r--r--. 1 root root  40233 3月  28 19:00 Xorg.3.log.old
-rw-r--r--. 1 root root  66966 6月  28 21:34 Xorg.4.log
-rw-r--r--. 1 root root  40754 6月  28 21:34 Xorg.5.log
-rw-r--r--. 1 root root  33584 3月  12 00:56 Xorg.9.log
-rw-------. 1 root root   2887 6月  28 16:00 yum.log

另外一方面也要看看日志存储规则,看看是如何定义的,是否合理,至于其中各项的意义,大家上网查一查即可。同时,也可顺便看下该文件和目录的权限。

[root@centos01 ~]# cat /etc/audit/auditd.conf;
#
#This file controls the configuration of the audit daemon
#

log_file = /var/log/audit/audit.log
log_format = RAW
log_group = root
priority_boost = 4
flush = INCREMENTAL
freq = 20
num_logs = 5
disp_qos = lossy
dispatcher = /sbin/audispd
name_format = NONE
##name = mydomain
max_log_file = 6 
max_log_file_action = ROTATE
space_left = 75
space_left_action = SYSLOG
action_mail_acct = root
admin_space_left = 50
admin_space_left_action = SUSPEND
disk_full_action = SUSPEND
disk_error_action = SUSPEND
##tcp_listen_port = 
tcp_listen_queue = 5
tcp_max_per_addr = 1
##tcp_client_ports = 1024-65535
tcp_client_max_idle = 0
enable_krb5 = no
krb5_principal = auditd
##krb5_key_file = /etc/audit/audit.key
[root@centos01 ~]# ls -l /etc/audit
总用量 12
-rw-r-----. 1 root root 701 6月  22 2012 auditd.conf
-rw-r-----. 1 root root 374 4月   8 23:47 audit.rules
-rw-r-----. 1 root root 389 4月   8 23:46 audit.rules~

[root@centos01 ~]# ls -ld /etc/audit
drwxr-x---. 2 root root 4096 4月   8 23:47 /etc/audit

4.2. 定期备份

定期备份一般是指将日志推送至日志服务器等设备进行备份,所以如果对方说有该类设备,就去查看相关配置以及是否存在实际的备份的日志文件即可。
如果对方说是手动定期备份的话,这个嘛,就要看你自己怎么判断了。

五、测评项d

图片.png

一方面验证即可,另一方面可以查看shell脚本里是如何设置对权限进行判断的:

[root@centos01 ~]#cat /etc/rc.d/init.d/auditd
#!/bin/bash
#
#auditd        This starts and stops auditd
#
#chkconfig: 2345 11 88
#description: This starts the Linux Auditing System Daemon, \
#             which collects security related events in a dedicated \
#             audit log. If this daemon is turned off, audit events \
#             will be sent to syslog.
#
#processname: /sbin/auditd
#config: /etc/sysconfig/auditd
#config: /etc/audit/auditd.conf
#pidfile: /var/run/auditd.pid
#
#Return values according to LSB for all commands but status:
#0 - success
#1 - generic or unspecified error
#2 - invalid or excess argument(s)
#3 - unimplemented feature (e.g. "reload")
#4 - insufficient privilege
#5 - program is not installed
#6 - program is not configured
#7 - program is not running
#


PATH=/sbin:/bin:/usr/bin:/usr/sbin
prog="auditd"

#Source function library.
. /etc/init.d/functions

#Allow anyone to run status
if [ "$1" = "status" ] ; then
	status $prog
	RETVAL=$?
	exit $RETVAL
fi

#Check that we are root ... so non-root users stop here
test $EUID = 0  ||  exit 4

#Check config
test -f /etc/sysconfig/auditd && . /etc/sysconfig/auditd

RETVAL=0

start(){
	test -x /sbin/auditd  || exit 5
	test -f /etc/audit/auditd.conf  || exit 6

	echo -n $"Starting $prog: "

#Localization for auditd is controlled in /etc/synconfig/auditd
	if [ -z "$AUDITD_LANG" -o "$AUDITD_LANG" = "none" -o "$AUDITD_LANG" = "NONE" ]; then
		unset LANG LC_TIME LC_ALL LC_MESSAGES LC_NUMERIC LC_MONETARY LC_COLLATE
	else
		LANG="$AUDITD_LANG"
		LC_TIME="$AUDITD_LANG"
		LC_ALL="$AUDITD_LANG"
		LC_MESSAGES="$AUDITD_LANG"
		LC_NUMERIC="$AUDITD_LANG"
		LC_MONETARY="$AUDITD_LANG"
		LC_COLLATE="$AUDITD_LANG"
		export LANG LC_TIME LC_ALL LC_MESSAGES LC_NUMERIC LC_MONETARY LC_COLLATE
	fi
	unset HOME MAIL USER USERNAME
	daemon $prog "$EXTRAOPTIONS"
	RETVAL=$?
	echo
	if test $RETVAL = 0 ; then
		touch /var/lock/subsys/auditd
		#Load the default rules
		test -f /etc/audit/audit.rules && /sbin/auditctl -R /etc/audit/audit.rules >/dev/null
	fi
	return $RETVAL
}

stop(){
	echo -n $"Stopping $prog: "
	killproc $prog
	RETVAL=$?
	echo
	rm -f /var/lock/subsys/auditd
	#Remove watches so shutdown works cleanly
	if test x"$AUDITD_CLEAN_STOP" != "x" ; then
		if test "`echo $AUDITD_CLEAN_STOP | tr 'NO' 'no'`" != "no"
		then
			/sbin/auditctl -D >/dev/null
		fi
	fi
	if test x"$AUDITD_STOP_DISABLE" != "x" ; then
		if test "`echo $AUDITD_STOP_DISABLE | tr 'NO' 'no'`" != "no"
		then
			/sbin/auditctl -e 0 >/dev/null
		fi
	fi
	return $RETVAL
}

reload(){
	test -f /etc/audit/auditd.conf  || exit 6
	echo -n $"Reloading configuration: "	
	killproc $prog -HUP
	RETVAL=$?
	echo
	return $RETVAL
}

rotate(){
	echo -n $"Rotating logs: "	
	killproc $prog -USR1
	RETVAL=$?
	echo
	return $RETVAL
}

resume(){
	echo -n $"Resuming logging: "	
	killproc $prog -USR2
	RETVAL=$?
	echo
	return $RETVAL
}

restart(){
	test -f /etc/audit/auditd.conf  || exit 6
	stop
	start
}

condrestart(){
	[ -e /var/lock/subsys/auditd ] && restart
	return 0
}


#See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	restart
	;;
    reload|force-reload)
	reload
	;;
    rotate)
	rotate
	;;
    resume)
	resume
	;;
    condrestart|try-restart)
	condrestart
	;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|rotate|resume}"
	RETVAL=3
esac

exit $RETVAL

注意开头的这一段:

#Check that we are root ... so non-root users stop here
test $EUID = 0  ||  exit 4

也就是说euid只要不是0(不具备root权限),那么就没办法继续执行代码,也自然做不了什么事情了。

六、最后

其实等级保护2.0这部分和1.0基本上没什么区别,个人觉得想要测评得比较完整、有力度,还是要看自己对测评项的理解,以及如何在具体的测评过程中去落实。这就需要对测评的目标有一定的了解,否则便无从下手。 

所以我的文章基本上就光描述相关的技术了,没怎么说具体怎么测评。 

但是我觉得技术搞明白了,百分之99的工作就都完成了。剩下的,面对测评要求,在实际测评过程中大家自然能做出合适的取舍,使用相应的技术作为测评支撑。 

要不然,就拿着初级教程或测评要求,在啥都不懂的情况下一条条的套,那只不过是在走过场拉低等保的水准(虽然其实也没多少水准啦)。

另外,在安全管理中心中也有关于审计的内容,那部分还是放到另外的文章里去写吧。

最后附上一个很有意思的QQ聊天截图,不知大家如何看:
图片.png图片.png 图片.png

*本文原创作者:起于凡而非于凡,本文属于FreeBuf原创奖励计划,未经许可禁止转载

# 安全审计 # 等保测评2.0 # centos6
本文为 独立观点,未经允许不得转载,授权请联系FreeBuf客服小蜜蜂,微信:freebee2022
被以下专辑收录,发现更多精彩内容
+ 收入我的专辑
+ 加入我的收藏
相关推荐
  • 0 文章数
  • 0 关注者