# 有Go讚 ## From memory safety to exploit in Go --- ## about me * Jerry CHEN 陳俊佑 * GIM backend * 寫 Golang 的入門 rust 玩家 ![image](https://hackmd.io/_uploads/SyqLOUM26.png) --- {%youtube 1rmDEP8oF34 %} --- ## google CTF 2019 ![D9hZBsaU4AAoHjL](https://hackmd.io/_uploads/rJ0J8PG2T.jpg) *https://twitter.com/googlestudents/status/1141760398867042304* --- ## what's CTF capture the flag as 解題、攻防 ![截圖 2024-02-21 01.35.33](https://hackmd.io/_uploads/HJv-XPfnp.png) *https://www.youtube.com/watch?v=PBvthC7soS4* --- ## PWN Gomium Browser ![image](https://hackmd.io/_uploads/H1Hc4FXnp.png) --- ## PWN Gomium Browser * `Browser that run go scirpt` * `pwn2own style (load html)` * `pop xcalc` --- ## Gomium DEMO ![截圖 2024-02-21 08.39.49](https://hackmd.io/_uploads/S1hPI6z36.png) --- ## hello world DEMO ``` cat hello.go make hello.html cat hello.html make hello ``` https://github.com/jynychen/gomium-exploit/blob/master/hello.go --- ## let's attack 呼叫個小算盤 DEMO ``` cat exec.go make exec.html cat exec.html make exec ``` https://github.com/jynychen/gomium-exploit/blob/master/exec.go --- ## what happend? `code walk on Gomium Browser Source` --- ## Gomium Browser Source Code ![Screenshot 2024-02-22 at 08.22.31](https://hackmd.io/_uploads/ryZ5NGV2a.png) --- ## Gomium Browser Source Code ![Screenshot 2024-02-22 at 08.22.45](https://hackmd.io/_uploads/H11bHM4ha.png) --- ## Gomium Browser Source Code ![Screenshot 2024-02-22 at 08.23.08](https://hackmd.io/_uploads/ryzr8G43T.png) --- ## Gomium Browser Source Code ![Screenshot 2024-02-22 at 08.23.15](https://hackmd.io/_uploads/rkzuHG43a.png) --- ## Gomium Browser Source Code ![Screenshot 2024-02-22 at 08.23.42](https://hackmd.io/_uploads/ryMg8M42p.png) --- ## 攻擊思路 1. oob write 2. control IP/PC 3. call target 4. exploit! --- ## 體驗一下 Go ![image](https://hackmd.io/_uploads/Hkh0rKQhp.png) --- ## golang interface 抽象物件 https://gobyexample.com/interfaces --- ## golang goroutine lightweight thread https://gobyexample.com/goroutines --- ## 攻擊思路 1. [oob write](https://) 2. control IP/PC 3. call target 4. exploit! --- ## interface race `code walk on race/race.go` --- ## interface race DEMO ``` go run race/race.go ``` https://github.com/Jyny/go-race-to-exploit/blob/main/race/race.go --- ## 攻擊思路 1. oob write 2. [control IP/PC](https://) 3. call target 4. exploit! --- ## 控制 PC/IP ![image](https://hackmd.io/_uploads/HJDO15mhT.png) *https://open4tech.com/microprocessor-program-counter/* --- ## 控制 PC/IP `code walk on funptr/funcptr.go` --- ## 控制 PC/IP DEMO ``` go run funcptr/funcptr.go ``` https://github.com/Jyny/go-race-to-exploit/blob/main/funcptr/funcptr.go --- ## 攻擊思路 1. oob write 2. control IP/PC 3. [call target](https://) 4. exploit! --- ## calling target with syscall `code walk on syscall/syscall.go` --- ## calling target with syscall DEMO ``` go run syscall/syscall.go ``` https://github.com/Jyny/go-race-to-exploit/blob/main/syscall/syscall.go --- ## 攻擊思路 1. oob write 2. control IP/PC 3. call target 4. [exploit!](https://) --- ## prepare exploit `code walk on exp.go` https://github.com/jynychen/gomium-exploit/blob/master/exp.go --- ## How to get addr of target finding gadget DEMO ``` make findobj make findpy ``` --- ## let's attack again DEMO ``` make exp ``` https://github.com/jynychen/gomium-exploit/blob/master/exp.go --- ![Screenshot 2024-02-21 at 22.47.18](https://hackmd.io/_uploads/Sku-pKm36.png) --- ## 修復現況 :( DEMO ``` uname -a //linux verion go version go run exp/exp.go ``` --- ## 核心問題 * thread safe (interface, slice, map) * go build ASLR disable by defaut --- ## thread unsafe `reference type` * interface * slice * map `protect with sync.Mutex x/sync` --- ## ASLR Address space layout randomization 定址空間隨機載入 ![Screenshot 2024-02-21 at 23.24.16](https://hackmd.io/_uploads/SkW2B5Qhp.png) *https://www.daniloaz.com/en/differences-between-aslr-kaslr-and-karl/* --- ## ASLR * only enable by default on M$ * NAS S vs Q (2018) --- ## 實況 https://youtu.be/T1lP1b89_cc?si=MHRQ6NWr0lADyoQ0&t=533 --- # Q&A --- ## Reference * https://github.com/Jyny/go-race-to-exploit * https://github.com/jynychen/gomium-exploit * https://github.com/google/google-ctf/tree/main/2019/finals/pwn-gomium * https://blog.stalkr.net/2019/12/the-gomium-browser-exploits.html * https://github.com/netanel01/ctf-writeups/tree/master/googlectf/2019/pwn_gomium
{"title":"有Go讚: From memory safety to exploit in Go","description":"golang interface• interface race (thread safe)• syscall• 跳過 compile time 型別檢查• 做到控制 var int 變成 funcPtr, 控制 EIP/PC• 思路","contributors":"[{\"id\":\"a3283302-4fa2-4474-ace8-9e17aa848aea\",\"add\":5784,\"del\":1352}]"}
    216 views