首页 > 系统相关 >ubuntu22.04 部署 Auditd

ubuntu22.04 部署 Auditd

时间:2023-04-04 13:35:09浏览次数:49  
标签:11 12 04 部署 ubuntu22.04 Auditd usr 2023 root

安装 Auditd

# apt -y install auditd

auditd.conf

#
# This file controls the configuration of the audit daemon
#

local_events = yes
write_logs = yes
log_file = /var/log/audit/audit.log     # 指定日志文件
log_group = adm
log_format = ENRICHED
flush = INCREMENTAL_ASYNC
freq = 50
max_log_file = 8                        # 日志文件的最大大小(兆字节)
num_logs = 5                            # 指定的日志文件数 [max_log_file_action=ROTATE]
priority_boost = 4
name_format = NONE                      # 日志文件中的主机名 有效值:NONE、HOSTNAME、FQD、NUMERIC、USER
##name = mydomain                       # [name_format=USER]
max_log_file_action = ROTATE            # 指定日志文件大小超过限制时的操作 有效值:IGNORE、SYSLOG、SUSPEND、ROTATE、KEEP_LOGS
space_left = 75
space_left_action = SYSLOG
verify_email = yes
action_mail_acct = root
admin_space_left = 50
admin_space_left_action = SUSPEND
disk_full_action = SUSPEND
disk_error_action = SUSPEND
use_libwrap = yes
##tcp_listen_port = 60
tcp_listen_queue = 5
tcp_max_per_addr = 1
##tcp_client_ports = 1024-65535
tcp_client_max_idle = 0
transport = TCP
krb5_principal = auditd
##krb5_key_file = /etc/audit/audit.key
distribute_network = no
q_depth = 1200
overflow_action = SYSLOG
max_restarts = 10
plugin_dir = /etc/audit/plugins.d
end_of_event_timeout = 2

Audit Rules

显示当前规则(默认情况下没有规则如下)

# auditctl -l
No rules

参数说明

usage: auditctl [options]
    -a <l,a>                          Append rule to end of <l>ist with <a>ction
    -A <l,a>                          Add rule at beginning of <l>ist with <a>ction
    -b <backlog>                      Set max number of outstanding audit buffers
                                      allowed Default=64
    -c                                Continue through errors in rules
    -C f=f                            Compare collected fields if available:
                                      Field name, operator(=,!=), field name
    -d <l,a>                          Delete rule from <l>ist with <a>ction
                                      l=task,exit,user,exclude,filesystem
                                      a=never,always
    -D                                Delete all rules and watches
    -e [0..2]                         Set enabled flag
    -f [0..2]                         Set failure flag
                                      0=silent 1=printk 2=panic
    -F f=v                            构建规则:字段名, operator(=,!=,<,>,<=,
                                      >=,&,&=) value
    -h                                Help
    -i                                Ignore errors when reading rules from file
    -k <key>                          设置用于搜索日志的关键字
    -l                                List rules
    -m text                           Send a user-space message
    -p [r|w|x|a]                      指定审计的目标操作
                                      r=read, w=write, x=execute, a=attribute
    -q <mount,subtree>                make subtree part of mount point's dir watches
    -r <rate>                         Set limit in messages/sec (0=none)
    -R <file>                         read rules from file
    -s                                Report status
    -S syscall                        构建规则:系统调用名称或编号
    --signal <signal>                 Send the specified signal to the daemon
    -t                                Trim directory watches
    -v                                Version
    -w <path>                         Insert watch at <path>
    -W <path>                         Remove watch at <path>
    --loginuid-immutable              Make loginuids unchangeable once set
    --backlog_wait_time               Set the kernel backlog_wait_time
    --reset-lost                      Reset the lost record counter
    --reset_backlog_wait_time_actual  Reset the actual backlog wait time counter

将审计规则(读取)设置为 [/etc/hosts]

设置规则

# auditctl -w /etc/hosts -p wa -k hosts_change

查看规则

