1 案例1:部署audit监控文件
1.1 问题
本案例要求熟悉audit审计工具的基本使用,完成以下任务操作:
使用audit监控/etc/ssh/sshd_config
当该文件发生任何变化即记录日志
通过手动和ausearch工具查看日志内容
- 1
- 2
- 3
1.2 方案
审计的目的是基于事先配置的规则生成日志,记录可能发生在系统上的事件(正常或非正常行为的事件),审计不会为系统提供额外的安全保护,但她会发现并记录违反安全策略的人及其对应的行为。
审计能够记录的日志内容:
a) 日期与事件以及事件的结果
b) 触发事件的用户
c) 所有认证机制的使用都可以被记录,如ssh等
d) 对关键数据文件的修改行为等都可以被记录
1.3 步骤
实现此案例需要按照如下步骤进行。
步骤一:配置audit审计系统
1)安装软件包,查看配置文件(确定审计日志的位置)
[root@svr5 ~]# yum -y install audit //安装软件包
[root@svr5 ~]# cat /etc/audit/auditd.conf //查看配置文件,确定日志位置
log_file = /var/log/audit/audit.log //日志文件路径
[root@svr5 ~]# systemctl start auditd //启动服务
[root@svr5 ~]# systemctl enable auditd //设置开机自启
- 1
- 2
- 3
- 4
- 5
2)配置审计规则
可以使用auditctl命令控制审计系统并设置规则决定哪些行为会被记录日志。
语法格式如下:
[root@svr5 ~]# auditctl -s //查询状态
[root@svr5 ~]# auditctl -l //查看规则
[root@svr5 ~]# auditctl -D //删除所有规则
- 1
- 2
- 3
定义临时文件系统规则:
#语法格式:auditctl -w path -p permission -k key_name
# path为需要审计的文件或目录
# 权限可以是r,w,x,a(文件或目录的属性发生变化)
# Key_name为可选项,方便识别哪些规则生成特定的日志项
[root@svr5 ~]# auditctl -w /etc/passwd -p wa -k passwd_change
//设置规则所有对passwd文件的写、属性修改操作都会被记录审计日志
[root@svr5 ~]# auditctl -w /etc/selinux/ -p wa -k selinux_change
//设置规则,监控/etc/selinux目录
[root@svr5 ~]# auditctl -w /usr/sbin/fdisk -p x -k disk_partition
//设置规则,监控fdisk程序
[root@svr5 ~]# auditclt -w /etc/ssh/sshd_conf -p warx -k sshd_config
//设置规则,监控sshd_conf文件
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
如果需要创建永久审计规则,则需要修改规则配置文件:
[root@svr5 ~]# vim /etc/audit/rules.d/audit.rules
-w /etc/passwd -p wa -k passwd_changes
-w /usr/sbin/fdisk -p x -k partition_disks
- 1
- 2
- 3
步骤二:查看并分析日志
1)手动查看日志
查看SSH的主配置文件/etc/ssh/sshd_conf,查看audit日志信息:
[root@svr5 ~]# tailf /var/log/audit/audit.log
type=SYSCALL msg=audit(1517557590.644:229228): arch=c000003e
syscall=2 success=yes exit=3
a0=7fff71721839 a1=0 a2=1fffffffffff0000 a3=7fff717204c0
items=1 ppid=7654 pid=7808 auid=0 uid=0 gid=0 euid=0 suid=0
fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts2 ses=3 comm="cat"
exe="/usr/bin/cat"
subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="sshd_config"
.. ..
#内容分析
# type为类型
# msg为(time_stamp:ID),时间是date +%s(1970-1-1至今的秒数)
# arch=c000003e,代表x86_64(16进制)
# success=yes/no,事件是否成功
# a0-a3是程序调用时前4个参数,16进制编码了
# ppid父进程ID,如bash,pid进程ID,如cat命令
# auid是审核用户的id,su - test, 依然可以追踪su前的账户
# uid,gid用户与组
# tty:从哪个终端执行的命令
# comm="cat" 用户在命令行执行的指令
# exe="/bin/cat" 实际程序的路径
# key="sshd_config" 管理员定义的策略关键字key
# type=CWD 用来记录当前工作目录
# cwd="/home/username"
# type=PATH
# ouid(owner's user id) 对象所有者id
# guid(owner's groupid) 对象所有者id
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
2)通过工具搜索日志
系统提供的ausearch命令可以方便的搜索特定日志,默认该程序会搜索/var/log/audit/audit.log,ausearch options -if file_name可以指定文件名。
[root@svr5 ~]# ausearch -k sshd_config -i
//根据key搜索日志,-i选项表示以交互式方式操作
- 1
- 2
</div>
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
<div class="more-toolbox">
<div class="left-toolbox">
<ul class="toolbox-list">
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count"></span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{"mod":"1582594662_002"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/xie_qi_chao">
<img src="https://profile.csdnimg.cn/B/F/6/3_xie_qi_chao" class="avatar_pic" username="xie_qi_chao">
<img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/xie_qi_chao" data-report-click="{"mod":"popu_379"}" target="_blank">解启超</a></span>
</div>
<div class="text"><span>发布了329 篇原创文章</span> · <span>获赞 52</span> · <span>访问量 3万+</span></div>
</div>
<div class="right-message">
<a href="https://im.csdn.net/im/main.html?userName=xie_qi_chao" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm attented bt-button personal-watch" data-report-click="{"mod":"popu_379"}">已关注</a>
</div>
</div>
</div>
</article>
1 案例1:部署audit监控文件
1.1 问题
本案例要求熟悉audit审计工具的基本使用,完成以下任务操作:
使用audit监控/etc/ssh/sshd_config
当该文件发生任何变化即记录日志
通过手动和ausearch工具查看日志内容
- 1
- 2
- 3
1.2 方案
审计的目的是基于事先配置的规则生成日志,记录可能发生在系统上的事件(正常或非正常行为的事件),审计不会为系统提供额外的安全保护,但她会发现并记录违反安全策略的人及其对应的行为。
审计能够记录的日志内容:
a) 日期与事件以及事件的结果
b) 触发事件的用户
c) 所有认证机制的使用都可以被记录,如ssh等
d) 对关键数据文件的修改行为等都可以被记录
1.3 步骤
实现此案例需要按照如下步骤进行。
步骤一:配置audit审计系统
1)安装软件包,查看配置文件(确定审计日志的位置)
[root@svr5 ~]# yum -y install audit //安装软件包
[root@svr5 ~]# cat /etc/audit/auditd.conf //查看配置文件,确定日志位置
log_file = /var/log/audit/audit.log //日志文件路径
[root@svr5 ~]# systemctl start auditd //启动服务
[root@svr5 ~]# systemctl enable auditd //设置开机自启
- 1
- 2
- 3
- 4
- 5
2)配置审计规则
可以使用auditctl命令控制审计系统并设置规则决定哪些行为会被记录日志。
语法格式如下:
[root@svr5 ~]# auditctl -s //查询状态
[root@svr5 ~]# auditctl -l //查看规则
[root@svr5 ~]# auditctl -D //删除所有规则
- 1
- 2
- 3
定义临时文件系统规则:
#语法格式:auditctl -w path -p permission -k key_name
# path为需要审计的文件或目录
# 权限可以是r,w,x,a(文件或目录的属性发生变化)
# Key_name为可选项,方便识别哪些规则生成特定的日志项
[root@svr5 ~]# auditctl -w /etc/passwd -p wa -k passwd_change
//设置规则所有对passwd文件的写、属性修改操作都会被记录审计日志
[root@svr5 ~]# auditctl -w /etc/selinux/ -p wa -k selinux_change
//设置规则,监控/etc/selinux目录
[root@svr5 ~]# auditctl -w /usr/sbin/fdisk -p x -k disk_partition
//设置规则,监控fdisk程序
[root@svr5 ~]# auditclt -w /etc/ssh/sshd_conf -p warx -k sshd_config
//设置规则,监控sshd_conf文件
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
如果需要创建永久审计规则,则需要修改规则配置文件:
[root@svr5 ~]# vim /etc/audit/rules.d/audit.rules
-w /etc/passwd -p wa -k passwd_changes
-w /usr/sbin/fdisk -p x -k partition_disks
- 1
- 2
- 3
步骤二:查看并分析日志
1)手动查看日志
查看SSH的主配置文件/etc/ssh/sshd_conf,查看audit日志信息:
[root@svr5 ~]# tailf /var/log/audit/audit.log
type=SYSCALL msg=audit(1517557590.644:229228): arch=c000003e
syscall=2 success=yes exit=3
a0=7fff71721839 a1=0 a2=1fffffffffff0000 a3=7fff717204c0
items=1 ppid=7654 pid=7808 auid=0 uid=0 gid=0 euid=0 suid=0
fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts2 ses=3 comm="cat"
exe="/usr/bin/cat"
subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key="sshd_config"
.. ..
#内容分析
# type为类型
# msg为(time_stamp:ID),时间是date +%s(1970-1-1至今的秒数)
# arch=c000003e,代表x86_64(16进制)
# success=yes/no,事件是否成功
# a0-a3是程序调用时前4个参数,16进制编码了
# ppid父进程ID,如bash,pid进程ID,如cat命令
# auid是审核用户的id,su - test, 依然可以追踪su前的账户
# uid,gid用户与组
# tty:从哪个终端执行的命令
# comm="cat" 用户在命令行执行的指令
# exe="/bin/cat" 实际程序的路径
# key="sshd_config" 管理员定义的策略关键字key
# type=CWD 用来记录当前工作目录
# cwd="/home/username"
# type=PATH
# ouid(owner's user id) 对象所有者id
# guid(owner's groupid) 对象所有者id
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
2)通过工具搜索日志
系统提供的ausearch命令可以方便的搜索特定日志,默认该程序会搜索/var/log/audit/audit.log,ausearch options -if file_name可以指定文件名。
[root@svr5 ~]# ausearch -k sshd_config -i
//根据key搜索日志,-i选项表示以交互式方式操作
- 1
- 2
</div>
<link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-b6c3c6d139.css" rel="stylesheet">
<div class="more-toolbox">
<div class="left-toolbox">
<ul class="toolbox-list">
<li class="tool-item tool-active is-like "><a href="javascript:;"><svg class="icon" aria-hidden="true">
<use xlink:href="#csdnc-thumbsup"></use>
</svg><span class="name">点赞</span>
<span class="count"></span>
</a></li>
<li class="tool-item tool-active is-collection "><a href="javascript:;" data-report-click="{"mod":"popu_824"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-Collection-G"></use>
</svg><span class="name">收藏</span></a></li>
<li class="tool-item tool-active is-share"><a href="javascript:;" data-report-click="{"mod":"1582594662_002"}"><svg class="icon" aria-hidden="true">
<use xlink:href="#icon-csdnc-fenxiang"></use>
</svg>分享</a></li>
<!--打赏开始-->
<!--打赏结束-->
<li class="tool-item tool-more">
<a>
<svg t="1575545411852" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5717" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><defs><style type="text/css"></style></defs><path d="M179.176 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5718"></path><path d="M509.684 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5719"></path><path d="M846.175 499.222m-113.245 0a113.245 113.245 0 1 0 226.49 0 113.245 113.245 0 1 0-226.49 0Z" p-id="5720"></path></svg>
</a>
<ul class="more-box">
<li class="item"><a class="article-report">文章举报</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="person-messagebox">
<div class="left-message"><a href="https://blog.csdn.net/xie_qi_chao">
<img src="https://profile.csdnimg.cn/B/F/6/3_xie_qi_chao" class="avatar_pic" username="xie_qi_chao">
<img src="https://g.csdnimg.cn/static/user-reg-year/1x/2.png" class="user-years">
</a></div>
<div class="middle-message">
<div class="title"><span class="tit"><a href="https://blog.csdn.net/xie_qi_chao" data-report-click="{"mod":"popu_379"}" target="_blank">解启超</a></span>
</div>
<div class="text"><span>发布了329 篇原创文章</span> · <span>获赞 52</span> · <span>访问量 3万+</span></div>
</div>
<div class="right-message">
<a href="https://im.csdn.net/im/main.html?userName=xie_qi_chao" target="_blank" class="btn btn-sm btn-red-hollow bt-button personal-letter">私信
</a>
<a class="btn btn-sm attented bt-button personal-watch" data-report-click="{"mod":"popu_379"}">已关注</a>
</div>
</div>
</div>
</article>