ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux-audit

2020-06-19 09:07:55  阅读:266  来源: 互联网

标签:audit syscall Linux etc auditctl 规则 审核


 

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.serviceenable守护进程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 OPTIONS cn
-b backlog Set 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_time Set 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倍。
-c Continue 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. 尽管有错误,仍继续加载规则。这总结了加载规则的结果。如果任何规则加载失败,则退出代码将不会成功。
-D Delete 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。
-h Help 帮帮我
-i When 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-immutable This 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,subtree If 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 rate Set 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-lost Reset the lost record counter shown by the status command. 重置status命令显示的丢失记录计数器。
-R file Read 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正在读取文件而不是重击。
-t Trim the subtrees after a mount command. 在安装命令后修剪子树。

2.2 STATUS OPTIONS

状态选项 STATUS OPTIONS  
-l List 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 text Send 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类型。
-s Report 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来解释几个字段。
-v Print the version of auditctl. 打印auditctl的版本。

2.3 RULE OPTIONS

规则选项 itme RULE 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: 通过操作将规则追加到列表的末尾。请注意用逗号分隔两个值。省略它会导致错误。字段可以是任意顺序。它可以是列表,动作或动作,列表。以下描述了有效的列表名称:
  task Add 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等。
  exit Add 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退出列表。从系统调用退出时,使用此列表来确定是否应创建审核事件。
  user Add 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的进程的事件都将被记录到审计跟踪中。这意味着此过滤器最有可能用于规则,该规则的作用是永不执行,因为无需执行任何操作即可记录事件。
  exclude Add 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,消息类型或主题上下文排除事件。该操作将被忽略,并使用其默认值“从不”。
  filesystem Add 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: 以下描述了该规则的有效操作:
  never No 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. 将不会生成审核记录。这可以用来抑制事件的产生。通常,您希望抑制显示在列表的顶部而不是底部。这是因为事件在第一个匹配规则上触发。
  always Allocate 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,action Add 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_gid The 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,action Delete 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, a3 Respectively, 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操作的平台上使用。
  arch The 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知道要使用哪个内部表来查找系统调用号。
  auid The 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。可以使用用户帐户文本或号码。
  devmajor Device Major Number 设备主号码
  devminor Device Minor Number 设备次编号
  dir Full 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”。
  egid Effective Group ID. May be numeric or the groups name. 有效的组ID。可以是数字或组名。
  euid Effective User ID. May be numeric or the user account name. 有效的用户ID。可以是数字或用户帐户名。
  exe Absolute path to application that while executing this rule will apply to. This can only be used on the exit list. 执行此规则时将应用到的应用程序的绝对路径。这只能在退出列表上使用。
  exit Exit value from a syscall. If the exit code is an errno, you may use the text representation, too. 从系统调用中退出值。如果退出代码是errno,则也可以使用文本表示形式。
  fsgid Filesystem Group ID. May be numeric or the groups name. 文件系统组ID。可以是数字或组名。
  fsuid Filesystem User ID. May be numeric or the user account name. 文件系统用户标识。可以是数字或用户帐户名。
  filetype The target file's type. Can be either file, dir, socket, link, character, block, or fifo. 目标文件的类型。可以是文件,目录,套接字,链接,字符,块或fifo。
  gid Group ID. May be numeric or the groups name. 组ID。可以是数字或组名。
  inode Inode Number 索引号
  key This is another way of setting a filter key. See discussion above for -k option. 这是设置过滤键的另一种方法。有关-k选项,请参见上面的讨论。
  msgtype This is used to match the event's record type. It should only be used on the exclude or user filter lists. 这用于匹配事件的记录类型。仅应在排除或用户过滤器列表上使用它。
  obj_uid Object's UID 对象的UID
  obj_gid Object's GID 对象的GID
  obj_user Resource's SE Linux User 资源的SE Linux用户
  obj_role Resource's SE Linux Role 资源在SE Linux中的角色
  obj_type Resource's SE Linux Type 资源的SE Linux类型
  obj_lev_low Resource's SE Linux Low Level 资源的SE Linux低级
  obj_lev_high Resource's SE Linux High Level 资源的SE Linux高级
  path Full Path of File to watch. It can only be used on exit list. 要观看的完整文件路径。它只能在退出列表上使用。
  perm Permission 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”。它只能在退出列表上使用。您可以在不指定系统调用的情况下使用它,内核将选择满足所请求权限的系统调用。
  pers OS Personality Number 操作系统个性编号
  pid Process ID 进程ID
  ppid Parent's Process ID 家长的进程ID
  sessionid User's login session ID 用户的登录会话ID
  subj_user Program's SE Linux User 程序的SE Linux用户
  subj_role Program's SE Linux Role 程序的SE Linux角色
  subj_type Program's SE Linux Type 程序的SE Linux类型
  subj_sen Program's SE Linux Sensitivity 程序的SE Linux敏感性
  subj_clr Program's SE Linux Clearance 程序的SE Linux许可
  sgid Saved Group ID. See getresgid(2) man page. 保存的组ID。请参见getresgid(2)手册页。
  success If 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表示否/否
  suid Saved User ID. See getresuid(2) man page. 保存的用户ID。请参见getresuid(2)手册页。
  uid User ID. May be numeric or the user account name. 用户身份。可以是数字或用户帐户名。
-k key Set 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 path Insert 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 path Remove 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=1005 To see all syscalls made by a specific program
查看特定程序进行的所有系统调用
auditctl -a always,exit -S openat -F auid=510 To see files opened by a specific user
查看特定用户打开的文件
auditctl -a always,exit -S openat -F success=0 To 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_uid To 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

标签:audit,syscall,Linux,etc,auditctl,规则,审核
来源: https://www.cnblogs.com/sztom/p/13161209.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有