当前位置:网站首页>DVWA practice - brute force cracking
DVWA practice - brute force cracking
2022-07-25 14:08:00 【The goal is technology house】
Damn Vulnerable Web App (DVWA), Literal translation Damn vulnerable Web application , It's based on PHP/MySQL Very fragile web application . Its main goal is to help security professionals test their skills and tools in a legitimate environment , help Web Developers have a better understanding of protection Web The application process , And help teachers / Students teach... In a classroom environment / Study Web Application security .
1.DVWA stay kali Installation tutorial on
Be careful not to configure ReCAPTCHA No problem . Others can follow the steps in the following tutorial .
https://www.cnblogs.com/JetpropelledSnake/p/9128613.html
2.DVWA Brute Force Brute force
LOW
Reference link :https://blog.csdn.net/qq_42357070/article/details/81109775
Add :
1.GET Method

You can see , stay low Below grade ,form The way to form is GET Method .GET Method will query the string in URL It shows that , Will be cached 、 Save in browser history 、 There is a length limit . adopt GET The characteristics of the method can be seen , When dealing with sensitive data , use GET The method is very unsafe . Generally in form In the form , The methods used are POST Method .
2. Source code parsing
<?php
//isset Function function : The variable does not exist or the variable exists but the value is NULL, return FALSE; Variable exists and the value is not NULL, return TRUE
// Here to determine whether you clicked login
if( isset( $_GET[ 'Login' ] ) ) {
// Get username
$user = $_GET[ 'username' ];
// Get password
$pass = $_GET[ 'password' ];
$pass = md5( $pass );
// Check the database Here I directly query the database
$query = "SELECT * FROM `users` WHERE user = '$user' AND password = '$pass';";
//mysqli_query(connection, query, resultmode) Execute a query on a database
//die Function outputs a message , And exit the current script
$result = mysqli_query($GLOBALS["___mysqli_ston"], $query ) or die( '<pre>' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . '</pre>' );
//mysqli_num_rows Returns the number of rows in the result
if( $result && mysqli_num_rows( $result ) == 1 ) {
// Get users details
// Take a row in the result as an associative array ,avatar Generally refers to the user's Avatar
$row = mysqli_fetch_assoc( $result );
$avatar = $row["avatar"];
// Login successful
echo "<p>Welcome to the password protected area {
$user}</p>";
echo "<img src=\"{
$avatar}\" />";
}
else {
// Login failed
echo "<pre><br />Username and/or password incorrect.</pre>";
}
((is_null($___mysqli_res = mysqli_close($GLOBALS["___mysqli_ston"]))) ? false : $___mysqli_res);
}
?>
3. Four labels
Sniper The sniper Set for each location payload, It is suitable for testing a single request parameter in the vulnerability
Number of requests = Number of positions *payload Number
Battering ram Big wooden hammer All positions are set to the same payload, It is suitable for putting the same input into multiple positions
Number of requests =payload Number
Pitchfork Fork Different positions use different payload Group , When attacking, all groups are iterated synchronously , It is suitable for inserting different but related inputs in different positions
Number of requests = Multiple payload The smallest in each group payload Number
Cluster Bomb cluster bomb Use several different payload Group , Iterate over each group when attacking , It is suitable for inserting different and irrelevant inputs in different positions
Number of requests = various payload In the group payload Product of quantity
4.SQL Inject
Reference link :https://ctf-wiki.github.io/ctf-wiki/web/sqli-zh/
The universal password that can be used this time :
1.admin'-- perhaps admin'#
Notice the space after the horizontal line
because -- and # It's an interline comment , The condition part of the query statement in the source code becomes where user = 'admin', So we can get a correct query result .
2.admin' or '1' = '1
The condition part becomes where user = 'admin' or '1' = '1' and password = '', because and Part of the statement connection has high priority ,'1' = '1' and password = '' Certainly not , So it is equivalent to executing conditional statements where user = 'admin', You can get a correct query result .
In fact, simplify this into admin' or ' You can also get the correct results .
For things like ' or '1' = '1 Universal statement , The conditional statement becomes where user = '' or '1' = '1' and password = '', Because there is no record with empty user name , So return error .
When constructing omnipotent statements , Also consider whether the query parameter is a string , If it's a string , Then the number of quotation marks should be appropriate .
MEDIUM
stay medium In the version ,$user and $password Variables are subject to the following restrictions :
$user = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $user ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
mysqli_real_escape_string() Function escape in SQL Special characters in strings used in statements .
Characters that will be escaped include : NUL (ASCII 0),\n,\r,\,’," and Control-Z.
So now SQL Statement injection is no longer valid .
HIGH
Compared with before , Joined again :
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
// Remove the backslash , If there are two consecutive backslashes, remove one
$user = stripslashes( $user );
// Login failed
sleep( rand( 0, 3 ) );
// Generate Anti-CSRF token
generateSessionToken();
Each time the user submits, a random token, Deposit in session in , And set expiration time . When the user submits again , Check token Whether it is consistent or expired .
This makes blind blasting impossible .
Two methods are given in the reference link , One is Python Script , One is still used burp suite, But use Grep-Extract Extracted from the web page token Information , And then as a payload, Use Pitchfork The attack .
Pay attention to the use of burp suite when ,Options Always follow redirection :

