linux安全审计和加固工具-lynis

0x00前言    

  lynis是一款开源的unix-based平台的审计工具。可以帮助审计员扫描unix系统以及可用的软件。程序主要探测,系统上安装的程序包,配置上的错误,以及安全问题和系统信息。

0x01 下载与安装

1 通过直接下载进行安装
步骤一:建立下载的目录
root@kali:~# mkdir -p /usr/local/lynis && cd /usr/local
步骤二:下载lynis
方式一:root@kali:~# wget https://cisofy.com/files/lynis-2.2.0.tar.gz
方式二:root@kali:~# curl https://cisofy.com/files/lynis-2.2.0.tar.gz -o lynis.tar.gz
方式三:直接使用浏览器打开页面:https://cisofy.com/download/lynis/ , 然后选择下载
步骤三:解压
方式一:root@kali:~# tar xfvz lynis.tar.gz
方式二:直接使用系统的解压软件直接进行解压(或者在win7解压,再拖入虚拟机)
2 通过 Git 进行安装
克隆项目
root@kali:~# cd /usr/local
root@kali:~# git clone https://github.com/CISOfy/lynis
root@kali:~# cd lynis
3. 通过包进行安装
Red Hat $ yum install lynis
Debian  $ apt-get install lynis
openSUSE $ zypper install lynis
4. 通过 Homebrew进行安装
对于Mac OS 用户来说, Homebrew 是可供选择的手工安装方式以及使用GIt

$ brew install lynis

0x02 运行

1 查看帮助
如果我们是通过包形式进行安装的话,我们可以在任何目录调用lynis,例如root@kali:~# lynis -h,否则我们需要通过以下方式进行使用:
root@kali:~/lynis# ./lynis -h #进入解压后的lynis目录,然后查看帮助信息;root@kali:~/lynis# ./lynis --man   该命令查看详细使用帮助
2 审计系统
root@kali:~/lynis# ./lynis audit system #该方式需要人工进行手动确认,确认后才能进行下一步检查
root@kali:~/lynis# ./lynis audit system -Q #该方式可以避免人工确认

root@kali:~/lynis# ./lynis -c -Q#全部检查(最常用)

root@kali:~/lynis# ./lynis -c -Q --pentest

root@kali:~# lynis -c -Q -q --auditor "yy mm"  #只显示告警输出

root@kali:~/lynis#./lynis -c -Q --auditor "yy mm" --cronjob > /var/log/lynis/report.txt
3停止和暂停
CTRL + C  去停止该程序的运行;
4 小技巧
4.1 如果lynis 不是通过带有man 页面的包进行安装的话,可以输入root@kali:~# man  lynis
4.2 对于那些SHELL终端背景是浅色的某些系统,可以使用root@kali:~# lynis --nocolors 后者root@kali:~# lynis --reverse-colors

4.3 可以使用-h 选项去显示所有可用参数,即是root@kali:~# lynis -h

0x03 报告和日志

1 屏幕输出:
OK or Warning
Found or Not found
A value
2. 日志文件
默认的日志文件位置:/var/log/lynis.log
该日志文件包含以下方面的内容:
每次行为/时间的时间
测试失败或者被忽略的原因
测试的输出
关于配置选项或者怎样去修补/改善问题的建议

威胁/影响分数

root@kali:~# leafpad /var/log/lynis.log

3 报告文件

默认的报告文件位置:/var/log/lynis-report.dat.

root@kali:~# leafpad /var/log/lynis-report.dat

4 命令参数

lynis [scan mode] [other options]
FIRST TIME USAGE
       When running Lynis for the first time, run: lynis audit system --quick
OPTIONS
       --auditor   Define  the  name of the auditor/pen-tester. When a full name is used, add double quotes, like "Your Name".
       --checkall (or -c)  Lynis performs a full check of  the  system, 
       --config   Show which settings file or profile is being used, then quit.
       --cronjob  Perform automatic scan with cron safe  options  (no  colors,  no questions, no breaks).

       --debug    Display  debug  information  to  screen for troubleshooting purposes.
       --dump-options    Show all available parameters.
       --logfile  Defines location and  name  of  log  file,  instead  of  default /var/log/lynis.log.
       --no-colors  Do not use colors for messages, warnings and sections.
       --no-log   Redirect all logging information to /dev/null, prevent sensitive information to be written to disk.
       --pentest Run a non-privileged scan, usually for penetration testing. Some of the tests will be skipped if they require root permissions.
       --plugin-dir  Define location where plugins can be found.
       --profile Provide alternative profile to perform the scan.
       --quick (-Q)  Do a quick scan (don't wait for user input).
       --quiet (-q)  Try  to  run  as silent as possible, showing only warnings. This option activates --quick as well.
       --report-file Provide an alternative name for report file.
       --reverse-colors  Optimize screen output for light backgrounds.
       --tests TEST-IDs   Only run the specific test(s). When using  multiple tests,add quotes around the line.
       --tests-category    Only  perform tests from particular tests. Use --view-categories to determine valid options.
       --upload Upload data to Lynis Enterprise server.
       --view-categories  Display all available test categories.
       Multiple parameters are allowed, though some  parameters  can  only  be
       used  together  with others. When running Lynis without any parameters,
       help will be shown and the program will exit.
EXIT CODES
       Lynis uses exit codes to signal any invoking script. Currently the fol-
       lowing codes are used:
       0      Program exited normally, nothing found
       1      Fatal error
       64     An unknown parameter is used, or incomplete
       65     Incorrect data encountered
       66     Can't open file or directory
       78     Lynis found 1 or more warnings or configurations errors

0x04 查看日志

grep Warning /var/log/lynis.log

grep Suggestingon /var/log/lynis.log

0x05 扩展阅读

1. lynis官方帮助文档
https://cisofy.com/documentation/lynis/get-started/
2. lynis官方介绍资料
https://cisofy.com
3github地址
https://github.com/CISOfy/lynis


欢迎大家分享更好的思路,热切期待^^_^^ !!!

你可能感兴趣的:(服务器安全)