DVWA靶场篇(一)——命令执行、CSRF、文件包含
一、命令执行
low
该级别没有对输入进行任何过滤。
输入:127.0.0.1 && whoami
源码分析
<?php
if( isset( $_POST[ 'Submit' ] ) ) { //检测是否已经提交
// Get input
$target = $_REQUEST[ 'ip' ]; #接受ip参数值,赋值给target
// Determine OS and execute the ping command. 确定操作系统并执行ping命令。
if( stristr( php_uname( 's' ), 'Windows NT' ) ) { #判断是否为windows操作系统
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>"; ##前端回显结果
}
?>
isset() 函数用于检测变量是否已设置并且非 NULL。
php_uname() 返回运行 PHP 的系统的有关信息。
‘a’:此为默认。包含序列 “s n r v m” 里的所有模式。
’s’:操作系统名称。例如: FreeBSD。
‘n’:主机名。例如: localhost.example.com。
‘r’:版本名称,例如: 5.1.2-RELEASE。
‘v’:版本信息。操作系统之间有很大的不同。
‘m’:机器类型。例如:i386。
stristr("Hello world!","WORLD") 查找 "world" 在 "Hello world!" 中的第一次出现,并返回字符串的剩余部分
medium
源码分析
<?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>";
}
?>
array() 函数用于创建数组
创建关联数组:
array_keys() 返回包含数组中所有键名的一个新数组
str_replace() 把字符串 "Hello world!" 中的字符 "world" 替换成 "Peter"
<?phpecho str_replace("world","Peter","Hello world!");?>
此关对&& ; 替换为空。所以输入 127.0.0.1 & whoami进行绕过
high
源码分析
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = trim($_REQUEST[ 'ip' ]);
// Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',