企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
1.存储型XSS与反射型XSS有什么区别? 1、存储型XSS是持久化,反射型式非持久化。 2、危害更大 2.前台代码html ``` <html> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <head> <title>存储型xss测试页面</title> </head> <div > <form name="xx" action="store.php" method="GET"> <p>填写你的个人信息</p> <tr><td>姓名:<td><td><input type="text" name="name"></td></tr><br> <tr><td>爱好:<td><td><input type="text" name="interest"></td></tr> <br> &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; <input type="submit" value="提交"> </form> <form name="xx" action="find_store.php" method="GET"> <p>查询个人信息</p> <tr><td>姓名:<td><td><input type="text" name="name"></td></tr><br> <br> &emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp; <input type="submit" value="查询"> </form> </div> </html> ``` 3.保存提交信息 ``` <?php error_reporting(0); $name = $_GET["name"]; $interest = $_GET["interest"]; //连接服务器 $conn = mysql_connect("127.0.0.1","root","root"); //打开数据库 mysql_select_db("xss",$conn); //执行SQL mysql_query("set names 'utf8'"); $sql_insert = "insert into xss(name,interest) values('$name','$interest')"; $result = mysql_query($sql_insert,$conn); echo 'success!!'; ?> ``` 4.查询信息 ``` <?php error_reporting(0); $name = $_GET["name"]; //连接服务器 $conn = mysql_connect("127.0.0.1","root","root"); //打开数据库 mysql_select_db("xss",$conn); //执行SQL mysql_query("set names 'utf8'"); $sql_select = "select * from xss where name like '%".$name."%'"; $results = mysql_fetch_array(mysql_query($sql_select)); ?> <html> <?php echo $results[name].'<br>'; echo $results[interest]; ?> </html> ``` 5.str_replace、 mysql_real_escape_string方法介绍 ![](https://img.kancloud.cn/ff/1d/ff1d63c431e211275ade8a9e71c327ec_819x279.png) 6.存储型xss漏洞修复方案 1、插入拦截器,对输入内容进行过滤。 ``` str_replace('<script>', '', $_GET['name’]); str_replace('<script>', '', $_GET['interest’]); $name = mysql_real_escape_string($name); ``` 2、采用安全的API ``` htmlspecialchars($_GET['name']); $name = mysql_real_escape_string($name); ``` htmlspecialchars定义和用法 htmlspecialchars() 函数把预定义的字符转换为 HTML 实体。 预定义的字符是: & (和号)成为 & " (双引号)成为 " ' (单引号)成为 ' < (小于)成为 < > (大于)成为 > 3、将输出的内容进行过滤。 ``` str_replace('<script>', '', $_GET['name’]); htmlspecialchars($_GET['name']); ```