# auditctl -l
-w /etc/hosts -p wa -k hosts_change

修改hosts文件

# echo "127.0.0.1    172-16-18-31" >> /etc/hosts

查看日志

# ausearch -k hosts_change | aureport -f -i
File Report
===============================================
# date time file syscall success exe auid event
===============================================
1. 04/04/2023 12:45:42 /etc/hosts~ rename yes /usr/bin/vim.basic ubuntu 82
2. 04/04/2023 12:45:42 /etc/hosts openat yes /usr/bin/vim.basic ubuntu 83
3. 04/04/2023 12:45:42 (null) fchown yes /usr/bin/vim.basic ubuntu 84
4. 04/04/2023 12:45:42 (null) fchown yes /usr/bin/vim.basic ubuntu 85
5. 04/04/2023 12:45:42 (null) fchmod yes /usr/bin/vim.basic ubuntu 86
6. 04/04/2023 12:45:42 /etc/hosts setxattr yes /usr/bin/vim.basic ubuntu 87

将审计规则(读取)设置为 [/opt/test/]

设置规则

# auditctl -w /opt/test -p r -k testdir_audit

查看规则

# auditctl -l
-w /etc/hosts -p wa -k hosts_change
-w /opt/test -p r -k testdir_audit

操作 /opt/test

# ls -l /opt/test/test1/
total 0

查看日志

# ausearch -k testdir_audit | aureport -f -i
File Report
===============================================
# date time file syscall success exe auid event
===============================================
1. 04/04/2023 12:54:56 /opt/test sendto yes /usr/sbin/auditctl ubuntu 88
...
13. 04/04/2023 13:17:09 /opt/test/test1/ lgetxattr no /usr/bin/ls ubuntu 122
14. 04/04/2023 13:17:09 /opt/test/test1/ getxattr no /usr/bin/ls ubuntu 123
15. 04/04/2023 13:17:09 /opt/test/test1/ getxattr no /usr/bin/ls ubuntu 124
16. 04/04/2023 13:17:09 /opt/test/test1/ openat yes /usr/bin/ls ubuntu 125

设置审计规则来监控 UID 超过 1000 的用户删除的文件

设置规则

# auditctl -a always,exit -F arch=b64 -S unlink,unlinkat -F 'auid>=1000' -F 'auid!=-1' -F key=delete_audit

操作记录

$ id
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd)
$ rm -rf 1.txt

查看日志

# ausearch -k delete_audit | aureport -f -i
File Report
===============================================
# date time file syscall success exe auid event
===============================================
1. 04/04/2023 13:11:33 1.txt unlinkat yes /usr/bin/rm ubuntu 111

规则持久化

# auditctl -l >> /etc/audit/rules.d/additional.rules

查看auditd日志

audit.log

# tail -f /var/log/audit/audit.log
type=PROCTITLE msg=audit(1680578718.830:70): proctitle="su"
type=UNKNOWN[1420] msg=audit(1680578718.830:70): subj_apparmor=unconfined
type=CRED_ACQ msg=audit(1680578718.830:71): pid=58628 uid=0 auid=1000 ses=51 subj=? msg='op=PAM:setcred grantors=pam_rootok acct="root" exe="/usr/bin/su" hostname=? addr=? terminal=/dev/pts/5 res=success'UID="root" AUID="ubuntu"
type=SYSCALL msg=audit(1680578718.830:71): arch=c000003e syscall=44 success=yes exit=132 a0=3 a1=7ffefad9bf10 a2=84 a3=0 items=0 ppid=58627 pid=58628 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts5 ses=51 comm="su" exe="/usr/bin/su" subj=? key=(null)ARCH=x86_64 SYSCALL=sendto AUID="ubuntu" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
type=PROCTITLE msg=audit(1680578718.830:71): proctitle="su"
type=UNKNOWN[1420] msg=audit(1680578718.830:71): subj_apparmor=unconfined
type=USER_START msg=audit(1680578718.830:72): pid=58628 uid=0 auid=1000 ses=51 subj=? msg='op=PAM:session_open grantors=pam_env,pam_env,pam_mail,pam_limits,pam_permit,pam_umask,pam_unix,pam_systemd acct="root" exe="/usr/bin/su" hostname=? addr=? terminal=/dev/pts/5 res=success'UID="root" AUID="ubuntu"
type=SYSCALL msg=audit(1680578718.830:72): arch=c000003e syscall=44 success=yes exit=204 a0=4 a1=7ffefad9bf10 a2=cc a3=0 items=0 ppid=58627 pid=58628 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts5 ses=51 comm="su" exe="/usr/bin/su" subj=? key=(null)ARCH=x86_64 SYSCALL=sendto AUID="ubuntu" UID="root" GID="root" EUID="root" SUID="root" FSUID="root" EGID="root" SGID="root" FSGID="root"
type=PROCTITLE msg=audit(1680578718.830:72): proctitle="su"
type=UNKNOWN[1420] msg=audit(1680578718.830:72): subj_apparmor=unconfined

