wasm(WebAssembly )
打開頁面是一個俄羅斯方塊的遊戲。F12發現了提示,猜測要打到一定分數才能獲取到flag
觀察得知這是一個wasm的遊戲,F12下載wasm文件
linux下安裝wabt
$ git clone --recursive https://github.com/WebAssembly/wabt cd wabt mkdir build cd build cmake ..
WABT(我們將其稱爲“ wabbit”)是用於WebAssembly的一套工具,包括:
- wat2wasm:從 WebAssembly文本格式轉換爲 WebAssembly二進制格式
- wasm2wat: wat2wasm的逆函數,從二進制格式轉換回文本格式(也稱爲.wat)
- wasm-objdump:顯示有關wasm二進制文件的信息。與objdump類似。
- wasm-interp:使用基於堆棧的解釋器解碼並運行WebAssembly二進制文件
- wasm-decompile:將wasm二進制文件反編譯爲可讀的類似C的語法。
- wat- desugar:解析規範解釋程序支持的.wat文本格式(S表達式,平面語法或混合格式)並打印“規範”平面格式
- wasm2c:將WebAssembly二進制文件轉換爲C源代碼和標頭
- wasm-strip:刪除WebAssembly二進制文件的部分
- wasm-validate:驗證WebAssembly二進制格式的文件
- wast2json:將wasm spec測試格式的文件轉換爲JSON文件和關聯的wasm二進制文件
- wasm-opcodecnt:計算指令的操作碼使用量
- spectest-interp:讀取Spectest JSON文件,然後在解釋器中運行其測試
使用WABT將wasm文件轉換爲文本格式
root@xxx:~/opt/wabt/build$ ./wasm2wat /home/xxx/temp/blocks.wasm -o /home/xxx/temp/test.wat
查找99999,發現了這個,更改數值即可
修改完成後使用WABT將文件
root@xxx:~/opt/wabt/build$ ./wat2wasm /home/xxx/temp/blocks.wat -o /home/xxx/temp/blocks.wasm
搭建服務器,複製題目原來的頁面,替換修改後的wasm運行遊戲即可得到一個網址,訪問後得到flag
注意:原題頁面會報錯,修改後的頁面代碼
<html> <script src="encoding.min.js"></script> <script src="wasm_exec.js"></script> <script src="pako_inflate.min.js"></script> <script> window.addEventListener('DOMContentLoaded', async () => { const go = new Go(); const name ="blocks"; const curWwwPath=window.document.location.href; const pathName=window.document.location.pathname; const pos=curWwwPath.indexOf(pathName); const localhostPath=curWwwPath.substring(0,pos); let url = `${localhostPath}/${name}.wasm.gz`; // 'await import' doesn't work on the old Edge browser: // await import('/scripts/pako_inflate.min.js'); let wasm = pako.ungzip(await (await fetch(url)).arrayBuffer()); // A fetched response might be decompressed twice on Firefox. // See https://bugzilla.mozilla.org/show_bug.cgi?id=610679 if (wasm[0] === 0x1f && wasm[1] === 0x8b) { wasm = pako.ungzip(wasm); } const result = await WebAssembly.instantiate(wasm, go.importObject).catch((err) => { console.error(err); }); go.run(result.instance); }); </script> </script> </html>
參考wasm逆向分析:https://www.cnblogs.com/Mayfly-nymph/p/12974921.html