利用lynis如何进行linux漏洞扫描详解

前言

lynis 是一款运行在 Unix/Linux 平台上的基于主机的、开源的安全审计软件。Lynis是针对Unix/Linux的安全检查工具,可以发现潜在的安全威胁。这个工具覆盖可疑文件监测、漏洞、恶意程序扫描、配置错误等。下面一起来看看使用lynis进行linux漏洞扫描的相关内容吧

安装lynis

在 archlinux 上可以直接通过 pacman 来安装

sudo pacman -S lynis --noconfirm
resolving dependencies...
looking for conflicting packages...

Packages (1) lynis-2.6.4-1

Total Installed Size: 1.35 MiB
Net Upgrade Size:  0.00 MiB

:: Proceed with installation? [Y/n]
(0/1) checking keys in keyring      [----------------------] 0%
(1/1) checking keys in keyring      [######################] 100%
(0/1) checking package integrity     [----------------------] 0%
(1/1) checking package integrity     [######################] 100%
(0/1) loading package files      [----------------------] 0%
(1/1) loading package files      [######################] 100%
(0/1) checking for file conflicts     [----------------------] 0%
(1/1) checking for file conflicts     [######################] 100%
(0/1) checking available disk space    [----------------------] 0%
(1/1) checking available disk space    [######################] 100%
:: Processing package changes...
(1/1) reinstalling lynis       [----------------------] 0%
(1/1) reinstalling lynis       [######################] 100%
:: Running post-transaction hooks...
(1/2) Reloading system manager configuration...
(2/2) Arming ConditionNeedsUpdate...

使用lynis进行主机扫描

首先让我们不带任何参数运行 lynis, 这会列出 lynis 支持的那些参数

[lujun9972@T520 linux和它的小伙伴]$ lynis

[ Lynis 2.6.4 ]

################################################################################
 Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
 welcome to redistribute it under the terms of the GNU General Public License.
 See the LICENSE file for details about using this software.

 2007-2018, CISOfy - https://cisofy.com/lynis/
 Enterprise support available (compliance, plugins, interface and tools)
################################################################################

[+] Initializing program
------------------------------------

 Usage: lynis command [options]

 Command:

 audit
  audit system     : Perform local security scan
  audit system remote <host> : Remote security scan
  audit dockerfile <file>  : Analyze Dockerfile

 show
  show       : Show all commands
  show version     : Show Lynis version
  show help      : Show help

 update
  update info     : Show update details

 Options:

 --no-log       : Don't create a log file
 --pentest       : Non-privileged scan (useful for pentest)
 --profile <profile>    : Scan the system with the given profile file
 --quick (-Q)      : Quick mode, don't wait for user input

 Layout options
 --no-colors      : Don't use colors in output
 --quiet (-q)      : No output
 --reverse-colors     : Optimize color display for light backgrounds

 Misc options
 --debug       : Debug logging to screen
 --view-manpage (--man)   : View man page
 --verbose       : Show more details on screen
 --version (-V)     : Display version number and quit

 Enterprise options
 --plugindir <path>    : Define path of available plugins
 --upload       : Upload data to central node

 More options available. Run '/usr/bin/lynis show options', or use the man page.

 No command provided. Exiting..

从上面可以看出,使用 lynis 进行主机扫描很简单,只需要带上参数 audit system 即可。 Lynis在审计的过程中,会进行多种类似的测试,在审计过程中会将各种测试结果、调试信息、和对系统的加固建议都被写到 stdin 。 我们可以执行下面命令来跳过检查过程,直接截取最后的扫描建议来看。

sudo lynis audit system |sed '1,/Results/d'

lynis将扫描的内容分成几大类,可以通过 show groups 参数来获取类别

lynis show groups

accounting
authentication
banners
boot_services
containers
crypto
databases
dns
file_integrity
file_permissions
filesystems
firewalls
hardening
homedirs
insecure_services
kernel
kernel_hardening
ldap
logging
mac_frameworks
mail_messaging
malware
memory_processes
nameservices
networking
php
ports_packages
printers_spools
scheduling
shells
snmp
squid
ssh
storage
storage_nfs
system_integrity
time
tooling
usb
virtualization
webservers

若指向扫描某几类的内容,则可以通过 –tests-from-group 参数来指定。

比如我只想扫描 shells 和 networking 方面的内容,则可以执行

sudo lynis --tests-from-group "shells networking" --no-colors
[ Lynis 2.6.4 ]

################################################################################
 Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
 welcome to redistribute it under the terms of the GNU General Public License.
 See the LICENSE file for details about using this software.

 2007-2018, CISOfy - https://cisofy.com/lynis/
 Enterprise support available (compliance, plugins, interface and tools)
################################################################################

[+] Initializing program
------------------------------------
[2C- Detecting OS... [41C [ DONE ]
[2C- Checking profiles...[37C [ DONE ]
[2C- Detecting language and localization[22C [ zh ]
[4CNotice: no language file found for 'zh' (tried: /usr/share/lynis/db/languages/zh)[0C

 ---------------------------------------------------
 Program version:   2.6.4
 Operating system:   Linux
 Operating system name:  Arch Linux
 Operating system version: Rolling release
 Kernel version:   4.16.13
 Hardware platform:   x86_64
 Hostname:     T520
 ---------------------------------------------------
 Profiles:     /etc/lynis/default.prf
 Log file:     /var/log/lynis.log
 Report file:    /var/log/lynis-report.dat
 Report version:   1.0
 Plugin directory:   /usr/share/lynis/plugins
 ---------------------------------------------------
 Auditor:     [Not Specified]
 Language:     zh
 Test category:    all
 Test group:    shells networking
 ---------------------------------------------------
[2C- Program update status... [32C [ NO UPDATE ]

[+] System Tools
------------------------------------
[2C- Scanning available tools...[30C
[2C- Checking system binaries...[30C

[+] Plugins (phase 1)
------------------------------------
[0CNote: plugins have more extensive tests and may take several minutes to complete[0C
[0C [0C
[2C- Plugins enabled[42C [ NONE ]

[+] Shells
------------------------------------
[2C- Checking shells from /etc/shells[25C
[4CResult: found 5 shells (valid shells: 5).[16C
[4C- Session timeout settings/tools[25C [ NONE ]
[2C- Checking default umask values[28C
[4C- Checking default umask in /etc/bash.bashrc[13C [ NONE ]
[4C- Checking default umask in /etc/profile[17C [ WEAK ]

[+] Networking
------------------------------------
[2C- Checking IPv6 configuration[30C [ ENABLED ]
[6CConfiguration method[35C [ AUTO ]
[6CIPv6 only[46C [ NO ]
[2C- Checking configured nameservers[26C
[4C- Testing nameservers[36C
[6CNameserver: 202.96.134.33[30C [ SKIPPED ]
[6CNameserver: 202.96.128.86[30C [ SKIPPED ]
[4C- Minimal of 2 responsive nameservers[20C [ SKIPPED ]
[2C- Getting listening ports (TCP/UDP)[24C [ DONE ]
[6C* Found 11 ports[39C
[2C- Checking status DHCP client[30C [ RUNNING ]
[2C- Checking for ARP monitoring software[21C [ NOT FOUND ]

[+] Custom Tests
------------------------------------
[2C- Running custom tests... [33C [ NONE ]

[+] Plugins (phase 2)
------------------------------------

================================================================================

 -[ Lynis 2.6.4 Results ]-

 Great, no warnings

 Suggestions (1):
 ----------------------------
 * Consider running ARP monitoring software (arpwatch,arpon) [NETW-3032] 

https://cisofy.com/controls/NETW-3032/

 Follow-up:
 ----------------------------
 - Show details of a test (lynis show details TEST-ID)
 - Check the logfile for all details (less /var/log/lynis.log)
 - Read security controls texts (https://cisofy.com)
 - Use --upload to upload data to central system (Lynis Enterprise users)

================================================================================

 Lynis security scan details:

 Hardening index : 33 [######    ]
 Tests performed : 13
 Plugins enabled : 0

 Components:
 - Firewall    [X]
 - Malware scanner  [X]

 Lynis Modules:
 - Compliance Status  [?]
 - Security Audit   [V]
 - Vulnerability Scan  [V]

 Files:
 - Test and debug information  : /var/log/lynis.log
 - Report data      : /var/log/lynis-report.dat

================================================================================

 Lynis 2.6.4

 Auditing, system hardening, and compliance for UNIX-based systems
 (Linux, macOS, BSD, and others)

 2007-2018, CISOfy - https://cisofy.com/lynis/
 Enterprise support available (compliance, plugins, interface and tools)

================================================================================

 [TIP]: Enhance Lynis audits by adding your settings to custom.prf (see /etc/lynis/default.prf for all settings)

查看详细说明

在查看审计结果时,你可以通过 show details 参数来获取关于某条警告/建议的详细说明。其对应的命令形式为:

lynis show details ${test_id}

比如,上面图中有一个建议

* Consider running ARP monitoring software (arpwatch,arpon) [NETW-3032]

我们可以运行命令:

sudo lynis show details NETW-3032
2018-06-08 18:18:01 Performing test ID NETW-3032 (Checking for ARP monitoring software)
2018-06-08 18:18:01 IsRunning: process 'arpwatch' not found
2018-06-08 18:18:01 IsRunning: process 'arpon' not found
2018-06-08 18:18:01 Suggestion: Consider running ARP monitoring software (arpwatch,arpon) [test:NETW-3032] [details:-] [solution:-]
2018-06-08 18:18:01 Checking permissions of /usr/share/lynis/include/tests_printers_spools
2018-06-08 18:18:01 File permissions are OK
2018-06-08 18:18:01 ===---------------------------------------------------------------===

查看日志文件

lynis在审计完成后会将详细的信息记录在 /var/log/lynis.log 中.

sudo tail /var/log/lynis.log
2018-06-08 17:59:46 ================================================================================
2018-06-08 17:59:46 Lynis 2.6.4
2018-06-08 17:59:46 2007-2018, CISOfy - https://cisofy.com/lynis/
2018-06-08 17:59:46 Enterprise support available (compliance, plugins, interface and tools)
2018-06-08 17:59:46 Program ended successfully
2018-06-08 17:59:46 ================================================================================
2018-06-08 17:59:46 PID file removed (/var/run/lynis.pid)
2018-06-08 17:59:46 Temporary files: /tmp/lynis.sGxCR0hSPz
2018-06-08 17:59:46 Action: removing temporary file /tmp/lynis.sGxCR0hSPz
2018-06-08 17:59:46 Lynis ended successfully.

同时将报告数据被保存到 /var/log/lynis-report.dat 中.

sudo tail /var/log/lynis-report.dat

另外需要注意的是,每次审计都会覆盖原日志文件.

检查更新

审计软件需要随时进行更新从而得到最新的建议和信息,我们可以使用 update info 参数来检查更新:

lynis update info --no-colors
== [1;37mLynis[0m ==

 Version   : 2.6.4
 Status    : [1;32mUp-to-date[0m
 Release date  : 2018-05-02
 Update location : https://cisofy.com/lynis/

2007-2018, CISOfy - https://cisofy.com/lynis/

自定义lynis安全审计策略

lynis的配置信息以 .prf 文件的格式保存在 /etc/lynis 目录中。 其中,默认lynis自带一个名为 default.prf 的默认配置文件。

不过我们无需直接修改这个默认的配置文件,只需要新增一个 custom.prf 文件将自定义的信息加入其中就可以了。

关于配置文件中各配置项的意义,在 default.prf 中都有相应的注释说明,这里就不详述了。

想了解lynis的更多信息,可以访问它的官网.

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对我们的支持。

(0)

相关推荐

  • Linux内核漏洞浅析

    与Windows相比,Linux被认为具有更好的安全性和其他扩展性能.这些特性使得Linux在操作系统领域异军突起,得到越来越多的重视.随着Linux应用量的增加,其安全性也逐渐受到了公众甚或黑客的关注.那么,Linux是否真的如其支持厂商们所宣称的那样安全呢?本期我们请到了启明星辰信息技术有限公司积极防御实验室工程师赵伟,对Linux进行专业的漏洞技术分析. Linux内核精短.稳定性高.可扩展性好.硬件需求低.免费.网络功能丰富.适用于多种cpu等特性,使之在操作系统领域异军突起.其独特的魅

  • Linux用户要注意修复漏洞

    安全专家正在敦促Linux服务器和工作站的用户立即采取措施修补在Linux内核中发现的两个缺陷.这些缺陷可以影响到目前所有版本的Linux,而且还可能导致黑客控制Linux系统. 上述缺陷均与内核的存储管理技术有关,它们是由一家波兰安全公司iSEC发现的.领军的Linux销售商红帽.SuSE以及Debian以及其他销售商已经发布了旨在弥补上述缺陷的补丁. 此外,上述销售商还发布了针对较小缺陷的补丁,其中包括一个影响到支持视频卡的内核模式的缺陷以及一个影响到USB驱动器的缺陷. 红帽公司的安全因应

  • 利用lynis如何进行linux漏洞扫描详解

    前言 lynis 是一款运行在 Unix/Linux 平台上的基于主机的.开源的安全审计软件.Lynis是针对Unix/Linux的安全检查工具,可以发现潜在的安全威胁.这个工具覆盖可疑文件监测.漏洞.恶意程序扫描.配置错误等.下面一起来看看使用lynis进行linux漏洞扫描的相关内容吧 安装lynis 在 archlinux 上可以直接通过 pacman 来安装 sudo pacman -S lynis --noconfirm resolving dependencies... lookin

  • Linux中利用sudo进行赋权的方法详解

    前言 学习怎么在保护 root 密码的安全性的同时,为可信用户赋予所管理的网络功能和特定服务的权限. 我最近写了一个简短的 Bash 程序来将 MP3 文件从一台网络主机的 USB 盘中拷贝到另一台网络主机上去.拷贝出来的文件存放在一台志愿者组织所属服务器的特定目录下,在那里,这些文件可以被下载和播放. 我的程序还会做些其他事情,比如为了自动在网页上根据日期排序,在拷贝文件之前会先对这些文件重命名.在验证拷贝完成后,还会删掉 USB 盘中的所有文件.这个小程序还有一些其他选项,比如 -h 会显示

  • Linux中多线程详解及简单实例

    Linux中多线程详解及简单实例 1.概念 进程:运行中的程序. 线程:一个程序中的多个执行路径.更准确的定义是:线程是一个进程内部的一个控制序列. 2.为什么要有线程? 用fork调用进程代价太高,需要让一个进程同时做多件事情,线程就非常有用. 3.线程的优点和缺点. 优点: (1)有时,让程序看起来是在同时做两件事是非常有用的. 比如在编辑文档时,还能统计文档里的单词个数. (2)一个混杂着输入.计算.输出的程序,利用线程可以将这3个部 分分成3个线程来执行,从而改变程序执行的性能. (3)

  • linux mkdir命令详解

    mkdir命令用来创建目录.该命令创建由dirname命名的目录.如果在目录名的前面没有加任何路径名,则在当前目录下创建由dirname指定的目录:如果给出了一个已经存在的路径,将会在该目录下创建一个指定的目录.在创建目录时,应保证新建的目录与它所在目录下的文件没有重名. 注意:在创建文件时,不要把所有的文件都存放在主目录中,可以创建子目录,通过它们来更有效地组织文件.最好采用前后一致的命名方式来区分文件和目录.例如,目录名可以以大写字母开头,这样,在目录列表中目录名就出现在前面. 在一个子目录

  • Linux之时钟中断详解

    在Linux的0号中断是一个定时器中断.在固定的时间间隔都发生一次中断,也是说每秒发生该中断的频率都是固定的.该频率是常量HZ,该值一般是在100 ~ 1000之间.该中断的作用是为了定时更新系统日期和时间,使系统时间不断地得到跳转.另外该中断的中断处理函数除了更新系统时间外,还需要更新本地CPU统计数.指的是调用scheduler_tick递减进程的时间片,若进程的时间片递减到0,进程则被调度出去而放弃CPU使用权. 时钟中断的产生 Linux的OS时钟的物理产生原因是可编程定时/计数器产生的

  • Linux curl命令详解

    在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具,可以说是一款很强大的http命令行工具.它支持文件的上传和下载,是综合传输工具,但按传统,习惯称url为下载工具. 语法: # curl [option] [url] 常见参数: -A/--user-agent <string> 设置用户代理发送给服务器 -b/--cookie <name=string/file> cookie字符串或文件读取位置 -c/--cookie-jar <file> 操作

  • linux top命令详解

    top 命令主要用于查看进程的相关信息,同时它也会提供系统平均负载,cpu 信息和内存信息.下面的截图展示了 top 命令默认提供的信息: 系统平均负载 top 命令输出中的第一行是系统的平均负载,这和 uptime 命令的输出是一样的: 13:05:49 表示系统当前时间. up 7 days 表示系统最后一次启动后总的运行时间. 1 user 表示当前系统中只有一个登录用户. load average: 0.01, 0.04, 0.00 表示系统的平均负载,最后的三个数字分别表示最后一分钟的

  • linux epoll机制详解

    在linux 没有实现epoll事件驱动机制之前,我们一般选择用select或者poll等IO多路复用的方法来实现并发服务程序.在linux新的内核中,有了一种替换它的机制,就是epoll. select()和poll() IO多路复用模型 select的缺点: 1.单个进程能够监视的文件描述符的数量存在最大限制,通常是1024,当然可以更改数量,但由于select采用轮询的方式扫描文件描述符,文件描述符数量越多,性能越差:(在linux内核头文件中,有这样的定义:#define __FD_SE

  • Web网络安全分析XSS漏洞原理详解

    目录 XSS基础 XSS漏洞介绍 XSS漏洞原理 反射型XSS 存储型XSS DOM型XSS XSS基础 XSS漏洞介绍 跨站脚本(Cross-Site Scripting,简称为XSS或跨站脚本或跨站脚本攻击)是一种针对网站应用程序的安全漏洞攻击技术,是代码注入的一种.它允许恶意用户将代码注入网页,其他用户在浏览网页时就会收到影响.恶意用户利用XSS代码攻击成功后,可能得到很高的权限(如执行一些操作).私密网页内容.会话和cookie等各种内容. XSS攻击可以分为三种:反射型.存储型和DOM

  • SpringCloud项目的log4j2漏洞解决方案详解流程

    步骤如下: <properties> <log4j2.version>2.15.0</log4j2.version> </properties> 下面为上边对应版本号的具体依赖 <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.15.

随机推荐