利用Audit审计系统行为

标题利用Audit审计系统行为

Linux Audit守护进程是一个可以审计Linux系统事件的框架

这个框架本身有数个组件,包括内核、二进制文件及其他文件。

1.内核·audit:钩在内核中来捕获事件并将它们发送到auditd。

2.二进制文件
·auditd:捕捉事件并记录它们(记录在日志文件中)的守护进程。·auditctl:配置auditd的客户端工具。
·audispd:多路复用事件的守护进程。
·aureport:从日志文件(auditd.log)中读取内容的报告工具。·ausearch:事件查看器(查看的内容是auditd.log)。
·autrace:使用内核中的审计组件来追踪二进制文件。
·aulast:和上一个类似,但是使用的是审计框架。
·aulastlog:和lastlog类似,但是使用的也是审计框架
·ausyscall:映射系统调用ID和名字。
·auvirt:展示和审计有关虚拟机的信息。

3.文件
·audit.rules:由auditctl使用,它读取该文件来决定需要使用什么规则。·auditd.conf:auditd的配置文件。

在Debian/Ubuntu中使用以下命令安装:

apt-get install auditd audispd-plugins

Centos中使用以下命令安装:

yum -y install audit

两个文件管理审计守护进程的配置,一个用于守护进程本身(auditd.conf),另一个是用于auditctl工具的规则(audit.rules)。

1.auditd.conf文件auditd.conf对Linux audit守护进程的配置聚焦在它应该在哪里以及如何记录事件。它也定义了如何应对磁盘满的情况、如何处理日志轮转和要保留的日志文件数量。通常,对大多数系统来说,默认配置是足够的。

2.audit.rules为了配置应该审计什么日志,审计框架使用了一个名为audit.rules的文件。和大多数情况一样,从零开始而不加载任何规则。通过用-l参数来运行auditctl,我们可以确定使用中的规则。
万一加载了任何规则的话,可用-D参数运行auditctl来删除已加载规则。

管理审计服务

配置 auditd 后,启动服务来收集审计信息:

# service auditd start

使用 service 命令而不是 systemctl 的唯一原因是正确记录用户 ID (UID) 值。

设置开机启动:

# systemctl enable auditd

定义审计规则

使用 auditctl 工具,可以在你想要的任何系统调用上添加审计规则。规则会按顺序执行。

下一步定义监视规则。此规则跟踪文件或目录是否由某些类型的访问触发,包括读取、写入、执行和属性更改。

定义规则的语法是:

auditctl -w path_to_file -p permissions -k key_name

-w #指定所要监控的文件或命令
-p #监控属性(如x执行)

        ·r=读取
        ·w=写入
        ·x=执行
        ·a=属性改变

-k #指定关键词(方便在日志中查询)
-D #清除规则(临时,不会清除配置文件规则)

如要审核用户创建操作,首先,向 /etc/passwd 文件添加监视以跟踪写入和属性更改访问,并添加自定义键以记录所有消息(此自定义键可用于过滤日志消息):

[root@localhost ~]# auditctl -w /etc/passwd -p wa -k user-modify

接下来,添加一个新用户。这样做会更改 /etc/passwd 文件:

[root@localhost ~]# useradd user01

最后,检查 auditd 是否记录了更改。默认情况下,auditd 将日志存储在 /var/log/audit/audit.log 文件中:

[root@localhost yy]# cat /var/log/audit/audit.log | grep modify

在这里插入图片描述

定义持久审计规则

要使audit规则在重新启动后保持不变,请将它们添加到/etc/audit/rules.d/audit.rules文件中。

下面在 audit.rules 文件中定义持久性规则以监视 /etc/passwd 文件的更改。

-w /etc/passwd -p wa -k user-modify

保存文件,然后重新加载 auditd 守护程序以实现对规则文件中配置的更改:

[root@localhost ~]# service auditd reload

可以运行auditctl -l列出规则:

[root@localhost ~]# auditctl -l

最后,添加新用户或更改 /etc/passwd 文件会出发审计。更改记录在 /var/log/audit/audit.log 中,即使系统重新启动,规则仍然存在。

搜索审计日志

使用ausearch工具搜索审计日志。默认情况下,它搜索 /var/log/audit/audit.log 文件。

例如,要根据 key_name 搜索日志条目,搜索有关user-modify相关的:

[root@localhost yy]# ausearch -i -k user-modify
	-i		#显示信息更清晰,比如显示日期而不是时间戳
	-k		#指定关键词(auditctl -k指定的关键词)
	-c  commond		#只显示与指令相关日志(如-c rm)

创建审计报告

使用 aureport 工具根据审计日志查询和创建审计报告。

[root@localhost ~]# aureport 
[root@localhost yy]# aureport 

Summary Report
======================
Range of time in logs: 2023年09月12日 15:46:48.403 - 2023年09月20日 02:58:23.161
Selected time for report: 2023年09月12日 15:46:48 - 2023年09月20日 02:58:23.161
Number of changes in configuration: 175
Number of changes to accounts, groups, or roles: 9
Number of logins: 5
Number of failed logins: 2
Number of authentications: 24
Number of failed authentications: 4
Number of users: 5
Number of terminals: 11
Number of host names: 3
Number of executables: 14
Number of commands: 16
Number of files: 3
Number of AVC's: 0
Number of MAC events: 12
Number of failed syscalls: 2
Number of anomaly events: 0
Number of responses to anomaly events: 0
Number of crypto events: 94
Number of integrity events: 0
Number of virt events: 0
Number of keys: 1
Number of process IDs: 215
Number of events: 994

查看关于尝试身份验证的报告:

[root@localhost yy]# aureport -au