IMPOSSIBLE
Lock for a period of time after three consecutive login failures . Record the number of consecutive login failures in the database , And the time when the last login failed .
<?php
// To determine whether these three have value
if( isset( $_POST[ 'Login' ] ) && isset ($_POST['username']) && isset ($_POST['password']) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );
// purify username Input
$user = $_POST[ 'username' ];
$user = stripslashes( $user );
$user = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $user ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
// Purify password input
$pass = $_POST[ 'password' ];
$pass = stripslashes( $pass );
$pass = ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $pass ) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));
$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 = strtotime( $row[ 'last_login' ] );
$timeout = $last_login + ($lockout_time * 60);
$timenow = time();
/* print "The last login was: " . date ("h:i:s", $last_login) . "<br />"; print "The timenow is: " . date ("h:i:s", $timenow) . "<br />"; print "The timeout is: " . date ("h:i:s", $timeout) . "<br />"; */
// After three consecutive login failures , Check whether enough time has elapsed since the last login failure
if( $timenow < $timeout ) {
$account_locked = true;
// print "The account is locked<br />";
}
}
// 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 successful
echo "<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 failed
sleep( rand( 2, 4 ) );
// Give the user some feedback
echo "<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();
?>
边栏推荐
- Leetcode202 --- Happy number
- 实现一个家庭安防与环境监测系统(一)
- maya建模练习
- From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part 2)
- wangeditor 富文本编辑器
- Apple failed to synchronize on its mobile terminal, and logged out. As a result, it could not log in again
- 力扣(LeetCode)205. 同构字符串(2022.07.24)
- 苹果手机端同步不成功,退出登录,结果再也登录不了
- einsum(): operands do not broadcast with remapped shapes [original->remapped]: [1, 144, 20, 17]->[1,
- Interpretation of featdepth self-monitoring model for monocular depth estimation (Part I) -- paper understanding and core source code analysis
猜你喜欢

Brush questions - Luogu -p1152 happy jump

Brush questions - Luogu -p1035 series summation
![einsum(): operands do not broadcast with remapped shapes [original->remapped]: [1, 144, 20, 17]->[1,](/img/bb/0fd0fdb7537090829f3d8df25aa59b.png)
einsum(): operands do not broadcast with remapped shapes [original->remapped]: [1, 144, 20, 17]->[1,

redis集群的三种方式

Mxnet implementation of densenet (dense connection network)

Tm1637 four digit LED display module Arduino driver with second dot

~5 new solution of CCF 2021-12-2 sequence query

Working mode and sleep mode of nlm5 series wireless vibrating wire sensor acquisition instrument

Brush questions - Luogu -p1085 unhappy Jinjin

What you must know about data engineering in mlops
随机推荐
[configure hifive1 revb] the device manager does not recognize the port, and can not connect to j-link via USB
Apple failed to synchronize on its mobile terminal, so it exited the login. As a result, it could not log in again
Four methods of importing CSV text files into Excel
Apple failed to synchronize on its mobile terminal, and logged out. As a result, it could not log in again
Data analysis business core
[原创]九点标定工具之机械手头部相机标定
Realize a family security and environmental monitoring system (II)
Business analysis report and data visualization report of CDA level1 knowledge point summary
在线问题反馈模块实战(十三):实现多参数分页查询列表
~4.1 sword finger offer 05. replace spaces
依迅总经理孙峰:公司已完成股改,准备IPO
Day1: 130 questions in three languages
einsum(): operands do not broadcast with remapped shapes [original->remapped]: [1, 144, 20, 17]->[1,
Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction
Brush questions - Luogu -p1035 series summation
科隆新能源IPO被终止:拟募资6亿 先进制造与战新基金是股东
From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part 2)
Mongodb源码部署以及配置
MySQL and Navicat installation and stepping on pits
飞沃科技IPO过会:年营收11.3亿 湖南文旅与沅澧投资是股东