Skip to content

Latest commit

 

History

History

zshfuck

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

zshfuck:misc:127pts

may your code be under par. execute the getflag binary somewhere in the filesystem to win
nc mc.ax 31774

jail.zsh

Solution

接続先とソースが渡される。
ソースは以下のようであった。

#!/bin/zsh
print -n -P "%F{green}Specify your charset: %f"
read -r charset
# get uniq characters in charset
charset=("${(us..)charset}")
banned=('*' '?' '`')

if [[ ${#charset} -gt 6 || ${#charset:|banned} -ne ${#charset} ]]; then
    print -P "\n%F{red}That's too easy. Sorry.%f\n"
    exit 1
fi
print -P "\n%F{green}OK! Got $charset.%f"
charset+=($'\n')

# start jail via coproc
coproc zsh -s
exec 3>&p 4<&p

# read chars from fd 4 (jail stdout), print to stdout
while IFS= read -u4 -r -k1 char; do
    print -u1 -n -- "$char"
done &
# read chars from stdin, send to jail stdin if valid
while IFS= read -u0 -r -k1 char; do
    if [[ ! ${#char:|charset} -eq 0 ]]; then
        print -P "\n%F{red}Nope.%f\n"
        exit 1
    fi
    # send to fd 3 (jail stdin)
    print -u3 -n -- "$char"
done

初めに*?`を除く6種類以下の文字を入力し、それらの文字種だけで構成されたスクリプトを入力するとzshで実行してくれる。
フラグはどこかにあるgetflagを実行する必要があるようだ。
まずはgetflagの場所だが、チームメンバがfind .でディレクトリが表示されることを発見していた。

$ nc mc.ax 31774
Specify your charset: find .

OK! Got f i n d   ..
find .
.
./y0u
./y0u/w1ll
./y0u/w1ll/n3v3r_g3t
./y0u/w1ll/n3v3r_g3t/th1s
./y0u/w1ll/n3v3r_g3t/th1s/getflag
./run
~~~
$ nc mc.ax 31774
Specify your charset: find .

OK! Got f i n d   ..
find ..
..
../app
../app/y0u
../app/y0u/w1ll
../app/y0u/w1ll/n3v3r_g3t
../app/y0u/w1ll/n3v3r_g3t/th1s
../app/y0u/w1ll/n3v3r_g3t/th1s/getflag
../app/run
../boot
../tmp
../libx32
../lib32
../etc
~~~

find ..で一つ上がルートディレクトリであり、/app/y0u/w1ll/n3v3r_g3t/th1s/getflagを実行すればよいことがわかる。
文字種を削減するため/a**/***/****/*********/****/g******のようにワイルドカードを利用したいが、禁止されている。
ここでzshのワイルドカードを調べると[a-z]のようにアルファベット小文字を指定できることがわかる。
[a-z]/で文字は6種類だが、パスに数字や記号がある場合にマッチしない。
試行錯誤すると[0-z]で数字や記号にもマッチすることがわかる。
以下のように文字種を入力し、getflagを実行する。

$ nc mc.ax 31774
Specify your charset: [0-z]/

OK! Got [ 0 - z ] /.
/[0-z][0-z][0-z]/[0-z][0-z][0-z]/[0-z][0-z][0-z][0-z]/[0-z][0-z][0-z][0-z][0-z][0-z][0-z][0-z][0-z]/[0-z][0-z][0-z][0-z]/[0-z][0-z][0-z][0-z][0-z][0-z][0-z]
dice{d0nt_u_jU5T_l00oo0ve_c0d3_g0lf?}

flagが得られた。

dice{d0nt_u_jU5T_l00oo0ve_c0d3_g0lf?}