TCPサーバの接続情報と、サーバのプログラム(ELFファイル)AbsoluteDiceが与えられた。
AbsoluteDiceをmain関数は"/dev/urandom"を引数として以下の_main関数を呼び出していた。
Information to connect to a TCP server and a server program (ELF file) AbsoluteDice were given.
Decompiling AbsoluteDice via main calling this function _main with "/dev/urandom" as the argument.
この関数は、乱数の値を31回連続で当てるとflag.txtの内容を出力するというものである。
ループでは、毎回fopen関数でファイルを開いて読み込み、その値を用いてsrand関数を呼び出していた。
また、逆コンパイルでは100回ループするようになっていたが、サーバに繋いで試すと32回で止まった。
AbsoluteDiceの挙動を調べた結果、
32回目のループでスタック上にあるファイル名へのポインタを入力値で上書きしており、
そのためにファイルの読み込みに失敗して落ちていることがわかった。
これを踏まえ、次の手順により乱数のシードを固定して正解の値を固定し、サーバにflagを出力させることができた。
"flag.txt"のアドレス134515641を入力する。
This function prints the contents of flag.txt after successfully guessing the value of the random number 31 times in a row.
It opens a file via the function fopen, read the file, and uses the value to call the function srand in each iteration.
Also, the result of decompilation suggested that the loop will run 100 times,
but I found it stopping after 32nd iteration when I connected to the server and observed the behavior.
I observed the behavior of AbsoluteDice on
Based on this, I had the server print the flag by fixing the value to guess by fixing the seed value for the random number generator.
134515641 (the address of "flag.txt" on Ghidra).