HTML Injection - Stored (Blog)

界面

  1. 1 <div id="main">
  2. 2
  3. 3 <h1>HTML Injection - Stored (Blog)</h1>
  4. 4
  5. 5 <form action="<?php echo($_SERVER["SCRIPT_NAME"]);?>" method="POST">
  6. 6
  7. 7 <table>
  8. 8
  9. 9 <tr>
  10. 10
  11. 11 <td colspan="6"><p><textarea name="entry" id="entry" cols="80" rows="3"></textarea></p></td>
  12. 12
  13. 13 </tr>
  14. 14
  15. 15 <tr>
  16. 16
  17. 17 <td width="79" align="left">
  18. 18
  19. 19 <button type="submit" name="blog" value="submit">Submit</button>
  20. 20
  21. 21 </td>
  22. 22
  23. 23 <td width="85" align="center">
  24. 24
  25. 25 <label for="entry_add">Add:</label>
  26. 26 <input type="checkbox" id="entry_add" name="entry_add" value="" checked="on">
  27. 27
  28. 28 </td>
  29. 29
  30. 30 <td width="100" align="center">
  31. 31
  32. 32 <label for="entry_all">Show all:</label>
  33. 33 <input type="checkbox" id="entry_all" name="entry_all" value="">
  34. 34
  35. 35 </td>
  36. 36
  37. 37 <td width="106" align="center">
  38. 38
  39. 39 <label for="entry_delete">Delete:</label>
  40. 40 <input type="checkbox" id="entry_delete" name="entry_delete" value="">
  41. 41
  42. 42 </td>
  43. 43
  44. 44 <td width="7"></td>
  45. 45
  46. 46 <td align="left"><?php echo $message;?></td>
  47. 47
  48. 48 </tr>
  49. 49
  50. 50 </table>
  51. 51
  52. 52 </form>
  53. 53
  54. 54 <br />
  55. 55
  56. 56 <table id="table_yellow">
  57. 57
  58. 58 <tr height="30" bgcolor="#ffb717" align="center">
  59. 59
  60. 60 <td width="20">#</td>
  61. 61 <td width="100"><b>Owner</b></td>
  62. 62 <td width="100"><b>Date</b></td>
  63. 63 <td width="445"><b>Entry</b></td>
  64. 64
  65. 65 </tr>
  66. 66
    // 上面是html,下面开始是PHP源码

  67. 67 <?php
  68. 68
  69. 69 // Selects all the records
  70. 70
  71. 71 $entry_all = isset($_POST["entry_all"]) ? 1 : 0;
  72. 72
  73. 73 if($entry_all == false)
  74. 74 {
  75. 75
  76. 76 $sql = "SELECT * FROM blog WHERE owner = '" . $_SESSION["login"] . "'";
  77. 77
  78. 78 }
  79. 79
  80. 80 else
  81. 81 {
  82. 82
  83. 83 $sql = "SELECT * FROM blog";
  84. 84
  85. 85 }
  86. 86
  87. 87 $recordset = $link->query($sql);
  88. 88
  89. 89 if(!$recordset)
  90. 90 {
  91. 91
  92. 92 // die("Error: " . $link->connect_error . "<br /><br />");
  93. 93
  94. 94 ?>
  95. 95 <tr height="50">
  96. 96
  97. 97 <td colspan="4" width="665"><?php die("Error: " . $link->error);?></td>
  98. 98 <!--
  99. 99 <td></td>
  100. 100 <td></td>
  101. 101 <td></td>
  102. 102 -->
  103. 103
  104. 104 </tr>
  105. 105
  106. 106 <?php
  107. 107
  108. 108 }
  109. 109
  110. 110 while($row = $recordset->fetch_object())
  111. 111 {
  112. 112
  113. 113 if($_COOKIE["security_level"] == "1" or $_COOKIE["security_level"] == "2")
  114. 114 {
  115. 115
  116. 116 ?>
  117. 117 <tr height="40">
  118. 118
  119. 119 <td align="center"><?php echo $row->id; ?></td>
  120. 120 <td><?php echo $row->owner; ?></td>
  121. 121 <td><?php echo $row->date; ?></td>
  122. 122 <td><?php echo xss_check_3($row->entry); ?></td>
  123. 123
  124. 124 </tr>
  125. 125
  126. 126 <?php
  127. 127
  128. 128 }
  129. 129
  130. 130 else
  131. 131 {
  132. 132
  133. 133 ?>
  134. 134 <tr height="40">
  135. 135
  136. 136 <td align="center"><?php echo $row->id; ?></td>
  137. 137 <td><?php echo $row->owner; ?></td>
  138. 138 <td><?php echo $row->date; ?></td>
  139. 139 <td><?php echo $row->entry; ?></td>
  140. 140
  141. 141 </tr>
  142. 142
  143. 143 <?php
  144. 144
  145. 145 }
  146. 146
  147. 147 }
  148. 148
  149. 149 $recordset->close();
  150. 150
  151. 151 $link->close();
  152. 152
  153. 153 ?>
  154. 154 </table>
  155. 155
  156. 156 </div>

