在无法修改任何脚本的情况下(在我看来)我们需要看看是否可以将某种 exit/abort 命令注入到我们的响应中(存储在变量name) ...对于那些熟悉关系数据库的人来说,这类似于SQL injection。
问题是因为我们提供的值(存储在name 变量中)在子外壳(bash -c ...)中被引用,所以我们需要一种方法来中止,不仅是子外壳shell 也是父 shell(由#!/bin/bash shebang 调用)。
注意:我不确定'return to bash' 的 OP 是什么意思,所以为了回答这个问题,我假设这意味着返回到父级的命令提示符脚本被调用。
一个想法是将kill 0 注入到答案中,这样子shell 实际运行kill 0,这反过来应该中止所有子shell 并将我们返回到命令提示符。
当前脚本正在寻找要提供给/usr/games/team 的某种答案,因此我们需要让该调用完成,然后发出kill 0。
由于我们没有得到/usr/games/team,我将four() 函数中的一行代码替换为以下代码:
set -xv # enable debugging so we can see how the next line is expanded at run time
bash -c "echo team name: ${name}"
set +xv # disable debugging
一种注入思路,假设父脚本名为team.bash:
$ team.bash
4. Print Team Badge
Enter choice [1 - 5]: 4
Enter your team: abc ; kill 0 # yeah, team name is "abc ; kill 0"
+ bash -c 'echo team name: abc ; kill 0' # this is what our injection expands to
team name: abc # our "echo" works as expected and ...
Terminated # here we see the result of running "kill 0" as a 2nd command
$ # and voilà, we're out of the script and back at the command prompt
没有set -xv/+xv 我们有:
$ team.bash
4. Print Team Badge
Enter choice [1 - 5]: 4
Enter your team: abc ; kill 0
team name: abc
Terminated
$