46

Yeah, I can fire up a VM or remote into something and try the password...I know...but is there a tool or script that will simulate a login just enough to confirm or deny that the password is correct?

Scenario:

A server service account's password is "forgotten"...but we think we know what it is. I'd like to pass the credentials to something and have it kick back with "correct password" or "incorrect password".

I even thought about a drive mapping script with that user account and password being passed to see if it mapped the drive successfully or not but got lost in the logic of making it work correctly...something like:

-Script asks for username via msgbox -script asks for password via msgbox -script tries to map a drive to a common share that everyone has access to -script unmaps drive if successful -script returns popup msgbox stating "Correct Password" or else "Incorrect Password"

Any help is appreciated...you'd think this would be a rare occurrence not requiring a tool to support it but...well....

  • What OS? What service? – Cristian Ciupitu Sep 23 '09 at 18:58
  • @Cristian - Windows domain accounts - just verify if the password is correct or not – TheCleaner Sep 23 '09 at 21:04
77
runas /u:yourdomain\a_test_user notepad.exe

The utility will prompt for the password, if the right password has been provided, notepad will launch, if not it will produce error 1326: the username or password is incorrect

  • 1
    Clever Roberto. +1 – TheCleaner Oct 10 '14 at 1:43
  • 3
    Simple. Elegant. I like it. – Lopsided Mar 4 '15 at 22:48
  • 5
    Awesome! This solution has two important advantages over the accepted answer: 1) available on Windows XP+ out of the box, don't have to download anything, 2) related to this: as it's from MS, it doesn't require me to trust my password to some third-party tool of unknown provenance. – akavel May 19 '15 at 10:16
  • 2
    Serverfault IT admins know this, but if you're a home user finding this answer off a web search (this is the best answer by the way–uses only stuff that comes with Windows): on a home computer, the yourdomain part above is your computer's name. Find that in Control Panel > System. One of the values is literally that, "Computer Name:". E.g. if you're computer's name is "smith-laptop" and your username is "joe", you'd do runas /u:smith-laptop\joe notepad.exe – Daryn Nov 13 '15 at 7:25
  • 1
    On a successful authentication, you may just get an error like 1385: Logon failure: the user has not been granted the requested logon type at this computer. – mwfearnley Apr 27 '18 at 11:46
10

Powershell script:

#usage: Test-UserCredential -username UserNameToTest -password (Read-Host)

Function Test-UserCredential { 
    Param($username, $password) 
    Add-Type -AssemblyName System.DirectoryServices.AccountManagement 
    $ct = [System.DirectoryServices.AccountManagement.ContextType]::Machine, $env:computername 
    $opt = [System.DirectoryServices.AccountManagement.ContextOptions]::SimpleBind 
    $pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ct 
    $Result = $pc.ValidateCredentials($username, $password).ToString() 
    $Result 
} 

http://powershellcommunity.org/Forums/tabid/54/aft/8034/Default.aspx

  • new-object directoryservices.directoryentry "",$username,$password - return value, credentials work, exception, they don't work. Taken from this answer where it's wrapped into a neat function: serverfault.com/q/596602/57144 – TessellatingHeckler May 11 '17 at 0:05
5

You can also use:

net use \\computername\sharename [password] /USER:]username]

If there's a share by that name on the remote computer. Or, use C$ if the account is an admin.

1

You can write an easy vbscript function which can verify this...something like:

Function GoodPassword(strAdminUsername, strAdminPassword, strNTDomain)
    Const ADS_SECURE_AUTHENTICATION = 1

    On Error Resume Next
    Set objIADS = GetObject("WinNT:").OpenDSObject("WinNT://" & _
                        strNTDomain, strAdminUserame, _
                        strAdminPassword, _
                        ADS_SECURE_AUTHENTICATION)
    if err.number = 0 then
       GoodPassword = True
    Else
       GoodPassword = False
    End If
    On Error GoTO 0
End Function

Sources:

http://www.4guysfromrolla.com/webtech/061202-1.shtml

http://hsdn.net/category_3.html

  • Please note this will lock an account out after 'n' amount failed logins, 'n' being whatever policy you have set. This should always be true of any solution which you use. – mrTomahawk Oct 1 '09 at 15:31
  • Also, that check might ignore the credentials of local users, unless you tweak it, specifying the username twice like this OpenDSObject("WinNT://domain/userName,user","userName", "password", 1). Source. – Agostino Nov 24 '17 at 14:08
1

On Windows desktop you can use Active Directory Explorer by SysInternals / MS itself :

https://docs.microsoft.com/en-us/sysinternals/downloads/adexplorer

  • I assume you're suggesting the initial "Connect to Active Directory" prompt as the password test case - that seems to do the job from my testing. Incorrect password results in a "username or password is incorrect" prompt fairly quickly, so this would be a decent GUI-based test to work through a mental list of possible passwords. – JimNim Jan 10 '18 at 18:37
0

You could use one of the many well known tools out there to test passwords. One I saw is L0phtcrack. Maybe there is even a way to do this offline with a dump of you authentication database. In "the other world", we use "john the ripper" for stuff like this.

  • 1
    I'm not talking about cracking passwords or testing their strength. I'm talking about a tool that can tell me if the password I enter for a particular account is that account's password. – TheCleaner Sep 22 '09 at 18:07
  • @TheCleaner: Sure, you can create a word-list with all possible passwords for a specific account and use this list for a set of accounts. or a single one... Testing with SMB or something is a rather bad idea. It fills your logs, messes up sessions to the file server, generates load on DCs and file servers and so on. – PEra Sep 29 '09 at 19:16
0

Using code from above, check all domain accounts to see if they are using a certain password.

$usernames = Get-ADUser -Filter * | select -ExpandProperty SamAccountName

foreach ($username in $usernames) {
$password = "Password"
Add-Type -AssemblyName System.DirectoryServices.AccountManagement 
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Machine, $env:computername 
$opt = [System.DirectoryServices.AccountManagement.ContextOptions]::SimpleBind 
$pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext -ArgumentList $ct 
$Result = $pc.ValidateCredentials("domain\$username", $password).ToString() 
If ($Result -eq "True") {echo "$username" >> C:\result.txt}
}
-1

Why not use a network service with authentication (telnet, POP, IMAP, SMTP, what you want) ? Other side, if you are on the machine you can try su - userToTest from a non priv account. If the password is OK, you will be allowed in the userToTest homedir if the shell allow the connection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.