Debian中Telnet服务遭遇攻击的处置与加固
一、立即止损
sudo ufw deny 23/tcp,或在iptables执行sudo iptables -A INPUT -p tcp --dport 23 -j DROP,仅对受信任网段按需放行。随后执行sudo ufw enable使策略持久。sudo systemctl stop telnet.socket与sudo systemctl disable telnet.socket;若由xinetd托管,编辑/etc/xinetd.d/telnet将disable = yes并重启xinetd;若由inetd托管,执行sudo systemctl stop inetd && sudo systemctl disable inetd。sudo apt-get remove --purge telnetd(如曾安装)。sudo apt update && sudo apt upgrade,随后重启SSH/系统以清除潜在被植入的持久化组件。二、排查入侵痕迹
grep -E '^(root|UID=0)' /etc/passwd、sudo grep -i 'sudo:' /var/log/auth.log、last -ai。ps auxf、ss -tnp | grep ':23\b',定位异常监听与已建立的Telnet会话。crontab -l -u root、grep -R "cron" /etc/ 2>/dev/null、systemctl list-timers --all、grep -R "@reboot" /etc/ 2>/dev/null。sudo tail -n 200 /var/log/auth.log /var/log/syslog | egrep -i 'telnet|in.telnetd|invalid|fail|refused',关注短时间内大量失败登录与来源IP。/etc/hosts.allow、/etc/hosts.deny是否被篡改。三、加固与替代方案
sudo apt install openssh-server && sudo systemctl start ssh && sudo systemctl enable ssh;在/etc/ssh/sshd_config中设置PermitRootLogin no、PubkeyAuthentication yes、PasswordAuthentication no、AllowUsers youruser,重启SSH生效。ufw allow from 192.168.1.0/24 to any port 22,并对23/TCP保持拒绝。apt update && apt upgrade保持补丁更新;通过PAM与账户策略实施强密码与登录限制;禁用不必要的服务与自启动项,减少攻击面。/etc/hosts.deny与/etc/hosts.allow中仅放行受控网段)。四、持续监控与响应
sudo tail -f /var/log/auth.log | egrep -i 'telnet|in.telnetd|fail|invalid',发现异常立即封禁来源IP并复核系统完整性。/etc/passwd、/etc/shadow、/etc/ssh/sshd_config与关键目录(如/root、/usr/sbin)做哈希校验与定期比对;将防火墙规则与关键配置纳入变更管理。