Powermad icon indicating copy to clipboard operation
Powermad copied to clipboard

Remote Remove-Machine Exception bug

Open towbes opened this issue 4 years ago • 1 comments

I added a machine on a remote domain controller through a socks proxy using the command:

New-MachineAccount -MachineAccount acctname -Password $(ConvertTo-SecureString 'password' -AsPlainText -Force) -Domain remote.domain -DomainController dc.remote.domain

However when I went to remove the account using the command:

New-MachineAccount -MachineAccount acctname -Credential $DomainAdminCred -Domain remote.domain -DomainController dc.remote.domain

I got this error:

[-] Exception calling "GetCurrentDomain" with "0" argument(s): "Current security context is not associated with an Active Directory domain or forest." Exception calling "GetCurrentDomain" with "0" argument(s): "Current security context is not associated with an Active Directory domain or forest." At C:\Users\ritzbitz\Desktop\Powermad-master\Powermad.ps1:1037 char:13

  •         $current_domain = [System.DirectoryServices.ActiveDirecto ...
    
  •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
    • FullyQualifiedErrorId : ActiveDirectoryOperationException

I believe this is due to the 'or' in the catch statement here:

if(!$DomainController -or !$Domain -or !$Zone)
{

    try
    {
        $current_domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
    }
    catch
    {
        Write-Output "[-] $($_.Exception.Message)"
        throw
    }

}

When I removed the check for or !$Zone and reloaded the Powermad module, the request completed successfully and removed the machine

towbes avatar Aug 07 '20 01:08 towbes

Fixed with PR #12

0xe7 avatar Jan 11 '23 14:01 0xe7