Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving password from Windows Credential Manager using CMD

I am trying to add and retrieve credentials from Windows Credential Manager using a command prompt.

To add a new credential, I have the command like below and it works perfectly:

cmdkey /add:testTarget /user:testUser /pass:testPassword

However, when I try to retrieve the credentials, which I have added earlier (testTraget) using CMD, I am unable to get the password using the command below:

cmdkey /list:testTarget

The command only returns the Target(testTarget),Type(Domain Password), and the Username(testUser)

How can I retrieve the testUser password?

I know this is possible in Mac OS using Bash and keychain.

like image 873
Benjamin Avatar asked Nov 01 '22 10:11

Benjamin


2 Answers

It's possible to work with passwords from cmdkey's credentialstore using powershell and the Credman.ps1 library.

https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Credentials-d44c3cde

Add credentials as system user (after a psexec -s in administrator's powershell console). Run powershell script as system user as well (ie. in task scheduler tasks) for safe usage.

To learn more about Sysinternal's psExec and cmdkey see this answer: https://superuser.com/questions/1206443/how-to-add-cached-credentials-for-the-windows-system-acount

--

Adding a password

cmdkey /generic:Foo /user:bar /pass:banana

Retrieving plain-text password with powershell

. "Credman.ps1"

$CredKey = "Foo"

$sourceCredential = Read-Creds $CredKey
$pass = $sourceCredential.CredentialBlob.tostring()
write-host $pass
like image 101
Michael D. Avatar answered Nov 15 '22 03:11

Michael D.


"How can I retrieve the testUser password?"

This is not possible using cmdkey.

Reference cmdkey:

Create, list or delete stored user names, passwords or credentials.

...

Once stored, passwords are not displayed.

like image 23
DavidPostill Avatar answered Nov 15 '22 04:11

DavidPostill