ELFファイル hash_browns が与えられた。
hash_browns をmain関数があった。
A ELF file hash_browns was given.
Decompiling hash_browns via main:
このmain関数は、コマンドライン引数として受け取った文字列の長さをチェックした後、
奇数番目の文字のMD5、偶数番目の文字のSHA-256を求め、それぞれの最初の5バイトの16進表記が指定のものかをチェックするものである。
比較対象は、MD5についてはテーブルを順に使うが、SHA-256は何らかの計算により使う場所を決めている。
また、ファイル hash_browns に strings コマンドを適用すると、16進文字列が並んでいる部分があった。
そこで、16進文字列から文字を求める以下のプログラムを作成した。
This function main firstly checks the length of string given as the command-line argument.
Then, it calculates hash values of each characters (MD5 for odd-position, SHA-256 for even-position)
and checks if the hexadecimal representations of the first 5 bytes of the hash values are what is desired.
Elements of a table is used in their order to compare with the MD5, and what element to compare with the SHA-256 is decided by some calculation.
Also, applying the strings command to the file hash_browns, I found a part with hexadecimal strings in a row.
Based on these, I created this program to obtain corresponding character from the hexadecimal strings:
stringsコマンドの出力をこのプログラムの入力として与えると、以下の文字列が得られた。
Giving the output of the strings command as the input for this program, I obtained this string:
MD5はテーブルにある順に比較するため前半は意味がありそうだが、後半は非自明な順番になっているようである。
そこで、ファイル hash_browns に以下の改造を行い、
チェックを無効化した上でSHA-256の最初の部分と比較している文字列を順番に出力させるようにした。
(位置は0-origin)
0x85を0x39に書き換える。 (test命令をcmp命令にする)0x59 0xfaを0xe9 0xf9に書き換える。 (strcmp関数のかわりにputs関数を呼び出す)0x85を0x39に書き換える。 (test命令をcmp命令にする)
改造したファイルをsolve.plで処理すると、以下の文字列が得られた。
The former half should be meaningful because the MD5 is compared in the order in the table, but the latter looks in some non-clear order.
I applied these modifications to the file hash_browns
to disable the checks and have it print the strings to compare with the prefixes of SHA-256 in the order.
(for the positions, the first byte is 0th)
0x85) to 0x39. (replace test instruction with cmp instruction)0x59 0xfa) to 0xe9 0xf9. (have it call the function puts instead of strcmp)0x85) to 0x39. (replace test instruction with cmp instruction)
I executed the modified file on solve.pl. The result was:
先ほど得られた文字列の前半と、この文字列を以下のプログラムで合体させることで、flagが得られた。
I obtained the flag by merging the former part of the string previously obtained and this string via this program: