
TP2 — AppArmor en pratique & simulation de la CVE-2021-3156 (Baron Samedit) sur sudo. Rapport FR avec captures, profil AppArmor et analyse des logs.
Operating System Security — CS.ENG.4 — 2025/2026 USTHB — Faculty of Computer Science Student: BOUIKNI Lydia Hana · Supervisor: Pr. Dr. Sofiane HAMRIOUI Session 02 — Saturday, April 11, 2026
⚠️ Disclaimer — All work was carried out on an isolated VMware virtual machine, for strictly educational purposes. Exploiting a vulnerability on a system you do not own is illegal.
sudo.| Item | Value |
|---|---|
| System | Ubuntu 24.04 LTS (VMware Virtual Platform) |
| User | hana |
Initial (patched) sudo version | 1.9.15p5 |
Vulnerable sudo version installed | 1.8.31 |
AppArmor (Application Armor) is a Linux kernel security module (LSM — Linux Security Module) that restricts the capabilities of programs through security profiles. Each profile defines, by path, the files a program may access and the permitted operations (read r, write w, execute x, etc.).
Unlike SELinux (which is label-based), AppArmor works by file path (path-based), which makes it simpler to read and maintain.
Two main modes:
| Mode | Behavior |
|---|---|
| Complain | The program runs normally; violations are only logged (useful for building a profile). |
| Enforce | Violations are blocked and logged. |
sudo aa-status
Figure 1.1 — AppArmor is active: apparmor module is loaded — 163 profiles loaded.
Result — AppArmor is properly loaded and active, with 163 profiles already present (provided by the system packages).
A simple bash script attempts to read /etc/shadow, a file containing the hashed passwords of all users (a read normally reserved for root).
#!/bin/bash
cat /etc/shadow
Figure 1.2 — Contents of mon_script.sh: reading /etc/shadow.
File provided in this repository:
scripts/mon_script.sh
chmod +x /home/hana/mon_script.sh
sudo /home/hana/mon_script.sh
Figure 1.3 — Without an AppArmor profile, the full contents of /etc/shadow are displayed.
⚠️ Important — Without protection, the password hashes of all users are exposed. This is precisely the behavior that AppArmor will block.
The profile is created manually in /etc/apparmor.d/home.hana.mon_script.sh with a deny rule on /etc/shadow:
#include <tunables/global>
/home/hana/mon_script.sh {
#include <abstractions/base>
#include <abstractions/bash>
/home/hana/mon_script.sh r,
/bin/bash rix,
/bin/cat rix,
/usr/bin/cat rix,
deny /etc/shadow r,
}
File provided in this repository:
profiles/home.hana.mon_script.sh
Loading the profile, then switching to enforce mode:
sudo apparmor_parser -r /etc/apparmor.d/home.hana.mon_script.sh
sudo aa-enforce /home/hana/mon_script.sh
Explanation of permissions
| Rule | Meaning |
|---|---|
/home/hana/mon_script.sh r, | The script can read itself. |
/bin/bash rix, | Execution of bash while inheriting the profile (ix = inherit execute). |
/bin/cat rix, / /usr/bin/cat rix, | cat allowed but confined by the same profile. |
deny /etc/shadow r, | Explicit prohibition on reading /etc/shadow. |
sudo /home/hana/mon_script.sh
Figure 1.4 — With the profile in enforce mode: cat: /etc/shadow: Permission non accordée.
✅ Expected result obtained —
cat: /etc/shadow: Permission non accordée. AppArmor effectively blocks access to the sensitive file, even viasudo: confinement applies to the program, not just to the user.
sudo aa-status | grep mon_script
sudo journalctl | grep -i "apparmor.*DENIED" | tail -10
Figure 1.5 — Violations are logged with the mention apparmor="DENIED".
The logs confirm enforce mode and trace every unauthorized access attempt (operation="...", profile="...", denied_mask="..."), which guarantees complete traceability.
✅ Step 1 summary — The script that could previously read
/etc/shadowis now blocked. Every violation is recorded, allowing an administrator to detect abnormal behavior.
| CVE-2021-3156 — Baron Samedit | |
|---|---|
| Type | Heap-based Buffer Overflow |
| Vector | Local |
| CVSS score | 7.8 (High) |
| Affected versions | sudo 1.8.2 → 1.9.5p1 |
| Fix | sudo 1.9.5p2 (January 27, 2021) |
| Discovery | Qualys Research Team, January 2021 |
CVE-2021-3156 is a heap-based buffer overflow in sudo. When sudo is run in sudoedit mode (sudo -s / sudo -i / sudoedit link), an error in command-line argument handling allows out-of-bounds data to be written to the heap. An unprivileged local user can leverage this for privilege escalation to root, without a password.
Why "Baron Samedit"? A pun on
sudoeditand Baron Samedi (a Vodou figure). The flaw remained in thesudocode for nearly 10 years.
Since the installed version (1.9.15p5) is patched, the vulnerable version 1.8.31 had to be installed manually:
wget http://archive.ubuntu.com/ubuntu/pool/main/s/sudo/sudo_1.8.31-1ubuntu1_amd64.deb
sudo dpkg -i --force-all sudo_1.8.31-1ubuntu1_amd64.deb
sudo --version | head -1 # => Version de sudo 1.8.31