apparmor
Prerequisites
Ensure apparmor daemon is running
Install neccessary tools
Default firefox profile shipped with Kali Linux
1. Generate a starting profile
Creates a profile in
/etc/apparmor.dwith the naming convention where the slashes (/) are converted to dots (.)
Eg. /usr/bin/firefox -> usr.bin.firefox
Default profile
Generated on Kali Linux (Kali 6.12.25-1kali1 (2025-04-30))
usr.bin.firefox
2. Optionally, load the profile using aa-genprof or aa-logprof
aa-genprof or aa-logprofThe
aa-genproftool usesaa-logprofunder the hood to augment the profile
Generate a new profile according to logs from the specified log file
For
/usr/bin/firefox, I usedaa-autodepinstead ofaa-genprofto generate the starting profile. This is because there are too many file reads from firefox (as shown in the log file), thusaa-genprofdisplays too much output.
Update the existing profile
3. View the profile and manually edit the configurations
Abstractions
The include <abstraction/...> statement allows reusable profile configurations to be defined. They can be found under /etc/apparmor.d/abstractions .
Profile language
Refer to the documentation for more information on what each statement in the profile configuration mean:
4. Load and enforce the profile
apparmor_parser
Used to compile the profile (understood by the kernel), and load it into the kernel
-rflag: To update the existing profile in the kernel
This flag is required if an AppArmor definition by the same name already exists in the kernel; used to replace the definition already in the kernel with the definition given on standard input.
5. View the status
6. View the logs and manually update the profile
After loading the profile into the kernel, we can run the application (controlled by apparmor in enforce mode), and view the logs for any DENIED error messages:
Install required packages
Filter the logs
View the logs in real-time
From the error messages, we can update the profile linked to the executable accordingly.
Example
Given the following error message:
The message tells us that firefox-esr is trying to write (w) to /proc/xxxx/xxxx, but got DENIED access. To fix this issue, we can add a rule to the profile:
For more information on file pattern matching, refer to the documentation on the File Globbing section:
7. Verify the apparmor configurations
...
Example
Given the configurations in place for firefox, we can now open up a window and check if the file restrictions are working.
...
8. Other useful commands
Refer to the documentation link at the start of this page
Last updated