Encontre contas bloqueadas no Active Directory (uma maneira que realmente funciona!)

8

Eu pesquisei como listar contas bloqueadas e encontrei dois métodos até agora, os quais não funcionam ...

Consulta salva - (&(&(&(objectCategory=Person)(objectClass=User)(lockoutTime>=1))))

Lista um número de contas, muitas das quais não estão bloqueadas. Se eu desbloquear um que eu saiba que está bloqueado, ele ainda será retornado pela consulta.

Comando do Powershell - Search-ADAccount -LockedOut

Não faz nada.

Então, ou - estou fazendo algo errado? Ou - Existe um método que realmente funciona?

    
por MrVimes 19.07.2013 / 12:31

1 resposta

11

Eu não necessariamente confiaria em Get-ADUser -LDAPFilter "(&(objectCategory=Person)(objectClass=User)(lockoutTime>=1))" -Properties LockedOut , pois ele não está retornando resultados confiáveis para mim, mas também não consigo entrar em contato diretamente com o PDCe no momento. Para obter melhores resultados, você desejaria direcionar diretamente seu emulador de PDC, pois ele sempre tem as informações mais atualizadas sobre bloqueios de conta em todo o domínio.

Isso é o que eu estou apostando que você está testemunhando aqui é um atraso na replicação:

... account lockout is urgently replicated to the primary domain controller (PDC) emulator role owner and is then urgently replicated to the following:

• Domain controllers in the same domain that are located in the same site as the PDC emulator.

• Domain controllers in the same domain that are located in the same site as the domain controller that handled the account lockout.

• Domain controllers in the same domain that are located in sites that have been configured to allow change notification between sites (and, therefore, urgent replication) with the site that contains the PDC emulator or with the site where the account lockout was handled. These sites include any site that is included in the same site link as the site that contains the PDC emulator or in the same site link as the site that contains the domain controller that handled the account lockout.

In addition, when authentication fails at a domain controller other than the PDC emulator, the authentication is retried at the PDC emulator. For this reason, the PDC emulator locks the account before the domain controller that handled the failed-password attempt if the bad-password-attempt threshold is reached. For more information about how the PDC emulator role owner manages password changes and account lockouts, see "Managing Flexible Single-Master Operations" in this book.

Então, tente Search-ADAccount -LockedOut -Server DC-PDCE e veja se seus resultados são melhores.

Além disso, aqui está outra coisa a considerar ao criar consultas em torno do atributo lockoutTime:

This attribute value is only reset when the account is logged onto successfully. This means that this value may be non zero, yet the account is not locked out. To accurately determine if the account is locked out, you must add the Lockout-Duration to this time and compare the result to the current time, accounting for local time zones and daylight savings time.

Editar: Por meio da engenharia reversa Microsoft.ActiveDirectory.Management.dll , posso dizer a você que Search-ADAccount -LockedOut , que parece produzir resultados bastante confiáveis, executa o seguinte código:

else if ((bool) this._paramSet.LockedOut)
      {
        list.Add(ADAccountFactory<ADAccount>.AttributeTable[cmdletSessionInfo.ConnectedADServerType]["AccountLockoutTime"].InvokeToSearcherConverter(ADOPathUtil.CreateFilterClause(ADOperator.Ge, "AccountLockoutTime", (object) 1), cmdletSessionInfo));
        this.OutputFilterFunction = new ADGetCmdletBase<SearchADAccountParameterSet, ADAccountFactory<ADAccount>, ADAccount>.OutputFilterDelegate(this.FilterIsLockedOut);
      }
      if (list.Count > 0)
        this.OutputSearchResults(list.Count != 1 ? ADOPathUtil.CreateAndClause(list.ToArray()) : list[0]);
      else
        this.OutputSearchResults((IADOPathNode) null);

Portanto, parece que Search-ADAccount -LockedOut também está analisando o atributo AccountLockoutTime!

Edite um pouco mais por uma grande justiça: Richard Mueller, Dir. Serviços MVP, diz isto:

You cannot use the userAccountControl attribute to identify users that are locked out. There is a bit of userAccountControl documented for this, but it is not used.

Eu posso verificar isso assim:

PS C:\Users\ryan> $(Search-ADAccount -LockedOut).Count
11
PS C:\Users\ryan> $(Get-ADUser -LDAPFilter "(&(objectCategory=User)(userAccountControl:1.2.840.113556.1.4.803:=16))").Count
0

Por fim, gostaria de terminar em esta postagem do blog sobre o tópico , que explica por que o lockoutTime>=1 está se aproximando da melhor solução, mas isso é apenas parte da história. Você precisa filtrar ainda mais a lista para incluir apenas os usuários em que o tempo de bloqueio é maior que $ (duração do bloqueio de domínio) minutos no passado.

    
por 19.07.2013 / 15:31