Credits to Hacktricks
Basic Information
AppArmor is a kernel enhancement designed to restrict the resources available to programs through per-program profiles, effectively implementing Mandatory Access Control (MAC) by tying access control attributes directly to programs instead of users. This system operates by loading profiles into the kernel, usually during boot, and these profiles dictate what resources a program can access, such as network connections, raw socket access, and file permissions.
There are two operational modes for AppArmor profiles:
- Enforcement Mode: This mode actively enforces the policies defined within the profile, blocking actions that violate these policies and logging any attempts to breach them through systems like syslog or auditd.
- Complain Mode: Unlike enforcement mode, complain mode does not block actions that go against the profileโs policies. Instead, it logs these attempts as policy violations without enforcing restrictions.
Components of AppArmor
- Kernel Module: Responsible for the enforcement of policies.
- Policies: Specify the rules and restrictions for program behavior and resource access.
- Parser: Loads policies into the kernel for enforcement or reporting.
- Utilities: These are user-mode programs that provide an interface for interacting with and managing AppArmor.
Profiles path
Apparmor profiles are usually saved in /etc/apparmor.d/
With sudo aa-status
you will be able to list the binaries that are restricted by some profile. If you can change the char โ/โ for a dot of the path of each listed binary and you will obtain the name of the apparmor profile inside the mentioned folder.
For example, a apparmor profile for /usr/bin/man
will be located in /etc/apparmor.d/usr.bin.man
Commands
Logs
Example of AUDIT and DENIED logs from /var/log/audit/audit.log
of the executable **service_bin**
:
You can also get this information using:
AppArmor Docker Bypass1
You can find which apparmor profile is running a container using:
Then, you can run the following line to find the exact profile being used:
In the weird case you can modify the apparmor docker profile and reload it. You could remove the restrictions and โbypassโ them.
AppArmor Docker Bypass2
AppArmor is path based, this means that even if it might be protecting files inside a directory like **/proc**
if you can configure how the container is going to be run, you could mount the proc directory of the host inside **/host/proc**
and it wonโt be protected by AppArmor anymore.
AppArmor Shebang Bypass
In this bug you can see an example of how even if you are preventing perl to be run with certain resources, if you just create a a shell script specifying in the first line **#!/usr/bin/perl**
and you execute the file directly, you will be able to execute whatever you want. E.g.: