鐵人賽 Day 5 逆向實戰 - 模擬請求計算總和 (簡單)

本系列文章所討論的 JavaScript 資安與逆向工程技術,旨在分享知識、探討防禦之道,並促進技術交流。
所有內容僅供學術研究與學習,請勿用於任何非法或不道德的行為。
讀者應對自己的行為負完全責任。尊重法律與道德規範是所有技術人員應共同遵守的準則。
挑戰網址
aHR0cHM6Ly93d3cubWFzaGFuZ3BhLmNvbS9wcm9ibGVtLWRldGFpbC8xLw==
解題過程
開啟 Network 並翻頁查看請求
可以一次翻兩頁查看兩次請求的Headers 及 UrlParams 或 PostData(若有),有沒有類似隨機變化的數值。

這兩個請求的Method為GET,所以沒有PostData需要檢查。

從這兩個請求的Headers中查看到的都是固定的參數,故猜測沒有任何的防護。
直接模擬請求看看是否能成功取得資料。
取得請求的 Node.js Fetch程式碼
在要複製的請求上點右鍵 Copy > Copy as fetch (Node.js) 即可得到程式碼
fetch("https://xxxxxxxxxx/api/problem-detail/1/data/?page=2", {
"headers": {
"accept": "*/*",
"accept-language": "zh-TW,zh;q=0.9,en;q=0.8,en-US;q=0.7",
"cache-control": "no-cache",
"pragma": "no-cache",
"priority": "u=1, i",
"sec-ch-ua": "\"Not;A=Brand\";v=\"99\", \"Google Chrome\";v=\"139\", \"Chromium\";v=\"139\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"cookie": "sessionid=xxxxxxxxxx",
"Referer": "https://xxxxxxxxxx/problem-detail/1/"
},
"body": null,
"method": "GET"
});
複製的程式碼沒有user-agent需要手動加上
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
完整程式碼
經過測試可以取得資料,所以我們將程式碼完善一下讓他抓滿20頁並計算總和即可得到挑戰題的答案。
const getPage = async(page) => {
console.log(`run page: ${page}`)
const response = await fetch(`https://xxxxxxxxxx/api/problem-detail/1/data/?page=${page}`, {
"headers": {
"accept": "*/*",
"accept-language": "zh-TW,zh;q=0.9,en;q=0.8,en-US;q=0.7",
"cache-control": "no-cache",
"pragma": "no-cache",
"priority": "u=1, i",
"sec-ch-ua": "\"Not;A=Brand\";v=\"99\", \"Google Chrome\";v=\"139\", \"Chromium\";v=\"139\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"cookie": "sessionid=xxxxxxxxxx",
"Referer": "https://xxxxxxxxxx/problem-detail/1/",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36",
},
"body": null,
"method": "GET"
});
let json = await response.json()
return json.current_array.reduce((a, b) => a + b, 0);
}
(async() => {
let total = 0;
for(let i = 1; i <= 20; i++){
total += (await getPage(i))
}
console.log(`total: ${total}`)
})()
使用Node執行JS程式

順利取得20頁的資訊並進行加總。
一個沒有任何防護的API,就相當於把資料裸露在網路上。
攻擊者不需要高深的技術,只要會改參數與模擬請求,就能惡意取得資料。