首先对DVWA代码执行高级进行一下简单代码审计查看一下它所使用的函数
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = trim($_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生成一个数组作为黑名单进行过滤。
主要利用函数:
trim
主要作用:trim函数用于删除字符串两侧的空白字符或其他预定义字符
举例:
<?php
$email = " example@example.com ";
$clean_email = trim($email);
echo $clean_email;
?>
执行结果:
example@example.com
str_replace
主要作用:str_replace()
它用于在字符串中的某个位置替换文本或字符
基本语法:mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )
$search
:要查找的值。$replace
:要用作替代值的新值。$subject
:要在其中进行搜索和替换操作的字符串或数组。$count
(可选):为进行计数而传入的变量名。
举例:
<?php
$original = "hello, world!";
$find = "world";
$replace = "xiaohei";
$new_string = str_replace($find, $replace, $original);
echo $new_string;
?>
执行结果:
hello,xiaohei
array_keys
主要作用:array_keys()
函数用于从关联数组中返回所有键名
举例:
<?php
$person = array("name"=>"Tom", "age"=>26);
$key = array_keys($person);
print_r($key);
?>
执行结果:
Array
(
[0] => name
[1] => age
)
stristr
主要作用:stristr()
它的工作方式与 strstr()
函数类似,但它是不区分大小写的
描述:此函数会在字符串中搜索给定的值,并从该值首次出现的位置开始直到字符串结束为止返回该部分的字符串。如果未找到该值,则返回 false
举例:
<?php
$str = "Hello, World!";
$find = "world";
$result = stristr($str, $find);
echo $result; // 输出 "World!"
?>
php_uname
主要作用:php_uname()
它返回有关服务器的信息,例如主机名、操作系统名称和版本号等
举例:
<?php
echo php_uname();
?>
执行结果:
Linux:
Linux localhost.localdomain 5.4.0-96-generic #120-Ubuntu SMP Wed Mar 9 21:½1:59 UTC 2023 x86_64
windows:
Windows NT �� 10.0 build 22631 (Windows 10) AMD64