Aqbeż għall-kontenut

Monitoring tools

This chapter presents a non-exhaustive list of additional tools for maintaining and monitoring CyberElements servers. debsums and AIDE, also tools of that family, are covered in System integrity and are not repeated here.

Information

No ANSSI-BP-028 recommendation names these tools specifically, except auditd (R71), which directly overlaps recommendations R30 to R44 (accountability, sudo) and R71 to R73 (logging) already cited in this guide. The other tools in this chapter belong to complementary operational good practice rather than to an explicit ANSSI requirement.

Summary

# Recommendation Edge Gateway
R68 arpwatch: monitoring of local ARP activity
R69 acct: accounting of connections and commands
R70 sysstat: system performance statistics
R71 auditd: audit of the Linux kernel subsystem
R72 Lynis: periodic configuration audit
R73 ClamAV: antivirus (to be validated depending on usage)

R68. arpwatch: monitoring of local ARP activity

Applies to: Edge Gateway

arpwatch monitors ARP activity on the local network by checking the correspondence between IP addresses and MAC addresses, which makes it possible to detect ARP spoofing attacks. It builds its reference database in /var/lib/arpwatch.

1
2
3
apt install arpwatch
systemctl enable arpwatch@<interface>
systemctl enable arpwatch@ens32

See /etc/arpwatch/README and the package manual for how to interpret the alerts.

R69. acct: accounting of connections and commands

Applies to: Edge Gateway

acct provides statistics on users' connection time (login accounting) and on the commands executed (process accounting).

1
apt install acct
  • ac: login/logout statistics;
  • lastcomm: commands previously executed by a user;
  • accton: start/stop accounting;
  • sa: summary of the commands executed;
  • last / lastb: most recent authenticated users (successful / failed).

R70. sysstat: system performance statistics

Applies to: Edge Gateway

sysstat bundles performance tracking utilities (sar, iostat, mpstat, pidstat, sadf, nfsiostat, cifsiostat), useful for establishing a baseline of normal operation and detecting drift.

1
apt install sysstat

Enable collection, in /etc/default/sysstat:

1
ENABLED="true"

The default collection interval (10 minutes) can be tightened in /etc/cron.d/sysstat, for instance every 2 minutes:

1
*/2 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
1
sar -A

R71. auditd: audit of the Linux kernel subsystem

Applies to: Edge Gateway

auditd stores and allows searching of the records generated by the Linux kernel audit subsystem: access to and modification of sensitive files, system calls, commands executed by users, sensitive configurations.

It is the most structuring tool of this chapter, and the one that most directly overlaps the ANSSI-BP-028 recommendations on accountability and logging (R30 to R44, R71 to R73).

1
apt install auditd

Warning!

This rule set generates a significant volume of logs, to be anticipated in the storage sizing covered in Centralised logging. The last line (-e 2) makes the configuration immutable until the next reboot: any subsequent change to the rules requires restarting the service, or even the server (worth bearing in mind before applying it in production).

Warning!

A watch rule (-w) pointing at a non-existent path makes the loading of the rules file fail and can prevent the following rules from being applied, including the final lock (-e 2). The set below has been stripped of the paths belonging to components absent from the CyberElements OVAs (local mail, stunnel, files inherited from SysV/upstart) and adapted to the distribution's current locations (/etc/modprobe.d/, /etc/audit/plugins.d/). After any adaptation, check that loading is complete with augenrules --check then auditctl -l.

File /etc/audit/rules.d/audit.rules:

Base configuration

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Deletes the existing rules before applying
-D
# Buffer size (to be increased according to system load)
-b 8192
# Failure mode: 1 = printk (logs the failure of the audit subsystem itself)
-f 1
# Audits the audit logs themselves, and the whole configuration
# (a rule on a directory is recursive: no need to list its files one by one)
-w /var/log/audit/ -k auditlog
-w /etc/audit/ -p wa -k auditconfig
# Use of the audit administration tools
-w /sbin/auditctl -p x -k audittools
-w /sbin/auditd -p x -k audittools

