DVWA high等级的解析写出代码利用漏洞
DVWA(Damn Vulnerable Web Application)是一个在线漏洞测试平台,用于测试和练习Web应用程序安全漏洞。DVWA分为四个安全等级:low、medium、high和impossible。在high等级中,存在以下漏洞:
- Command Injection:命令注入漏洞。在用户输入的数据中未进行过滤或者过滤不严格,导致攻击者可以在输入中插入恶意命令,从而执行系统命令。
漏洞代码如下:
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
$html .= "<pre>{$cmd}</pre>";
}
攻击者可以通过在IP地址输入框中输入恶意命令来执行系统命令,比如输入:127.0.0.1;ls,即可列出当前目录下的文件。
- SQL Injection:SQL注入漏洞。在用户输入的数据中未进行过滤或者过滤不严格,导致攻击者可以在输入中插入恶意SQL语句,从而执行数据库操作。
漏洞代码如下:
if( isset( $_GET[ 'Submit' ] ) ) {
// Get input
$id = $_GET[ 'id' ];
// Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
$result = mysqli_query( $db, $query ) or die( '<pre>' . mysqli_error( $db ) . '</pre>' );
// Get results
while( $row = mysqli_fetch_assoc( $result ) ) {
// Display values
$html .= print_r( $row, true ) . '<br />';
}
}
攻击者可以在ID输入框中输入恶意SQL语句,比如输入:1' OR '1'='1,即可绕过身份验证并获取所有用户的信息。
- File Inclusion:文件包含漏洞。在用户输入的数据中未进行过滤或者过滤不严格,导致攻击者可以在输入中插入恶意文件路径,从而包含任意文件并执行其中的代码。
漏洞代码如下:
if( isset( $_GET[ 'page' ] ) ) {
$page = $_GET[ 'page' ];
}
else {
$page = 'home';
}
// White list the pages
if( $page == 'home' ) {
$html .= "<h1>Home</h1>";
}
elseif( $page == 'about' ) {
$html .= "<h1>About</h1>";
}
elseif( $page == 'contact' ) {
$html .= "<h1>Contact</h1>";
}
// Allow the user to view their page
elseif( $page == 'user' ) {
$html .= "<h1>User Content</h1>";
// Only allow .txt files
if( isset( $_GET[ 'file' ] ) ) {
$file = $_GET[ 'file' ];
if( strpos( $file, 'user' ) !== false && strpos( $file, '.txt' ) !== false ) {
include( $file );
}
}
}
攻击者可以在page参数中输入恶意文件路径,比如输入:../../../../../../../etc/passwd,即可包含系统文件并显示其中的内容。
- File Upload:文件上传漏洞。在文件上传功能中,未对上传的文件类型进行校验或校验不严格,导致攻击者可以上传恶意文件,执行其中的代码或者获取系统权限。
漏洞代码如下:
if( isset( $_FILES[ 'uploaded' ] ) ) {
// Get the uploaded file information
$file_name = $_FILES[ 'uploaded' ][ 'name' ];
$file_tmp = $_FILES[ 'uploaded' ][ 'tmp_name' ];
$file_type = $_FILES[ 'uploaded' ][ 'type' ];
$file_size = $_FILES[ 'uploaded' ][ 'size' ];
$file_error = $_FILES[ 'uploaded' ][ 'error' ];
// Check if the file meets the requirements
if( $file_error == 0 ) {
$file_path = './' . $file_name;
if( move_uploaded_file( $file_tmp, $file_path ) ) {
$html .= "<pre>{$file_name} successfully uploaded!</pre>";
}
}
else {
$html .= "<pre>There was an error uploading {$file_name}!</pre>";
}
}
攻击者可以上传恶意文件,比如上传一个webshell,从而执行其中的代码并获取系统权限。
综上所述,DVWA high等级中存在多种漏洞,攻击者可以利用这些漏洞来执行恶意代码、获取系统权限等。为了保障Web应用程序的安全性,开发人员需要对这些漏洞进行深入的了解,并采取相应的安全措施来防范这些漏洞。
原文地址: https://www.cveoy.top/t/topic/EWn 著作权归作者所有。请勿转载和采集!