lynis—*nix安全審計工具

一、介紹

Lynis是一款*nix(我在mac os x10.8.3,ubuntu 10.04, Debian 2.6上都測試過,能正常運行)上的開源的系統安全審計功能工具,該工具由一系列的shell腳本構成,可以在移動硬盤上運行(但運行需要root權限)。可以審計如下內容:

1. 系統上安裝的二進制文件(例如/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin目錄下的)
2.啓動服務(例如GRUB是否有密碼保護)
3.系統內核信息(例如默認運行級別,內核加載模塊,內核配置文件)
4.內存與進程信息(例如是否有殭屍進程,是否有等待中的I/O操作)
5.賬戶,羣組與身份驗證(例如sudoers文件,PAM配置等密碼策略,unmask設置等)
6.Shell(/etc/shells)
7.文件系統(例如tmp目錄下是否有90天前的文件,root文件系統是否有ACL策略
8.是否禁止外設(usb,fireware)
9.NFS
10.DNS域名服務(/etc/resolv.conf,BIND,PowerDNS, ypbind,nscd)
11.軟件包管理(dpkg,rpm)
12.網絡信息(網卡,網關,ip,處於waiting狀態的連接)
13.打印機(cups)
14.郵件系統(e.g.Postfix,Exim ,Qmail smtpd)
15.防火牆(iptable)
16、web服務器(apache,nignx)安全配置
17.SSH安全配置(例如不運行root遠程登錄)
18.SNMP安全配置
19.數據庫安全配置(MySQL,PostgreSQL,Oracle)
20.LDAP安全配置
21.PHP安全配置
22.Squid安全配置
23.日誌文件管理(syslog,logrotate)
24.危險服務 (inetd.conf)
25.系統指紋(/etc/motd /etc/issue /etc/issue.net)
26.定時任務(crontab/cronjob)
27.審計模塊是否開啓(auditd)
28. 時間同步服務(NTP)
29.加密(例如SSL證書有效期)
30.是否應用安全框架(SELinux,AppArmor ,grsecurity)
31.是否有文件系統完整性檢測工具(AFICK,AIDE, Osiris,Samhain,Tripwire
32.是否有惡意程序檢測工具(chkrootkit,Rootkit Hunter,ClamAV scanner)
33.特定文件的權限是否合理(例如/root/.ssh是否爲rwx------)
34.home目錄下是否有敏感文件(例如shell history文件內容是否可疑)
35.是否做過內核加固(掃描sysctl內容)
二、安裝及運行

很簡單,如下所示:

安裝

wget http://www.rootkit.nl/files/lynis-1.3.0.tar.gz
tar zxvf lynis-1.3.0.tar.gz
cd lynis-1.3.0/

查看幫助

sudo ./lynis --man

全部檢查(最常用)

sudo ./lynis --check-all -Q

採用crontab自動檢查

sudo ./lynis -c --auditor "automated" --cronjob > /var/log/lynis/report.txt

三、查看日誌中的敏感信息

grep Warning /var/log/lynis.log
grep Suggestingon /var/log/lynis.log

結果如下(以一臺debian操作系統爲例)

dani@10:~/lynis-1.3.0$ sudo grep Warning /var/log/lynis.log
[sudo] password for dani: 
[14:40:54] Warning: No password set on GRUB bootloader [test:BOOT-5121] [impact:M]
[14:42:33] Warning: Found 8 files in /tmp which are older than 90 days [test:FILE-6354] [impact:L]
[14:42:41] Warning: Couldn't find 2 responsive nameservers [test:NETW-2705] [impact:L]
[14:42:41] Warning: Found promiscuous interface (peth0) [test:NETW-3015] [impact:H]
[14:52:27] Warning: iptables module(s) loaded, but no rules active [test:FIRE-4512] [impact:L]
[14:52:49] Warning: Found SSL certificate expiration (/etc/ssl/certs/ca-certificates.crt) [test:CRYP-7902] [impact:M]
dani@10:~/lynis-1.3.0$ sudo grep Suggestion /var/log/lynis.log
[14:40:54] Suggestion: Run grub-md5-crypt and create a hashed password. Add a line below the line timeout=<value>, add: password --md5 <password hash> [test:BOOT-5121]
[14:42:29] Suggestion: When possible set expire dates for all password protected accounts [test:AUTH-9282]
[14:42:29] Suggestion: Default umask in /etc/profile could be more strict like 027 [test:AUTH-9328]
[14:42:29] Suggestion: Default umask in /etc/login.defs could not be found and defaults usually to 022, which could be more strict like 027 [test:AUTH-9328]
[14:42:29] Suggestion: Default umask in /etc/init.d/rc could be more strict like 027 [test:AUTH-9328]
[14:42:33] Suggestion: To decrease the impact of a full /tmp file system, place /tmp on a separated partition [test:FILE-6310]
[14:42:33] Suggestion: Clean up unused files in /tmp [test:FILE-6354]
[14:42:34] Suggestion: The database required for 'locate' could not be found. Run 'updatedb' or 'locate.updatedb' to create this file. [test:FILE-6410]
[14:42:34] Suggestion: Disable drivers like USB storage when not used, to prevent unauthorized storage or data theft [test:STRG-1840]
[14:42:34] Suggestion: Disable drivers like firewire storage when not used, to prevent unauthorized storage or data theft [test:STRG-1846]
[14:42:40] Suggestion: Purge removed packages (2 found) with aptitude purge command, to cleanup old configuration files, cron jobs and startup scripts. [test:PKGS-7346]
[14:42:41] Suggestion: Check your resolv.conf file and fill in a backup nameserver if possible [test:NETW-2705]
[14:52:27] Suggestion: Disable iptables kernel module if not used or make sure rules are being used [test:FIRE-4512]
[14:52:27] Suggestion: Configure a firewall/packet filter to filter incoming and outgoing traffic [test:FIRE-4590]
[14:52:42] Suggestion: Add legal banner to /etc/issue, to warn unauthorized users [test:BANN-7126]
[14:52:42] Suggestion: Add legal banner to /etc/issue.net, to warn unauthorized users [test:BANN-7130]
[14:52:48] Suggestion: Enable auditd to collect audit information [test:ACCT-9628]
[14:52:51] Suggestion: Renew SSL expired certificates. [test:CRYP-7902]
[14:52:53] Suggestion: Install a file integrity tool [test:FINT-4350]
[14:53:03] Suggestion: One or more sysctl values differ from the scan profile and could be tweaked [test:KRNL-6000]
[14:53:03] Suggestion: Harden the system by removing unneeded compilers. This can decrease the chance of customized trojans, backdoors and rootkits to be compiled and installed [test:HRDN-7220]
[14:53:03] Suggestion: Harden compilers and restrict access to world [test:HRDN-7222]
[14:53:03] Suggestion: Harden the system by installing one or malware scanners to perform periodic 

結果如下(以一臺debian操作系統爲例)

四、小結
該款工具比較全面的涵蓋了系統安全的審計內容,但每個審計項都不深入,需要具體的擴展,例如PHP、Apache,MySQL的安全配置,就需要細化。

五、附錄
安全加固列表
(1)OS加固:debian(真機/虛擬機)
(2)DB加固:mysql3306,PostgreSQL5432,Oracle2483-2484,SQLServer1433-1434
(3)web服務器加固:apache,nignx,lighthttpd
(4)應用程序服務器加固:php
(5)LDAP服務器:OpenLDAP(ldap 389)
(6)DNS服務器,BIND (dns 53)
(7)電子郵件服務器,SendMail(Postfix):SMTP (smtp 25)
(8)FTP服務器:VSFTPD,Server-U (ftp 21 tftp 69)
(9)Samba服務器:smb協議 (smb445)
(10)NFS服務器(nfs 2049)
(11)Squid服務器
(12)SSH服務器:OpenSSH (ssh 22 telnet23)
(13)Linux防火牆:iptables
(14)VPN服務:OpenVPN (ipsec 500, PPTP 1723, L2TP 1701)
(15)IDS:snort
(16)網絡監控:Nagios
(17)網絡監控策略:snmp服務 (snmp 161)
(18)SVN服務
(19)RTX
(20)kerberos
(21)SSL:OpenSSL
(22)PAM
(23)DHCP服務器
(24)數據備份
(25)遠程桌面VNC (VNC 5900)
(26)NTP(network time protocol) 123
參考:

http://xmodulo.com/2013/04/how-to-scan-linux-for-vulnerabilities.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章