1, 服务器遭到攻击的一般处理思路
(1) 切断网络
(2) 查找攻击源
通过分析系统日志和登录日志, 查找可疑信息. 通过查看系统打开了那些端口, 运行了哪些进程, 分析哪些是可疑程序.
(3) 分析入侵原因和途径
(4) 备份用户数据
(5) 重新安装系统
(6) 修复程序或系统漏洞
(7) 恢复数据并连接网络
2, 处理过程
(1) 检查系统中的可疑用户
使用 w 命令查看登陆过系统的用户, 可以看出用户名和登录地址
- [[email protected] ~]# w
- 06:41:21 up 8:17, 7 users, load average: 0.00, 0.01, 0.04
- USER TTY FROM [email protected] IDLE JCPU PCPU WHAT
- root pts/3 10.0.0.1 03:21 2:58m 0.07s 0.07s -bash
- root pts/4 10.0.0.1 04:40 2:00m 0.03s 0.03s -bash
- user01 pts/5 10.0.0.1 06:37 3:26 0.02s 0.02s -bash
- user03 pts/6 10.0.0.1 06:38 2:33 0.03s 0.00s Less -s
(2) 锁定可疑用户
一般遭受攻击, 会有一些本身无法登录系统的系统用户登录. 一旦发现有这种用户, 需要进行如下操作:
禁用 / 锁定用户登录系统的方法
1,usermod 命令
usermod -L username 锁定用户
usermod -U username 解锁
2,passwd 命令
passwd -l username 锁定用户
passwd -u username 解锁
3, 修改用户的 shell 类型为 / sbin/nologin(/etc/passwd 文件里修改)
4, 在 / etc / 下创建空文件 nologin, 这样就锁定了除 root 之外的全部用户
(3) 通过 last 命令查看用户登录
[[email protected] ~]# last
此命令的来源是 / var/log/wtmp, 该文件是二进制文件, 可以通过 who 命令查看
- [[email protected] ~]# who -u /var/log/wtmp
- root pts/4 2020-04-04 04:40 03:32 20628 (10.0.0.1)
- root pts/0 2020-04-04 06:08 . 24900 (10.0.0.1)
- root pts/1 2020-04-04 06:36 00:35 26282 (10.0.0.1)
- user01 pts/5 2020-04-04 06:37 ? 26416 (10.0.0.1)
- user03 pts/6 2020-04-04 06:38 01:34 26485 (10.0.0.1)
(4) 查看系统日志
/var/log/messages 和 / var/log/secure, 这两个文件记录着软件的运行状态和用户远程登录状态.
此外, 还可以查看每个用户家目录下的. bash_history, 以及 root 用户的. bash_history
(5) 检查系统可以进程
通过 ps -ef 查看进程, 得到 pid 后, 通过 lsof 命令查看打开的文件和端口
[[email protected] ~]# lsof -p PID
也可以使用 pidof 命令
- [[email protected] ~]# pidof sshd
- 26497 26485 26278 24896 854
可以查看 exe 文件信息和服务打开的文件句柄
- [[email protected] ~]# ls -l /proc/26485/exe
- lrwxrwxrwx. 1 root root 0 Apr 4 06:38 /proc/26485/exe -> /usr/sbin/sshd
- [[email protected] ~]# ls -l /proc/26485/fd
- total 0
- lr-x------. 1 root root 64 Apr 4 06:38 0 -> /dev/null
- lrwx------. 1 root root 64 Apr 4 06:38 1 -> /dev/null
- lrwx------. 1 root root 64 Apr 4 06:38 2 -> /dev/null
- lrwx------. 1 root root 64 Apr 4 06:38 3 -> socket:[70285]
- lrwx------. 1 root root 64 Apr 4 06:38 4 -> socket:[69484]
- lrwx------. 1 root root 64 Apr 4 06:38 5 -> /dev/ptmx
- l-wx------. 1 root root 64 Apr 4 07:24 6 -> /run/systemd/sessions/17.ref
- lrwx------. 1 root root 64 Apr 4 07:24 7 -> socket:[69488]
(6) 检查网络
正常情况下网卡不应工作在混杂模式, 否则可能存在 sniffer
[[email protected] ~]# ip l | grep PROMISC
(7) 检查系统后门
- [[email protected] ~]# cat /etc/crontab
- [[email protected] ~]# ls /var/spool/cron/
- [[email protected] ~]# cat /etc/rc.d/rc.local
- [[email protected] ~]# ls /etc/rc.d
- [[email protected] ~]# ls /etc/rc3.d
(8) 有时候系统二进制可执行文件被更改, 需要使用第三方工具检测
例如 rkhunter 工具 , 详见 https://www.cnblogs.com/zh-dream/p/12635523.html
(9) 文件系统完整性检查
- [[email protected] ~]# rpm -Va
- S.5....T. c /etc/sysconfig/authconfig
- ..5....T. c /etc/SSH/ssh_config
- .M....... g /etc/pki/ca-trust/extracted/java/cacerts
- .M....... g /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
- .M....... g /etc/pki/ca-trust/extracted/pem/email-ca-bundle.pem
- .M....... g /etc/pki/ca-trust/extracted/pem/objsign-ca-bundle.pem
- .M....... g /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
- .......T. c /etc/selinux/targeted/contexts/customizable_types
- S.5....T. c /etc/bashrc
- S.5....T. c /etc/sudoers
- S.5....T. c /etc/issue
- S.5....T. c /etc/issue.NET
- S.5....T. c /etc/yum/vars/contentdir
- .M....... g /boot/initramfs-3.10.0-862.el7.x86_64.img
- S.5....T. c /etc/SSH/sshd_config
- ....L.... c /etc/pam.d/fingerprint-auth
- ....L.... c /etc/pam.d/password-auth
- ....L.... c /etc/pam.d/postlogin
- ....L.... c /etc/pam.d/smartcard-auth
- ....L.... c /etc/pam.d/system-auth
- .......T. c /etc/named.conf
- S.5....T. c /etc/yum.conf
每个标记的含义如下:
S 表示文件长度发生了变化
M 表示文件的访问权限或文件类型发生了变化
5 表示 MD5 校验和发生了变化
D 表示设备节点的属性发生了变化
L 表示文件的符号链接发生了变化
U 表示文件, 子目录, 设备节点的 owner 发生了变化
G 表示文件, 子目录, 设备节点的 group 发生了变化
T 表示文件的最后一次修改时间发生了变化
如果在检测中有 "M" 标记的出现, 说明对应的文件可能被篡改或者替换了, 需要卸载这个 RPM 包重新安装.
常见的入侵情况
1) 服务器出去的带宽会跑高这个是中毒的一个特征.
因为服务器中毒之后被别人拿去利用, 常见的就是拿去当肉鸡攻击别人; 再者就是拿你的数据之类的.
所以服务器带宽方面需要特别注意下, 如果服务器出去的带宽跑很高, 那肯定有些异常, 需要及时检查一下!
2) 系统里会产生多余的不明的用户
中毒或者被入侵之后会导致系统里产生一些不明用户或者登陆日志, 所以这方面的检查也是可以看出一些异常的.
3) 开机是否启动一些不明服务和 crond 任务里是否有一些来历不明的任务?
因为中毒会随系统的启动而启动的, 所以一般会开机启动, 检查一下启动的服务或者文件是否有异常, 一般会在 / etc/rc.local 和 crondtab -l 显示出来
来源: http://www.bubuko.com/infodetail-3492591.html