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.")

🤔

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.

Solve

unzip -c flag.zip | grep Alpaca{