Record traffic exception handling_PHP tutorial
记一次流量异常处理
前两天接到一个做开发的朋友电话,说他们客户一台服务器开机后,所有一个网段的机器上网都变慢了,他远程操作这台服务器也一卡一卡的。我第一反应就是机器被人攻击过了,因为我之前也遇到过类似的现象。大概都是tomcat管理密码设置的比较弱,被人上传了一些war包,导致服务器拼命往外发包,或者是被人恶意上传了一些php文件,也是往外发送大量的数据包。总而言之,往外发送大量数据包基本都是被人攻击过啦!下面看看我是怎么处理的。
1、首先我给他一个脚本,确认一下是网卡异常流量引起。注意网卡改成你的外网网卡名称。
<ol style="margin:0 1px 0 0px;padding-left:40px;" start="1" class="dp-css"><li>while : ; do</li><li>time=`date "+%Y-%m-%d %H:%M:%S"`</li><li>rx_before=`ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-`</li><li>tx_before=`ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-`</li><li>sleep 2</li><li>rx_after=`ifconfig eth0|sed -n "8"p|awk '{print $2}'|cut -c7-`</li><li>tx_after=`ifconfig eth0|sed -n "8"p|awk '{print $6}'|cut -c7-`</li><li>rx_result=$[(rx_after-rx_before)/256]</li><li>tx_result=$[(tx_after-tx_before)/256]</li><li>echo "$time Now_In_Speed: "$rx_result"kbps Now_OUt_Speed: "$tx_result"kbps"</li><li>sleep 2</li><li>done</li></ol>
<ol style="margin:0 1px 0 0px;padding-left:40px;" start="1" class="dp-css"><li>sh traffic.sh</li></ol>
<ol style="margin:0 1px 0 0px;padding-left:40px;" start="1" class="dp-css"><li>2016-02-03 13:32:01 Now_In_Speed: 5kbps Now_OUt_Speed: 0kbps</li><li>2016-02-03 13:32:05 Now_In_Speed: 2kbps Now_OUt_Speed: 0kbps</li><li>2016-02-03 13:32:09 Now_In_Speed: 1kbps Now_OUt_Speed: 0kbps</li><li>2016-02-03 13:32:13 Now_In_Speed: 1kbps Now_OUt_Speed: 664567kbps</li><li>2016-02-03 13:32:17 Now_In_Speed: 6kbps Now_OUt_Speed: 657895kbps</li><li>2016-02-03 13:32:21 Now_In_Speed: 3kbps Now_OUt_Speed: 568462kbps</li><li>2016-02-03 13:32:25 Now_In_Speed: 4kbps Now_OUt_Speed: 0kbps</li></ol>
3、在用ps -ef看了一下基本看不出,因为进程太多了,而且很多系统的进程我也不认识,没有看到什么异常进程。只有一个tomcat进程,kill之后一会又起来了,很奇怪。肯定是什么守护程序一直启动。
4、上面说了一开机启动就会出现这个现象,那么还肯定是启动服务或者启动脚本里面写了什么代码,结果rc.local文件也正常。那么看/etc/init.d目录下的启动脚本,有没有新增的或者可疑的?果然发现了一个functions和DbSecuritySpt文件,我将这两个文件移走,然后故障依旧。看了一下DbSecuritySpt文件里面内容:
<ol style="margin:0 1px 0 0px;padding-left:40px;" start="1" class="dp-css"><li>#!/bin/bash</li><li>/usr/local/apache-tomcat-6.0.44/webapps/eei/gfty</li></ol>

一看上图的报错我心想肯定是那个functions文件移走报错了。不过还好这是个虚拟机,我远程连接宿主机上。
然后在上图界面输入root密码后,执行mount -o remount rw /后将functions文件移到/etc/init.d目录下重新启动。但是重启还是报错,说要检查文件系统块文件,又执行fsck -y /dev/sda后提示重启,重启后系统正常运行。没有tomcat那个进程了,但是还是偶尔往外拼命往外发包啊!
5、我又上网查了一下很多网友说是将/tmp目录下有一些的文件里面写了PID号,但是我根据这些PID号没有找到这些进程,我把这两个文件移走了。重启系统故障依旧。而且操作很卡真的很恶心,加上我自己的笔记本一上午关机7次,应该硬件老化的原因,比较2010年买的。哎!此处心中一万个草泥马飘过。
6、又咨询了朋友说iftop工具能看的出来,我试了也不行,爆卡,后来又是是iptraf工具,这两个工具都没安装,又花了很多安装时间,结果也看不出来啊!拿一个iptraf工具我们看看,如下图所示:

