AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • Início
  • system&network
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • Início
  • system&network
    • Recentes
    • Highest score
    • tags
  • Ubuntu
    • Recentes
    • Highest score
    • tags
  • Unix
    • Recentes
    • tags
  • DBA
    • Recentes
    • tags
  • Computer
    • Recentes
    • tags
  • Coding
    • Recentes
    • tags
Início / server / Perguntas / 930582
Accepted
mythofechelon
mythofechelon
Asked: 2018-09-13 06:08:27 +0800 CST2018-09-13 06:08:27 +0800 CST 2018-09-13 06:08:27 +0800 CST

Verifique se a conta de usuário tem a senha definida

  • 772

No Windows autônomo (não associado ao domínio), é possível usar o PowerShell para verificar se uma determinada conta de usuário local tem uma senha definida/uma senha em branco?

De acordo com https://gallery.technet.microsoft.com/scriptcenter/How-to-check-if-a-local-870ab031 e https://blogs.technet.microsoft.com/heyscriptingguy/2005/10/06/ how-can-i-verify-that-none-of-my-local-user-accounts-have-a-blank-password/ , isso é possível com o VBScript, mas apenas porque ChangePasswordexige que você forneça a senha original enquanto os comandos do PowerShell não parece.

Eu li em algum lugar que você pode verificar uma senha executando um processo como usuário com suas credenciais e anotando o resultado, mas, aparentemente, você não pode usar uma string vazia como credenciais.

windows
  • 2 2 respostas
  • 3355 Views