Information

For readability, this rule set does not duplicate each system call rule for the 32-bit architecture (arch=b32): Debian no longer supports i386 as a standard architecture, and a minimal amd64 virtual machine runs no 32-bit process. If a specific need exists (32-bit libraries or binaries installed), the corresponding b32 rules can be duplicated identically, replacing arch=b64 with arch=b32.

File system and boot

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Creation of special files (devices)
-a exit,always -F arch=b64 -S mknod -S mknodat -k specialfiles
# Mount operations
-a exit,always -F arch=b64 -S mount -S umount2 -k mount
# System time changes
-a exit,always -F arch=b64 -S adjtimex -S settimeofday -S clock_settime -k time
-w /etc/localtime -p wa -k localtime
# System startup scripts
-w /etc/init.d/ -p wa -k init
# Library search paths
-w /etc/ld.so.conf -p wa -k libpath
# Kernel parameters and modules
-w /etc/sysctl.d/ -p wa -k sysctl
-w /etc/modprobe.d/ -p wa -k modprobe
# Hostname changes
-a exit,always -F arch=b64 -S sethostname -k hostname

Scheduled tasks

1
2
3
-w /etc/cron.d/ -p wa -k cron
-w /etc/crontab -p wa -k cron
-w /var/spool/cron/crontabs/ -k cron

Information

This group of rules directly overlaps R17 (scheduled tasks): auditd traces here the changes to cron configuration, whereas R17 deals with the regular review of its content.

Accounts, authentication and privilege escalation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Account, group and password databases
-w /etc/group -p wa -k etcgroup
-w /etc/passwd -p wa -k etcpasswd
-w /etc/gshadow -k etcgroup
-w /etc/shadow -k etcpasswd
-w /etc/security/opasswd -k opasswd
# Use of the passwd command
-w /usr/bin/passwd -p x -k passwd_modification
# Account and group management tools
-w /usr/sbin/groupadd -p x -k group_modification
-w /usr/sbin/groupmod -p x -k group_modification
-w /usr/sbin/addgroup -p x -k group_modification
-w /usr/sbin/useradd -p x -k user_modification
-w /usr/sbin/usermod -p x -k user_modification
-w /usr/sbin/adduser -p x -k user_modification
# Login configuration and history
-w /etc/login.defs -p wa -k login
-w /var/run/faillock/ -p wa -k login
# Network configuration
-w /etc/hosts -p wa -k hosts
-w /etc/network/ -p wa -k network
# PAM configuration and account security (directory watched recursively)
-w /etc/pam.d/ -p wa -k pam
-w /etc/security/ -p wa -k pam
# SSH configuration
-w /etc/ssh/sshd_config -k sshd
# Changes to the system banner
-w /etc/issue -p wa -k etcissue
-w /etc/issue.net -p wa -k etcissue
# su and sudo, including the drop-in rules and the dedicated log
-w /bin/su -p x -k priv_esc
-w /usr/bin/sudo -p x -k priv_esc
-w /etc/sudoers -p wa -k priv_esc
-w /etc/sudoers.d/ -p wa -k priv_esc
-w /var/log/sudo.log -p wa -k priv_esc
# Session events (logins and logouts)
-w /var/run/utmp -p wa -k session
-w /var/log/wtmp -p wa -k session
-w /var/log/btmp -p wa -k session
# Shutdown and reboot
-w /sbin/halt -p x -k power
-w /sbin/poweroff -p x -k power
-w /sbin/reboot -p x -k power
-w /sbin/shutdown -p x -k power

Information

This group overlaps R8 and R9 (accounts and sudo) as well as R26 and R27 (access control and key authentication): auditd provides the traceability of changes here, where those chapters define the policy itself. The file /var/log/sudo.log is the one configured in R9; /var/run/faillock/ replaces the former /var/log/faillog, obsolete since the move to pam_faillock (R10).

Traceability of privileged commands and denied accesses

