正在逃脱<和>足以阻止XSS攻击吗?和>
我确信这个问题的答案是否定的,但我似乎找不到一种简单地将 <
和 >
转换为 & ;lt;
和 >
并不能完全阻止反射型和持久型 XSS。
我不是在谈论 CSRF。
如果这不能阻止 XSS,您能否提供一个如何绕过此防御的示例?
I'm sure that the answer to this question is No, but I can't seem to find a way that simply transforming <
and >
to <
and >
doesn't completely block reflected and persistent XSS.
I'm not talking about CSRF.
If this doesn't block XSS, can you provide an example of how to bypass this defence?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
并非所有 XSS 攻击都包括 <或>完全取决于数据插入的位置。
https://www.owasp.org/index.php /XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#Why_Can.27t_I_Just_HTML_Entity_Encode_Untrusted_Data.3F
Not all XSS attacks include < or > at all, depending on where the data is being inserted.
https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet#Why_Can.27t_I_Just_HTML_Entity_Encode_Untrusted_Data.3F
在属性中使用不受信任的字符串(用
"
引用)时,您需要将"
转义为"
。否则你可以很容易地注入 JavaScript。例如,
,其中
str
为" onmouseover='something-evil'"
。When using an untrusted string in an attribute (quoted with
"
) you need to escape"
as"
.Otherwise you could easily inject javascript. For example,
<a href="{{str}}">
withstr
being, for example," onmouseover='something-evil'"
.不。这里有几个转义
<
、>
、'
、"
和的示例>&
还不够:示例 1:
XSS 攻击:
示例 2:
XSS 攻击:
请参阅https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet 了解防止这些攻击的方法。
No. Here are a couple of examples where escaping
<
,>
,'
,"
and&
is not enough:Example 1:
XSS Attack:
Example 2:
XSS Attack:
See https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet for ways of preventing these attacks.
不,这还不够。请记住,XSS 不仅仅与 HTML 中的不可信数据有关,您还会在 JavaScript 和 CSS 中发现它。考虑诸如“var myVar = [input];”之类的情况您可以使用该[输入]值执行各种恶意操作,而无需靠近尖括号。 XSS 备忘单中还有更多示例: http://ha.ckers.org/xss.html< /a>
您在标签中提到了 ASP.NET;您想要查看的是
[AntiXSS 库][1]
。抓住这个并使用适当的输出编码:等等等等。绝对没有理由尝试在 .NET 中进行自己的字符替换。
No, it's not sufficient. Remember that XSS isn't just about untrusted data in HTML, you'll also find it in JavaScript and CSS. Think about a situation such as "var myVar = [input];" There are all sorts of malicious things you can do with that [input] value without going anywhere near angle brackets. There's many more examples over in the XSS cheat sheet: http://ha.ckers.org/xss.html
You've mentioned ASP.NET in the tag; what you want to be looking at is the
[AntiXSS library][1]
. Grab this and use the appropriate output encoding:etc. etc. There's absolutely no reason to try and do your own character substitution in .NET.