这个功能是否足以进行xss检测?

时间:2012-02-18 12:36:24

标签: php string xss

我在“symphony CMS”应用程序中找到它,它非常小:

https://github.com/symphonycms/xssfilter/blob/master/extension.driver.php#L100

我正在考虑窃取它并在我自己的应用程序中使用它来清理带有HTML的字符串以供显示。你觉得它做得好吗?

ps:我知道有HTML Purifier,但那个东西很大。我宁愿选择不太宽容的东西,但我仍然希望它有效率。


我一直在针对此页面中的字符串对其进行测试:http://ha.ckers.org/xss.html。但是如果对“XSS定位器2”失败了。不知道如何使用该字符串来破解网站:)

2 个答案:

答案 0 :(得分:8)

不,我不会用它。有许多不同的攻击都依赖于插入数据的上下文。单一功能不会涵盖所有功能。如果仔细观察,实际上只有四个测试:

// Set the patterns we'll test against
$patterns = array(
    // Match any attribute starting with "on" or xmlns
    '#(<[^>]+[\x00-\x20\"\'\/])(on|xmlns)[^>]*>?#iUu',

    // Match javascript:, livescript:, vbscript: and mocha: protocols
    '!((java|live|vb)script|mocha):(\w)*!iUu',
    '#-moz-binding[\x00-\x20]*:#u',

    // Match style attributes
    '#(<[^>]+[\x00-\x20\"\'\/])style=[^>]*>?#iUu',

    // Match unneeded tags
    '#</*(applet|meta|xml|blink|link|style|script|embed|object|iframe|frame|frameset|ilayer|layer|bgsound|title|base)[^>]*>?#i'
);

没有其他测试。除了这些测试没有检测到的攻击(假阴性)之外,它还可以将一些输入错误地报告为攻击(误报)。

因此,不要试图检测XSS攻击,只需确保使用正确的清理。

答案 1 :(得分:1)

我认为它在测试字符串方面做得很好,至少根据我的测试,这是我可以说的。

相关问题