2 respostas

  • Voted
  1. Best Answer
    mythofechelon
    2018-09-13T07:56:53+08:002018-09-13T07:56:53+08:00

    Consegui isso com os seguintes comandos/scripts do PowerShell:

    Write-Output "It's only possible to detect whether user accounts have blank passwords if the minimum password length is 0.";
    
    $PasswordMinimumLength = 0;
    Write-Output "Implementing new minimum password length of $PasswordMinimumLength...";
    
    $Secedit_CFGFile_Path = [System.IO.Path]::GetTempFileName();
    $Secedit_Path = "$env:SystemRoot\system32\secedit.exe";
    $Secedit_Arguments_Export = "/export /cfg $Secedit_CFGFile_Path /quiet";
    $Secedit_Arguments_Import = "/configure /db $env:SystemRoot\Security\local.sdb /cfg $Secedit_CFGFile_Path /areas SecurityPolicy";
    
    Start-Process -FilePath $Secedit_Path -ArgumentList $Secedit_Arguments_Export -Wait;
    
    $SecurityPolicy_Old = Get-Content $Secedit_CFGFile_Path;
    
    $SecurityPolicy_New = $SecurityPolicy_Old -Replace "MinimumPasswordLength = \d+", "MinimumPasswordLength = $PasswordMinimumLength";
    
    Set-Content -Path $Secedit_CFGFile_Path -Value $SecurityPolicy_New;
    
    Try {
        Start-Process -FilePath $Secedit_Path -ArgumentList $Secedit_Arguments_Import -Wait;
    } Catch {
        Write-Output "...FAILED.";
        Break;
    }
    If ($?){
        Write-Output "...Success.";
    }
    Write-Output "";
    Write-Output "----------------------------------------------------------------";
    Write-Output "";
    
    Write-Output "Searching for user accounts with blank passwords...";
    
    $BlankPasswordsFoundWording_PreUsername = "Found user account";
    $BlankPasswordsFoundWording_PostUsername = "with a blank password.";
    $NoBlankPasswordsFoundWording = "No user accounts with blank passwords found.";
    
    $VBS_IdentifyBlankPasswords_Commands = @"
    On Error Resume Next
    
    Dim strComputerName
    Dim strPassword
    
    strComputerName = WScript.CreateObject("WScript.Network").ComputerName
    strPassword = ""
    
    Set LocalAccounts = GetObject("WinNT://" & strComputerName)
    LocalAccounts.Filter = Array("user")
    
    Dim Flag
    Flag = 0 
    
    For Each objUser In LocalAccounts
        objUser.ChangePassword strPassword, strPassword
        If Err = 0 or Err = -2147023569 Then
            Flag = 1
            Wscript.Echo "$BlankPasswordsFoundWording_PreUsername """ & objUser.Name & """ $BlankPasswordsFoundWording_PostUsername"
        End If
        Err.Clear
    Next
    
    If Flag = 0 Then
        WScript.Echo "$NoBlankPasswordsFoundWording"
    End If
    "@
    # The above here-string terminator cannot be indented.;
    
    # cscript won't accept / process a file with extension ".tmp" so ".vbs" needs to be appended.;
    $VBS_IdentifyBlankPasswords_File_Path_TMP = [System.IO.Path]::GetTempFileName();
    $VBS_IdentifyBlankPasswords_File_Directory = (Get-ChildItem $VBS_IdentifyBlankPasswords_File_Path_TMP).DirectoryName;
    $VBS_IdentifyBlankPasswords_File_Name_TMP = (Get-ChildItem $VBS_IdentifyBlankPasswords_File_Path_TMP).Name;
    $VBS_IdentifyBlankPasswords_File_Name_VBS = $VBS_IdentifyBlankPasswords_File_Name_TMP + ".vbs";
    $VBS_IdentifyBlankPasswords_File_Path_VBS = "$VBS_IdentifyBlankPasswords_File_Directory\$VBS_IdentifyBlankPasswords_File_Name_VBS";
    
    Set-Content -Path $VBS_IdentifyBlankPasswords_File_Path_VBS -Value $VBS_IdentifyBlankPasswords_Commands;
    
    $VBS_IdentifyBlankPasswords_Output = & cscript /nologo $VBS_IdentifyBlankPasswords_File_Path_VBS;
    # Write-Output $VBS_IdentifyBlankPasswords_Output;
    
    $UsersWithBlankPasswords = $VBS_IdentifyBlankPasswords_Output | Select-String -Pattern "$BlankPasswordsFoundWording_PreUsername";
    
    If ($UsersWithBlankPasswords -NE $Null){
        ForEach ($UserWithBlankPassword in $UsersWithBlankPasswords){
            $Username = [regex]::match($UserWithBlankPassword, '"([^"]+)"').Groups[1].Value;
    
            Write-Output "...$BlankPasswordsFoundWording_PreUsername ""$Username"" $BlankPasswordsFoundWording_PostUsername";
        }
    } ElseIf ($UsersWithBlankPasswords -Eq $Null){
        Write-Output "$NoBlankPasswordsFoundWording";
    }
    
    Write-Output "";
    Write-Output "----------------------------------------------------------------";
    Write-Output "";
    
    Write-Output "Implementing original minimum password length...";
    
    Set-Content -Path $Secedit_CFGFile_Path -Value $SecurityPolicy_Old;
    
    Try {
        Start-Process -FilePath $Secedit_Path -ArgumentList $Secedit_Arguments_Import -Wait;
    } Catch {
        Write-Output "...FAILED.";
        Break;
    }
    If ($?){
        Write-Output "...Success.";
    }
    

    insira a descrição da imagem aqui

    • 2
  2. SteepUnderstanding
    2020-11-15T05:02:47+08:002020-11-15T05:02:47+08:00

    Muita pesquisa e tentativa e erro me levaram a desenvolver isso:

    $PrincipalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext('Machine')
    
    Get-LocalUser | Where-Object Enabled -eq $true | ForEach-Object {
        $myUsername = $_.Name
        $myPasswordIsBlank = $PrincipalContext.ValidateCredentials($myUserName, $null)
        If ($myPasswordIsBlank) {
            # Do whatever you want here to output or alert the fact that you found a blank password.
        }
    }
    

    Para executar isso no meu RMM, tive que adicionar o seguinte ao início do código para evitar um erro:

    Add-Type -AssemblyName System.DirectoryServices.AccountManagement
    
    • 2

relate perguntas

Sidebar

Stats

  • Perguntas 205573
  • respostas 270741
  • best respostas 135370
  • utilizador 68524
  • Highest score
  • respostas
  • Marko Smith

    Você pode passar usuário/passar para autenticação básica HTTP em parâmetros de URL?

    • 5 respostas
  • Marko Smith

    Ping uma porta específica

    • 18 respostas
  • Marko Smith

    Verifique se a porta está aberta ou fechada em um servidor Linux?

    • 7 respostas
  • Marko Smith

    Como automatizar o login SSH com senha?

    • 10 respostas
  • Marko Smith

    Como posso dizer ao Git para Windows onde encontrar minha chave RSA privada?

    • 30 respostas
  • Marko Smith

    Qual é o nome de usuário/senha de superusuário padrão para postgres após uma nova instalação?

    • 5 respostas
  • Marko Smith

    Qual porta o SFTP usa?

    • 6 respostas
  • Marko Smith

    Linha de comando para listar usuários em um grupo do Windows Active Directory?

    • 9 respostas
  • Marko Smith

    O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL?

    • 3 respostas
  • Marko Smith

    Como determinar se uma variável bash está vazia?

    • 15 respostas
  • Martin Hope
    Davie Ping uma porta específica 2009-10-09 01:57:50 +0800 CST
  • Martin Hope
    kernel O scp pode copiar diretórios recursivamente? 2011-04-29 20:24:45 +0800 CST
  • Martin Hope
    Robert ssh retorna "Proprietário incorreto ou permissões em ~/.ssh/config" 2011-03-30 10:15:48 +0800 CST
  • Martin Hope
    Eonil Como automatizar o login SSH com senha? 2011-03-02 03:07:12 +0800 CST
  • Martin Hope
    gunwin Como lidar com um servidor comprometido? 2011-01-03 13:31:27 +0800 CST
  • Martin Hope
    Tom Feiner Como posso classificar a saída du -h por tamanho 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich O que é um arquivo Pem e como ele difere de outros formatos de arquivo de chave gerada pelo OpenSSL? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent Como determinar se uma variável bash está vazia? 2009-05-13 09:54:48 +0800 CST

Hot tag

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • Início
  • Perguntas
    • Recentes
    • Highest score
  • tag
  • help

Footer

AskOverflow.Dev

About Us

  • About Us
  • Contact Us

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve