## 首頁(其他picoCTF writeup) https://hackmd.io/@sunfrancis12/ry_LLAgp3 作者: [台中教育大學 白帽社](https://hackmd.io/@ntcuhack/index) -sunfrancis12 ## login 這題十分的簡單,只需要一點搜尋而工具的使用 打開網頁後,可以看到一個登入介面,老樣子f12 ![](https://hackmd.io/_uploads/ry0CWcrTn.png) index.js內容 ``` (async()=>{ await new Promise((e=>window.addEventListener("load", e))), document.querySelector("form").addEventListener("submit", (e=>{ e.preventDefault(); const r = { u: "input[name=username]", p: "input[name=password]" } , t = {}; for (const e in r) t[e] = btoa(document.querySelector(r[e]).value).replace(/=/g, ""); return "YWRtaW4" !== t.u ? alert("Incorrect Username") : "cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ" !== t.p ? alert("Incorrect Password") : void alert(`Correct Password! Your flag is ${atob(t.p)}.`) } )) } )(); ``` 我觀察程式碼後可以發現,其實他在前端(也就是這份js就)就驗證密碼了,用的是if/else的方法,因此我們只要知道滿足if的條件後就好辦了 ``` t[e] = btoa(document.querySelector(r[e]).value).replace(/=/g, ""); return "YWRtaW4" !== t.u ? alert("Incorrect Username") : "cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ" !== t.p ? alert("Incorrect Password") : void alert(`Correct Password! Your flag is ${atob(t.p)}.`) ``` 從上述程式碼中,我們知道只要username = YWRtaW4 而且 password = cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ 就可以拿到flag 但是在這個判斷式前面還有一行程式 ``` t[e] = btoa(document.querySelector(r[e]).value).replace(/=/g, ""); ``` 去搜尋bota() function後,知道他是將內容加密成base64的function ![](https://hackmd.io/_uploads/r1v2VcB63.png) > [Stackoverflow](https://stackoverflow.com/questions/68849233/convert-a-string-to-base64-in-javascript-btoa-and-atob-are-deprecated) 我們打開[Cyberchef](https://gchq.github.io/CyberChef/),進行base64的decode **YWRtaW4** ![](https://hackmd.io/_uploads/HJdOScB6h.png) **cGljb0NURns1M3J2M3JfNTNydjNyXzUzcnYzcl81M3J2M3JfNTNydjNyfQ** ![](https://hackmd.io/_uploads/H1nTS9ra3.png) ### flag到手囉