bWAPP----SQL Injection (GET/Search)

SQL Injection (GET/Search)

输入单引号

报错,在%'附近出错,猜测参数被 '%  %'这种形式包裹,没有任何过滤,直接带入了数据库查询

输入order by查询列

union select 确定显示位

然后分别查询用户,数据库名,数据库版本

根据数据库版本知道可以通过information_schema表查询信息,查询table_name,从information_schema.tables

查询当前数据库的tablename

查询users表的列

查询字段的内容

贴上源码

 1 <?php
 2 if(isset($_GET["title"]))
 3 {
 4 
 5     $title = $_GET["title"];
 6 
 7     $sql = "SELECT * FROM movies WHERE title LIKE '%" . sqli($title) . "%'";
 8 
 9     $recordset = mysql_query($sql, $link);
10 
11     if(!$recordset)
12     {
13 
14         // die("Error: " . mysql_error());
15 
16 ?>
17 
18         <tr height="50">
19 
20             <td colspan="5" width="580"><?php die("Error: " . mysql_error()); ?></td>
21             <!--
22             <td></td>
23             <td></td>
24             <td></td>
25             <td></td>
26             -->
27 
28         </tr>
29 <?php
30 
31     }
32 
33     if(mysql_num_rows($recordset) != 0)
34     {
35 
36         while($row = mysql_fetch_array($recordset))         
37         {
38 
39             // print_r($row);
40 
41 ?>

防御代码

function sqli($data)
{

    switch($_COOKIE["security_level"])
    {

        case "0" :

            $data = no_check($data);
            break;

        case "1" :

            $data = sqli_check_1($data);
            break;

        case "2" :

            $data = sqli_check_2($data);
            break;

        default :

            $data = no_check($data);
            break;

low

没有过滤

medium

function sqli_check_1($data)
{
 
 return addslashes($data);
 

 

high

1 function sqli_check_2($data)
2 {
3    
4     return mysql_real_escape_string($data);
5     
6 }
原文地址:https://www.cnblogs.com/hongren/p/7225250.html