HackThisSite - JavaScript Mission 3

posted
read
188 words · 1 min
contents

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

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

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

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

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=426 \times 7 = 42,5+42=475 + 42 = 47。
  • bar = foo % 8。47 mod 8=747 \bmod 8 = 7(47=5×8+747 = 5 \times 8 + 7)。
  • moo = bar * 2。7×2=147 \times 2 = 14。
  • rar = moo / 3。14/3=4.666…14 / 3 = 4.666\ldots。这一行算完就没被用过,是干扰项:校验里只引用了 moo。

用 Node 运行一遍确认:

Terminal window
$ 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 字符的串:

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