Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auditbeat] Allow setting kernel audit config immutable #8352

Closed
ndubss opened this issue Sep 18, 2018 · 14 comments · Fixed by #32381
Closed

[Auditbeat] Allow setting kernel audit config immutable #8352

ndubss opened this issue Sep 18, 2018 · 14 comments · Fixed by #32381

Comments

@ndubss
Copy link

ndubss commented Sep 18, 2018

I don't believe auditbeat supports any type of tamper feature of this type. Specifically, this is to prevent an attacker from disabling the system that would be used to alert to intrusion.

The closest thing I can find is failure_mode: log
Although I haven't tested yet.

There is also an auditd immutability mode (-e) that auditbeat will not allow in the accepted config. I do like that an attacker would likely go after auditd first (with auditctl -l), see rules, and then attempt auditctl -D. That (and any other recon) would be logged.

@andrewkroh andrewkroh changed the title AuditBeat Tamper/Immutability [Auditbeat] Allow setting kernel audit config immutable Sep 18, 2018
@ceeeekay
Copy link

+1 for allowing auditbeat to set -e 2

@kleekai-gsd
Copy link

+1 to auditbeat setting -e 2

@dmlary
Copy link

dmlary commented Jul 17, 2019

This workaround does not work for systems that don't support Multicast sockets for audit data

Workaround for CentOS/RHEL:

  • Edit the auditbeat.service, and add the following line to the [Service] section:
ExecStartPre=/usr/sbin/augenrules --load
  • Keep your rules files in /etc/audit/rules.d/*.rules.
  • Comment out both audit_rules_files and audit_rules in auditbeat.yml

Now, augenrules is responsible for parsing & loading audit rules out of /etc/audit/rules.d/*.rules before auditbeat starts. Auditbeat will not add any rules.

Why didn't it work?

auditbeat can't register as the pid handling audit events after the rules have been made immutable. You'll get the error from
https://github.com/elastic/beats/blob/fec835c970c0d2ea34f483c238a1d13be51428f8/auditbeat/module/auditd/audit_linux.go#L830:L836, Cannot continue: audit configuration is locked in the kernel (enabled=2) which prevents using unicast sockets.

Dug down and found the why here.
#6019 (comment)

@dmlary
Copy link

dmlary commented Aug 6, 2019

Workaround for unicast-only systems

Along the same lines as the previous workaround, modify auditbeat.service and add the following line to the [Service] section:

ExecStartPost=/bin/sh -c "/usr/bin/sleep 15;/usr/sbin/augenrules --load"

The key here is the sleep. When I did just augenrules --load, sometimes the rules would be immutable before auditbeat performed the check to see if the rules were locked.

I'd also suggest throwing RefuseManualStop=yes into [Unit] so you don't accidentally restart auditbeat. Once you do that, it can't receive the audit events anymore.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/siem (Team:SIEM)

@admlko
Copy link

admlko commented Mar 20, 2020

This really needs to be implemented.

@Erni
Copy link

Erni commented May 14, 2020

Is there any plan to implement this in the near future?

@ndubss
Copy link
Author

ndubss commented Aug 12, 2020

@andrewkroh thank you! This can be closed. elastic/go-libaudit@ba0bbab

@ndubss ndubss closed this as completed Aug 12, 2020
@andrewkroh
Copy link
Member

I did add support for this feature in the go-libaudit library, but Auditbeat still needs updated to use the feature and also to provide helpful errors when certain actions cannot be performed due to the kernel being immutable.

@andrewkroh andrewkroh reopened this Aug 14, 2020
@cynorsense
Copy link

cynorsense commented Dec 24, 2020

This is still a problem on 7.10.1 auditbeat. Not sure if this will come up as highest priority.

@wilrodriguez
Copy link

Does anyone know when this change might occur?

@boomcubist
Copy link

boomcubist commented Oct 7, 2021

@dmlary does this workaround work on RHEL 7 servers? Specifically one's with the C2S profile applied? I'm not having much luck with either workaround.

@dmlary
Copy link

dmlary commented Oct 7, 2021

@boomcubist over the past few years, this has evolved into something a little more complicated.

With the version of auditbeat I'm running (6.8.1), I would see auditbeat crash at startup on occasion, which prevents the audit data from being correctly captured after the rules have been set immutable (you can't change the destination pid). To work around this, I pulled the immutable flag from the audit rules, and moved it into a separate service entirely.

This service will only start after auditbeat service is up and running. It will check if auditbeat has been running for more than 60 seconds, and if so, it will set the audit rules immutable.

audit-rules-immutable.service:

[Unit]
Description=Make audit rules immutable
After=auditbeat.service

[Service]
ExecStart=/bin/bash -xc '[[ $(ps -o etimes= -C auditbeat) -ge 60 ]] && auditctl -e 2'
Restart=on-failure
RestartSec=15

[Install]
WantedBy=multi-user.target

@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.