TCPサーバの接続情報とELFファイル card-theft が与えられ、クレジットカードの番号を要求された。
このELFファイルを
main関数は、以下のことをしている。
5a 08 11 22 33 44 55 66 77 88 42 02 11 22 を process_emv関数で処理する。process_emv関数で処理する。process_emv関数は、データをprocess_tlv関数で処理している。process_tlv関数は、以下のことをしている。
0x42 のとき、read_iin関数0x5a のとき、read_pan関数read_value関数read_pan関数は、copy_data関数でデータを配列panにコピーし、その最後の2要素を出力している。copy_data関数は、バッファサイズを参照し、バッファの範囲内からのみコピーを行う。
copy_data関数の仕様より、実際に与えるデータより長さの情報を長く設定すると、以前に配列panにコピーされたデータがそのまま出力される。
以下のように、長さの情報を適宜設定していくことで後ろの6バイトの情報は得られたが、長さの情報を4バイト未満に設定すると拒否されるので、最初の2バイトは得られなかった。
Information to connect to a TCP server, and an ELF file card-theft were given, and the credit card number was asked.
Decompiling this ELF file using
main does is:
5a 08 11 22 33 44 55 66 77 88 42 02 11 22 with the function process_emv.process_emv.process_emv processes the data with the function process_tlv.process_tlv is:
read_iin for the tag 0x42read_pan for the tag 0x5aread_value for the other tagsread_pan copies data to an array pan via the function copy_data, and prints the last 2 elements.copy_data copies data from only the valid range of the buffer referring the buffer size.
Due to the behavior of the function copy_data, when the length information is set to longer than data actually given, data previously copied to the array pan is printed.
I obtained the 6 bytes from the tail by setting the length information properly in this way, but the first 2 bytes weren't available because it refuses to process length information less than 4 bytes.
ここで、ファイル card-theft に埋め込まれているデータを見ると、PANの最初の2バイトはIINと同じに設定されていることに気がついた。
そこで、とりあえず残りの2バイトにIINの値を入れてみると、正解になり、flagが得られた。
Seeing the data embed in the file card-theft, I found that the first 2 bytes of PAN is set to the same as the IIN.
I tried setting the 2 bytes left to the IIN. As a result, it was accepted and I obtained the flag.