搜索 USER_LOGIN 相关日志

# ausearch --message USER_LOGIN --interpret
----
type=USER_LOGIN msg=audit(04/04/2023 11:24:50.830:62) : pid=58555 uid=root auid=ubuntu ses=51 subj=? msg='op=login id=ubuntu exe=/usr/sbin/sshd hostname=172.16.3.213 addr=172.16.3.213 terminal=/dev/pts/4 res=success' 

通过用户 ID 1000 搜索 sudo 操作

# ausearch -x sudo -ua 1000
----
time->Tue Apr  4 11:25:16 2023
type=USER_ACCT msg=audit(1680578716.738:63): pid=58625 uid=1000 auid=1000 ses=51 subj=? msg='op=PAM:accounting grantors=pam_permit acct="ubuntu" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/4 res=success'
----
time->Tue Apr  4 11:25:16 2023
type=UNKNOWN[1420] msg=audit(1680578716.738:63): subj_apparmor=unconfined
type=PROCTITLE msg=audit(1680578716.738:63): proctitle=7375646F0073
type=SYSCALL msg=audit(1680578716.738:63): arch=c000003e syscall=44 success=yes exit=140 a0=6 a1=7ffc2bea29d0 a2=8c a3=0 items=0 ppid=58615 pid=58625 auid=1000 uid=1000 gid=1000 euid=0 suid=0 fsuid=0 egid=1000 sgid=1000 fsgid=1000 tty=pts4 ses=51 comm="sudo" exe="/usr/bin/sudo" subj=? key=(null)
----
time->Tue Apr  4 11:25:16 2023
type=USER_CMD msg=audit(1680578716.738:64): pid=58625 uid=1000 auid=1000 ses=51 subj=? msg='cwd="/home/ubuntu" cmd="s" exe="/usr/bin/sudo" terminal=pts/4 res=failed'
----
time->Tue Apr  4 11:25:16 2023
type=UNKNOWN[1420] msg=audit(1680578716.738:64): subj_apparmor=unconfined
type=PROCTITLE msg=audit(1680578716.738:64): proctitle=7375646F0073
type=SYSCALL msg=audit(1680578716.738:64): arch=c000003e syscall=44 success=yes exit=92 a0=6 a1=7ffc2be9ea60 a2=5c a3=0 items=0 ppid=58615 pid=58625 auid=1000 uid=1000 gid=1000 euid=0 suid=0 fsuid=0 egid=1000 sgid=1000 fsgid=1000 tty=pts4 ses=51 comm="sudo" exe="/usr/bin/sudo" subj=? key=(null)
----

搜索从 2023/01/19 到 2023/04/04 登录用户 ID 1000 的用户的日志

