Linux Audit
Analyze Linux Audit.
1. Audit
![[Figure 1] Linux Audit](/blog-software/docs/theory-analysis/linux-audit/images/linux-audit-architecture.png)
[Figure 1] Linux Audit
Linux Audit is a Linux Framework that records various security-related Events occurring in the Linux Kernel as Logs and delivers them to User Apps. It can detect Events such as Binary execution, File Access, System Calls, and Network configuration manipulation. In Audit, these security-related Events are called Audit Events. Audit Events occur according to Audit Rules registered and managed by system administrators. [Figure 1] shows the Architecture of Audit. Audit components can be largely divided into Kernel Level and User Level.
1.1. Kernel Level
Audit uses System Call Hooking by default to collect Audit Events. When an App calls a System Call, the Kernel writes Audit Logs for Audit Events during System Call processing and stores Audit Logs in a Queue.
| |
When the Kernel writes Audit Logs, it uses Audit Context. Audit Context exists as the audit-context Structure in Linux Kernel Code and stores various information such as System Call Parameters, System Call Return Code, System Call Entry Time, Thread ID, and Thread Working Directory needed for System Call processing analysis and Audit Log writing. Since Audit Context must be maintained for each Thread, the task-struct Structure that stores each Thread’s information has a Pointer to audit-context. Each Audit Context is initialized by the Kernel with System Call and Thread information before System Call processing and is cleaned up after the System Call ends.
kauditd is a Kernel Process that collects Audit Logs stored in the Queue and delivers them to auditd as Audit Events. It also receives Audit Rule-related commands through auditctl to configure Audit. kauditd communicates with auditd and auditctl using netlink (NETLINK-AUDIT Option). kauditd directly manages the netlink Connection with auditd and connects with only one auditd. That is, even if multiple auditd processes are running, it only delivers Audit Events to one auditd.
1.2. User Level
Multiple User Level Tools/Processes related to Audit exist. auditd records Audit Events received from kauditd in the audit.log file and delivers them to audispd. auditctl is used for Audit control such as adding/deleting Audit Rules by communicating with kauditd. aureport shows summary information of Audit Events that have occurred so far based on the audit.log file. ausearch searches and shows specific Audit Events based on the audit.log file.
audispd is a Child Process of auditd that multiplexes Audit Events received from auditd to audisp Plugin Processes, which are Child Processes of audispd. audisp Plugin refers to Binaries/Processes that receive Audit Events from audispd. audispd basically uses af-unix Plugin and syslog Plugin, but separate Plugins can also be created. The af-unix Plugin creates a Unix Socket file and delivers Audit Events received from audispd through the created Unix Socket file. The syslog Plugin delivers Audit Events to syslogd so that syslogd can log Audit Events. In addition, various other User Level Tools/Processes and audisp plugins exist.
1.3. Example
| |
[Shell 1] is an example of setting Audit Rules on the passwd Binary that changes Linux User passwords and the /etc/shadow file that records passwords. It shows the process of setting Rules so that Audit Events occur when the passwd Binary is executed and when the /etc/shadow file is Read, and then checking the Logs left by auditd.