作为IT工程师,进行Linux系统的安全漏洞扫描和修复是维护系统安全的重要工作。以下是详细的流程和方法:
# 安装OpenVAS/GVM
sudo apt update && sudo apt install gvm
# 初始化设置
sudo gvm-setup
# 启动服务
sudo gvm-start
# 访问web界面: https://localhost:9392
# 下载安装包(需要先注册获取)
wget https://www.tenable.com/downloads/api/v1/public/pages/nessus/downloads/<package-id>/download?i_agree_to_tenable_license_agreement=true -O Nessus.deb
# 安装
sudo dpkg -i Nessus.deb
# 启动服务
sudo systemctl start nessusd
# 访问web界面: https://localhost:8834
# 安装
sudo apt install lynis
# 运行系统审计
sudo lynis audit system
# 检查可更新的软件包
sudo apt update
sudo apt list --upgradable
# 检查安全更新
sudo unattended-upgrade --dry-run --debug
# 检查安全更新
sudo yum updateinfo list security
sudo yum updateinfo summary
# 或使用dnf
sudo dnf updateinfo list security
# Debian/Ubuntu
sudo apt update && sudo apt upgrade -y
sudo apt autoremove
# RHEL/CentOS
sudo yum update -y
# 或
sudo dnf upgrade -y
# 检查当前内核版本
uname -r
# 更新内核(Debian/Ubuntu)
sudo apt install linux-image-generic
# 更新内核(RHEL/CentOS)
sudo yum update kernel
# 查看运行的服务
sudo systemctl list-units --type=service --state=running
# 禁用服务示例
sudo systemctl disable <service-name>
sudo systemctl stop <service-name>
# 编辑SSH配置
sudo nano /etc/ssh/sshd_config
# 推荐修改项:
PermitRootLogin no
PasswordAuthentication no
AllowUsers yourusername
Port 2222 # 修改默认端口
MaxAuthTries 3
LoginGraceTime 1m
# 重启SSH服务
sudo systemctl restart sshd
# 示例playbook (update_system.yml)
- hosts: all
become: yes
tasks:
- name: Update all packages
apt:
update_cache: yes
upgrade: dist
when: ansible_os_family == 'Debian'
- name: Update all packages (RHEL)
yum:
name: '*'
state: latest
when: ansible_os_family == 'RedHat'
# 设置无人值守更新(Debian/Ubuntu)
sudo dpkg-reconfigure unattended-upgrades
# 或手动编辑配置
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
# 安装OSSEC
sudo apt install ossec-hids-server
# 配置监控规则
sudo nano /var/ossec/etc/rules/local_rules.xml
# 使用logwatch分析日志
sudo apt install logwatch
sudo nano /etc/logwatch/conf/logwatch.conf
# 每日发送日志摘要
sudo logwatch --detail High --mailto admin@example.com --range yesterday
通过以上方法和工具,您可以有效地识别和修复Linux系统中的安全漏洞,大大提高系统的安全性。