# ausearch --start 04/04/2023 --end 04/04/2023 -ul 1000
time->Tue Apr  4 11:25:18 2023
type=UNKNOWN[1420] msg=audit(1680578718.826:66): subj_apparmor=unconfined
type=PROCTITLE msg=audit(1680578718.826:66): proctitle=7375646F007375
type=SYSCALL msg=audit(1680578718.826:66): arch=c000003e syscall=44 success=yes exit=92 a0=6 a1=7fff96df32b0 a2=5c a3=0 items=0 ppid=58615 pid=58626 auid=1000 uid=1000 gid=1000 euid=0 suid=0 fsuid=0 egid=1000 sgid=1000 fsgid=1000 tty=pts4 ses=51 comm="sudo" exe="/usr/bin/sudo" subj=? key=(null)
----
time->Tue Apr  4 11:25:18 2023
type=CRED_REFR msg=audit(1680578718.826:67): pid=58626 uid=1000 auid=1000 ses=51 subj=? msg='op=PAM:setcred grantors=pam_permit,pam_cap acct="root" exe="/usr/bin/sudo" hostname=? addr=? terminal=/dev/pts/4 res=success'
----

aureport

显示没有参数的完整摘要

# aureport
总结报告
======================
日志中的时间范围: 04/04/2023 11:17:43.528 - 04/04/2023 12:17:01.477
选定报告时间: 04/04/2023 11:17:43 - 04/04/2023 12:17:01.477
配置更改次数:4
帐户、组或角色的更改次数:5
登录次数:10
登录失败次数:3
认证数量:14
认证失败次数:7
用户数:4
终端数量:6
主机名数量:3
可执行文件数量:10
命令数:12
文件数:0
AVC 的数量:0
MAC 事件数:0
失败的系统调用数:0
异常事件数:0
异常事件响应数:0
加密事件数:0
完整性事件数:0
虚拟事件数:0
键数:0
进程 ID 数:38
事件数:491

显示认证日志种类 

# aureport -au

鉴定报告
============================================
# 日期时间 acct host term exe 成功事件
============================================
1. 04/04/2023 11:25:18 root ? /dev/pts/5 /usr/bin/su yes 69

显示各种失败的认证日志

# aureport -au --failed --summary
失败的身份验证摘要报告
=============================
total  acct
=============================
3  debian
3  ubuntu
1  root

显示用户帐户日志的修改类型

# aureport -m -i
账户修改报告
=============================================== == 
# date time auid addr term exe acct 成功事件
====================================== =========== 
1. 12/20/2022 11:30:47 root dlp.srv.world ttyS0 /usr/sbin/groupadd ? yes 68
2. 12/20/2022 11:30:47 root dlp.srv.world ttyS0 /usr/sbin/groupadd ? yes 69
3. 12/20/2022 11:30:47 root dlp.srv.world ttyS0 /usr/sbin/groupadd ? yes 70
4. 12/20/2022 11:30:47 root dlp.srv.world ttyS0 /usr/sbin/useradd ? yes 71
5. 12/20/2022 11:30:54 root dlp.srv.world ttyS0 /usr/bin/passwd debian yes 74

显示自本月以来用户帐户日志的修改类型

# aureport -m -i --start this-month
Account Modifications Report
=================================================
# date time auid addr term exe acct success event
=================================================
1. 12/20/2022 11:30:47 root dlp.srv.world ttyS0 /usr/sbin/groupadd ? yes 68
2. 12/20/2022 11:30:47 root dlp.srv.world ttyS0 /usr/sbin/groupadd ? yes 69
3. 12/20/2022 11:30:47 root dlp.srv.world ttyS0 /usr/sbin/groupadd ? yes 70
4. 12/20/2022 11:30:47 root dlp.srv.world ttyS0 /usr/sbin/useradd ? yes 71
5. 12/20/2022 11:30:54 root dlp.srv.world ttyS0 /usr/bin/passwd debian yes 74

显示各种执行日志

