Webhacking.kr old-17

Challenge

Evaluate the JavaScript arithmetic expression and submit the result.

计算 JavaScript 算术表达式并提交结果。

1
https://webhacking.kr/challenge/js-4/

Analysis

页面脚本把长算术表达式的结果存入全局变量 unlock。sub() 使用 JavaScript 的 == 比较输入框值和 unlock,相等时跳转到 ? 加上 unlock / 10。因此不需要手工重算表达式,直接在题面上下文中读取已经由 JavaScript 求出的变量即可。

Solution

在 challenge 页面开发者工具的 Console 中运行以下完整代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(() => {
const input = document.querySelector('input[name="pw"]');
if (!input) {
throw new Error('password input was not found');
}
if (typeof unlock !== 'number' || !Number.isFinite(unlock)) {
throw new Error('unlock is not a finite number');
}

input.value = String(unlock);
if (typeof sub === 'function') {
sub();
} else if (input.form) {
input.form.requestSubmit();
} else {
throw new Error('challenge submit function was not found');
}
})();

这段代码保留题面原本的计算语义,并让题面的 sub() 负责跳转;该跳转的查询值是 unlock / 10。