网站地图    收藏   

主页 > 后端 > 网站安全 >

Buy one XSS, get a CSRF for free - 网站安全 - 自学php

来源:自学PHP网    时间:2015-04-17 10:16 作者: 阅读:

[导读] Cross Site Request Forging (see http: en wikipedia org wiki Cross-site_request_forgery for more information) has been around for a while now It misuses the trust of a web...

Cross Site Request Forging (see http://en.wikipedia.org/wiki/Cross-site_request_forgery for more information) has been around for a while now. It misuses the trust of a web application that every request sent by the browser is wanted by its user.

For example, if you know that i am logged in to our blog admin backend most of the time, and you know its url and software, you could trick me into visiting a special prepared url. That url contains a small javascript that automatically submits a fake form to our admin backend, and short time later everybody is surprised to read on our blog that Mayflower will leave the domain of web application development and open a butcher’s shop instead.

Since the authors of our blog software are smart people, they implemented a CSRF protection. And not only them, even we not as smart PHProjekt developers implemented one.
There are three popular ways to protect your software against CSRF:

  1. using POST instead of GET
    The non working but popular counter measure. It helps against requests hidden in image tags, but it won’t for requests forged by javascript.

     

  2. a hidden one time key / token in every form This is what we – and a lot of other people, too – did. Every form gets a token, and only if this token exists the form is accepted. The remote javascript can’t know the token, so it can’t submit a valid form
  3. referrer-check
    Another neat way to protect against CSRF, if there is no strange browser or proxy configuration that prevents the referrer header involved.
    If the origin of a submission is from a different domain, don’t trust it.

Whether you implemented a, b or c – if you got an XSS on your site, your protection does not help anymore. XSS allows you to inject javascript into the target hosts javascript sandbox. This allows you to submit XmlHttpRequest (XHR) calls to the target server.

  1. XHR, as well as javascript DOM injections, can be used to submit a post form
  2. The token can be circumvented by a XHR request that reads the original form page and extracts the token form variable
  3. XmlHttpRequest.setRequestHeader(‘Referer’, ‘http://targetdomain.com/spoofedreferer.php’) allows you to set a fake header.

Conclusion:
If you want to secure your application against CSRF, make sure that there are no XSS on your site, too.

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论