当前位置:网站首页>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();
?>
边栏推荐
- 金鱼哥RHCA回忆录:CL210管理存储--对象存储
- Detailed explanation of nat/napt address translation (internal and external network communication) technology [Huawei ENSP]
- Brush questions - Luogu -p1151 sub number integer
- ~4.2 CCF 2021-12-1 sequence query
- opencv视频跟踪「建议收藏」
- idea正则表达式替换(idea正则搜索)
- Brush questions - Luogu -p1047 trees outside the school gate
- Brush questions - Luogu -p1161 turn on the light
- Application engineering safety monitoring of wireless vibrating wire acquisition instrument
- Working principle of Lora to 4G and gateway repeater
猜你喜欢

基于redis的keys、scan删除ttl为-1的key

应急科普|收好这份暑期安全指南,让孩子安全过暑假!

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

Advantages of wireless relay acquisition instrument and wireless network for engineering monitoring

Multidimensional pivoting analysis of CDA level1 knowledge points summary

Tm1638 LED digital display module Arduino drive code

A small part is exposed on one or both sides of the swiper

Practice of online problem feedback module (13): realize multi parameter paging query list

Realize a family security and environmental monitoring system (I)

Brush questions - Luogu -p1161 turn on the light
随机推荐
Digital Twins - cognition
Internal error of LabVIEW
Alibaba mqtt IOT platform "cloud product circulation" practice - the two esp32 achieve remote interoperability through the IOT platform
wangeditor 富文本编辑器
MySQL table operation
Business analysis report and data visualization report of CDA level1 knowledge point summary
Tm1638 LED digital display module Arduino drive code
Apple failed to synchronize on its mobile terminal, and logged out. As a result, it could not log in again
~4.1 sword finger offer 05. replace spaces
Brush questions - Luogu -p1059 clear random number
[原创]九点标定工具之机械手头部相机标定
Leetcode202 --- Happy number
opencv视频跟踪「建议收藏」
Working principle of Lora to 4G and gateway repeater
CSV文本文件导入excel的四种方法
Dr. Berkeley's "machine learning engineering" big truth; AI vice president '2022 ml job market' analysis; Large list of semiconductor start-ups; Large scale video face attribute data set; Cutting edge
Goldfish rhca memoirs: cl210 managing storage -- managing shared file systems
@Wrap decorator
Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction
手把手教你申请SSL证书