一、檢查系統日志
檢查系統錯誤登陸日志,統計IP重試次數
# 這里使用了lastb命令,該命令需要root權限,可以顯示所有登陸信息。這里僅僅顯示的root用戶的,讀者可以更具實際情況自行確定,或者直接全部都顯示,你會有不一樣的收獲,每個人的腳本都不一樣,更具實際情況自行編寫。
# lastb root | awk '{print $3}' | sort | uniq -c | sort -nr| more
以下是我部署在阿里雲上主機被多次掃描的日志
isadmin ssh:notty 121.42.165.44 Mon Aug 7 23:56 - 23:56 (00:00)
deploy ssh:notty 121.42.165.44 Mon Aug 7 23:54 - 23:54 (00:00)
deploy ssh:notty 121.42.165.44 Mon Aug 7 23:54 - 23:54 (00:00)
vagrant ssh:notty 121.42.165.44 Mon Aug 7 23:51 - 23:51 (00:00)
vagrant ssh:notty 121.42.165.44 Mon Aug 7 23:51 - 23:51 (00:00)
Iqadmin ssh:notty 121.42.165.44 Mon Aug 7 23:47 - 23:47 (00:00)
Iqadmin ssh:notty 121.42.165.44 Mon Aug 7 23:47 - 23:47 (00:00)
debian ssh:notty 121.42.165.44 Mon Aug 7 23:45 - 23:45 (00:00)
debian ssh:notty 121.42.165.44 Mon Aug 7 23:45 - 23:45 (00:00)
gpadmin ssh:notty 121.42.165.44 Mon Aug 7 23:43 - 23:43 (00:00)
gpadmin ssh:notty 121.42.165.44 Mon Aug 7 23:43 - 23:43 (00:00)
oracle ssh:notty 121.42.165.44 Mon Aug 7 23:40 - 23:40 (00:00)
oracle ssh:notty 121.42.165.44 Mon Aug 7 23:40 - 23:40 (00:00)
tomovic ssh:notty 121.42.165.44 Mon Aug 7 23:38 - 23:38 (00:00)
tomovic ssh:notty 121.42.165.44 Mon Aug 7 23:38 - 23:38 (00:00)
nginx ssh:notty 185.56.146.16 Mon Aug 7 23:37 - 23:37 (00:00)
nginx ssh:notty 185.56.146.16 Mon Aug 7 23:36 - 23:36 (00:00)
root ssh:notty 121.42.165.44 Mon Aug 7 23:36 - 23:36 (00:00)
root ssh:notty 121.42.165.44 Mon Aug 7 23:34 - 23:34 (00:00)
aaa ssh:notty 121.42.165.44 Mon Aug 7 23:12 - 23:12 (00:00)
aaa ssh:notty 121.42.165.44 Mon Aug 7 23:12 - 23:12 (00:00)
通過檢測,我們可以發現可以得到該惡意ip,然后添加到過濾名單中
二、檢查系統用戶
1、cat /etc/passwd 查看是否有異常的系統用戶
2、grep “0” /etc/passwd 查看是否產生了新用戶,UID和GID為0的用戶
3、ls -l /etc/passwd 查看passwd的修改時間,判斷是否在不知的情況下添加用戶
4、查看是否存在特權用戶 awk -F":" '{if($3 == 0){print $1}}' /etc/passwd
5、查看是否存在空口令帳戶 awk -F: '{if(length($2)==0) {print $1}}' /etc/passwd
三、檢查系統異常進程
1、注意UID為0的進程 使用ps -ef命令查看進程
2、察看該進程所打開的端口和文件 lsof -p pid命令查看
3、檢查隱藏進程# ps -ef | awk '{print $2}'| sort -n | uniq >1 ls /proc |sort -n|uniq >2 diff 1 2
“linux即文件,所有的進程在/proc均有記錄,需要注意,這里的信息是最詳細的,一些系統指令可能會出現被替換的的問題。”
四、檢查系統異常文件
# find / -uid 0 -perm 4000 -print
# find / -size +10000k –print
# find / -name “…” –print
# find / -name “.. ” –print
# find / -name “. ” –print
# find / -name ” ” –print
注意SUID文件,可疑大於10M和空格文件
# find / -name core -exec ls -l {} \ (檢查系統中的core文件)find -perm 高級用法
-perm mode:文件許可正好符合mode
-perm +mode:文件許可部分符合mode
-perm -mode: 文件許可完全符合mode
五、檢查系統文件的完整性
# rpm –qf /bin/ls
# rpm -qf /bin/login
# md5sum –b 文件名
# md5sum –t 文件名
六、檢查系統安裝包的完整性(這里主要檢驗的rpm包)
# rpm –Va 輸出格式:
S – File size differs
M – Mode differs (permissions)
5 – MD5 sum differs
D – Device number mismatch
L – readLink path mismatch
U – user ownership differs
G – group ownership differs
T – modification time differs
注意相關的 /sbin, /bin, /usr/sbin, and /usr/bin
對於不同的linux系統,你需要根據實際情況進行檢查。
七、檢查網絡
# ip link | grep PROMISC(正常網卡不該在promisc混雜模式,可能存在sniffer)
網卡處於混雜模式,這樣通過網卡的流量都會被監聽
# lsof –i 如查看所有打開80端口的進程: lsof –i :80
查看惡意程序開放的端口
# netstat –nap(察看不正常打開的TCP/UDP端口)# arp –a 查看流量在內網是否被劫持
八、檢查系統計划任務
注意root和UID是0的schedule
# crontab –u root –l
# cat /etc/crontab
# ls /etc/cron.*
九、檢查系統后門
# cat /etc/crontab
# ls /var/spool/cron/
# cat /etc/rc.d/rc.local
# ls /etc/rc.d # ls /etc/rc3.d
# find / -type f -perm 4000
十、檢查系統服務
# chkconfig —list
# rpcinfo -p(查看RPC服務)
這個主要檢測的是啟動服務,目前在centos7以上都采用systemd 來管理相應的服務。Systemd是一個系統管理守護進程、工具和庫的集合,用於取代System V初始進程。Systemd的功能是用於集中管理和配置類UNIX系統。
查看所有的可用單元
# systemctl list-unit-files
十一、檢查rootkit
# rkhunter -c
# chkrootkit -q
年紀大了,記憶力越來越差,有些東西還是記下來比較好。
轉載請注明