Authentication Report
============================================
# date time acct host term exe success event
============================================
1. 2023年09月12日 15:47:38 gnome-initial-setup localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 145
2. 2023年09月12日 15:48:53 yy localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 177
3. 2023年09月12日 08:43:01 yy ? /dev/pts/0 /usr/bin/sudo yes 205
4. 2023年09月12日 21:42:08 yy localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 282
5. 2023年09月12日 21:44:15 root 192.168.171.1 ssh /usr/sbin/sshd no 296
6. 2023年09月12日 21:44:23 root 192.168.171.1 ssh /usr/sbin/sshd no 297
7. 2023年09月12日 21:44:33 root 192.168.171.1 ssh /usr/sbin/sshd yes 298
8. 2023年09月12日 21:44:49 yy 192.168.171.1 ssh /usr/sbin/sshd yes 332
9. 2023年09月12日 21:45:26 yy 192.168.171.1 ssh /usr/sbin/sshd yes 353
10. 2023年09月13日 04:54:31 yy localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 398
11. 2023年09月13日 04:57:58 gdm localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 54
12. 2023年09月13日 04:58:13 yy localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 150
13. 2023年09月15日 05:00:30 yy localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker no 192
14. 2023年09月15日 05:00:35 yy localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 193
15. 2023年09月15日 05:01:17 yy ? /dev/pts/0 /usr/bin/sudo yes 198
16. 2023年09月15日 05:25:28 yy localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 219
17. 2023年09月15日 05:26:02 yy ? /dev/pts/0 /usr/bin/sudo no 224
18. 2023年09月15日 05:26:05 yy ? /dev/pts/0 /usr/bin/sudo yes 225
19. 2023年09月17日 22:51:08 yy ? ? /usr/lib/polkit-1/polkit-agent-helper-1 yes 266
20. 2023年09月17日 22:52:34 yy 192.168.171.1 ssh /usr/sbin/sshd yes 299
21. 2023年09月17日 23:16:01 yy ? /dev/pts/1 /usr/bin/sudo yes 313
22. 2023年09月17日 23:26:06 yy localhost.localdomain pts/1 /usr/lib/polkit-1/polkit-agent-helper-1 yes 332
23. 2023年09月20日 02:45:51 yy localhost.localdomain /dev/tty1 /usr/libexec/gdm-session-worker yes 380
24. 2023年09月20日 02:46:17 yy 192.168.171.1 ssh /usr/sbin/sshd yes 400
25. 2023年09月20日 02:48:57 yy ? /dev/pts/1 /usr/bin/sudo yes 415
26. 2023年09月20日 02:52:12 yy localhost.localdomain pts/1 /usr/lib/polkit-1/polkit-agent-helper-1 yes 434
27. 2023年09月20日 02:52:15 yy localhost.localdomain pts/1 /usr/lib/polkit-1/polkit-agent-helper-1 yes 436
28. 2023年09月20日 02:58:23 root localhost.localdomain pts/1 /usr/bin/su yes 470

其中no代表验证失败。yes代表验证成功。

在 CentOS8 系统上配置审计功能可以极大地提高系统的安全性和可靠性,帮助我们更好地监控系统的操作记录,并追踪系统日志,及时发现可能的安全问题。

转换系统调用

系统调用是以数字类型的值来记录的。因为在不同的服务器架构之间,这些值会有重叠,。通过使用uname-m,我们可以确定服务器架构,并使用ausyscall来确定数字为188的系统调用代表了什么。

[root@localhost yy]# ausyscall x86_64 54
setsockopt
[root@localhost yy]# ausyscall x86_64 150
munlock
[root@localhost yy]# ausyscall x86_64 188
setxattr
[root@localhost yy]#

审计Linux的进程

审计框架有一个名为autrace的工具。它使用了审计框架,并增加了合适的规则来捕获信息并记录它们。收集到的信息可以使用ausearch来展示。

[root@localhost yy]# auditctl -D
No rules
[root@localhost yy]# autrace /bin/ls
Waiting to execute: /bin/ls
公共  视频  文档  音乐	iscsi-initiator-utils-6.2.1.4-8.git095f59c.el8.x86_64.rpm
模板  图片  下载  桌面	iscsi-initiator-utils-iscsiuio-6.2.1.4-8.git095f59c.el8.x86_64.rpm
Cleaning up...
Trace complete. You can locate the records with 'ausearch -i -p 13141'
[root@localhost yy]# ausearch -i -p 13141

按照用户来审计文件访问

审计框架可以用于监控系统调用,包括对文件的访问。如果你希望知道一个特定的用户ID访问了什么文件,可使用如下规则:

[root@localhost yy]# auditctl -a exit,always -F arch=x86_64 -S open -F auid=1001

其中,-F arch=x86_64定义了使用什么架构(uname-m)来监控正确的系统调用(一些系统调用在不同的架构之间是不同的);-S open定义选择“open”系统调用;-F auid=80定义相关的用户ID。

扩展知识

unhide使用如下的6种技术来审计隐藏进程:
·对比/proc和/bin/ps命令的输出。
·对比来自/bin/ps命令输出的信息和遍历procfs获得信息。
·对比来自/bin/ps命令输出的信息和系统调用(syscall)获得的信息(系统调用扫描)。
·全部PID空间的占用(PID暴力破解)。
·逆向搜索,以验证ps命令看到的所有线程也是被内核所见到的。
·快速对比/bin/ps命令的输出、/proc分析的结果、遍历procfs的结果这三者。使用如下的命令安装unhide:
需要下载,编译安装

使用如下的命令进行暴力PID检测以发现隐藏进程:

./unhide-linux brute

使用如下的命令进行proc分析以发现隐藏进程:

./unhide-linux procall、

lsof(list open files)是Linux系统中强大的工具,它用于列出系统中打开的文件(包括普通文件、网络套接字等)。因此,它也常常被用于审计。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值