2020-06-30

archlinux-pacdiff

 
1. Pacnew_and_Pacsave
 1.1 查找.pac *文件
  1.1.1 要在/etc存储大多数全局配置的位置进行搜索:
  1.1.2 也可以使用locate
  1.1.3 使用pacman的日志查找它们:
 1.2 管理.pac*文件 pacdiff
 1.3 paddiff帮助
2. pacman-contrib

1. Pacnew_and_Pacsave

https://wiki.archlinux.org/index.php/Pacman/Pacnew_and_Pacsave
*.pacnew文件
在软件包升级期间pacman -Syu (也有覆盖安装时pacman -S upacman -U), 为避免覆盖已存在的用户先前修改过的文件, 会创建一个.pacnew文件。发生这种情况时,pacman的输出中将显示以下消息:
  warning: /etc/pam.d/usermod installed as /etc/pam.d/usermod.pacnew
*.pacsave文件
当卸载一个软件包(pacman -R), 或者upgrade(必须先removed)一个软件包时, 会创建.pacsave文件. When the pacman database has a record that a certain file owned by the package should be backed up, it will create a .pacsave file. 生这种情况时,pacman的输出中将显示以下消息:
  warning: /etc/pam.d/usermod saved as /etc/pam.d/usermod.pacsave

1.1 查找.pac *文件

Pacman不会自动处理.pacnew文件:您必须自己维护这些文件。要发现是否已安装任何.pac *文件,请使用以下方法之一:

1.1.1 要在/etc存储大多数全局配置的位置进行搜索:

$ find /etc -regextype posix-extended -regex ".+\.pac(new|save)" 2> /dev/null
/etc/locale.gen.pacnew
/etc/shadow.pacnew
/etc/v2ray/config.json.pacsave
/etc/pacman.conf.pacnew
/etc/security/limits.d/10-gcr.conf.pacnew
/etc/default/grub.pacnew
/etc/pacman.d/mirrorlist.pacnew
/etc/nftables.conf.pacnew

1.1.2 也可以使用locate

$ sudo updatedb
$ locate --existing --regex "\.pac(new|save)$"
/etc/locale.gen.pacnew
/etc/nftables.conf.pacnew
/etc/pacman.conf.pacnew
/etc/shadow.pacnew
/etc/default/grub.pacnew
/etc/pacman.d/mirrorlist.pacnew
/etc/security/limits.d/10-gcr.conf.pacnew
/etc/v2ray/config.json.pacsave

1.1.3 使用pacman的日志查找它们:

$ grep --extended-regexp "\.pac(new|save)" /var/log/pacman.log
...
[2020-06-25T04:58:54+0800] [ALPM] warning: /etc/pacman.d/mirrorlist installed as /etc/pacman.d/mirrorlist.pacnew

1.2 管理.pac*文件 pacdiff

pacman-contrib提供了用于管理 .pac *文件的简单 pacdiff工具。它将搜索所有 .pacnew和 .pacsave文件,并要求对它们进行任何操作。默认情况下,它使用 vimdiff,但您可以使用指定其他工具。有关其他常见的比较工具,请参见应用程序/实用程序列表#比较,差异,合并。 DIFFPROG=your_editor pacdiff
https://wiki.archlinux.org/index.php/List_of_applications/Utilities#Comparison,_diff,_merge
仅打印出待处理文件
$ pacdiff -l -o
/etc/locale.gen.pacnew
/etc/nftables.conf.pacnew
/etc/pacman.conf.pacnew
/etc/shadow.pacnew
/etc/default/grub.pacnew
/etc/pacman.d/mirrorlist.pacnew
/etc/security/limits.d/10-gcr.conf.pacnew
/etc/v2ray/config.json.pacsave
使用meld作为合并程序处理/etc目录下的*.pac*文件
$ sudo DIFFPROG=meld DIFFSEARCHPATH="/etc" pacdiff
==> pacnew file found for /etc/shadow
:: (V)iew, (S)kip, (R)emove pacnew, (O)verwrite with pacnew, (Q)uit: [v/s/r/o/q] v
r
:: (V)iew, (S)kip, (R)emove pacnew, (O)verwrite with pacnew, (Q)uit: [v/s/r/o/q] removed '/etc/shadow.pacnew'
==> pacnew file found for /etc/security/limits.d/10-gcr.conf
...
命令会逐个列出每一个待处理文件:
输入(v) 回车, 查看差异:
  程序会自动打开meld对比软件, 这里可以手动逐条同步文件, 有时新的配置文件会由于软件的新功能添加新的属性项目, 这时候可以合并到在用的配置文件中,
  然后保存, 退出meld软件后. 进入下一步. (通过(v)打开meld软件查看差异, 不管是否修改保存, 退出后还是等待处理同一对文件.)
  • 如果已经手动合并保存了, 这个*.pac*文件就没用了, 可以使用(r) 回车, 删除该*.pac*文件. 然后开始处理下一对文件.
  • 如果在用的配置文件并没有什么自定义的修改, 可以使用(o) 回车, 使用*.pac*文件覆盖旧的配置文件. 然后开始处理下一对文件.
  • 或者使用(s) 回车, 跳过, 以后在说...

1.3 paddiff帮助

$ pacdiff --helpA simple program to merge or remove pacnew/pacsave files.合并或删除pacnew/pacsave文件的简单程序。
pacdiff v1.3.0Usage: pacdiff [-l | -f | -p] [--nocolor]
Search Options:select one (default: --pacmandb)选择一个(默认值:-pacmandb)
-l/--locatescan using locate使用定位扫描
-f/--findscan using find使用查找扫描
-p/--pacmandbscan active config files from pacman database扫描pacman数据库中的活动配置文件
General Options:

-o/--outputprint files instead of merging them打印文件而不是合并文件
--nocolorremove colors from output从输出中删除颜色
Environment Variables:

DIFFPROGoverride the merge program: (default: 'vim -d')覆盖合并程序:(默认值:'vim -d')
DIFFSEARCHPATHoverride the search path. (only when using find) (default: /etc)覆盖搜索路径。 (仅在使用查找时)

2. pacman-contrib

pacman-contrib包含的命令:
checkupdates检测更新(-Sy)
paccache清理缓存($ sudo paccache -rk1)
pacdiff对比管理pac*配置文件($ pacdiff -l -o)
paclist按库repository列出包
paclog-pkglist列出所有安装包(pacman -Q)
pacscripts查看安装脚本
pacsearch搜索包(pacman -Ss)
pacsort实现alpm_pkg_vercmp的排序实用程序
pactree依赖树
rankmirrors通过连接和打开速度对pacman镜子进行排名。
Pacman镜像文件位于/etc/pacman.d/中。
如果提供了URL,它也可以排名一个镜像。
updpkgsums

$ paclog-pkglist |wc -l
779

$ sudo paccache -rk1
==> finished: 16 packages removed (disk space saved: 230.82 MiB)
$ sudo pacman -Sc
Packages to keep:
  All locally installed packages
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove all other packages from cache? [Y/n] y
removing old packages from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] y
removing unused sync repositories...

$ paclog-pkglist |wc -l
779

$ sudo paccache -rk1
==> finished: 16 packages removed (disk space saved: 230.82 MiB)
$ sudo pacman -Sc
Packages to keep:
  All locally installed packages
Cache directory: /var/cache/pacman/pkg/
:: Do you want to remove all other packages from cache? [Y/n] y
removing old packages from cache...
Database directory: /var/lib/pacman/
:: Do you want to remove unused repositories? [Y/n] y
removing unused sync repositories...

$ paclist community |wc -l
104
$ paclist core |wc -l
175
$ paclist extra |wc -l
499

$ pacscripts vlc
==> ERROR: Package vlc does not include any .INSTALL script
$ pacscripts chromium
post_upgrade() {
  if (($(vercmp $2 42.0.2311.90-1) < 0)); then
...
  fi
}
# vim:set ts=2 sw=2 et:

$ checkupdates
ca-certificates-mozilla 3.53.1-1 -> 3.54-1
curl 7.70.0-1 -> 7.71.0-1
gtk-update-icon-cache 1:3.24.20-1 -> 1:3.24.21-1
gtk3 1:3.24.20-1 -> 1:3.24.21-1
imagemagick 7.0.10.21-1 -> 7.0.10.22-1
libfontenc 1.1.4-2 -> 1.1.4-3
libglvnd 1.3.1-1 -> 1.3.2-1
libwacom 1.3-1 -> 1.4-2
nspr 4.25-1 -> 4.26-1
nss 3.53.1-1 -> 3.54-1
perl-http-message 6.24-2 -> 6.25-1
unrar 1:5.9.3-2 -> 1:5.9.4-1
v2ray-domain-list-community 202006261804-1 -> 202006290805-1

