TCPサーバの接続情報が与えられた。
また、ELFファイル chall やC言語のソースコード baby_heap.c などのファイルが与えられた。
問題文より、今回扱うプログラムはメモリの確保や開放と値の書き込みが自由にでき、
main_ret に system('/bin/sh') のアドレスを書き込めばいいらしいことがわかった。
また、main_ret および system('/bin/sh') のアドレスは出力された。
ここで、自分が以前書いた以下の記事を参照する。
Information to connect to a TCP server was given.
Also, files including an ELF file chall and a C source code baby_heap.c were given.
The challenge descryption explained that the program to deal with in this challenge allows arbitrary allocation, deallocation, and writing of a value,
and that the address of system('/bin/sh') should be written to main_ret.
Also, the addresses of main_ret and system('/bin/sh') are printed.
Here I'll refer this article I wrote before:
free()した場所への書き込みで、malloc()の結果を操作する - Qiita
すると、以下の操作を行うことで、malloc() に任意のアドレスを返させることができることがわかる。
この操作を行うことで、メモリ確保の結果としてmain関数のリターンアドレスの場所を返させ、そこに system('/bin/sh') を書き込むことができた。
この状態で終了操作を行うことで、シェルを起動できた。
ls -al コマンドを実行するとファイル flag.txt があることがわかり、cat flag.txt コマンドを実行するとflagが得られた。
According to this article, we can have malloc() return arbitrary address by these steps:
Using this method, I succeeded to have it return the address where the return address of the function main is stored as a result of memory allocation, and to write system('/bin/sh') there.
After that, requesting to exit launched the shell.
Executing a command ls -al revealed that there is a file flag.txt, and I obtained the flag by executing a command cat flag.txt.