关于XSS 跨站脚本漏洞怎么修复?这个是需要JS过滤掉吗?

vipcha111 2015-05-30 01:46:10
关于XSS 跨站脚本漏洞怎么修复?这个是需要JS过滤掉吗? 还是输入框里过滤掉?


引用
<?php
@error_reporting (E_ALL & ~E_NOTICE & ~E_WARNING);
set_time_limit(0);
$prescription = trim($_GET['q']);
$id = intval(base64_decode($_GET['id']));
$r_num = 0; //结果个数
$lan = 2; //首页分列
$pf = "";
$pf_l = "";
$page=is_numeric($_REQUEST['page'])?$_REQUEST['page']:1;
$dreamdb=file("date/jf.dat");//读取库
$count=count($dreamdb);//计算行数
$zs=intval($count/30);
if($prescription!=""){
$searchCount = 0;//搜索结果个数
for($i=0; $i<$count; $i++) {
$keyword=explode(" ",$prescription);//拆分关键字
$dreamcount=count($keyword);//关键字个数
for ($ai=0; $ai<$dreamcount; $ai++) {
@eval("\$found = eregi(\"$keyword[$ai]\",\"$dreamdb[$i]\");");
if(($found)){
if($searchCount < 60) {
$detail=explode("\t",$dreamdb[$i]);//按tab
if(fmod($r_num,$lan)==0) $pf_l .= "<tr>";
$pf_l .= '<td width="'.(100/$lan).'%"><img src="/img/dot.gif" />';
$pf_l .= '<a href="'.base64_encode(($i+1)).'.html">'.($r_num+1).":".$detail[0].'</a></br></td>';
if(fmod($r_num,$lan)+1==$lan) $pf_l .= "</tr>";
}
$r_num++;
$searchCount++;
}
}
}
$info = '<div class="zt"><b><a href="./">酒方大全</a>:找到 <a href="./?q='.urlencode($prescription).'"><font color="#c60a00">'.$prescription.'</font></a> 的相关'.$r_num.'个</b>';
if($searchCount > 60) {
$info .= ' <font color="#c60a00">[由于数据太多,本次查询只显示前60条,请核实您输入的信息准确性]</font>';
}
$pf_l = $info.'</div><div class="wenzi"><table cellpadding="5" cellspacing="10" width="100%">'.$pf_l.'</table></p></div> <!--内容结束--> ';
}else{
if($id > 0) {
$detail_only=explode("\t",$dreamdb[$id-1]);
$pf = '<div class="zt"><b><a href="./">酒方大全</a> /'.$detail_only[0].'</b><td align="right">';
if($id>1 && $id<=$count) $pf .= '<a href="'.base64_encode(($id-1)).'.html">上一个</a> ';
$pf .= '<a href="./">查看全部</a>';
if($id>=1 && $id<$count) $pf .= ' <a href="'.base64_encode(($id+1)).'.html">下一个</a>';
$pf .= '</td></tr><tr></div><div class="wenzi"><table cellpadding="5" cellspacing="10" width="100%"><tr><td colspan="3">
<h2>'.$detail_only[0].'</h2><br />'.$detail_only[3].'</td></tr></table></div>';
}
$pfl = rand(0,intval($count/30));
for($i=$page*30; $i<$page*30+30; $i++) {
if($i>=$count-1) break;
$detail=explode("\t",$dreamdb[$i]);
if(fmod($r_num,$lan)==0) $pf_i .= "<tr>";
$pf_i .= '<td width="'.(100/$lan).'%"><img src="/img/dot.gif" />';
$pf_i .= '<a href="'.base64_encode(($i+1)).'.html">'.$detail[0].'</a></br></td>';
if(fmod($r_num,$lan)+1==$lan) $pf_i .= "</tr>";
$r_num++;
}
$pf_i = '<div class="zt"><b>推荐<a href="./">酒方大全</a>'.$count.'个</b></div><div class="wenzi"><table cellpadding="5" cellspacing="10" width="100%">'.$pf_i.'</table> </p></div><!--内容结束-->';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>酒方大全_药酒配方_在线酒方查询</title>
</head>
<body>
<div align="center">
<br />
<form action="./" method="get" name="f1">
<input name="q" type="text" size="20" maxlength="20" />
<input type="submit" id="sub" value="查询" /></form>
<?php
if($prescription!=""){
echo $pf_l;
}else{
if($id > 0 && $id < $count) {
echo $pf;
}
echo $pf_i;
}
?>
</div>
</body>
</html>
...全文
4547 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dleno 2015-05-31
  • 打赏
  • 举报
回复
***************** #for之外 $keyword = $prescription; if (!get_magic_quotes_gpc()){ $keyword = addslashes($keyword); } $keyword=explode(" ",$keyword);//拆分关键字 #for之外 ********* ********* $info = '<div class="zt"><b><a href="./">酒方大全</a>:找到 <a href="./?q='.urlencode($prescription).'"><font color="#c60a00">'.stripslashes($prescription).'</font></a> 的相关'.$r_num.'个</b>';
vipcha111 2015-05-30
  • 打赏
  • 举报
回复
引用 2 楼 dingsongtao 的回复:
主要说的是你: <font color="#c60a00">'.$prescription.'</font>这个地方 你这样显示,如果$prescription的内容是恶意的HTML、js代码,那它就会直接执行了。 显示之前用stripslashes处理下就好。
可以帮改一下吗? 你们说的太高深……我html还行……太复杂不行阿。
vipcha111 2015-05-30
  • 打赏
  • 举报
回复
引用 1 楼 xuzuning 的回复:
$prescription = trim($_GET['q']); <a href="./?q='.urlencode($prescription).'"> <input name="q" type="text" size="20" maxlength="20" /> 这是 url 参数 q 的几次出现的地方 是否会招来 XSS 攻击这很难说,但不验证传入参数的来源和合法性总是不妥的 你至少需要将表单的提交方式由 get 改成 post
可以帮我修改一下吗? 这个东西不太在行……。html还行。
Dleno 2015-05-30
  • 打赏
  • 举报
回复
主要说的是你: <font color="#c60a00">'.$prescription.'</font>这个地方 你这样显示,如果$prescription的内容是恶意的HTML、js代码,那它就会直接执行了。 显示之前用stripslashes处理下就好。
xuzuning 2015-05-30
  • 打赏
  • 举报
回复
$prescription = trim($_GET['q']); <a href="./?q='.urlencode($prescription).'"> <input name="q" type="text" size="20" maxlength="20" /> 这是 url 参数 q 的几次出现的地方 是否会招来 XSS 攻击这很难说,但不验证传入参数的来源和合法性总是不妥的 你至少需要将表单的提交方式由 get 改成 post

20,359

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