----------不定期更新------------
Linux服務器發包
關於服務器網絡流量異常,卡死,遭受入侵,對外發包...
以下只是一些小工具,用於檢測流量及哪些進程有問題,需要豐富的經驗配合。
yum install ifstat nload iptraf sysstat
大多數是因爲PHP-ddos木馬原因導致發包
watch ifconfig-------------查看數據包新增情況
ifstat----查看網卡流量
eth0 eth1
KB/s in KB/s out KB/s in KB/s out
407.34 154.99 134.96 324.29
274.08 191.48 210.72 248.32
240.20 192.91 257.22 179.06
136.48 236.72 203.89 179.84
nload-------以流量圖顯示
iptraf------------很直觀的工具
sar -n DEV 1 4查看4次數據
[root@ct-nat ~]# sar -n DEV 1 4
Linux 2.6.18-164.el5PAE (ct-nat) 06/05/2014
02:20:38 PM IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
02:20:39 PM lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
02:20:39 PM eth0 855.10 290.82 832319.39 140028.57 0.00 0.00 0.00
netstat -tu -c
查看發包的端口
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 124.1.1.68:49995 218.66.170.184:10991 ESTABLISHED
tcp 0 0 ::ffff:118.26.96.1:ssh ::ffff:118.26.96.248:41077 ESTABLISHED
tcp 0 0 ::ffff:118.26.96.1:ssh ::ffff:118.26.96.248:42562 ESTABLISHED
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 124.1.1.68:49995 218.66.170.184:10991 ESTABLISHED
tcp 0 0 ::ffff:118.26.96.1:ssh ::ffff:118.26.96.248:41077 ESTABLISHED
tcp 0 0 ::ffff:118.26.96.1:ssh ::ffff:118.26.96.248:42562 ESTABLISHED
用 lsof -i
:39733 查看端口的進程,Kill就可以了
一篇博客的解決辦法:
從服務器上使用命令sar -n DEV 1 4 ,確實出現大量發包的問題,(下邊是正常的,異常的情況eth0txpck/s 10000左右了)
先進行限速或者拔掉網線:
開始之前,先要清除 eth0所有隊列規則
tc qdisc del dev eth0 root 2> /dev/null > /dev/null
1) 定義最頂層(根)隊列規則,並指定 default 類別編號
tc qdisc add dev eth0 root handle 1: htb default 20
tc class add dev eth0 parent 1: classid 1:20 htb rate 2000kbit
(1KB/s = 8KBit/s)
TC命令格式:
tc qdisc [ add | change |
replace | link ] dev DEV [ parent qdisc-id | root ] [ handle qdisc-id ]qdisc
[ qdisc specific parameters ]
tc class [ add | change |
replace ] dev DEV parent qdisc-id [ classid class-id ]qdisc
[ qdisc specific parameters ]
tc filter [ add | change
| replace ] dev DEV [ parent qdisc-id | root ]protocol
protocol prio priority filtertype [ filtertype specific parameters ]flowid flow-id
顯示
tc [-s | -d ] qdisc show [ dev DEV ]
tc [-s | -d ] class show dev DEV tc filter show dev DEV
查看TC的狀態
tc -s -d qdisc show dev eth0
tc -s -d class show dev eth0
刪除tc規則
tc qdisc del dev eth0 root
查看狀態:
top
CPU和MEM都正常,看不出異常的進程。
yum install -y tcpdump
tcpdump -nn
找到大量的IP地址
本機(192.168.35.145)和主機114.114.110.110之間的數據
tcpdump -n -i eth0 host 192.168.35.145 and 114.114.110.110
還有截取全部進入服務器的數據可以使用以下的格式
tcpdump -n -i eth0 dst 192.168.35.145
或者服務器有多個IP 可以使用參數
tcpdump -n -i eth0 dst 192.168.35.145 or 192.168.35.155
我們抓取全部進入服務器的TCP數據包使用以下的格式,大家可以參考下
tcpdump -n -i eth0 dst 192.168.35.145 or 192.168.35.155 and tcp
從本機出去的數據包
tcpdump -n -i eth0 src 192.168.35.145 or 192.168.35.155
tcpdump -n -i eth0 src 192.168.35.145 or 192.168.35.155 and port ! 22 and tcp
或者可以條件可以是or 和 and 配合使用即可篩選出更好的結果。
可以將異常IP加入到/etc/hosts.deny中,或者防火牆設置下
NetHogs查看網絡使用情況
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpm
yum clean all
yum makecache
yum install nethogs -y
nethogs
下圖顯示各進程當前網絡使用情況:
按“m”鍵可以切換到統計視圖,顯示各進程總的網絡使用情況
使用幫助:
[root@localhost ~]# nethogs --help
usage: nethogs [-V] [-b] [-d seconds] [-t] [-p] [device [device [device ...]]]
-V : 顯示版本信息,注意是大寫字母V.
-d : 延遲更新刷新速率,以秒爲單位。默認值爲 1.
-t : 跟蹤模式.
-b : bug 狩獵模式 — — 意味着跟蹤模式.
-p : 混合模式(不推薦).
設備 : 要監視的設備名稱. 默認爲 eth0
當 nethogs 運行時, 按:
q: 退出
m: 總數和當前使用情況模式之間切換
找到大量發包的進程,之後kill掉,再排查下這個進程是什麼程序,文件路徑在哪裏,刪除掉異常的文件。
個人學習筆記,不當之處還請指正。
----------不定期更新------------
----------不定期更新------------
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.