简体   繁体   English

在这些限制下是否可能发生 XSS 攻击?

[英]Is an XSS attack possible under these constraints?

The output is: output 是:

<img src="http://example.com/[input]"
     oncontextmenu="openUrl('http://example.com/[input]')">

Where [input] is the user input, which is sanitised through this function:其中[input]是用户输入,通过此 function 进行清理:

a => {
  a = String(a);
  a = this.replaceAll(a, "&", "&amp;");
  a = this.replaceAll(a, '"', "&quot;");
  a = this.replaceAll(a, "'", "&#39;");
  a = this.replaceAll(a, "<", "&lt;");
  return a = this.replaceAll(a, ">", "&gt;")
}

in other words, we seemingly can't break out or use quotes of any kind?换句话说,我们似乎无法突破或使用任何形式的引号?

Is an XSS attack possible at all under these constraints?在这些限制下,是否可能发生 XSS 攻击? Or is it possible to redirect the user to any domain besides example.com?或者是否可以将用户重定向到除 example.com 之外的任何域? Or indeed, load an image from (or make a request to) evil.com?或者实际上,从 evil.com 加载图像(或向其发出请求)? Thanks!谢谢!

Yes, this is a XSS vulnerability.是的,这是一个 XSS 漏洞。

While you do escape the HTML attribute syntax fine (so that nothing can break out of the src and oncontextmenu values), it does lack虽然您确实可以很好地转义 HTML 属性语法(这样就不会脱离srconcontextmenu值),但它确实缺少

  • validation of the example.com path.验证 example.com 路径。 src attribute values can be malicious on their own , and if someone gets the visitor to load http://example.com/logout , http://example.com/user-content?from=eve&file=bad-icon or http://example.com/redirect.php?target=evil.com/ , they might have won. src属性值本身可能是恶意的,如果有人让访问者加载http://example.com/logouthttp://example.com/user-content?from=eve&file=bad-iconhttp://example.com/redirect.php?target=evil.com/ ,他们可能赢了。 Yes, this depends on who controls example.com and possible vulnerabilities in there, but getting the victim to load certain URLs is part of many attacks.是的,这取决于谁控制 example.com 以及其中可能存在的漏洞,但是让受害者加载某些 URL 是许多攻击的一部分。
  • escaping of the JS string content! JS字符串内容的escaping! Let's say input is '.replace(/.*/,'evil.com')+' , you will end up with oncontextmenu="openUrl('http://example.com/'.replace(/.*/,'evil.com')+'')" .假设input'.replace(/.*/,'evil.com')+' ,你最终会得到oncontextmenu="openUrl('http://example.com/'.replace(/.*/,'evil.com')+'')" The HTML entities won't help you there - &apos; HTML 实体不会帮助你 - &apos; in the attribute becomes ' in the script.在属性中变为'在脚本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM