使用 Linux 安全工具进行渗透测试

使用 Kali Linux 和其他开源工具来发现您系统中的安全漏洞和弱点。
138 位读者喜欢这篇文章。
How to find files in Linux

Lewis Cowles,CC BY-SA 4.0

大型消费公司被广泛宣传的违规行为突显了系统安全管理的关键重要性。 幸运的是,有许多不同的应用程序可以帮助保护计算机系统。 其中之一是 Kali,这是一个为安全和渗透测试开发的 Linux 发行版。 本文演示了如何使用 Kali Linux 来调查您的系统以查找弱点。

Kali 安装了许多工具,所有这些工具都是开源的,默认安装使事情变得更容易。

本教程中我将使用的系统是

  1. kali.usersys.redhat.com:这是我将启动扫描和攻击的系统。 它具有 30GB 内存和六个虚拟化 CPU (vCPU)。
  2. vulnerable.usersys.redhat.com:这是一个 Red Hat Enterprise Linux 8 系统,将作为目标。 它具有 16GB 内存和六个 vCPU。 这是一个相对较新的系统,但某些软件包可能已过时。
  3. 该系统还包括 httpd-2.4.37-30.module+el8.3.0+7001+0766b9e7.x86_64mariadb-server-10.3.27-3.module+el8.3.0+8972+5e3224e9.x86_64tigervnc-server-1.9.0-15.el8_1.x86_64vsftpd-3.0.3-32.el8.x86_64 和 WordPress 版本 5.6.1。

我包括了上面的硬件规格,因为其中一些任务非常苛刻,特别是对于目标系统的 CPU 在运行 WordPress 安全扫描器 (WPScan) 时。

调查您的系统

我从对目标系统进行基本的 Nmap 扫描开始进行调查。(您可以通过阅读使用 Nmap 结果来帮助加强 Linux 系统来深入了解 Nmap。)Nmap 扫描是一种快速了解从启动 Nmap 扫描的系统可以查看哪些端口和服务的方法。

此默认扫描显示有几个可能有趣的开放端口。 实际上,任何开放端口都可能很有趣,因为它可能是攻击者入侵您网络的一种方式。 在此示例中,端口 21、22、80 和 443 很高兴扫描,因为它们是常用服务。 在这个早期阶段,我只是在进行侦察工作,并试图获得尽可能多的关于目标系统的信息。

我想使用 Nmap 调查端口 80,所以我使用 -p 80 参数来查看端口 80,并使用 -A 来获取操作系统和应用程序版本等信息。

此输出中的一些关键行是

PORT   STATE SERVICE VERSION
80/tcp open  http	Apache httpd 2.4.37 ((Red Hat Enterprise Linux))
|_http-generator: WordPress 5.6.1

既然我知道这是一个 WordPress 服务器,我可以使用 WPScan 来获取有关潜在弱点的信息。 一个好的调查是尝试查找一些用户名。 使用 --enumerate u 告诉 WPScan 在 WordPress 实例中查找用户。 例如