# aureport -x -i
Executable Report
====================================
# date time exe term host auid event
====================================
1. 04/04/2023 11:17:43 /usr/sbin/auditctl (none) ? unset 37
2. 04/04/2023 11:17:43 /usr/sbin/auditctl (none) ? unset 38
3. 04/04/2023 11:17:43 /usr/sbin/auditctl (none) ? unset 39
4. 04/04/2023 11:17:43 /usr/lib/systemd/systemd ? ? unset 40
5. 04/04/2023 11:17:43 /usr/lib/systemd/systemd ? ? unset 43
...
69. 04/04/2023 12:17:01 /usr/sbin/cron (none) ? unset 75
70. 04/04/2023 12:17:01 /usr/sbin/cron cron ? unset 76
71. 04/04/2023 12:17:01 /usr/sbin/cron (none) ? unset 76
72. 04/04/2023 12:17:01 /usr/sbin/cron (none) ? root 77
73. 04/04/2023 12:17:01 /usr/sbin/cron cron ? root 78
74. 04/04/2023 12:17:01 /usr/sbin/cron (none) ? root 78
75. 04/04/2023 12:17:01 /usr/sbin/cron cron ? root 79
76. 04/04/2023 12:17:01 /usr/sbin/cron (none) ? root 79
77. 04/04/2023 12:17:01 /usr/sbin/cron cron ? root 80
78. 04/04/2023 12:17:01 /usr/sbin/cron (none) ? root 80

显示从 2022/12/19 到 2022/12/20 的执行日志种类

# aureport -x -i --start 12/19/2022 --end 12/20/2022
Executable Report
====================================
# date time exe term host auid event
====================================
1. 12/20/2022 11:29:48 /usr/sbin/auditctl (none) ? unset 17
2. 12/20/2022 11:29:48 /usr/sbin/auditctl (none) ? unset 18
3. 12/20/2022 11:29:48 /usr/sbin/auditctl (none) ? unset 19
4. 12/20/2022 11:29:48 /usr/lib/systemd/systemd ? ? unset 20
5. 12/20/2022 11:30:29 /usr/bin/login /dev/ttyS0 dlp.srv.world root 23

通过 UserID 1000 搜索并显示 sudo 日志

# ausearch -x sudo -ua 1000 | aureport -au
Authentication Report
============================================
# date time acct host term exe success event
============================================
1. 12/20/2022 11:32:39 ubuntu dlp.srv.world /dev/ttyS0 /usr/bin/sudo yes 191
2. 12/20/2022 11:34:22 ubuntu dlp.srv.world /dev/ttyS0 /usr/bin/sudo no 277
3. 12/20/2022 11:34:26 ubuntu dlp.srv.world /dev/ttyS0 /usr/bin/sudo no 278
4. 12/20/2022 11:34:28 ubuntu dlp.srv.world /dev/ttyS0 /usr/bin/sudo no 279

通过UserID 1000搜索并显示执行日志

# ausearch -ui 1001 | aureport -x -i

Executable Report
====================================
# date time exe term host auid event
====================================
1. 12/20/2022 11:33:56 /usr/bin/sudo /dev/ttyS0 dlp.srv.world debian 252
2. 12/20/2022 11:33:56 /usr/bin/sudo ttyS0 ? debian 252
3. 12/20/2022 11:33:56 /usr/bin/sudo /dev/ttyS0 dlp.srv.world debian 253
4. 12/20/2022 11:33:56 /usr/bin/sudo ttyS0 ? debian 253
5. 12/20/2022 11:33:56 /usr/bin/sudo ttyS0 ? debian 254
6. 12/20/2022 11:33:56 /usr/bin/sudo ttyS0 ? debian 254
7. 12/20/2022 11:33:59 /usr/bin/su /dev/ttyS0 dlp.srv.world debian 255
8. 12/20/2022 11:33:59 /usr/bin/su ttyS0 ? debian 255

参考文档

https://www.server-world.info/en/note?os=Ubuntu_22.04&p=audit&f=1

