deadcode
TCPサーバの接続情報と、ELFファイル deadcode
が与えられた。
このファイルをTDM-GCCのobjdump
で逆アセンブルすると、
main
関数内でgets
関数を用いて入力を読み込んでいるのが見えた。
また、以下のsystem("/bin/sh")
を呼び出すコードがあった。
Information to connect to a TCP server and a ELF file deadcode
were given.
Disassembling the file via objdump
in TDM-GCC,
I found that the function gets
is used to read some input in the function main
.
Also, I found this code that calls system("/bin/sh")
:
4011ef: 48 8d 3d d5 0e 00 00 lea 0xed5(%rip),%rdi # 4020cb <_IO_stdin_used+0xcb>
4011f6: b8 00 00 00 00 mov $0x0,%eax
4011fb: e8 50 fe ff ff callq 401050 <system@plt>
さらに、gets
関数が読み込んだデータは-0x20(%rbp)
から読み込まれ、リターンアドレスは%rbp
の8バイト先なので、
リターンアドレスはgets
関数のデータの読み込み先から0x28バイト先にあることが読み取れた。
これらを踏まえ、Tera Termでサーバに接続し、
以下のデータを「ファイル送信」することで、シェルを起動できた。
シェルで ls -al
コマンドを実行するとファイル flag.txt
があることがわかり、
cat flag.txt
コマンドを実行することでflagが得られた。
Moreover, I found that the return address is 0x28 bytes ahead from where the function gets
saves data read
because it saves from -0x20(%rbp)
and the return address is 8 bytes ahead from %rbp
.
Based on these, I succeeded to launch the shell by connecting to the server via Tera Term
and sending this data via "Send file".
I found that a file flag.txt
exists by executing a commnand ls -al
in the shell,
and obtained the flag via a command cat flag.txt
.
launch_shell.bin
DUCTF{y0u_br0ught_m3_b4ck_t0_l1f3_mn423kcv}
writeup by MikeCAT
DownUnderCTF 2021