標簽:WordPress、rbash、爆破、git提權
0x00 環(huán)境準備
下載地址:https://www.vulnhub.com/entry/dc-2,311/
flag數(shù)量:5
攻擊機:kali
攻擊機地址:192.168.1.22
靶機描述:
Much like DC-1, DC-2 is another purposely built vulnerable lab for the purpose of gaining experience in the world of penetration testing.
As with the original DC-1, it's designed with beginners in mind.
Linux skills and familiarity with the Linux command line are a must, as is some experience with basic penetration testing tools.
Just like with DC-1, there are five flags including the final flag.
And again, just like with DC-1, the flags are important for beginners, but not so important for those who have experience.
In short, the only flag that really counts, is the final flag.
For beginners, Google is your friend. Well, apart from all the privacy concerns etc etc.
I haven't explored all the ways to achieve root, as I scrapped the previous version I had been working on, and started completely fresh apart from the base OS install.
0x01 信息搜集
1.探測靶機地址
命令:arp-scan -l

靶機地址是192.168.1.23
2.探測靶機開放端口
命令:nmap -sV -p- 192.168.1.23

有個80端口,有個SSH服務,那就先看一下80上的服務。
0x02 flag1
打開瀏覽器訪問192.168.1.23,發(fā)現(xiàn)是wordpress CMS

看到了flag,打開發(fā)現(xiàn)了flag1

我看其他表哥做的時候不能直接訪問靶機的80端口,要修改host文件,但是我這個直接就能訪問了。
說一下修改kali host文件的方法吧,命令:vim /etc/hosts,按i鍵切換到插入模式,添加下圖的語句,IP地址是你的靶機地址,然后按esc鍵,輸入:wq就好了。

0x03 flag2
看一下flag1的提示
Flag 1:
Your usual wordlists probably won’t work, so instead, maybe you just need to be cewl.
More passwords is always better, but sometimes you just can’t win them all.
Log in as one to see the next flag.
If you can’t find it, log in as another.
大概意思是說要用cewl工具,登錄后會看到下一個flag。
cewl是一個密碼字典生成工具,它可以根據(jù)爬取的url來生成特定的密碼字典。

命令:cewl -w /root/cewl/dc2_passwd.txt http://dc-2/

現(xiàn)在有了密碼字典,但是還不知道用戶名,kali自帶了一個wpscan工具,它可以查詢出wordpress的用戶名。命令:wpscan --url http://dc-2/ -e u
-e u是枚舉用戶名,默認從1-10

這里枚舉出了3個用戶名,現(xiàn)在有了用戶名,有了密碼字典,只要找到登錄鏈接就可以了。先去網(wǎng)上查一下默認的登錄地址:

也可以使用dirb去掃目錄,命令:dirb http://dc-2/

找到登錄鏈接后,現(xiàn)在開始爆破,為了方便,先把剛才掃描到的3個用戶名存到一個txt文件里當做用戶名字典。

爆破使用wpscan,命令:wpscan --url http://dc-2 -U /root/cewl/dc2_user.txt -P /root/cewl/dc2_passwd.txt

在枚舉處的三個用戶名中,爆破出了2個,分別是:jerry / adipiscing和tom / parturient。
登錄jerry賬號,發(fā)現(xiàn)了flag2


提示:
Flag 2:
If you can't exploit WordPress and take a shortcut, there is another way.
Hope you found another entry point.
大概意思是不要走wordpress的捷徑,換一個切入點。
0x04 flag3
剛才掃描的時候還發(fā)現(xiàn)了SSH服務,那就嘗試用剛才爆破出的賬號登錄SSH。
jerry不能登錄,tom可以

ls查看當前目錄,發(fā)現(xiàn)了flag3.txt,cat查看,不能執(zhí)行

看了一下表哥的文章,原因是我們的shell是rbash,所以 shell 被限制了。
受限shell是LinuxShell限制一些bash shell中的功能,并且是從名字上很清楚。 該限制很好地實現(xiàn)了命令以及腳本在受限shell中運行。 它為Linux中的bash shell提供了一個額外的安全層。
我是第一次遇到,所以用表哥的方法繞過一下,先查看環(huán)境變量:echo $PATH,發(fā)現(xiàn)被寫到了/home/tom/usr/bin下面,用vi轉(zhuǎn)義受限制的shell:
vi
:set shell=/bin/bash
:shell

然后再設置一下環(huán)境變量:
export PATH=/bin:/usr/bin:$PATH
export SHELL=/bin/bash:$SHELL
這個時候就可以執(zhí)行命令了

Poor old Tom is always running after Jerry. Perhaps he should su for all the stress he causes.
翻譯成中文:可憐的老湯姆總是在追求杰瑞。也許他應該為他所造成的壓力而道歉。一臉懵逼,看一下表哥怎么做的。
0x05 flag4
原來是要切換到jerry用戶,使用su jerry進行切換,但是當我輸入密碼的時候,只輸入一個字符它就會自動回車,最后沒辦法,我只好把密碼復制到剪切板上,輸入密碼時直接粘貼上去,密碼就是上面爆破出來的密碼,終于進去了。

ls查看當前目錄,報錯了,那就cd /home/jerry/切換到jerry的目錄,ls看到了flag4.txt

Good to see that you've made it this far - but you're not home yet.
You still need to get the final flag (the only flag that really counts!!!).
No hints here - you're on your own now. :-)
Go on - git outta here!!!!
大概意思是:很高興看到你已經(jīng)走了這么遠,但你還沒有到家。您仍然需要獲得最后的標志(惟一真正有意義的標志!!)。這里沒有提示——你現(xiàn)在只能靠自己了。
0x06 flag5
看提示應該是要我們用git提權,這又到了我的知識盲區(qū)了,去網(wǎng)上查一下吧,發(fā)現(xiàn)了一個用git提權的方法。

動手嘗試一下,命令:sudo git help config,然后輸入!/bin/bash,保存退出

提權成功了,ls發(fā)現(xiàn)了flag文件

截止到現(xiàn)在5個flag就全部找到了。
由于我不會每天都登錄簡書,所以有什么私信或者評論我都不能及時回復,如果想要聯(lián)系我最好給我發(fā)郵件,郵箱:Z2djMjUxMTBAMTYzLmNvbQ==,如果發(fā)郵件請備注“簡書”