标签:11,12,04,部署,ubuntu22.04,Auditd,usr,2023,root
From: https://www.cnblogs.com/wangguishe/p/17285807.html

相关文章

  • windows本地部署redis
    1:了解自己php扩展版本,在php文件里输入phpinfo();执行看php版本,看phpExtensionBiuld的值。 2:下载redis配置文件:址:https://windows.php.net/downloads/pecl/releases/redis/点5.3.4版本里的根据phpExtensionBiuld选一个下载。 3:把下载的文件里的php_redis.dll和php_......
  • docker 部署mongoDB集群与读写分离
    一.生成key文件需要注意集群中所有机器都需要用同一个文件,否则会出现验证失败的情况#生成keyopensslrand-base64756>/data/volume/mongodb/configdb/mongo.key#设置访问权限chmod400/data/volume/mongodb/configdb/mongo.key 二.启动MongoDB的docker容器d......
  • 虚拟机ubuntu22.04搭建esp-matter环境
    一. 安装esp-idfStep1:编译ESP-IDF需要以下软件包。请根据使用的Linux发行版本,选择合适的安装命令。Ubuntu和Debian: sudoapt-getinstallgitwgetflexbisongperfpython3python3-venvpython3-setuptoolscmakeninja-buildccachelibffi-devlibssl-devdf......
  • 2-nacos运行环境部署
    1、下载nacos最新的二进制压缩包;下载地址:https://github.com/alibaba/nacos/releases 2、解压下载下来的nacos最新的二进制压缩包;tar-zxvfnacos-server-1.3.1.tar.gzcdnacos/bin3、启动nacosserver./startup.sh-mstandalone 注:单机环境必须带-mstandalone参数启动......
  • 关于 Angular 应用部署时的 base-href 参数
    import{existsSync}from'fs';server.get(['/shop/*','/shop'],(req,res)=>{res.render(indexHtml,{req,providers:[{provide:APP_BASE_HREF,useValue:req.baseUrl}],});});server.set('views',distFo......
  • XXL-JOB Linux环境部署安装实战
    一、下载XXL-JOB 下载源码: https://github.com/xuxueli/xxl-job 以2.3.0的版本为例:https://github.com/xuxueli/xxl-job/archive/refs/tags/2.3.0.tar.gz xxl-job文档: https://www.xuxueli.com/xxl-job/二、依赖环境 因为需要打包,所以要有Maven环境 因为部署的是jar......
  • 常用软件Docker部署命令
    前言我们在日常开发中经常会用到一些中间件,用docker快速部署是一个不错的选择。本帖将记录一些日常开发中用到的一些软件的docker部署命令,方便查阅。PostgreSqldockerrun--namedockerPG11-ePOSTGRES_PASSWORD=123456-p5432:5432-dpostgres:12用户名:postgres密......
  • 5G网络架构与组网部署-2
    1.35G组网部署1.3.1SA组网与NSA组网5G标准分为非独立组网(NSA)与独立组网(SA)两种。 独立组网(SA)两种方案,其中Option2为最终目标。gNB:5G基站,ng-eNB:4G增强型基站。 非独立组网(NSA)三种方案:Option3、Option7、Option4。组网是逐步演进的,由最初的4G基站逐步演进为......
  • ansible 部署mysql 5.7
    准备工作创建roles目录#mkdir-pv/data/apps/ansible/roles/mysql-5.7/{files,tasks,handlers,templates,vars}hosts[ubuntu]172.16.18.31ansible_ssh_port=22ansible_ssh_user=ubuntuhostname=app-01测试连通性#ansibleubuntu-mping172.16.18.247|SUCCESS=......
  • ansible 部署 docker
    准备工作创建roles目录#mkdir-pv/data/apps/ansible/roles/docker/{files,tasks,handlers,templates,vars}hosts[ubuntu]172.16.18.31ansible_ssh_port=22ansible_ssh_user=ubuntuhostname=app-01测试连通性#ansibleubuntu-mping172.16.18.247|SUCCESS=>{......