7、又看了一下chkconfig开机启动有没有异常的服务,一看服务太多了,也很难发现。
8、我在想是不是每次连续发送几个大包的时候是不是那个进程也会占用很高的CPU使用率呢?再一边观察流量脚本运行的情况,一边又执行top看看是不是哪个进程导致。有一个getty进程偶尔能跑到70%多,结果一查看是有6个终端,然后关闭了多余的终端,但是还是异常。也没发现别的进程占用很高的CPU使用率。
9、最后我想用netstat -an | more测试,一个一个排查当前服务器开放端口,因为我朋友说客户也不是很懂linux,开放了很多端口暴露在互联网上。发现了一个xxxx.51545->119.147.145.221:6001异常,然后我查看了一下这个51545端口对应的进程,如下所示:

This process executes the getty command, which indicates that the getty process above me occasionally reaches a usage rate of more than 70%, which is exactly consistent with what I checked. I tried to kill the 1587 process number, and after observing for a while, the script outflow traffic was basically 0, which is normal. That is to say, this server connects to port 6001 of the server 119.147.145.221 on the Internet through port 51545. It is found that the IP address belongs to Guangdong Telecom.
But the matter is not over yet. As mentioned above, it must be running in the boot program, and the destination address 119.147.145.221 must be hidden in the virus file. I went into the /etc/rc.d directory and took a look:

It seems that virus files have been placed at every startup level!

It’s all software! However, this file was removed in my fourth step, and then we also saw a suspicious selinux file, because the timestamps of it and the DbSecuritySpt file were different from other startup script files. This is a test of whether your eyes are sharp~~


Look at the stuff in the /usr/bin/bsd-port directory again!

Hurry up and delete the /etc/init.d/selinux file and the /usr/bin/bsd-port directory. Then restart and try again, the system will be fine! Network card traffic is also normal. Then I changed the root password, but unfortunately I couldn’t find out whether the code file was maliciously uploaded due to a system vulnerability or a program vulnerability.

Summary of troubleshooting:
1. The server must use a password as little as possible to log in, preferably a key plus a password.
2. Open fewer ports that have nothing to do with business.
3. When checking problems, you must use the elimination method. Eyes should be sharp.
4. I am still not very familiar with many scripts and processes in the system.
4. Although it has been solved, this machine has still been uploaded. I am not sure if there are still some unstable factors. It is recommended that it is best to reinstall the system.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

OnLeaks has now partnered with Android Headlines to provide a first look at the Galaxy S25 Ultra, a few days after a failed attempt to generate upwards of $4,000 from his X (formerly Twitter) followers. For context, the render images embedded below h

Alongside announcing two new smartphones, TCL has also announced a new Android tablet called the NXTPAPER 14, and its massive screen size is one of its selling points. The NXTPAPER 14 features version 3.0 of TCL's signature brand of matte LCD panels

The Vivo Y300 Pro just got fully revealed, and it's one of the slimmest mid-range Android phones with a large battery. To be exact, the smartphone is only 7.69 mm thick but features a 6,500 mAh battery. This is the same capacity as the recently launc

Samsung has not offered any hints yet about when it will update its Fan Edition (FE) smartphone series. As it stands, the Galaxy S23 FE remains the company's most recent edition, having been presented at the start of October 2023. However, plenty of

In recent days, Ice Universe has been steadily revealing details about the Galaxy S25 Ultra, which is widely believed to be Samsung's next flagship smartphone. Among other things, the leaker claimed that Samsung only plans to bring one camera upgrade

The Redmi Note 14 Pro Plus is now official as a direct successor to last year'sRedmi Note 13 Pro Plus(curr. $375 on Amazon). As expected, the Redmi Note 14 Pro Plus heads up the Redmi Note 14 series alongside theRedmi Note 14and Redmi Note 14 Pro. Li

OnePlus'sister brand iQOO has a 2023-4 product cycle that might be nearlyover; nevertheless, the brand has declared that it is not done with itsZ9series just yet. Its final, and possibly highest-end,Turbo+variant has just beenannouncedas predicted. T
