duplicate-entry — Daily AlpacaHack
import os, zipfile
FLAG = os.getenv("FLAG", "Alpaca{DUMMY}")
def writestr(z, name, data):
info = zipfile.ZipInfo(name)
z.writestr(info, data, compress_type=zipfile.ZIP_DEFLATED)
with zipfile.ZipFile("flag.zip", "w") as z:
writestr(z, "README.txt", "The flag is in flag.txt.")
for i in range(100):
if i == 50:
writestr(z, "flag.txt", FLAG)
else:
writestr(z, "flag.txt", "No flag here. Try harder.")
flag.txt という同名ファイルがたくさん格納されている
ふつうに unzip flag.zip すると replace README.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: を100回聞かれるので面倒である
とはいえ Windows の標準機能で展開すると「どのファイルを保存しますか?」で 25 bytes のファイルしか出ない

"No flag here. Try harder." が同じバイト数になっている...CubeICE を使うとリネームする選択肢が出るが、展開後のファイルから探すのが面倒である
Linux における unzip を使う
man unzip して説明を読むと -c オプションを使って標準出力に展開結果を表示できることがわかるman unzip
一部抜粋する
-c extract files to stdout/screen (``CRT''). This option is similar to
the -p option except that the name of each file is printed as it is
extracted, the -a option is allowed, and ASCII-EBCDIC conversion is
automatically performed if appropriate. This option is not listed in
the unzip usage screen.
Alpaca{ から始まることがわかっている
Alpaca{ から始まるものをフィルタすればよいunzip -c flag.zip | grep Alpaca{