┌──(root?kali)-[~]
└─# wpscan --url vulnerable.usersys.redhat.com --enumerate u
_______________________________________________________________
     	__      	_______   _____
     	\ \    	/ /  __ \ / ____|
      	\ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
       	\ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
        	\  /\  /  | | 	____) | (__| (_| | | | |
         	\/  \/   |_|	|_____/ \___|\__,_|_| |_|

     	WordPress Security Scanner by the WPScan Team
                     	Version 3.8.10
   	Sponsored by Automattic - https://automattic.com/
   	@_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________

[+] URL: http://vulnerable.usersys.redhat.com/ [10.19.47.242]
[+] Started: Tue Feb 16 21:38:49 2021

Interesting Finding(s):
...
[i] User(s) Identified:

[+] admin
 | Found By: Author Posts - Display Name (Passive Detection)
 | Confirmed By:
 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 |  Login Error Messages (Aggressive Detection)

[+] pgervase
 | Found By: Author Posts - Display Name (Passive Detection)
 | Confirmed By:
 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 |  Login Error Messages (Aggressive Detection)

这显示有两个用户:adminpgervase。 我将尝试使用密码字典来猜测 admin 的密码,密码字典是一个包含大量可能密码的文本文件。 我使用的字典是 37G,有 3,543,076,137 行。

就像您可以选择多种文本编辑器、Web 浏览器和其他应用程序一样,也有多种工具可用于启动密码攻击。 以下是使用 Nmap 和 WPScan 的两个示例命令

# nmap -sV --script http-wordpress-brute --script-args userdb=users.txt,passdb=/path/to/passworddb,threads=6 vulnerable.usersys.redhat.com
# wpscan --url vulnerable.usersys.redhat.com --passwords /path/to/passworddb --usernames admin --max-threads 50 | tee nmap.txt

这个 Nmap 脚本是我可以使用的众多脚本之一,而使用 WPScan 扫描 URL 只是此工具可以执行的众多任务之一。 您可以决定您更喜欢使用哪一个

此 WPScan 示例在文件末尾显示密码

┌──(root?kali)-[~]
└─# wpscan --url vulnerable.usersys.redhat.com --passwords passwords.txt --usernames admin
_______________________________________________________________
     	__      	_______   _____
     	\ \    	/ /  __ \ / ____|
      	\ \  /\  / /| |__) | (___   ___  __ _ _ __ ®
       	\ \/  \/ / |  ___/ \___ \ / __|/ _` | '_ \
        	\  /\  /  | | 	____) | (__| (_| | | | |
         	\/  \/   |_|	|_____/ \___|\__,_|_| |_|

     	WordPress Security Scanner by the WPScan Team
                     	Version 3.8.10
   	Sponsored by Automattic - https://automattic.com/
   	@_WPScan_, @ethicalhack3r, @erwan_lr, @firefart
_______________________________________________________________

[+] URL: http://vulnerable.usersys.redhat.com/ [10.19.47.242]
[+] Started: Thu Feb 18 20:32:13 2021

Interesting Finding(s):

…..

[+] Performing password attack on Wp Login against 1 user/s
Trying admin / redhat Time: 00:01:57 <==================================================================================================================> (3231 / 3231) 100.00% Time: 00:01:57
Trying admin / redhat Time: 00:01:57 <=========================================================                                                      	> (3231 / 6462) 50.00%  ETA: ??:??:??
[SUCCESS] - admin / redhat                                                                                                                                                               	 

[!] Valid Combinations Found:
 | Username: admin, Password: redhat

[!] No WPVulnDB API Token given, as a result vulnerability data has not been output.
[!] You can get a free API token with 50 daily requests by registering at https://wpscan.com/register

[+] Finished: Thu Feb 18 20:34:15 2021
[+] Requests Done: 3255
[+] Cached Requests: 34
[+] Data Sent: 1.066 MB
[+] Data Received: 24.513 MB
[+] Memory used: 264.023 MB
[+] Elapsed time: 00:02:02

末尾附近的“找到的有效组合”部分包含管理员用户名和密码。 仅用了两分钟就完成了 3,231 行。

我还有另一个字典文件,其中包含 3,238,659,984 个唯一条目,这将花费更长的时间并留下更多的证据。

使用 Nmap 产生结果的速度更快

┌──(root?kali)-[~]
└─# nmap -sV --script http-wordpress-brute --script-args userdb=users.txt,passdb=password.txt,threads=6 vulnerable.usersys.redhat.com
Starting Nmap 7.91 ( https://nmap.org ) at 2021-02-18 20:48 EST
Nmap scan report for vulnerable.usersys.redhat.com (10.19.47.242)
Host is up (0.00015s latency).
Not shown: 995 closed ports
PORT 	STATE SERVICE VERSION
21/tcp   open  ftp 	vsftpd 3.0.3
22/tcp   open  ssh 	OpenSSH 8.0 (protocol 2.0)
80/tcp   open  http	Apache httpd 2.4.37 ((Red Hat Enterprise Linux))
|_http-server-header: Apache/2.4.37 (Red Hat Enterprise Linux)
| http-wordpress-brute:
|   Accounts:
| 	admin:redhat - Valid credentials              <<<<<<<
| 	pgervase:redhat - Valid credentials         <<<<<<< 
|_  Statistics: Performed 6 guesses in 1 seconds, average tps: 6.0
111/tcp  open  rpcbind 2-4 (RPC #100000)
| rpcinfo:
|   program version	port/proto  service
|   100000  2,3,4    	111/tcp   rpcbind
|   100000  2,3,4    	111/udp   rpcbind
|   100000  3,4      	111/tcp6  rpcbind
|_  100000  3,4      	111/udp6  rpcbind
3306/tcp open  mysql   MySQL 5.5.5-10.3.27-MariaDB
MAC Address: 52:54:00:8C:A1:C0 (QEMU virtual NIC)
Service Info: OS: Unix

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 7.68 seconds

但是,像这样的扫描可能会在目标系统上留下大量的 HTTPD 日志消息

10.19.47.170 - - [18/Feb/2021:20:14:01 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"
10.19.47.170 - - [18/Feb/2021:20:14:00 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"
10.19.47.170 - - [18/Feb/2021:20:14:00 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"
10.19.47.170 - - [18/Feb/2021:20:14:00 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"
10.19.47.170 - - [18/Feb/2021:20:14:00 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"
10.19.47.170 - - [18/Feb/2021:20:14:00 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"
10.19.47.170 - - [18/Feb/2021:20:14:02 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"
10.19.47.170 - - [18/Feb/2021:20:14:02 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"
10.19.47.170 - - [18/Feb/2021:20:14:02 -0500] "POST /wp-login.php HTTP/1.1" 200 7575 "http://vulnerable.usersys.redhat.com/" "WPScan v3.8.10 (https://wpscan.org/)"

为了获取有关我的初始 Nmap 扫描中发现的 HTTPS 服务器的信息,我使用了 sslscan 命令

┌──(root?kali)-[~]
└─# sslscan vulnerable.usersys.redhat.com
Version: 2.0.6-static
OpenSSL 1.1.1i-dev  xx XXX xxxx

Connected to 10.19.47.242

Testing SSL server vulnerable.usersys.redhat.com on port 443 using SNI name vulnerable.usersys.redhat.com

  SSL/TLS Protocols:
SSLv2 	disabled
SSLv3 	disabled
TLSv1.0   disabled
TLSv1.1   disabled
TLSv1.2   enabled
TLSv1.3   enabled
<snip>

这显示了有关已启用的 SSL 协议的信息,以及输出中更下方有关 Heartbleed 漏洞的信息

  Heartbleed:
TLSv1.3 not vulnerable to heartbleed
TLSv1.2 not vulnerable to heartbleed

预防或减轻攻击者的技巧

有很多方法可以保护您的系统免受众多攻击者的侵害。 几个要点是

  • 了解您的系统: 这包括了解哪些端口是开放的,哪些端口应该是开放的,谁应该能够看到这些开放端口,以及这些服务上的预期流量是多少。 Nmap 是了解网络上系统的好工具。
  • 使用当前的最佳实践: 今天被认为是最佳实践的,将来可能不再是最佳实践。 作为管理员,及时了解信息安全领域的趋势非常重要。
  • 了解如何使用您的产品: 例如,与其让攻击者不断攻击您的 WordPress 系统,不如阻止他们的 IP 地址并限制他们在被阻止之前可以尝试登录的次数。 在现实世界中,阻止 IP 地址可能没有那么有用,因为攻击者很可能使用受感染的系统来发起攻击。 但是,这是一个易于启用的设置,可以阻止一些攻击。
  • 维护和验证良好的备份: 如果攻击者破坏了您的一个或多个系统,能够从已知的良好和干净的备份中重建可以节省大量时间和金钱。
  • 检查您的日志: 如上面的示例所示,扫描和渗透命令可能会留下大量日志,表明攻击者正在 targeting 系统。 如果您注意到它们,您可以采取先发制人的行动来降低风险。
  • 更新您的系统、应用程序和任何额外的模块: 正如 NIST 特别出版物 800-40r3 解释的那样,“补丁通常是缓解软件缺陷漏洞最有效的方法,并且通常是唯一完全有效的解决方案。”
  • 使用您的供应商提供的工具: 供应商有不同的工具来帮助您维护他们的系统,因此请确保您充分利用它们。 例如,Red Hat Enterprise Linux 订阅中包含的 Red Hat Insights 可以帮助调整您的系统并提醒您注意潜在的安全威胁。

了解更多

对安全工具以及如何使用它们的介绍只是冰山一角。 要深入了解,您可能需要研究以下资源

接下来阅读什么
User profile image.
我目前在红帽担任解决方案架构师。 我在这里工作了 14 年,多年来一直在调动,在担任当前职位之前曾在前线支持和咨询部门工作。 在我的空闲时间,我喜欢与家人共度时光、锻炼和木工。

评论已关闭。

Creative Commons License本作品根据 Creative Commons Attribution-Share Alike 4.0 International License 获得许可。
© . All rights reserved.