Privesc With DirtyCow Exploitation
DirtyCOW Privilege Escalation (CVE-2016-5195)
DirtyCOW is a privilege escalation vulnerability found in the Linux kernel 2.6.22 < 3.9. This vulnerability allows an unprivileged user to overwrite files that should only be accessible by root, including /etc/passwd
, granting them root access to the system.
๐ How Does This Exploit Work?โ
This exploit uses DirtyCOW's ptrace_pokedata "pokemon" method to modify the /etc/passwd
entry. The process works as follows:
- Creates a backup of
/etc/passwd
at/tmp/passwd.bak
. - Overwrites the root entry with a new one that allows login without a password.
- Runs the exploit to gain root access.
- After use, restores the original
/etc/passwd
file.
๐ง How to Use This Exploitโ
โ ๏ธ WARNING:
Using this exploit without authorization may be illegal. Ensure that you only use it in a testing environment or with explicit permission.
-
Compile the exploit:
gcc -pthread dirty.c -o dirty -lcrypt
-
Run the exploit with a new password:
./dirty
or
./dirty my-new-password
-
Don't forget to restore
/etc/passwd
after execution.mv /tmp/passwd.bak /etc/passwd
๐ About CVE-2016-5195โ
CVE-2016-5195 is a vulnerability in the Linux memory subsystem related to copy-on-write (COW). This bug allows an unprivileged process to write to read-only memory mappings, effectively escalating its privileges.
Why is it called DirtyCOW?
Because the bug exploits a copy-on-write (COW) race condition, allowing memory modifications without proper permission checks.
Who discovered this bug?
It was discovered by Phil Oester, who detected the exploit in the wild through an intercepted HTTP packet.
๐ Is My System Vulnerable?โ
- If your system is running an unpatched kernel (before October 2016), it is likely still vulnerable.
- Best solution: Update your Linux kernel to a patched version.
๐ ๏ธ How to Fix Itโ
- Update the Linux kernel using your distribution's package manager (Ubuntu, Debian, Red Hat, etc.).
- If updating is not possible, apply available hotfix patches for temporary mitigation.
๐ References & More Informationโ
- DirtyCOW Exploit: GitHub - FireFart/dirtycow
- Exploit on Exploit-DB: Exploit-DB 40839
- Official DirtyCOW Website: dirtycow.ninja