漏洞描述
2020年5月21日,阿里雲應急響應中心監測到某安全研究人員披露Apache Tomcat在一定條件下使用自帶session同步功能時存在反序列化代碼執行漏洞,並在GitHub上公佈該漏洞遠程命令執行可利用EXP程序,風險較大。
Apache Tomcat是由Apache軟件基金會屬下Jakarta項目開發的Servlet容器。當Apache Tomcat集羣使用了自帶session同步功能,並且沒有使用EncryptInterceptor,或者處於不可信的網絡環境中,攻擊者可能可以構造惡意請求,造成反序列化代碼執行漏洞。目前網絡上已披露相關利用代碼,實際利用需要相關JDK版本支持以及Tomcat Session同步端點可訪問。阿里雲應急響應中心提醒Apache Tomcat用戶儘快排查Cluster相關配置是否安全以防止漏洞攻擊。
安全建議
漏洞由不安全配置造成,加強配置即可防範漏洞攻擊:
1、若Tomcat啓用了session同步功能,配置EncryptInterceptor對通信進行加密,使用參考:http://tomcat.apache.org/tomcat-10.0-doc/config/cluster-interceptor.html#org.apache.catalina.tribes.group.interceptors.EncryptInterceptor_Attributes
2、禁止Tomcat集羣端點對不可信網絡開放(只能防範外網攻擊,內網依舊有風險)
不安全配置類似example:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="0.0.0.0"
port="5000"
selectorTimeout="100"
maxThreads="6"/>
</Channel>
</Cluster>
應改爲如下,以下是一些重要的默認值說明:
- 組播地址是228.0.0.4
- 組播端口爲45564(端口和地址共同決定羣集成員資格。
- 廣播的IP是java.net.InetAddress.getLocalHost().getHostAddress()(確保您不廣播127.0.0.1,這是一個常見錯誤)
- 偵聽複製消息的TCP端口是範圍中的第一個可用服務器套接字 4000-4100
- 偵聽器已配置 ClusterSessionListener
- 配置了兩個攔截器TcpFailureDetector,MessageDispatch15Interceptor
以下是默認的羣集配置:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener">
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener">
</Cluster>