How to Configure Security Event Audit on FreeBSD?
The FreeBSD operating system supports the auditing of security events. Event auditing facilitates the dependable, granular, and flexible recording of several security-relevant system events, including configuration changes, logins, and file and network access. These log data are useful for live system monitoring, intrusion detection, and postmortem examination. FreeBSD incorporates Sun's Basic Security Module (BSM) Application Programming Interface (API) and file format and is compatible with Solaris and Mac OS X audit implementations.
In this article, we focus on event auditing installation and setup. It describes audit rules and presents an example audit setup. After completing this document, you will understand:
-
Event auditing definition and operation.
-
How to set up event auditing for users and processes on FreeBSD.
-
How to do an audit trail review utilizing audit reduction and review tools.
The audit facility is recognized to have several restrictions. Some login systems, such as Xorg-based display managers and third-party daemons, do not correctly set up auditing for user login sessions. The auditing function for security events is able to provide very thorough records of system activity. When set for high detail, trail file data on a busy system may surpass terabytes per week in certain configurations. Administrators must consider the disk space requirements for audit settings with a large volume. For instance, it is beneficial to devote a file system to /var/audit so that other file systems are not impacted if /var/audit fills up.
What are the Audit Terms?
The words listed below are associated with security event auditing:
-
Event: An auditable event is any event that can be recorded by the audit subsystem. Security-relevant events include the creation of a file, the establishment of a network connection, and the login of a user. Events are "attributable" if they can be traced back to an authorized user, or "non-attributable" if they cannot. Non-attributable events include those that occur prior to authentication in the login procedure, such as incorrect password attempts.
-
Class: Class is a designated collection of linked events used in selection expressions. "file creation" (fc), "exec" (ex), and "login logout" (lo) are classes of events that are often used.
-
Trail: A trail is a log file containing audit information documenting security occurrences. Trails are arranged approximately in chronological order according to the completion of events. Only approved procedures are permitted to add data to the audit trail.
-
Record: A record is a log entry that describes a security incident. Records include a record event type, information on the subject (user doing the action), date and time information, details on any objects or arguments, and a success or failure state.
-
Reduction: Reduction is the process of selecting records for preservation, printing, or analysis from existing audit trails. Similarly, the process of removing unwanted audit records from the audit trail. Administrators create procedures for the preservation of audit data using reduction. For instance, comprehensive audit trails are maintained for one month, but after that, they are streamlined to save merely login information for archive reasons.
-
Selection Expression: The selection expression is a string holding a list of audit event prefixes and class names that are used to match events.
-
Preselection: Preselection is the method through which the system determines which occurrences are of interest to the administrator. The preselection setup employs a number of selection expressions to determine which event classes to audit for which users, as well as global settings that apply to both authorized and unauthenticated processes.
How to Enable and Configure Audit?
User space support for event auditing is included as part of the base FreeBSD operating system. By default, kernel support is included in the GENERIC kernel. FreeBSD provides an audit management utility that controls the state of the audit system. audit utility requires one of the following flags as an argument:
-
-e: Compels the audit system to instantly delete audit log files that fulfill the expiry conditions given in the audit control file, without performing log rotation. -
-i: Initializes and begins auditing. This option is only available on Mac OS X at now and needsauditdto be set up to operate underlaunchd. -
-n: Compels the audit system to close the current audit log file and create a new log file at the location provided in the audit control file. Additionally, audit log files that fulfill the expiry conditions provided in the audit control file are deleted. -
-s: Specifies that the audit system's configuration should be [re]synchronized with the audit control file. A fresh log file will be generated. -
-t: Indicates that the auditing system should end. The log files are closed and renamed to reflect the shutdown time.
The auditd service must already be active. It may optionally be configured to be launched on demand by launchd (Mac OS X only). For proper functioning, the audit utility needs audit administrator credentials.
auditd is an audit log management daemon that responds to requests from the audit tool and kernel notifications. It maintains the resultant audit log files and the locations given for log files. The options are as follows:
-
-d: Starts the daemon in debug mode; it will not become a daemon. -
-l: This option is applicable whenauditdis set to start on-demand usinglaunchd.
The audit review group "audit" may be formed optionally. Members of this group who do not possess privileges may access audit trail log files.
You may enable auditd by following the steps given below.
- Add the following line to
/etc/rc.conf:
auditd_enable="YES"
- Run the next command to start the audit demon:
service auditd start
Users who want to develop a custom kernel must add the following line in the configuration file for their own kernel:
options AUDIT
What are Event Selection Expressions?
Multiple locations in the audit settings employ selection expressions to decide which events should be audited. Expressions contain a list of matching event classes. Expressions for selection are assessed from left to right, and two expressions are joined by adding them together.
The following table highlights the default audit event classes:
| Class Name | Description | Action |
|---|---|---|
| all | all | Match all event classes. |
| aa | authentication and authorization | |
| ad | administrative | Administrative actions performed on the system as a whole. |
| ap | application | Application-defined action. |
| cl | file close | Audit calls to the close system call. |
| ex | exec | Audit program execution. Auditing of command line arguments and environmental variables is controlled via audit_control using the argv and envv parameters to the policy setting. |
| fa | file attribute access | Audit the access of object attributes such as stat and pathconf. |
| fc | file create | Audit events where a file is created as a result. |
| fd | file delete | Audit events where file deletion occurs. |
| fm | file attribute modify | Audit events where file attribute modification occurs, such as by chown, chflags, and flock. |
| fr | file read | Audit events in which data is read or files are opened for reading. |
| fw | file write | Audit events in which data is written or files are written or modified. |
| io | ioctl | Audit use of the ioctl system call. |
| ip | ipc | Audit various forms of Inter-Process Communication, including POSIX pipes and System V IPC operations. |
| lo | login_logout | Audit login and logout events. |
| na | non attributable | Audit non-attributable events. |
| no | invalid class | Match no audit events. |
| nt | network | Audit events related to network actions such as connect and accept. |
| ot | other | Audit miscellaneous events. |
| pc | process | Audit process operations such as exec and exit. |
| Table 1. Default audit event classes |
You may alter these audit event classes by editing the audit_class and audit_event configuration files.
Each audit event class may be paired with a prefix that indicates if successful/failed operations are matched and whether the entry adds or removes matching for the class and type. Prefixes for Audit Event Classes are listed in the next table:
| Prefix | Action |
|---|---|
+ | Audit successful events in this class. |
- | Audit failed events in this class. |
^ | Audit neither successful nor failed events in this class. |
^+ | Do not audit successful events in this class. |
^- | Do not audit failed events in this class. |
| Table 2. Prefixes for Audit Event Classes |
In the absence of a prefix, both successful and unsuccessful occurrences of the event will be audited.
The selection string example below picks both successful and unsuccessful login/logout events, but only successful execution events:
lo,+ex
What are the Configuration Files?
/etc/security directory contains the following configuration files for security event auditing:
-
audit_class: holds the audit classes' definitions. -
audit_control: regulates features of the audit subsystem, including the default audit classes, the minimum disk space to leave on the audit log volume, and the maximum audit trail size. -
audit_event: contains the textual names and descriptions of system audit events, as well as a list of the classes each event belongs to. -
audit_user: combines user-specific audit criteria with global defaults upon login. -
audit_warn: This file is a configurable shell script used byauditdto create warning messages in extreme circumstances, such as when space for audit records is running out or the audit trail file has been rotated.
In the majority of instances, just audit_control and audit_user need to be modified. The first file handles auditing attributes and rules for the whole system, while the second file is used to fine-tune auditing per user.
Audit configuration files should be modified and maintained with care since configuration mistakes might result in erroneous event recordings.
How to Configure audit_control File?
audit_control file specifies a set of default options for the audit subsystem. A sample of audit_control file is described below:
dir:/var/audit
dist:off
flags:lo,aa
minfree:5
naflags:lo,aa
policy:cnt,argv
filesz:2M
expire-after:10M
-
dir: The dir element is used to specify one or more audit log storage directories. If several directory entries exist, they are used in the order in which they are filled. Commonly, the audit is configured such that audit logs are saved on a dedicated file system to minimize interference between the audit subsystem and other subsystems if the file system becomes full. -
dist: If thedistparameter is set toonoryes, hard links to all trail files in/var/audit/distare established. -
flags: Theflagsfield establishes the global default preselection mask for traceable events. All users' successful and unsuccessful login/logout events, as well as their authentication and authorization, are audited in the preceding example. -
minfree: Theminfreeentry specifies the minimum percentage of free space required for the audit trail file system. -
naflags: Thenaflagsitem defines audit classes for non-attributed events, such as the login/logout procedure and authentication and authorization. -
policy: Thepolicyitem provides a comma-separated set of policy flags that regulate different audit behavior characteristics. Thecntspecifies that the operation of the system should continue notwithstanding an audit failure (this flag is highly recommended). The other flag,argv, permits theexecvesystem call's command line arguments to be audited as part of command execution. -
filesz: Thefileszentry sets the maximum file size for an audit trail prior to its automated termination and rotation. A value of0disables auto-rotation of logs. If the requested file size is less than 512k, the request will be disregarded and a log notice will be created. -
expire-after: The expire-after parameter indicates when audit log files will become obsolete and be deleted.
How to Configure audit_user File?
audit_user file allows the administrator to establish additional audit criteria for certain users. Each line configures auditing for a user via the use of two fields:
-
alwaysaudit: thealwaysauditfield indicates a collection of events that should always be audited for the user. -
neveraudit: theneverauditfield specifies a range of events that should never be audited for the user.
The following sample entries audit login/logout events and command execution success for root, as well as file creation and command execution success for nginx. If audit_control is set to its default value, the lo item for root is redundant, and login/logout events will also be audited for nginx.
root:lo,+ex:no
nginx:fc,+ex:no