Challenge
Move the target link to the goal position.
将目标链接移动到终点位置。
https://webhacking.kr/challenge/code-1/Analysis
hackme 元素的 onclick 处理器每次把 style.left 增加 1px;当结果恰好为 1600px 时,脚本才把 href 设置为 ?go=1600px:
this.style.left = parseInt(this.style.left, 10) + 1 + "px";if (this.style.left == "1600px") this.href = "?go=" + this.style.left;记录中的直接请求返回 no hack,浏览器路径则通过 click 生成链接。服务端无法直接观察 DOM click;未保留两条路径的完整请求差异,不能把 click 本身视为服务端校验条件。把元素放到终点前 1px,再触发一次 click,可沿页面既有的链接生成流程请求。
Solution
在题目页面的浏览器开发者工具 Console 中运行完整脚本:
(function moveTargetToGoal() { const target = document.getElementById("hackme"); if (!target) { throw new Error("#hackme was not found"); }
target.style.left = "1599px"; target.click();
if (target.style.left !== "1600px") { throw new Error(`unexpected position: ${target.style.left}`); } if (target.getAttribute("href") !== "?go=1600px") { throw new Error(`unexpected href: ${target.getAttribute("href")}`); }})();