ファイルreally_awesome_console_application.exeが与えられ、
ユーザ名John Smithのライセンスキーを求められた。
really_awesome_console_application.exeをentry関数からFUN_00401220関数が以下のようにmain関数っぽい形で呼び出されていた。
A file really_awesome_console_application.exe wag given and
asked for the license key for the username John Smith.
I decompiled really_awesome_console_application.exe via FUN_00401220 is called from the function entry like how the function main should be called like this:
FUN_00401220関数の中身は以下のようになっており、
local_48にファイル名を構築した後、何らかの処理を行い、
local_48を引数としてsystem関数とremove関数を呼び出していた。
Here is the function FUN_00401220:
This program first constructs a file name on local_48.
Then, after doing some process, it calls the functions system and remove
with local_48 as the arguments.
そこで、system関数に何が渡されているのかを調査するため、以下の改造を行った。
system関数とremove関数を呼び出している部分をNOPで埋める。[0x40142a, 0x40143b)、ファイル中の位置では[0x82a, 0x83b)を0x90で埋める。
[0x401444, 0x401449)、ファイル中の位置では[0x844, 0x849)を0x90で埋める。
local_48の値をEAXのかわりにEDXに入れる。0x401428、ファイル中の位置では0x828のバイトを0x45から0x55に書き換える。
[0x401273, 0x40127b)、ファイル中の位置では[0x673, 0x67b)を0x90で埋める。
この改造によりlocal_48に格納されたパスを出力させることを狙ったが、アクセス違反になってしまった。
そこで、GDB上で実行し、アクセス違反になった時のスタック上のデータを調査することで、パスを発見した。
結果、このパスが示す場所には別の実行可能ファイルがあった。
FUN_004010e0関数がmain関数に相当しそうだった。
Seeing this, I made following modifications to the executable file to observe what is passed to the system function.
systen and remove with NOP.[0x40142a, 0x40143b) on Ghidra ([0x82a, 0x83b) in the file) with 0x90.
[0x401444, 0x401449) on Ghidra ([0x844, 0x849) in the file) with 0x90.
local_48 to EDX instead of EAX.0x401428 on Ghidra (0x828 in the file) from 0x45 to 0x55.
[0x401273, 0x40127b) on Ghidra ([0x673, 0x67b) in the file) with 0x90.
The aim of this modifications is having it to print the path stored in local_48, but it resulted in Segmentation Fault.
I ran this modified program on GDB and examined what is on the stack on Segmentation Fault to find the path.
As a result, I found another executable file on where the path points at.
Decompiling with FUN_004010e0 should corresponds to the main function.
この関数は、入力を読み込んだ後何らかの処理をし、最後に生成されたデータと入力したデータを比較している。
実行してみると、your name と License key の入力を求められた。
GDB上で実行してみると、Unauthorized software detected! と出力されて実行が終了した。
そこで、プログラムを書き換えて比較処理の直前で処理を止め、後からGDBをアタッチすることにした。
具体的には、Ghidra上の表示で0x401239、ファイル中の位置で0x639からeb fe (同じ命令に飛ぶjmp) を書き込んだ。
実行し、your name に指定のJohn Smithを入れ、License key は適当に入力した。
停止後GDBをアタッチし、スタック上に見つかった値にractf{}を加えることで、flagが得られた。
This function reads some input, does some processing, and compares the generated data with the entered data.
When I executed the program, I was asked to enter "your name" and "License key".
When I executed the program on GDB, it printed "Unauthorized software detected!" and the execution ended.
I decided to stop the execution just before the comparision by modifying the program and attach GDB after that.
I put eb fe (jmp instruction to jump to the same instruction) from 0x401239 on Ghidra (0x639 in the file).
I executed the modified program, put John Smith as specified to "your name", and entered some random string for "License key".
I attached GDB after the program stopped. Then I obtained the flag by adding ractf{} to the value I found on the stack.