1
2
3
4
5
# Logs every command run by root
-a exit,always -F arch=b64 -F euid=0 -S execve -k rootcmd
# Captures failed accesses to the most sensitive directories
-a exit,always -F arch=b64 -S open -F dir=/etc -F success=0 -k unauthedfileacess
-a exit,always -F arch=b64 -S open -F dir=/usr/sbin -F success=0 -k unauthedfileacess

Information

That last rule can be extended to other sensitive directories (/bin, /home, /sbin, /srv, /usr/bin, /usr/local/bin, /var…) depending on context; it is deliberately not generalised to the whole system by default, because it then generates a large volume of events unrelated to any malicious attempt: the normal access controls of an unprivileged account.

Additions from the OpenSCAP report (ANSSI-BP-028 R73 coverage)

Of the 44 individual controls attached to R73 (auditd) failing in the OpenSCAP report (profile anssi_bp28_enhanced) analysed ahead of this work, the rule set above, inherited from the previous guide, covered only a small part. The following categories close most of that gap.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Changes to permissions, owners and extended attributes (DAC)
-a always,exit -F arch=b64 -S chmod,fchmod,fchmodat -F auid>=1000 -F auid!=unset -k perm_mod
-a always,exit -F arch=b64 -S chown,fchown,fchownat,lchown -F auid>=1000 -F auid!=unset -k perm_mod
-a always,exit -F arch=b64 -S setxattr,fsetxattr,lsetxattr,removexattr,fremovexattr,lremovexattr -F auid>=1000 -F auid!=unset -k perm_mod
# File deletion by a user
-a always,exit -F arch=b64 -S unlink,unlinkat,rename,renameat,rmdir -F auid>=1000 -F auid!=unset -k delete
# Denied file access attempts (insufficient permissions or rights)
-a always,exit -F arch=b64 -S creat,open,openat,truncate,ftruncate -F exit=-EACCES -F auid>=1000 -F auid!=unset -k access
-a always,exit -F arch=b64 -S creat,open,openat,truncate,ftruncate -F exit=-EPERM -F auid>=1000 -F auid!=unset -k access
# Kernel module loading and unloading (system call level)
-a always,exit -F arch=b64 -S init_module,finit_module -k module_chng
-a always,exit -F arch=b64 -S delete_module -k module_chng
# Use of the module management tools (privileged commands)
-w /usr/sbin/insmod -p x -k privileged-insmod
-w /usr/sbin/modprobe -p x -k privileged-modprobe
-w /usr/sbin/rmmod -p x -k privileged-rmmod
-w /usr/bin/kmod -p x -k privileged-kmod

Warning!

The audit_rules_media_export control (data export to removable media) has not been included: CyberElements servers are deployed as virtual machines with no removable media exposed by design.

1
2
# Makes the audit configuration immutable until the next reboot
-e 2

Applying and checking:

1
2
3
4
augenrules --check
augenrules --load
auditctl -l
ausearch -k priv_esc

R72. Lynis: periodic configuration audit

Applies to: Edge Gateway

Lynis is an audit tool run on demand, not a permanent agent: it analyses the system's configuration at a given moment and produces a hardening report with a score and improvement leads.

1
2
apt install lynis
lynis audit system

Information

This tool fits naturally into the logic of regular configuration auditing: it can be run after each application of this guide on a server, then periodically, so as to detect configuration drift over time rather than to replace the recommendations themselves.

R73. ClamAV: antivirus (to be validated depending on usage)

Applies to: Edge Gateway

ClamAV is an antivirus engine able to scan files on demand or on access.

1
2
3
apt install clamav clamav-daemon
systemctl enable --now clamav-freshclam clamav-daemon
systemctl status --no-pager clamav-freshclam clamav-daemon

Warning!

Its usefulness depends directly on the server's actual role rather than being uniform across the architecture. On an Edge Gateway whose published resources include file transfer or SMB sharing, scanning the files passing through becomes relevant. Classified to be validated against the resources actually published, rather than recommended uniformly (see Classification of recommendations).