TCPサーバの接続情報、サーバのプログラム (ELFファイル) walkthrough、そのソースコード walkthrough.c、テキストファイル Dockerfile が与えられた。
walkthrough.c を読むと、main関数から呼び出されてgets関数によりデータを読み込むrop関数と、
呼び出されないがflag.txtの内容を出力する部分を持つfmtstr関数があることがわかった。
objdumpによる walkthrough の逆アセンブル結果を見ると、
rop関数におけるgets関数で読み込んだデータは-0x50(%rbp)から書き込まれ、
-8(%rbp)にcanaryがあり、リターンアドレスは%rbpの8バイト先にあることがわかった。
さらに、fmtstr関数内のflag.txtの内容を出力する部分は 0x401ce4 から始まることが読み取れた。
この部分では-0x78(%rbp)への値の読み書きが行われるので、%rbpを適切な値に設定しておかないといけない。
リターンアドレスの前の8バイトが関数から帰る際のleave命令によって%rbpに書き込まれるので、ここの値を適切に設定する。
今回は、関数のメモリ上のアドレスが格納される部分の少し先に%rbpを設定することにした。
出力されたcanaryの値を以下のファイルの*canary*の部分に書き込み、「ファイル送信」することで、flagが得られた。
Information to connect to a TCP server, a program of the server (a ELF file) walkthrough, its source code walkthrough.c, and a text file Dockerfile were given.
Reading walkthrough.c, I found a function rop that is called from the function main and read some data via the function gets,
and a functon fmtstr that is not called but has a part to print the contents of flag.txt.
Disassembling walkthrough via objdump in gets in the function rop is written from -0x50(%rbp),
and that there is a canary on -8(%rbp), and that the return address is 8 bytes ahead from %rbp.
Also, I found that the part to output the contents of flag.txt in the function fmtstr begins from 0x401ce4.
This part reads and writes values to -0x78(%rbp), so proper value has to be set to %rbp.
The 8-byte data before the return address will be written to %rbp via the leave instructon, so we should set data for this area properly.
I decided to set %rbp to a little bit ahead from the area to store the addresses of functions in the memory.
Connecting to the server via
I sent this file via "Send file" after putting the printed value of canary to the *canary* part to obtain the flag.