感觉防护代码这有点问题,我没看明白

  1. 1 function htmli($data)
  2. 2 {
  3. 3
  4. 4 include("connect_i.php"); //链接数据库
  5. 5
  6. 6 switch($_COOKIE["security_level"]) //检测级别在cookie里
  7. 7 {
  8. 8
  9. 9 case "0" :
  10. 10
  11. 11 $data = sqli_check_3($link, $data);
  12. 12 break;
  13. 13
  14. 14 case "1" :
  15. 15
  16. 16 $data = sqli_check_3($link, $data);
  17. 17 // $data = xss_check_4($data);
  18. 18 break;
  19. 19
  20. 20 case "2" :
  21. 21
  22. 22 $data = sqli_check_3($link, $data);
  23. 23 // $data = xss_check_3($data);
  24. 24 break;
  25. 25
  26. 26 default :
  27. 27
  28. 28 $data = sqli_check_3($link, $data);
  29. 29 break;
  30. 30
  31. 31 }

无论case是几,执行的都是

sqli_check_3()进行过滤

sqli_check_3()的定义是

应该把xss的防御加在这里

  1. 1 function sqli_check_3($link, $data)
  2. 2 {
  3. 3
  4. 4 return mysqli_real_escape_string($link, $data);
  5. 5
  6. 6 }

mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。

下列字符受影响:

  • \x00
  • \n
  • \r
  • \
  • '
  • "
  • \x1a

如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。

1.low

级别同时不进行保护

2.medium

xss_check_4进行防xss保护
函数功能为
  1. function xss_check_4($data)
  2. {
  3.  
  4. // addslashes - returns a string with backslashes before characters that need to be quoted in database queries etc.
  5. // These characters are single quote ('), double quote ("), backslash (\) and NUL (the NULL byte).
  6. // Do NOT use this for XSS or HTML validations!!!
  7.  
  8. return addslashes($data);
  9.  
  10. }

在预定义字符前加反斜杠

预定义字符是:

  • 单引号(')
  • 双引号(")
  • 反斜杠(\)
  • NULL

3.high

xss_check_3功能
 
  1. 1 function xss_check_3($data, $encoding = "UTF-8")
  2. 2 {
  3. 3
  4. 4 // htmlspecialchars - converts special characters to HTML entities
  5. 5 // '&' (ampersand) becomes '&amp;'
  6. 6 // '"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set
  7. 7 // "'" (single quote) becomes ''' (or &apos;) only when ENT_QUOTES is set
  8. 8 // '<' (less than) becomes '&lt;'
  9. 9 // '>' (greater than) becomes '&gt;'
  10. 10
  11. 11 return htmlspecialchars($data, ENT_QUOTES, $encoding);
  12. 12
  13. 13 }

htmlspecialchars()功能,将部分字符转化为html字符

bWAPP----HTML Injection - Stored (Blog)的更多相关文章

  1. bWAPP练习--injection篇之HTML Injection - Reflected (GET)

    什么是Injection? injection,中文意思就是注入的意思,常见的注入漏洞就是SQL注入啦,是现在应用最广泛,杀伤力很大的漏洞. 什么是HTML injection? 有交互才会产生漏洞, ...

  2. bWAPP练习--injection篇SQL Injection (GET/Search)

    SQL注入: SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具体来说,它是利用现有应用程序,将(恶意)的SQL命令注入到 ...

  3. bWAPP练习--injection篇之HTML Injection - Reflected (POST)

    POST的和之前的GET的过程差不多,只是表单的提交方式不一样而已. low 我们在表单中填入一个超链接 <a href="http://www.cnblogs.com/ESHLkan ...

  4. webgote的例子(5)Sql注入(Blog)

    SQL Injection - Stored (Blog) (本章内容):留言板的注入 看到这个页面先看以下这个页面是做什么的.进行正常的写入发现我每写一句话,其内容都会写到下面的entry里面 在尝 ...

  5. Angular2经典文章集锦

    Angular Metadata 等基础知识 http://www.jianshu.com/p/aeb11061b82c Metadata告诉Angular如何处理一个类,只有我们将它通告给Angul ...

  6. sqli-labs学习笔记 DAY8

    DAY 8 sqli-lab Page-3 sqli-labs lesson 38 What is Stacked injection? https://blog.csdn.net/Fly_hps/a ...

  7. Web API接口安全了解

    2017版OWASP top 10 将API安全纳入其中,足以说明API被广泛使用且安全问题严重.自己尝试整理一下,但限于本人搬砖经验还不足.水平有限,本文只能算是抛砖引玉,希望大伙不吝赐教. 了解W ...

  8. Metasploitable2使用指南

    Metasploitable2使用指南 Metasploitable2 虚拟系统是一个特别制作的ubuntu操作系统,本身设计作为安全工具测试和演示常见漏洞攻击.版本2已经可以下载,并且比上一个版本包 ...

  9. 前端 跨站脚本(XSS)攻击的一些问题,解决<script>alert('gansir')</script>

    问题1:跨站脚本(XSS)的一些问题,主要漏洞证据: <script>alert('gansir')</script>,对于这个问题怎么解决? (测试应当考虑的前端基础攻击问题 ...

随机推荐

  1. Python 从入门到精通:一个月就够了

    毫无疑问,Python 是当下最火的编程语言之一.对于许多未曾涉足计算机编程的领域「小白」来说,深入地掌握 Python 看似是一件十分困难的事.其实,只要掌握了科学的学习方法并制定了合理的学习计划, ...

  2. python的各种库的用法

    scipy.io 用于输入和输出数据的操作,可操作matlab的.mat文件. (1)加载.mat文件的数据 import scipy.io as sci data_dir = sci.loadmat ...

  3. 【1】TensorFlow光速入门-tensorflow开发基本流程

    本文地址:https://www.cnblogs.com/tujia/p/13862339.html 系列文章: [0]TensorFlow光速入门-序 [1]TensorFlow光速入门-tenso ...

  4. 用匿名内部类实现 Java 同步回调

    在一个应用系统中,不论使用何种编程语言,模块之间要进行调用,仅存在三种方式:同步调用.异步调用.回调.本文就其中回调方式进行详细解读,并通过匿名内部类的手段,在最后实现一个同步回调的过程. 一.回调的 ...

  5. Docker部署Mysql, Tomcat, Nginx, Redis

    1. Mysql部署 问题及解决方案 容器内的网络和外部机器不能直接通信 外部机器和宿主机可以直接通信 宿主机和容器可以直接通信 当容器中的网络服务需要被外部机器访问时,可以将容器中提供服务的端口映射 ...

  6. scrapy和scrapy-redis 详解一 入门demo及内容解析

    架构及简介 Scrapy是用纯Python实现一个为了爬取网站数据.提取结构性数据而编写的应用框架,用途非常广泛. Scrapy 使用了 Twisted(其主要对手是Tornado)异步网络框架来处理 ...

  7. 使用 k8s 搭建 confluence 6.10.x 版本

    将公司中已有的 confluence 服务迁移到 k8s 集群中,需要保留当前已有的数据.整体需要分为如下几个步骤: 备份 mysql 数据 备份 confluence 安装目录 备份 conflue ...

  8. 【SpringBoot】12.全局配置文件(properties)与yml配置文件

    一.SpringBoot全局配置文件 1.修改内嵌容器端口号 #application.properties server.port=8888 2.自定义属性的配置 使用@Value来给成员变量赋值 ...

  9. 蒲公英 &#183; JELLY技术周刊 Vol.29: 前端智能化在阿里的那些事

    蒲公英 · JELLY技术周刊 Vol.29 前端智能化是指借助于 AI 和机器学习的能力拓展前端,使其拥有一些超出现阶段前端能力的特性,这将是未来前端方向中一场重要的变革.目前各家互联网厂商都有自己 ...

  10. 利用Kotlin扩展函数实现任意View的点击处理(点击效果和防止快速点击)

    利用Kotlin扩展函数实现View的点击处理(点击效果和防止快速点击) kotlin经典写法: view?.setOnClickListener { //实现 } 项目实践证明,这种写法存在问题 例 ...