一、入侵事件快速判定
1. 常见入侵迹象
- 异常进程:存在
/tmp/.x
等隐藏进程 - 未知用户:
/etc/passwd
中出现hacker:x:0:0::/root:/bin/bash
- 可疑连接:服务器主动外联非常用IP(如东欧地区)
ps auxf | grep -E '(\./|tmp)'
netstat -antp | grep ESTABLISHED
cat /etc/passwd | grep -E ':0:'
2. 恶意文件特征识别
find / -type f -perm /111 -mtime -3 -print
readelf -l /usr/bin/sshd | grep 'GNU_STACK'
二、入侵应急响应五步法
1. 隔离网络
iptables -P INPUT DROP
iptables -A INPUT -s 10.0.0.0/24 -p tcp --dport 22 -j ACCEPT
2. 取证分析
aws ec2 create-snapshot --volume-id vol-123456 --description "Attack_Evidence"
insmod lime.ko "path=/memdump.lime format=lime"
3. 清除后门
import hashlib
valid_sshd_hash = "a1b2c3..."
current_hash = hashlib.sha256(open("/usr/sbin/sshd","rb").read()).hexdigest()
if current_hash != valid_sshd_hash:
print("SSH二进制文件被篡改!")
os.system("apt-get install --reinstall openssh-server")
三、系统加固方案
1. 文件完整性监控(Python实时检测)
import hashlib, time, os
BASE_DIR = "/etc"
hashes = {}
def init_hashes():
for root, _, files in os.walk(BASE_DIR):
for f in files:
path = os.path.join(root, f)
hashes[path] = hashlib.sha256(open(path,"rb").read()).hexdigest()
def monitor():
while True:
for path in hashes.copy():
if not os.path.exists(path):
print(f"文件被删除: {path}")
continue
current_hash = hashlib.sha256(open(path,"rb").read()).hexdigest()
if current_hash != hashes[path]:
print(f"文件被篡改: {path}")
os.system(f"chattr +i {path}")
time.sleep(60)
init_hashes()
monitor()