
CVE-2016-5195 (Dirty COW) privilege escalation on Ubuntu Server 16.04.1 — exploit, impact & mitigation
Privilege escalation lab exploiting the Dirty COW vulnerability (CVE-2016-5195), a race condition in the Linux kernel's copy-on-write subsystem that allows an unprivileged user to write to read-only system files, thereby gaining root access.
This lab was run on a deliberately vulnerable virtual machine (Ubuntu Server 16.04.1 without security patches), in an isolated environment and on equipment I own. No third-party system was attacked. The documented techniques are intended exclusively for educational, defensive and professional portfolio purposes. Using them against systems without express written authorization is illegal.
| Indicator | Value |
|---|---|
| Target machine | Ubuntu Server 16.04.1 (kernel vulnerable to Dirty COW) |
| Vector | CVE-2016-5195 — race condition in copy-on-write |
| Exploit | 40847.cpp (EDB-ID 40847, Gabriele Bonacini) |
| Result | Privilege escalation: access as root |
| Captured flag | 4GEEKS{Y0u_G0t_R00t} |
| Context | 4Geeks Academy Cybersecurity Bootcamp practice |
40847.cpp source code on the target system./etc/passwd and overwrite the root password.Verification of the kernel version to confirm that it is vulnerable:
uname -r
cat /etc/os-release
Linux kernels prior to version 4.8.3 are vulnerable to Dirty COW. Ubuntu 16.04.1 with an unpatched kernel meets this condition.
The 40847.cpp exploit modifies the /etc/passwd file by taking advantage of the race condition in the kernel's copy-on-write mechanism. Before running it, make a backup of the original file.
g++ -Wall -pedantic -O2 -std=c++11 -pthread -o dcow 40847.cpp -lutil
Running the exploit with the -s option to disable dirty writeback and open a shell with root privileges:
./dcow -s
The exploit overwrites the root entry in /etc/passwd with a known password (dirtyCowFun), allowing access as root.
Successful exploit execution: a shell with root privileges is obtained.
Confirmation of root access and capture of the exercise flag:
whoami
# root
cat FlagUserRoot.txt
# 4GEEKS{Y0u_G0t_R00t}
Screenshot of the flag confirming root access on the target system.
| ID | Finding | CVE | Severity |
|---|---|---|---|
| F-01 | Kernel vulnerable to Dirty COW — allows privilege escalation to root | CVE-2016-5195 | 🔴 Critical (CVSS 7.8) |
| F-02 | System without security patches applied | — | 🔴 Critical |
| Timeframe | Action |
|---|---|
| Immediate | Update the kernel to a patched version (≥ 4.8.3) |
| Short (7–30 days) | Apply all pending security updates (apt update && apt upgrade) |
| Medium (30–90 days) | Implement automated patch management and integrity monitoring of critical files (/etc/passwd, /etc/shadow) |
Root cause: unpatched Linux kernel on an exposed system. The underlying mitigation is an update and vulnerability management cycle, not just patching this CVE.
/etc/passwd; without a backup, the system could become unusable.Dirty-Cow-Ubuntu-Server-16.04.1/
├── README.md
├── 40847.cpp # Exploit CVE-2016-5195 (EDB-ID 40847)
├── FlagUserRoot.txt # Flag del ejercicio
├── dirtyrootpasswoord.png # Evidencia: ejecución del exploit
├── flagroot.png # Evidencia: captura del flag
└── .gitignore
Practice based on an exercise from the 4Geeks Academy Cybersecurity Bootcamp. The execution, evidence, and documentation in this repository are my own work.
The 40847.cpp exploit was created by Gabriele Bonacini and published under the GPL v3 license.
Bryan Calderón Herrera · Cybersecurity | Networks and Telecommunications GitHub: cbry-96