$ sudo pacman -Syu
:: Synchronizing package databases...
 core                                                     134.5 KiB   193 KiB/s 00:01 [#################################################] 100%
 extra                                                   1698.5 KiB   765 KiB/s 00:02 [#################################################] 100%
 community                                                  5.0 MiB  1190 KiB/s 00:04 [#################################################] 100%
:: Starting full system upgrade...
:: Replace intel-tbb with extra/tbb? [Y/n] y
resolving dependencies...
looking for conflicting packages...
Package (16)                           Old Version     New Version     Net Change  Download Size
core/ca-certificates-mozilla           3.53.1-1        3.54-1           -0.02 MiB       0.32 MiB
core/curl                              7.70.0-1        7.71.0-1          0.02 MiB       1.01 MiB
extra/gtk-update-icon-cache            1:3.24.20-1     1:3.24.21-1       0.00 MiB       0.01 MiB
extra/gtk3                             1:3.24.20-1     1:3.24.21-1       0.19 MiB      11.24 MiB
extra/imagemagick                      7.0.10.21-1     7.0.10.22-1       0.03 MiB       2.52 MiB
intel-tbb                              2020.2-1                         -2.18 MiB               
extra/tbb                                              2020.2-1          2.18 MiB       0.38 MiB
extra/libfontenc                       1.1.4-2         1.1.4-3           0.00 MiB       0.02 MiB
extra/libglvnd                         1.3.1-1         1.3.2-1           0.01 MiB       0.36 MiB
extra/libwacom                         1.3-1           1.4-2            -0.01 MiB       0.09 MiB
core/nspr                              4.25-1          4.26-1            0.00 MiB       0.20 MiB
core/nss                               3.53.1-1        3.54-1            0.01 MiB       1.45 MiB
extra/perl-http-message                6.24-2          6.25-1            0.00 MiB       0.07 MiB
extra/unrar                            1:5.9.3-2       1:5.9.4-1         0.00 MiB       0.14 MiB
community/v2ray-domain-list-community  202006261804-1  202006290805-1    0.00 MiB       0.04 MiB
extra/xorg-fonts-encodings                             1.0.5-2           0.61 MiB       0.55 MiB

Total Download Size:    18.40 MiB
Total Installed Size:  100.52 MiB
Net Upgrade Size:        0.85 MiB
:: Proceed with installation? [Y/n] 

2020-06-19

Linux-audit


1. Audit_framework原文翻译
 1.1 添加规则
  1.1.1 审核文件和目录访问
  1.1.2 审核系统调用
 1.2 搜索日志
  1.2.1 使用pid
  1.2.2 使用keys
 1.3 寻找异常
 1.4 哪些文件或系统调用值得审核?
2. man auditctl 译文
 2.1 CONFIGURATION OPTIONS
 2.2 STATUS OPTIONS
 2.3 RULE OPTIONS
 2.4 PERFORMANCE TIPS 性能提示
 2.5 EXAMPLES
3. man auditd 译文
 3.1 OPTIONS
 3.2 SIGNALS 讯号
 3.3 Notes
4. man audit.rules 译文
 4.1 审核规则分为3种
  4.1.1 control 控制
  4.1.2 file 文件系统
  4.1.3 syscall 系统调用
 4.2 Notes
 4.3 TROUBLESHOOTING 故障排除
 4.4 EXAMPLES
 4.5 HARD WIRED EVENTS
5. See also

1. Audit_framework原文翻译

https://wiki.archlinux.org/index.php/Audit_framework
Linux审核框架提供了一个符合CAPP的(受控访问保护配置文件)审核系统,该系统可靠地收集有关系统上任何与安全相关(或与安全无关)事件的信息。它可以帮助您跟踪在系统上执行的操作。
Linux审核通过为您提供详细分析系统中发生的情况的手段,有助于使您的系统更安全。但是,它本身并不能提供额外的安全性-它不能保护您的系统免受代码故障或任何形式的利用。相反,审核对于跟踪这些问题很有用,并可以帮助您采取其他安全措施来防止这些问题。
审核框架通过侦听内核报告的事件并将它们记录到日志文件中来工作。

为了获得用户空间支持,请安装 audit 并 start/enable auditd.service。
注意:为了完全禁用审核并禁止审核消息出现在日志中,您可以将其设置audit=0为内核参数和/或mask systemd-journald-audit.socket。
https://wiki.archlinux.org/index.php/Kernel_parameters#Parameter_list
https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html
audit= [KNL] Enable the audit sub-system. 启用审核子系统 Format: { "0" | "1" | "off" | "on" }
  •  unset - (Default)内核审核已初始化但被禁用,并将由userspace auditd完全启用。
  •  0 | off - kernel audit is disabled and can not be enabled until the next reboot. 内核审核已禁用,直到下次重启才能启用.
  •  1 | on - kernel audit is initialized and partially enabled, storing at most audit_backlog_limit messages in RAM until it is fully enabled by the userspace auditd. 内核审核已初始化并被部分启用,最多将audit_backlog_limit消息存储在RAM中,直到被审核的用户空间完全启用为止。
审核框架由auditd守护程序组成,该守护程序负责编写通过审核内核接口生成并由应用程序和系统活动触发的审核消息。
守护程序包含如下命令及相关文件:
  • auditctl 即时控制审计守护进程的行为的工具,如添加规则等。
  • aureport 查看和生成审计报告的工具。
  • ausearch 查找审计事件的工具
  • autrace 类似 strace, 用于跟踪进程. 将结果写入日志文件
  • audispd 转发事件通知给其他应用程序,而不是写入到审计日志文件中。
  • auditd auditd 守护进程负责把内核产生的信息写入到 /var/log/audit/audit.log
  • augenrules 读取/etc/audit/rules.d/中的规则 并将其编译为audit.rules文件
  • /etc/audit/auditd.conf 审计守护进程的配置文件
  • /etc/audit/audit.rules 在启动时加载审核规则
  • /etc/audit/rules.d/ 包含要由augenrules编译成一个文件的各个规则集的目录。
  • /var/log/audit/audit.log 日志
  • /usr/lib/systemd/system/auditd.service enable守护进程auditd
  • aulast  类似autrace,但是使用的是审计框架
  • aulastlog 和lastlog类似,但是也使用的是审计框架
  • ausyscall 映射系统调用ID和名字
  • auvirt  展示和审计有关虚拟机的信息
  • audisp-remote, audispd-zos-remote, /etc/audit/audit-stop.rules ... 

1.1 添加规则

在添加规则之前,您必须知道审核框架可能非常冗长,并且在有效部署之前必须仔细测试每个规则。确实,只有一条规则可以在几分钟之内淹没您的所有日志。

1.1.1 审核文件和目录访问

审核框架最基本的用途是记录对所需文件的访问。为此,您必须使用监视-w文件或目录的方法。要设置的最基本规则是跟踪对passwd文件的访问:
 # auditctl -w /etc/passwd -p rwxa

您可以使用以下命令跟踪对文件夹的访问:
 # auditctl -w /etc/security/
第一条规则跟踪每读r,写w,执行x,属性变化a 的文件/etc/passwd。第二个跟踪对/etc/security/文件夹的任何访问。

您可以使用以下命令列出所有活动规则:
 # auditctl -l

您可以使用以下命令删除所有规则:
 # auditctl -D

验证规则后,您可以将它们附加到/etc/audit/audit.rules文件中,如下所示:
-w /etc/audit/audit.rules -p rwxa
-w /etc/security/

1.1.2 审核系统调用

审核框架使您可以审核使用该-a选项执行的系统调用。
与安全性相关的规则是跟踪chmod syscall,以检测文件所有权更改:
 # auditctl -a entry,always -S chmod
有关所有系统调用的列表:syscalls(2). 有很多规则和可能性,请参见auditctl(8)和audit.rules(7)。

1.2 搜索日志

审核框架提供了一些工具,以简化对系统中发生的事件的使用和研究。

1.2.1 使用pid

您可以使用来搜索与特定pid相关的事件ausearch:
 # ausearch -p 1
该命令将向您显示根据与PID 1(即systemd)相关的规则记录的所有事件。

1.2.2 使用keys

审核框架的一大功能是它具有keys管理事件的能力,建议使用这种用法。
您可以-k在规则中使用该选项,以便能够轻松找到相关事件:
 # auditctl -w /etc/passwd -p rwxa -k KEY_pwd
然后,如果您使用键搜索事件,则KEY_pwdausearch将仅显示与该文件相关的事件/etc/passwd。
 # ausearch -k KEY_pwd

1.3 寻找异常

该aureport工具可用于快速报告系统上执行的任何异常事件,包括在混杂模式下使用的网络接口,进程或线程崩溃或因ENOMEM错误退出等。
最简单的使用方法aureport是:
 # aureport -n

1.4 哪些文件或系统调用值得审核?

请记住,添加的每个审核规则都会生成日志,因此您必须准备好处理此大量信息。基本上,必须监视每个与安全性相关的事件/文件,例如id,ips,anti-rootkits等。另一方面,跟踪每个写入syscall完全没有用,最小的编译将用此事件填充日志。
可以设置更复杂的规则集,以非常细粒度的基础执行审核。如果要这样做,请参见auditctl(8)。

2. man auditctl 译文

https://jlk.fjfi.cvut.cz/arch/manpages/man/auditctl.8
auditctl程序用于与审计配置内核选项,查看配置的状态,并加载全权审核规则。

2.1 CONFIGURATION OPTIONS

配置选项CONFIGURATION OPTIONScn
-b backlogSet max number of outstanding audit buffers allowed (Kernel Default=64) If all buffers are full, the failure flag is consulted by the kernel for action.设置允许的未完成审核缓冲区的最大数量(内核默认值= 64)如果所有缓冲区都已满,则内核会向故障标志咨询以采取措施。
--backlog_wait_time wait_timeSet the time for the kernel to wait (Kernel Default 60*HZ) when the backlog_limit is reached before queuing more audit events to be transferred to auditd. The number must be greater than or equal to zero and less that 10 times the default value.设置到达backlog_limit之前内核等待的时间(内核默认值为60 * HZ),然后再排队更多审核事件以将其转移到auditd。该数字必须大于或等于零且小于默认值的10倍。
-cContinue loading rules in spite of an error. This summarizes the results of loading the rules. The exit code will not be success if any rule fails to load.尽管有错误,仍继续加载规则。这总结了加载规则的结果。如果任何规则加载失败,则退出代码将不会成功。
-DDelete all rules and watches. This can take a key option (-k), too.删除所有规则和手表。这也可以采用关键选项(-k)。
-e [0..2]Set enabled flag. When 0 is passed, this can be used to temporarily disable auditing. When 1 is passed as an argument, it will enable auditing. To lock the audit configuration so that it can't be changed, pass a 2 as the argument. Locking the configuration is intended to be the last command in audit.rules for anyone wishing this feature to be active. Any attempt to change the configuration in this mode will be audited and denied. The configuration can only be changed by rebooting the machine.设置启用标志。传递0时,可用于暂时禁用审核。当将1作为参数传递时,它将启用审核。要锁定审核配置以使其无法更改,请传递2作为参数。对于希望启用此功能的任何人,锁定配置都将成为audit.rules中的最后一条命令。以此方式更改配置的任何尝试都将被审核并拒绝。只能通过重新引导计算机来更改配置。
-f [0..2]Set failure mode 0=silent 1=printk 2=panic. This option lets you determine how you want the kernel to handle critical errors. Example conditions where this mode may have an effect includes: transmission errors to userspace audit daemon, backlog limit exceeded, out of kernel memory, and rate limit exceeded. The default value is 1. Secure environments will probably want to set this to 2.设置故障模式0 =静音1 =打印2 =紧急。该选项使您可以确定希望内核如何处理严重错误。此模式可能会起作用的示例条件包括:到用户空间审核守护程序的传输错误,超出积压限制,内核内存不足和超出速率限制。默认值为1.安全环境可能需要将此设置为2。
-hHelp帮帮我
-iWhen given by itself, ignore errors when reading rules from a file. This causes auditctl to always return a success exit code. If passed as an argument to -s then it gives an interpretation of the numbers to human readable words if possible.如果单独给出,则从文件读取规则时忽略错误。这将导致auditctl始终返回成功退出代码。如果将其作为参数传递给-s,则在可能的情况下将数字解释为人类可读的单词。
--loginuid-immutableThis option tells the kernel to make loginuids unchangeable once they are set. Changing loginuids requires CAP_AUDIT_CONTROL. So, its not something that can be done by unprivileged users. Setting this makes loginuid tamper-proof, but can cause some problems in certain kinds of containers.此选项告诉内核一旦设置登录ID,便使其不可更改。更改登录名需要CAP_AUDIT_CONTROL。因此,非特权用户无法做到这一点。设置此选项可以使loginuid防篡改,但可能会在某些类型的容器中引起一些问题。
-q mount-point,subtreeIf you have an existing directory watch and bind or move mount another subtree in the watched subtree, you need to tell the kernel to make the subtree being mounted equivalent to the directory being watched. If the subtree is already mounted at the time the directory watch is issued, the subtree is automatically tagged for watching. Please note the comma separating the two values. Omitting it will cause errors.如果您有一个现有的目录监视并在监视的子树中绑定或移动其他子树的挂载,则需要告诉内核使要挂载的子树等效于被监视的目录。如果在发出目录监视时已经安装了子树,则该子树会被自动标记以进行监视。请注意用逗号分隔两个值。省略它会导致错误。
-r rateSet limit in messages/sec (0=none). If this rate is non-zero and is exceeded, the failure flag is consulted by the kernel for action. The default value is 0.以消息/秒为单位设置限制(0 =无)。如果该速率不为零且超过该速率,则内核将查询故障标志以采取措施。默认值为0。
--reset-lostReset the lost record counter shown by the status command.重置status命令显示的丢失记录计数器。
-R fileRead rules from a file. The rules must be 1 per line and in the order that they are to be executed in. The rule file must be owned by root and not readable by other users or it will be rejected. The rule file may have comments embedded by starting the line with a '#' character. Rules that are read from a file are identical to what you would type on a command line except they are not preceded by auditctl (since auditctl is the one executing the file) and you would not use shell escaping since auditctl is reading the file instead of bash.从文件中读取规则。规则必须每行1条,并且必须按执行顺序排列。规则文件必须归root拥有,其他用户不能读取,否则它将被拒绝。规则文件可以通过以'#'字符开头的行来嵌入注释。从文件中读取的规则与您在命令行上键入的规则相同,只是它们之前没有auditctl(因为auditctl是执行文件的规则),并且您不会使用外壳转义,因为auditctl正在读取文件而不是重击。
-tTrim the subtrees after a mount command.在安装命令后修剪子树。

2.2 STATUS OPTIONS

状态选项STATUS OPTIONS
-lList all rules 1 per line. Two more options may be given to this command. You can give either a key option (-k) to list rules that match a key or a (-i) to have a0 through a3 interpreted to help determine the syscall argument values are correct .每行列出所有规则1。可以给此命令另外两个选项。您可以给键选项(-k)列出匹配键的规则,也可以给(-i)给出解释a0到a3的规则,以帮助确定syscall参数值正确。
-m textSend a user space message into the audit system. This can only be done if you have CAP_AUDIT_WRITE capability (normally the root user has this). The resulting event will be the USER type.向审核系统发送用户空间消息。仅当您具有CAP_AUDIT_WRITE功能(通常root用户具有此功能)时,才能完成此操作。结果事件将为USER类型。
-sReport the kernel's audit subsystem status. It will tell you the in-kernel values that can be set by -e, -f, -r, and -b options. The pid value is the process number of the audit daemon. Note that a pid of 0 indicates that the audit daemon is not running. The lost entry will tell you how many event records that have been discarded due to the kernel audit queue overflowing. The backlog field tells how many event records are currently queued waiting for auditd to read them. This option can be followed by the -i to get a couple fields interpreted.报告内核的审核子系统状态。它将告诉您可以通过-e,-f,-r和-b选项设置的内核内值。 pid值是审核守护程序的进程号。请注意,pid为0表示审核守护程序未运行。丢失的条目将告诉您有多少事件记录由于内核审核队列溢出而被丢弃。待办事项字段告诉当前有多少事件记录正在排队,等待审核以读取它们。此选项后可以跟-i来解释几个字段。
-vPrint the version of auditctl.打印auditctl的版本。

2.3 RULE OPTIONS

规则选项itmeRULE OPTIONS谷歌翻译
-a [list,action|action,list]Append rule to the end of list with action. Please note the comma separating the two values. Omitting it will cause errors. The fields may be in either order. It could be list,action or action,list. The following describes the valid list names:通过操作将规则追加到列表的末尾。请注意用逗号分隔两个值。省略它会导致错误。字段可以是任意顺序。它可以是列表,动作或动作,列表。以下描述了有效的列表名称:

taskAdd a rule to the per task list. This rule list is used only at the time a task is created -- when fork() or clone() are called by the parent task. When using this list, you should only use fields that are known at task creation time, such as the uid, gid, etc.将规则添加到每个任务列表。此规则列表仅在创建任务时使用-父任务调用fork()或clone()时。使用此列表时,应仅使用任务创建时已知的字段,例如uid,gid等。

exitAdd a rule to the syscall exit list. This list is used upon exit from a system call to determine if an audit event should be created.将规则添加到syscall退出列表。从系统调用退出时,使用此列表来确定是否应创建审核事件。

userAdd a rule to the user message filter list. This list is used by the kernel to filter events originating in user space before relaying them to the audit daemon. It should be noted that the only fields that are valid are: uid, auid, gid, pid, subj_user, subj_role, subj_type, subj_sen, subj_clr, and msgtype. All other fields will be treated as non-matching. It should be understood that any event originating from user space from a process that has CAP_AUDIT_WRITE will be recorded into the audit trail. This means that the most likely use for this filter is with rules that have an action of never since nothing has to be done to allow events to be recorded.将规则添加到用户消息过滤器列表。内核使用此列表来过滤源自用户空间的事件,然后再将其中继到审计守护程序。应该注意的是,唯一有效的字段是:uid,auid,gid,pid,subj_user,subj_role,subj_type,subj_sen,subj_clr和msgtype。所有其他字段将被视为不匹配。应该理解,任何来自用户空间的,来自具有CAP_AUDIT_WRITE的进程的事件都将被记录到审计跟踪中。这意味着此过滤器最有可能用于规则,该规则的作用是永不执行,因为无需执行任何操作即可记录事件。

excludeAdd a rule to the event type exclusion filter list. This list is used to filter events that you do not want to see. For example, if you do not want to see any avc messages, you would using this list to record that. Events can be excluded by process ID, user ID, group ID, login user ID, message type or subject context. The action is ignored and uses its default of "never".将规则添加到事件类型排除过滤器列表。该列表用于过滤您不想看到的事件。例如,如果您不想看到任何AVC消息,则可以使用此列表进行记录。可以通过进程ID,用户ID,组ID,登录用户ID,消息类型或主题上下文排除事件。该操作将被忽略,并使用其默认值“从不”。

filesystemAdd a rule that will be applied to a whole filesystem. The filesystem must be identified with a fstype field. Normally this filter is used to exclude any events for a whole filesystem such as tracefs or debugfs.添加将应用于整个文件系统的规则。必须使用fstype字段标识文件系统。通常,此过滤器用于排除整个文件系统的任何事件,例如tracefs或debugfs。


The following describes the valid actions for the rule:以下描述了该规则的有效操作:

neverNo audit records will be generated. This can be used to suppress event generation. In general, you want suppressions at the top of the list instead of the bottom. This is because the event triggers on the first matching rule.将不会生成审核记录。这可以用来抑制事件的产生。通常,您希望抑制显示在列表的顶部而不是底部。这是因为事件在第一个匹配规则上触发。

alwaysAllocate an audit context, always fill it in at syscall entry time, and always write out a record at syscall exit time.分配审核上下文,始终在syscall进入时填写它,并始终在syscall退出时写出一条记录。
-A list,actionAdd rule to the beginning list with action.通过操作将规则添加到开始列表中。
-C [f=f | f!=f]Build an inter-field comparison rule: field, operation, field. You may pass multiple comparisons on a single command line. Each one must start with -C. Each inter-field equation is anded with each other as well as equations starting with -F to trigger an audit record. There are 2 operators supported - equal, and not equal. Valid fields are:建立字段间比较规则:字段,操作,字段。您可以在单个命令行上通过多个比较。每个人都必须以-C开头。每个场间方程式以及以-F开头的方程式之间相互和运算,以触发审核记录。支持2个运算符-相等和不相等。有效字段为:
auid, uid, euid, suid, fsuid, obj_uid; and gid, egid, sgid, fsgid, obj_gidThe two groups of uid and gid cannot be mixed. But any comparison within the group can be made. The obj_uid/gid fields are collected from the object of the event such as a file or directory.uid和gid这两组不能混用。但是可以在组内进行任何比较。 obj_uid / gid字段是从事件对象(例如文件或目录)中收集的。
-d list,actionDelete rule from list with action. The rule is deleted only if it exactly matches syscall name(s) and every field name and value.从列表中删除规则并执行操作。仅当规则与系统调用名称以及每个字段名称和值完全匹配时,才会删除该规则。
-F [n=v | n!=v | n<v | n>v | n<=v | n>=v | n&v | n&=v]Build a rule field: name, operation, value. You may have up to 64 fields passed on a single command line. Each one must start with -F. Each field equation is anded with each other (as well as equations starting with -C) to trigger an audit record. There are 8 operators supported - equal, not equal, less than, greater than, less than or equal, and greater than or equal, bit mask, and bit test respectively. Bit test will "and" the values and check that they are equal, bit mask just "ands" the values. Fields that take a user ID may instead have the user's name; the program will convert the name to user ID. The same is true of group names. Valid fields are:建立一个规则字段:名称,操作,值。单个命令行上最多可以传递64个字段。每个必须以-F开头。每个字段方程式相互关联(以及以-C开头的方程式)以触发审核记录。支持8种运算符-分别等于,不等于,小于,大于,小于或等于以及大于或等于,位掩码和位测试。位测试将“与”这些值并检查它们是否相等,位掩码仅“与”这些值。带有用户ID的字段可以改用用户名;程序会将名称转换为用户ID。组名也是如此。有效字段为:

a0, a1, a2, a3Respectively, the first 4 arguments to a syscall. Note that string arguments are not supported. This is because the kernel is passed a pointer to the string. Triggering on a pointer address value is not likely to work. So, when using this, you should only use on numeric values. This is most likely to be used on platforms that multiplex socket or IPC operations.分别是syscall的前4个参数。请注意,不支持字符串参数。这是因为向内核传递了指向字符串的指针。在指针地址值上触发不太可能起作用。因此,使用此选项时,仅应在数字值上使用。这最有可能在多路套接字或IPC操作的平台上使用。

archThe CPU architecture of the syscall. The arch can be found doing 'uname -m'. If you do not know the arch of your machine but you want to use the 32 bit syscall table and your machine supports 32 bit, you can also use b32 for the arch. The same applies to the 64 bit syscall table, you can use b64. In this way, you can write rules that are somewhat arch independent because the family type will be auto detected. However, syscalls can be arch specific and what is available on x86_64, may not be available on ppc. The arch directive should precede the -S option so that auditctl knows which internal table to use to look up the syscall numbers.syscall的CPU体系结构。可以使用“ uname -m”找到该拱门。如果您不知道计算机的拱门,但要使用32位syscall表并且您的计算机支持32位,则也可以将b32用于拱门。同样适用于64位syscall表,可以使用b64。这样,您可以编写在某种程度上与拱形无关的规则,因为将自动检测族类型。但是,系统调用可能是特定于arch的,而x86_64上可用的系统调用可能在ppc上不可用。 arch指令应在-S选项之前,以便auditctl知道要使用哪个内部表来查找系统调用号。

auidThe original ID the user logged in with. Its an abbreviation of audit uid. Sometimes its referred to as loginuid. Either the user account text or number may be used.用户登录时使用的原始ID。它是Audit uid的缩写。有时将其称为loginuid。可以使用用户帐户文本或号码。

devmajorDevice Major Number设备主号码

devminorDevice Minor Number设备次编号

dirFull Path of Directory to watch. This will place a recursive watch on the directory and its whole subtree. It can only be used on exit list. See "-w".要观看的目录的完整路径。这将在目录及其整个子树上放置递归监视。它只能在退出列表上使用。请参见“ -w”。

egidEffective Group ID. May be numeric or the groups name.有效的组ID。可以是数字或组名。

euidEffective User ID. May be numeric or the user account name.有效的用户ID。可以是数字或用户帐户名。

exeAbsolute path to application that while executing this rule will apply to. This can only be used on the exit list.执行此规则时将应用到的应用程序的绝对路径。这只能在退出列表上使用。

exitExit value from a syscall. If the exit code is an errno, you may use the text representation, too.从系统调用中退出值。如果退出代码是errno,则也可以使用文本表示形式。

fsgidFilesystem Group ID. May be numeric or the groups name.文件系统组ID。可以是数字或组名。

fsuidFilesystem User ID. May be numeric or the user account name.文件系统用户标识。可以是数字或用户帐户名。

filetypeThe target file's type. Can be either file, dir, socket, link, character, block, or fifo.目标文件的类型。可以是文件,目录,套接字,链接,字符,块或fifo。

gidGroup ID. May be numeric or the groups name.组ID。可以是数字或组名。

inodeInode Number索引号

keyThis is another way of setting a filter key. See discussion above for -k option.这是设置过滤键的另一种方法。有关-k选项,请参见上面的讨论。

msgtypeThis is used to match the event's record type. It should only be used on the exclude or user filter lists.这用于匹配事件的记录类型。仅应在排除或用户过滤器列表上使用它。

obj_uidObject's UID对象的UID

obj_gidObject's GID对象的GID

obj_userResource's SE Linux User资源的SE Linux用户

obj_roleResource's SE Linux Role资源在SE Linux中的角色

obj_typeResource's SE Linux Type资源的SE Linux类型

obj_lev_lowResource's SE Linux Low Level资源的SE Linux低级

obj_lev_highResource's SE Linux High Level资源的SE Linux高级

pathFull Path of File to watch. It can only be used on exit list.要观看的完整文件路径。它只能在退出列表上使用。

permPermission filter for file operations. See "-p". It can only be used on exit list. You can use this without specifying a syscall and the kernel will select the syscalls that satisfy the permissions being requested.文件操作的权限过滤器。请参阅“ -p”。它只能在退出列表上使用。您可以在不指定系统调用的情况下使用它,内核将选择满足所请求权限的系统调用。

persOS Personality Number操作系统个性编号

pidProcess ID进程ID

ppidParent's Process ID家长的进程ID

sessionidUser's login session ID用户的登录会话ID

subj_userProgram's SE Linux User程序的SE Linux用户

subj_roleProgram's SE Linux Role程序的SE Linux角色

subj_typeProgram's SE Linux Type程序的SE Linux类型

subj_senProgram's SE Linux Sensitivity程序的SE Linux敏感性

subj_clrProgram's SE Linux Clearance程序的SE Linux许可

sgidSaved Group ID. See getresgid(2) man page.保存的组ID。请参见getresgid(2)手册页。

successIf the exit value is >= 0 this is true/yes otherwise its false/no. When writing a rule, use a 1 for true/yes and a 0 for false/no如果出口值> = 0,则为true / yes,否则为false / no。编写规则时,将1表示是/是,将0表示否/否

suidSaved User ID. See getresuid(2) man page.保存的用户ID。请参见getresuid(2)手册页。

uidUser ID. May be numeric or the user account name.用户身份。可以是数字或用户帐户名。
-k keySet a filter key on an audit rule. The filter key is an arbitrary string of text that can be up to 31 bytes long. It can uniquely identify the audit records produced by a rule. Typical use is for when you have several rules that together satisfy a security requirement. The key value can be searched on with ausearch so that no matter which rule triggered the event, you can find its results. The key can also be used on delete all (-D) and list rules (-l) to select rules with a specific key. You may have more than one key on a rule if you want to be able to search logged events in multiple ways or if you have an audispd plugin that uses a key to aid its analysis.在审核规则上设置筛选键。过滤键是任意文本字符串,最长31个字节。它可以唯一地标识规则产生的审核记录。当您具有多个同时满足安全性要求的规则时,通常用于这种情况。可以使用ausearch搜索键值,以便无论触发该事件的规则是什么,您都可以找到其结果。该键还可用于删除所有(-D)和列出规则(-l),以选择具有特定键的规则。如果您希望能够以多种方式搜索记录的事件,或者您有一个使用键来帮助对其进行分析的audispd插件,则规则上可能有多个键。
-p [r|w|x|a]Describe the permission access type that a file system watch will trigger on. r=read, w=write, x=execute, a=attribute change. These permissions are not the standard file permissions, but rather the kind of syscall that would do this kind of thing. The read & write syscalls are omitted from this set since they would overwhelm the logs. But rather for reads or writes, the open flags are looked at to see what permission was requested.描述文件系统监视将触发的权限访问类型。 r =读取,w =写入,x =执行,a =属性更改。这些权限不是标准的文件权限,而是执行这种操作的那种syscall。读和写syscall从该集合中省略,因为它们会使日志不堪重负。但是,对于读取或写入,将查看打开标志以查看请求的权限。
-S [Syscall name or number|all]Any syscall name or number may be used. The word 'all' may also be used. If the given syscall is made by a program, then start an audit record. If a field rule is given and no syscall is specified, it will default to all syscalls. You may also specify multiple syscalls in the same rule by using multiple -S options in the same rule. Doing so improves performance since fewer rules need to be evaluated. Alternatively, you may pass a comma separated list of syscall names. If you are on a bi-arch system, like x86_64, you should be aware that auditctl simply takes the text, looks it up for the native arch (in this case b64) and sends that rule to the kernel. If there are no additional arch directives, IT WILL APPLY TO BOTH 32 & 64 BIT SYSCALLS. This can have undesirable effects since there is no guarantee that any syscall has the same number on both 32 and 64 bit interfaces. You will likely want to control this and write 2 rules, one with arch equal to b32 and one with b64 to make sure the kernel finds the events that you intend. See the arch field discussion for more info.可以使用任何系统调用名称或编号。也可以使用单词“ all”。如果给定的系统调用是由程序进行的,则开始审核记录。如果给出了字段规则,但未指定任何系统调用,则它将默认为所有系统调用。您也可以在同一规则中通过在同一规则中使用多个-S选项来指定多个系统调用。由于需要评估的规则较少,因此可以提高性能。或者,您可以传递以逗号分隔的系统调用名称列表。如果您使用的是x86_64之类的双体系结构,则应注意,auditctl只是获取文本,在本地体系结构(在本例中为b64)中查找文本,然后将该规则发送至内核。如果没有其他arch指令,则它将同时应用于32位和64位SYSCALLS。由于不能保证任何系统调用在32位和64位接口上都具有相同的编号,因此这可能会产生不良影响。您可能需要控制它并编写2条规则,其中一条的arch等于b32,另一条的b64确保内核能够找到您想要的事件。有关更多信息,请参见拱形字段讨论。
-w pathInsert a watch for the file system object at path. You cannot insert a watch to the top level directory. This is prohibited by the kernel. Wildcards are not supported either and will generate a warning. The way that watches work is by tracking the inode internally. If you place a watch on a file, its the same as using the -F path option on a syscall rule. If you place a watch on a directory, its the same as using the -F dir option on a syscall rule. The -w form of writing watches is for backwards compatibility and the syscall based form is more expressive. Unlike most syscall auditing rules, watches do not impact performance based on the number of rules sent to the kernel. The only valid options when using a watch are the -p and -k. If you need to anything fancy like audit a specific user accessing a file, then use the syscall auditing form with the path or dir fields. See the EXAMPLES section for an example of converting one form to another.在路径中插入监视文件系统对象的路径。您不能将手表插入顶层目录。这是内核禁止的。也不支持通配符,并且会生成警告。监视工作的方式是通过内部跟踪inode。如果将监视放在文件上,则与在系统调用规则上使用-F path选项相同。如果将监视放置在目录上,则与在系统调用规则上使用-F dir选项相同。写手表的-w形式是为了向后兼容,而基于syscall的形式更具表现力。与大多数syscall审核规则不同,监视不会根据发送给内核的规则数量来影响性能。使用手表时,唯一有效的选项是-p和-k。如果您需要进行诸如审核特定用户访问文件的操作,请使用syscall审核表单以及path或dir字段。有关将一种形式转换为另一种形式的示例,请参见“示例”部分。
-W pathRemove a watch for the file system object at path. The rule must match exactly. See -d discussion for more info.删除监视路径下的文件系统对象。规则必须完全匹配。有关更多信息,请参见-d讨论。

2.4 PERFORMANCE TIPS 性能提示

系统会对每个程序的每个系统调用评估系统调用规则。如果您有10个syscall规则,则系统中的每个程序都会在syscall期间延迟,而审核系统会评估每个规则。太多的系统调用规则将损害性能。每当过滤器,操作,键和字段相同时,尝试尽可能多地合并。例如:
auditctl -a always,exit -S openat -F success=0
auditctl -a always,exit -S truncate -F success=0
可以重写为一个规则:
auditctl -a always,exit -S openat -S truncate -F success=0

另外,请在可行的地方尝试使用文件系统审核。这样可以提高性能。例如,如果您想捕获所有如上所述的失败打开和截断,但只关心/ etc中的文件,而不关心/ usr或/ sbin,则可以使用以下规则:
auditctl -a always,exit -S openat -S truncate -F dir=/etc -F success=0
由于内核不会在每个系统调用中对其进行评估,因此这将具有更高的性能。它将由文件系统审核代码处理,并且仅在与文件系统相关的syscall中进行检查。

2.5 EXAMPLES

auditctl -a always,exit -S all -F pid=1005To see all syscalls made by a specific program
查看特定程序进行的所有系统调用
auditctl -a always,exit -S openat -F auid=510To see files opened by a specific user
查看特定用户打开的文件
auditctl -a always,exit -S openat -F success=0To see unsuccessful openat calls
查看不成功的openat呼叫
auditctl -w /etc/shadow -p wa
auditctl -a always,exit -F path=/etc/shadow -F perm=wa
To watch a file for changes (2 ways to express)
观看文件中的更改(两种表达方式)
auditctl -w /etc/ -p wa
auditctl -a always,exit -F dir=/etc/ -F perm=wa
To recursively watch a directory for changes
递归查看目录中的更改(两种表达方式)
auditctl -a always,exit -F dir=/home/ -F uid=0 -C auid!=obj_uidTo see if an admin is accessing other user's files
查看管理员是否正在访问其他用户的文件

3. man auditd 译文

https://jlk.fjfi.cvut.cz/arch/manpages/man/auditd.8.en
auditd是Linux审核系统的用户空间组件。它负责将审核记录写入磁盘。使用ausearch或aureport实用程序可以查看日志。使用auditctl实用程序配置审计系统或加载规则。在启动过程中,auditctl读取/etc/audit/audit.rules中 的规则并将其加载到内核中。另外,还有一个 augenrules程序,它读取/etc/audit/rules.d/中的规则 并将其编译为audit.rules文件。审核守护程序本身具有一些管理员可能希望自定义的配置选项。它们位于auditd.conf文件。

3.1 OPTIONS

-f 将审核守护程序放在前台进行调试。消息还会发送到stderr,而不是审核日志。
-l 允许审核守护程序遵循配置文件的符号链接。
-n 没有叉子 这对于运行inittab或systemd非常有用。
-s=ENABLE_STATE 在启动时指定auditd是否应更改内核启用标志的当前值。ENABLE_STATE的有效值为 "disable", "enable" or "nochange".默认设置为启用(在审计结束时禁用)。启用标志的值可以在使用'auditctl -e'进行审核的期间更改。
-c 指定备用配置文件目录。请注意,该目录将传递给调度程序。(default: /etc/audit/)

3.2 SIGNALS 讯号

SIGHUP: 导致审核重新配置。这意味着auditd重新读取配置文件。如果没有语法错误,它将继续实施请求的更改。如果重新配置成功,则将DAEMON_CONFIG事件记录在日志中。如果未成功,则错误处理由auditd.conf中的space_left_action,admin_space_left_action,disk_full_action和disk_error_action参数控制。
SIGTERM: 使审计对象停止处理审计事件,编写关闭审计事件,然后退出。
SIGUSR1: 使审计后立即轮换日志。它将查询max_log_file_action以查看是否应保留日志。
SIGUSR2: 使审核的尝试恢复日志记录。暂停日志记录后通常需要这样做。

3.3 Notes

应该添加引导参数 audit=1 以确保内核将在审核守护程序启动之前运行的所有进程标记为可审核。不这样做将使一些过程无法正确审核。
审核守护程序可以通过audisp-remote audispd插件从其他审核守护程序接收审核事件。审核守护程序可以与tcp_wrappers链接以控制可以连接的计算机。在这种情况下,可以将条目添加到hosts.allow和deny。

4. man audit.rules 译文

https://jlk.fjfi.cvut.cz/arch/manpages/man/audit.rules.7
audit.rules是一个包含审核规则的文件,只要启动该守护程序,该文件就会由审核守护程序的init脚本加载。初始化脚本使用auditctl程序执行此操作。
规则的语法与在shell提示符下键入auditctl命令时的语法基本相同,不同之处在于您无需键入auditctl命令名,因为这是隐含的。

4.1 审核规则分为3种

4.1.1 control 控制

控制命令通常涉及配置审核系统,而不是告诉它要注意什么。这些命令通常包括删除所有规则,设置内核的待办事项队列的大小,设置故障模式,设置事件速率限制,或告诉auditctl忽略规则中的语法错误并继续加载。通常,这些规则位于规则文件的顶部。

4.1.2 file 文件系统

文件系统规则有时称为监视。这些规则用于审核对您可能感兴趣的特定文件或目录的访问。如果监视规则中给出的路径是目录,则使用的规则将递归到目录树的底部,但不包括可能存在的任何目录。安装点。这些监视规则的语法通常遵循以下格式:
-w path-to-file -p permissions -k keyname
其中 -p 选项可用: r -读取文件; w -写入文件; x -执行文件; a -更改文件属性.
还可以使用下面描述的syscall格式创建watch,以提供更大的灵活性和更多选择。使用syscall规则,您可以在path和dir之间进行选择,它们分别针对特定的inode或目录树。还应注意,如果父目录下有一个挂载点,则递归目录监视将停止。选项( a -q 规则)可以使挂载的子目录等效。

4.1.3 syscall 系统调用

系统调用规则被加载到匹配的引擎中,该引擎拦截系统上所有程序进行的每个syscall。因此,仅在必要时才使用系统调用规则非常重要,因为它们会影响性能。规则越多,性能影响越大。不过,只要有可能,您可以通过将系统调用组合到一个规则中来提高性能。
Linux内核有4个规则匹配列表(matching lists)或过滤器(有时也称filters)。它们是: task, exit, user, and exclude(任务,退出,用户和排除)。
task: 仅在fork或clone克隆syscall期间检查任务列表task list。在实践中很少使用它。
exit: 退出筛选器是评估所有系统调用和文件系统审核请求的地方。
user: 用户过滤器用于过滤(删除)源自用户空间的某些事件。默认情况下,允许源于用户空间的任何事件。因此,如果您不想看到某些事件,那么可以在其中删除一些事件。有关有效字段,请参见auditctl(8)。
exclude: 排除过滤器用于排除某些事件的发出。msgtype和许多主题属性字段可用于告诉内核您不想记录的消息类型。此过滤器可以整体删除事件,并且对其他任何属性都不具有选择性。用户过滤器和退出过滤器更适合选择性地审核事件。该过滤器的操作将被忽略,默认为从不"never"。

Syscall规则的一般形式为:
-a action,list -S syscall -F field=value -k keyname
其中-a选项告诉内核的规则匹配引擎,我们希望在规则列表的末尾追加一个规则。但是我们需要指定它继续执行哪个规则列表,以及在触发时采取什么操作。操作有:
always: -总是创建一个事件
never: -从不创建事件
-a 操作和列表用逗号分隔,但两者之间没有空格。有效列表为: task , exit , user , and exclude .它们的含义已在前面进行了解释。

-S 规则中的下一个通常是-S选项。该字段可以是系统调用名称或号码。为了便于阅读,几乎总是使用该名称。您可以通过指定另一个-S来在一个规则中提供多个系统调用选项。当发送到内核时,所有syscall字段都放入一个掩码中,以便一个比较可以确定syscall是否有意义。因此,在一个规则中添加多个系统调用非常有效。当您指定系统调用名称时,auditctl将查找该名称并获取其系统调用编号。这会导致在双体系结构计算机上出现一些问题。32位和64位syscall号码有时(但不总是)排队。因此,要解决此问题,通常需要将规则分为2个,其中一个指定 -F arch=b32 ,另一个指定 -F arch=b64 。这需要放在-S选项前面,以便auditctl在返回数字时可以查看正确的查找表。

-F 指定syscall后,通常将具有一个或多个-F选项来微调要匹配的内容。读者应该查看auditctl手册页,而不是在此处列出所有有效的字段类型,该手册页完整列出了每个字段及其含义。但值得一提。
审核系统认为uid为无符号数字。审核系统使用数字-1表示未设置登录ID。这意味着当它打印出来时,看起来像是4294967295。如果您编写了想要获取系统有效用户的规则,则需要查看/etc/login.defs以查看用户帐户的起始位置。例如,如果UID_MIN为500,那么您还需要考虑-1的无符号表示大于500。因此,您可以使用以下规则来解决此问题:
-F auid>=500 -F auid!=4294967295
这些单独的检查是 "anded" 并且都必须是真实的。

关于syscall规则要了解的最后一件事是,您可以添加一个关键字段,该字段是要插入事件的自由格式文本字符串,以帮助标识其含义。在NOTES部分中将对此进行详细讨论。

4.2 Notes

审核的目的是能够定期或每当事件发生时进行调查。预先计划一些简单的步骤将使这项工作变得容易。最好的建议是在监视规则和系统调用规则中都使用键来赋予规则含义。如果规则相关或一起满足特定要求,则为它们指定一个公共键名。您可以在调查过程中使用它来仅选择具有特定含义的结果。

在进行调查时,通常会从主要aureport输出开始,以了解系统上正在发生的事情。该报告主要告诉您有关审计系统硬编码的事件,例如登录/注销,身份验证的使用,系统异常,计算机上有多少用户以及SE Linux是否检测到任何AVC。
aureport --start this-week

查看报告后,您可能希望获得有关已加载的哪些规则已触发的第二个视图。这是密钥变得重要的地方。通常,您将像这样运行关键摘要报告:
aureport --start this-week --key --summary

这将给出与已触发的规则关联的键的有序列表。例如,如果您有一个syscall审核规则,该规则在使用EPERM打开文件失败时触发,该文件具有如下所示的关键访问字段:
-a always,exit -F arch=b64 -S open -S openat -F exit=-EPERM -k access

然后,您可以使用ausearch隔离这些故障,并将结果通过管道传输到aureport进行显示。假设您的调查发现很多拒绝访问事件。如果要查看尝试未经授权访问的文件,可以运行以下命令:
ausearch --start this-week -k access --raw |aureport --file --summary

这将给出一个有序列表,显示由于EPERM故障而正在访问哪些文件。假设您想查看哪些用户访问失败,可以运行以下命令:
ausearch --start this-week -k access --raw |aureport --user --summary

如果调查显示对特定文件的访问失败很多,则可以运行以下报告查看谁在执行此操作:
ausearch --start this-week -k access -f /path-to/file --raw |aureport --user -i

此报告将为您提供按人进行的单独访问尝试。如果需要查看正在报告的实际审核事件,则可以查看日期,时间和事件列。假设事件为822,并且发生在2009年9月1日的2:30,并且您使用的是en_US.utf8语言环境,则命令将类似于以下内容:
ausearch --start 09/01/2009 02:30 -a 822 -i --just-one

这将选择该日期和时间中具有匹配事件ID的第一个事件,并将数字值解释为人类可读的值。
能够进行这种分析的最重要步骤是在最初编写规则时设置关键字段。还应指出,您可以将多个关键字字段与任何给定规则关联。

4.3 TROUBLESHOOTING 故障排除

如果没有收到您认为应该使用的系统调用规则上的事件,请尝试在strace下运行测试程序,以便可以看到系统调用。您可能已经确定了错误的系统调用。
如果从auditctl得到警告,说“ XX行中的32/64位syscall不匹配,则应指定一个arch”。"32/64 bit syscall mismatch in line XX, you should specify an arch".
这意味着您在双体系结构上指定了系统调用规则,其中该系统调用对于32位和64位接口具有不同的系统调用编号。这意味着在这些接口之一上,您可能正在审核错误的syscall。要解决此问题,请将规则重写为两个规则,为每个规则指定预期的拱门。例如,
    -always,exit -S openat -k access
将被重写为
    -always,exit -F arch=b32 -S openat -k access
    -always,exit -F arch=b64 -S openat -k access

如果您收到一条警告,指出“不赞成使用输入规则,请更改为退出规则”。 "entry rules deprecated, changing to exit rule".
这意味着您有一个适用于条目过滤器的规则,但是该过滤器不再可用。Auditctl将您的规则移至退出过滤器,以免丢失。但是要解决此问题,使您不再收到警告,则需要从进入到退出更改违规规则。

4.4 EXAMPLES

以下规则显示了由于权限问题如何审计对文件的失败访问。请注意,由于每个文件访问ABI都会失败,并且有两个不同的失败代码表示权限问题,因此访问每个Arch ABI都需要两个规则。
-a always,exit -F arch=b32 -S open -S openat -F exit=-EACCES -k access
-a always,exit -F arch=b32 -S open -S openat -F exit=-EPERM -k access
-a always,exit -F arch=b64 -S open -S openat -F exit=-EACCES -k access
-a always,exit -F arch=b64 -S open -S openat -F exit=-EPERM -k access

4.5 HARD WIRED EVENTS

如果启用了审核,那么您可以得到不是由syscall或文件监视规则引起的任何事件(因为您没有加载任何规则)。
因此,这意味着可以发出1100-1299、1326、1328、1331及更高版本中的任何事件。
之所以存在许多硬性关联的事件,是因为它们是合规性所必需的,并且为了方便而自动发送。
(例如,在所有安全指南中,登录/注销都是强制性事件。)
如果您不希望这样做,则可以使用“排除”筛选器删除不需要的事件。
-a always,exclude -F msgtype=CRED_REFR

5. See also

Linux 用户空间审计工具 audit 曹 元其 2017 年 11 月 06 日发布
https://www.ibm.com/developerworks/cn/linux/l-lo-use-space-audit-tool/index.html
Linux auditd 工具可以将审计记录写入日志文件。包括记录系统调用和文件访问。管理员可以检查这些日志,确定是否存在安全漏洞。本文首先介绍用户空间审计系统的结构,然后介绍主要的 audit 工具的使用方法。

redhat 5.5. 定义审核规则
https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/security_guide/sec-defining_audit_rules_and_controls

* 推荐阅读 2014-04-06 (last updated at June 13th, 2018)
原文链接: Configuring and auditing Linux systems with Audit daemon
https://linux-audit.com/configuring-and-auditing-linux-systems-with-audit-daemon/
译文: 用Audit守护进程配置和审计Linux系统
https://posts.careerengine.us/p/5dd4b21fb1bc2b756d694c13

Auditd - Linux 服务器安全审计工具
Auditd - Tool for Security Auditing on Linux Server Updated December 27, 2019By Pungki AriantoHOWTOS, SECURITY
原文连接(2019u): http://linoxide.com/how-tos/auditd-tool-security-auditing/
译文(2015): https://linux.cn/article-4907-1.html

How To Use Journalctl to View and Manipulate Systemd Logs
https://www.digitalocean.com/community/tutorials/how-to-use-journalctl-to-view-and-manipulate-systemd-logs

 201209规则样例
https://blog.51cto.com/purplegrape/1010148
-w /etc/at.allow
-w /etc/at.deny

-w /etc/inittab -p wa
-w /etc/init.d/
-w /etc/init.d/auditd -p wa

-w /etc/cron.d/ -p wa
-w /etc/cron.daily/ -p wa
-w /etc/cron.hourly/ -p wa
-w /etc/cron.monthly/ -p wa
-w /etc/cron.weekly/ -p wa
-w /etc/crontab -p wa

-w /etc/group -p wa
-w /etc/passwd -p wa
-w /etc/shadow
-w /etc/sudoers -p wa

-w /etc/hosts -p wa
-w /etc/sysconfig/
-w /etc/sysctl.conf -p wa

-w /etc/modprobe.d/

-w /etc/aliases -p wa

-w /etc/bashrc -p wa
-w /etc/profile -p wa
-w /etc/profile.d/
-w /var/log/lastlog
-w /var/log/yum.log

-w /etc/issue -p wa
-w /etc/issue.net -p wa

-w /usr/bin/ -p wa
-w /usr/sbin/ -p wa
-w /bin -p wa
-w /etc/ssh/sshd_config

2020-06-18

aide

1. aide(AUR)
 1.1 Source & Homepage
 1.2 About AIDE
 1.3 Features 特征
2. Use AIDE(aur) on Arch
3. 几种主机/文件完整性监视程序的比较(2006年)
 3.1 对比表
 3.2 对比项目说明
4. See also

1. aide(AUR)

1.1 Source & Homepage

https://github.com/aide/aide
https://aide.github.io/
IRC #aide on irc.oftc.net

1.2 About AIDE

AIDE (高级入侵检测环境, [eyd]) 是文件和目录完整性检查器。
AIDE (Advanced Intrusion Detection Environment, [eyd]) is a file and directory integrity checker.
它根据从配置文件中找到的正则表达式规则创建数据库。初始化该数据库后,就可以用来验证文件的完整性。它具有几种消息摘要算法(请参阅下文),用于检查文件的完整性。还可以检查所有通常的文件属性是否存在不一致。它可以读取旧版本或更新版本的数据库。有关更多信息,请参见发行版中的手册页。

1.3 Features 特征

  • 支持的消息摘要算法: md5, sha1, rmd160, tiger, crc32, sha256, sha512, whirlpool (additionally with libmhash: gost, haval, crc32b)
  • 支持的文件属性attributes: File type, Permissions, Inode, Uid, Gid, Link name, Size, Block count, Number of links, Mtime, Ctime and Atime
  • 如果在以下位置编译支持Posix ACL,SELinux,XAttrs和扩展文件系统属性的支持
  • 纯文本配置文件和数据库,以简化操作
  • 强大的正则表达式支持可选择性地包括或排除要监视的文件和目录
  • gzip数据库压缩(如果在zlib支持中编译)
  • 独立的静态二进制文件,可轻松进行客户端/服务器监视配置
  • 还有很多...

2. Use AIDE(aur) on Arch

https://wiki.archlinux.org/index.php/AIDE
高级入侵检测环境(AIDE)是用于检查文件完整性的基于主机的入侵检测系统(HIDS)。它通过在初始运行时创建文件的基准数据库来执行此操作,然后在后续运行中对照系统检查该数据库。可以检查的文件属性包括索引节点,权限,修改时间,文件内容等。
AIDE仅进行文件完整性检查。它不会像其他一些HIDS(例如OSSEC)那样检查rootkit或分析日志文件是否存在可疑活动。对于这些功能,您可以使用其他的HIDS(请参阅此处以获得可能存在的偏差比较),或使用独立的rootkit扫描程序(rkhunter,chkrootkit)和日志监视解决方案(logwatch,logcheck)。
默认配置文件/etc/aide.conf具有相当合理的默认值,并带有大量注释。如果要更改规则,请参见man aide.conf 和AIDE手册 以获取文档。https://aide.github.io/doc/
用法:
  • 要检查您的配置,请使用aide -D。
  • 要初始化数据库,请使用aide -i或aideinit。根据您的配置和系统,此命令可能需要一段时间才能完成。
  • 您可以使用对照基准数据库检查系统aide -C,或使用来更新基准数据库aide -u。

3. 几种主机/文件完整性监视程序的比较(2006年)

A comparison of several host/file integrity monitoring programs
https://www.la-samhna.de/library/scanners.html
By Rainer Wichmann rainer@la-samhna.de    (last update: Dec 29, 2009)
注意: 对比软件版本多在2006年左右, 十几年前, 仅供参考. 另外这项研究的作者也是这些文件完整性检查程序之一(Samhain)的作者。也就是说,该研究在测试基于用户对Samhain的反馈以及作者对文件完整性扫描程序应提供哪些基本功能的个人意见的基础上是有偏见的。这就是Samhain通过所有这些测试的原因。研究的重点是测试扫描仪的功能, 而不是列出和/或比较其功能。

3.1 对比表

NameAfickAIDEFCheckIntegritOsirisOSSECSamhainTripwire
Version2.9-10.13.12.07.5944.2.22.32.2.62.4.0.1
Date2006-10-052006-12-152001-05-032006-04-192006-09-142009-12-042006-10-312005-12-01
PGP signedNOYESNONOYESYESYESNO
LanguagePerlCPerlCCCCC++
Required
libmhashmd5sum (or md5)
OpenSSL 0.9.6j or newer
GnuPG (only if signed config/database used)
Log Optionsstdoutstdout, stderr, file, file descriptorstdout, syslogstdoutcentral log server (email+file on server side)central log server (email+file on server side)stderr, email, file, pipe, syslog, RDBMS, central log server, prelude, external script, IPC message queuestdout, file, email, syslog
DB sign/cryptNONONONONONOsignsign+crypt
Conf sign/cryptNONONONONONOsignsign+crypt
Name Expansionshell-styleregexNONOregexignored files only (regex)shell-styleNO
Duplicate Pathsee remarksNONOWarnsN/AWarnsWarnsExits
PATH_MAXNOOKOKNONONOOKOK
Root InodeOKsee remarksNOOKOKNOOKOK
Non-printableNONONONOOKNOOKOK
No UserOKOKOKOKOKOKOKOK
No GroupOKOKOKOKOKOKOKOK
LockHangsOKHangsHangsHangsHangsTimes outHangs
RaceHangsHangsHangsHangsHangsHangsOKHangs
/procNONONONONOOKOKNO
/devOKOKOKOKOKNOOKOK
New/DelOKOKOKOKOKOKOKOK

3.2 对比项目说明

  • PGP SIGNATURE: 分布式源代码PGP是否签名?如果没有签名,则有可能在源代码中放入特洛伊木马(过去曾发生过一些与安全性相关的知名程序)!
  • REQUIRED: 要求(编译器或解释器除外)。
  • LOG OPTIONS: 支持哪些通道进行日志记录?
  • DB SIGN/CRYPT: 扫描仪是否支持签名或加密的基准数据库?
  • CONF SIGN/CRYPT: 扫描仪是否支持签名或加密的配置文件?
  • NAME EXPANSION: 扫描程序是否支持在配置文件中扩展文件名(shell样式的模式或正则表达式)?
  • DUPLICATE PATH: 扫描程序是否在配置文件中检查文件/目录的重复项(可能对重复项使用不同的检查策略)?严格检查配置文件可以帮助避免用户错误。
  • PATH_MAX: 扫描程序可以处理其路径具有允许的最大长度的文件(在Linux上为4095)吗?
  • ROOT INODE: 扫描程序可以处理“ /”目录索引节点吗?这是路径最短的文件,也是文件名中唯一带有“ /”的文件,因此它可能会暴露编程错误(并且您确实要检查该inode)。
  • NON-PRINTABLE: 扫描仪可以处理带有奇怪或不可打印字符的文件名吗?如果它可以在内部处理它们,是否可以以有用的方式报告结果?...
  • NO USER: 扫描程序可以处理不存在的用户(在/etc/passwd中没有的UID条目)拥有的文件吗?
  • NO GROUP: 扫描程序可以处理不存在的组(在/etc/group中没有的GID条目)拥有的文件吗?
  • LOCK: 如果另一个进程已在其上获得了强制性(内核强制)锁(是的,Linux拥有这种锁),则扫描程序可以处理文件 吗?可以打开()这样的文件以进行读取,但是read()本身将阻塞,因此,除非采取预防措施,否则扫描程序将无限期挂起。在Linux上,强制锁定需要特殊的挂载选项,因此通常不能由非特权用户强制执行。
  • RACE: 文件完整性扫描程序首先使用lstat()确定文件是否为常规文件,然后使用open()对其进行读取以进行校验和。在这两个调用之间,对目录具有写访问权的用户可以用命名管道替换文件。结果,除非采取预防措施,否则open()调用将被阻塞,并且扫描程序可能会无限期挂起。
  • /proc: 扫描程序能够扫描/proc目录吗?在Linux上,/proc中至少有一些文件是 可写的,并且可以在运行时用于配置内核,因此您可能需要检查这些文件。但是,/proc中的文件 可能列出的文件大小为零,即使您可以从中读取大量数据也是如此。几乎所有扫描程序都通过不对零长度文件进行校验和来“优化”,这在Linux /proc文件系统中是不正确的。此外,某些文件可能会阻止从中读取文件。
  • /dev: /dev目录 是否存在扫描程序问题?是否允许检查设备文件(例如,获得正确的权限)?
  • NEW/DEL: 扫描仪能否报告丢失(已删除)或新创建的文件?

4. See also

wikipedia: 基于主机的入侵检测系统比较; 数据包分析仪的比较.
https://en.wikipedia.org/wiki/Advanced_Intrusion_Detection_Environment
https://en.wikipedia.org/wiki/Host-based_intrusion_detection_system_comparison
https://en.wikipedia.org/wiki/Comparison_of_packet_analyzers

Solaris服务器配置高级入侵检测工具AIDE
https://sites.google.com/site/linuxxuexi/wang-luo-an-quan/solaris-fu-wu-qi-pei-zhi-gao-ji-ru-qin-jian-ce-gong-juaide
Linux超实用的AIDE(高级入qin检测系统) 2017-11
https://blog.51cto.com/xsboke/1979229
如何在Linux中使用“AIDE”检查文件和目录的完整性
https://www.howtoing.com/check-integrity-of-file-and-directory-using-aide-in-linux

Gentoo Docs-入侵检测
https://wiki.gentoo.org/wiki/Security_Handbook?part=1&chap=13#doc_chap1

威胁和漏洞检测
https://wiki.archlinux.org/index.php/List_of_applications/Security#Threat_and_vulnerability_detection
 || lynis — Security and system auditing tool to harden Unix/Linux systems.
https://cisofy.com/lynis/
https://en.wikipedia.org/wiki/Lynis
Lynis是用于运行Linux,FreeBSD,macOS,OpenBSD,Solaris和其他Unix派生产品的计算机系统的可扩展安全审核工具。它协助系统管理员和安全专业人员扫描系统及其安全防御措施,最终目标是加强系统。
 || metasploit Metasploit Framework — An advanced open-source platform for developing, testing, and using exploit code.
https://www.metasploit.com/

File security 文件安全
 || aide AUR — File and directory integrity checker.
 || logwatch — Customizable log analysis system.
https://sourceforge.net/projects/logwatch/
https://wiki.archlinux.org/index.php/Logwatch

Anti malware 反恶意软件
 || clamav — Open source antivirus engine for detecting trojans, viruses, malware & other malicious threats.
http://www.clamav.net/
 || rkhunter Rootkit Hunter — Checks machines for the presence of rootkits and other unwanted tools.
http://rkhunter.sourceforge.net/

Diode

导航 (返回顶部) 1. Diode 1.1 Diode 概述 1.2 肖克利二极管方程 1.3 缩写 Abbreviations 2. 主要功能 2.1 单向电流 (Unidirectional current flow) 2.2 阈值电压 (Threshold...