[CTF Writeup / Misc] DiceCTF 2024 - zshfuck
may your code be under par. execute the getflag binary somewhere in the filesystem to win
nc mc.ax 31774
#!/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개의 whitelist를 지정할 수 있고, whitelist를 기반으로 명령을 실행시킬 수 있다.
ls를 실행시키면 run, y0u 디렉토리가 나온다. flag를 찾기 위해 find 명령을 사용해보았다.
여러 디렉토리를 거쳐 getflag가 있다. 그러나 경로 구성에 필요한 알파벳이 이미 6가지가 넘는다.
범위를 표현하여 접근할 수 있다는 점을 이용해 다음과 같은 페이로드를 작성했다.
/[0-~][0-~][0-~]/[0-~]0[0-~]/[0-~][0-~][0-~][0-~]/[0-~][0-~][0-~][0-~][0-~][0-~][0-~][0-~][0-~]/[0-~][0-~][0-~][0-~]/[0-~][0-~][0-~][0-~][0-~][0-~][0-~]
댓글
댓글 쓰기