TCPサーバの接続情報と、サーバのファイル一式が与えられた。
chall.py を読むと、以下の処理をしていることが読み取れた。
そこで、
Information to connect to a TCP server, and the files for the server were given.
Reading chall.py, I found it doing this process:
Seeing this, I decided to create machine code using
まず、以下のコードを用い、実行中のプログラムカウンタを出力してみることを試みた。
Firstly, I tried to print the value of the program counter in execution using this program:
しかし、UnicodeDecodeError というエラーが出てしまった。
そこで、簡単な実装でアドレスを文字で表現するため、16進数のそれぞれの桁をa~pのアルファベットで表現する以下のコードを実行した。
Unfortunately, this resulted in an error UnicodeDecodeError.
Seeing this, to express the address using characters in a simple implementation, I executed this code to express each hexadecimal digits using alphabets from a to p.
結果、qiling による実行とELFによる実行でともに aaaaaaaaabbppaaa (00000000011ff000) と出力され、判別はできなそうだった。
なお、出力のデコードは以下のRecipeで行える。
As a result, it printed aaaaaaaaabbppaaa (00000000011ff000) in both of executions on qiling and ELF, and it didn't look distinguishable.
I used this Recipe to decode the output:
次に、同様にスタックポインタの値を出力してみた。
Then, I tried printing the value of the stack pointer in the same way:
すると、qiling による実行では aaaaaaaaabbpopoi (00000000011fefe8)、ELFによる実行では aaaahppoodlfimki (00007ffee3b58ca8) と出力され、差が見つかった。
これを利用し、小さいスタックポインタを用いた qiling による実行ではシステムコール 60 - 0 = 60 (exit) を実行し、
大きいスタックポインタを用いたELFによる実行ではシステムコール 60 - 1 = 59 (execve) を実行する、以下のコードを実行した。
As a result, the execution on qiling printed aaaaaaaaabbpopoi (00000000011fefe8) and the execution using ELF printed aaaahppoodlfimki (00007ffee3b58ca8). Here is a difference!
Based on this, I executed this program to execute a system call 60 - 0 = 60 (exit) on qiling, which uses a small value of the stack pointer,
and a system call 60 - 1 = 59 (execve) on ELF, which uses a large value of the stack pointer.
このプログラムを実行させると、シェルの操作が可能になった。
ls -al コマンドを実行すると、ファイル flag.txt があることがわかった。
cat flag.txt コマンドを実行すると、flagが得られた。
Executing this program made the shell available.
I found a file flag.txt by executing a command ls -al.
I obtained the flag by executing a command cat flag.txt.