猿问

带有 javascript:alert() 的 XSS

我正在处理Reflected Cross-site scripting (XSS)我们网站上的一些漏洞(php、html、...) AppSpider 报告了一个我无法解决的漏洞。

Location: javascript:alert(10829224)

通常 AppSpider 会列出包含 js 的 url。这次没有。它只列出查询字符串:url=javascript:alert(12345)

当我尝试通过将其添加到列出的页面的 url 进行测试时,我什么也没得到:/path/to/page.html?url=javascript:alert(12345) 如果我添加脚本标签:/path/to/page.html?url=<script>javascript:alert(12345)</script>我会收到警报弹出窗口。

问题 1-javascript:alert()没有脚本标签可以工作吗?可行的js?

问题 2 - 我怎样才能逃避或防止这种类型的攻击?

感谢您提供任何提示或技巧


莫回无
浏览 596回答 3
3回答

开满天机

事实证明,我正在处理的页面需要$_REQUEST['url']var 中文件的相对路径。因此,我能够采取不同的方法,然后尝试解析或替换 javascript。我使用了php的parse_url()功能。便宜的黑客,但它适用于这个一次性页面/案例。if (isset($_REQUEST['url']) && valid_script_name_passed_in($_REQUEST['url']) ) {&nbsp;...}else{&nbsp;...}function valid_script_name_passed_in($request_value){&nbsp; &nbsp; $parts = parse_url($request_value);&nbsp; &nbsp; if( is_array($parts) ){&nbsp; &nbsp; &nbsp; &nbsp; if( isset($parts['scheme']) || isset($parts['host'] ){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return false;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; return true;}

炎炎设计

问题 1- javascript:alert() 没有脚本标签是否有效?在您的网站上,查询字符串有时会呈现在页面上。如果它是在 html 中呈现的 - 那么需要标签。如果它是在 javascript 代码中呈现的 - 那么它可能在没有标签的情况下工作。问题 2 - 我怎样才能逃避或防止这种类型的攻击?一般的解决方案是在页面上打印时转义用户的输入。在 PHP 中,最好的函数是htmlspecialchars。它将用 html 实体替换所有特殊字符。例如,它将 & 替换为 & 。这样文本看起来不会改变,但会阻止 XSS 注入。在您的情况下,我猜您希望 ?url=xxx 查询参数中有一个有效的 URL。然后转义将不起作用,因为转义会破坏 URL。在这种情况下,您可能想要验证提供的字符串是否是有效的 URL。这里讨论了几个 URL 验证选项。
随时随地看视频慕课网APP
我要回答