RootMe-Writeup-Unquoted-Expression-Injection
RootMe 题目 Unquoted-Expression-Injection
题目内容:
题目链接如下:
https://www.root-me.org/en/Challenges/App-Script/Powershell-Command-Injection
靶机目录内容展示如下:
#!/bin/bash
PATH=$(/usr/bin/getconf PATH || /bin/kill $$)
PASS=$(cat .passwd)
if test -z "${1}"; then
echo "USAGE : $0 [password]"
exit 1
fi
if test $PASS -eq ${1} 2>/dev/null; then
echo "Well done you can validate the challenge with : $PASS"
else
echo "Try again ,-)"
fi
exit 0
题解 Writeup:
从题目当中可以看到最关键的 Bash 漏洞点如下:
if test $PASS -eq ${1} 2>/dev/null; then
这句 Bash 语句中 由于对输入的变量没有加 quoto,即正确的写法是 "${1}"
,而由于没有quoto,导致 ${1}
存在注入点。
这里的对于未加 quato 的常见注入方法:
test 1234 -eq 0 -o foo
这句话有如下含义:
-
- 在bash中 -o 表示逻辑或,即如上语句等价于
test 1234 -eq 0 || foo
-
- foo在执行时永远返回为真
这里补充一点 test foo 和 test $foo 的区别,前者主要把 foo 看成字符串,因此只要字符串不为空则test foo 永远为真,而后者代表如果没有foo变量,则返回false,如果定义过foo变量,则为真。
- foo在执行时永远返回为真
Member discussion