HackThisSite - JavaScript Mission 3

Challenge

Math time!. The page hands you the checker source in a textarea; the password is a length, not a secret string.

第三关 Math time!:页面直接把校验源码放在一个 textarea 里,密码是一段算出来的长度,不是一个固定字符串。

Solution

用带登录态的会话取关卡页:

1
2
$ curl -s -b 'HackThisSite=<mission-cookie>' \
'https://www.hackthissite.org/missions/javascript/3/'

页面里的 textarea 给出这段源码:

1
2
3
4
5
6
7
8
9
10
11
12
var foo = 5 + 6 * 7;
var bar = foo % 8;
var moo = bar * 2;
var rar = moo / 3;
function check(x) {
if (x.length == moo) {
alert("win!");
window.location += "?lvl_password=" + x;
} else {
alert("Fail D:");
}
}
  • foo = 5 + 6 * 7。乘法优先:6 * 7 = 425 + 42 = 47
  • bar = foo % 847 % 8 = 747 = 5 * 8 + 7)。
  • moo = bar * 27 * 2 = 14
  • rar = moo / 314 / 3 = 4.666…。这一行算完就没被用过,是干扰项:校验里只引用了 moo

用 Node 运行一遍确认:

1
2
$ node -e 'var foo = 5 + 6 * 7, bar = foo % 8, moo = bar * 2, rar = moo / 3; console.log(foo, bar, moo, rar)'
47 7 14 4.666666666666667

校验条件是 x.length == moo,也就是 x.length == 14

Verify

提交一个 14 字符的串:

1
2
3
$ curl -s -b 'HackThisSite=<mission-cookie>' \
-e 'https://www.hackthissite.org/missions/javascript/3/' \
'https://www.hackthissite.org/missions/javascript/3/?lvl_password=aaaaaaaaaaaaaa'