Seeing a Hashed Password - linux

Is there a linux command to see the hashed password? Not the actual password but just the hash over it. I have tried showing hash table and such but that has yet to work. Feel like I'm just missing a simple command.

On Unix/Linux systems the hashed passwords of all users are stored into the file /etc/shadow and - for security reasons - this is readable only to root.
Therefore there is no way for an unprivileged user to read its contents.
However, if the NIS service is enabled in your system/network, you can see the hashed passwords in the second column of the output of the command ypcat passwd.

Related

msmtp and smtp account password - how to obfuscate

I configured msmtp with my gmail account.
I obviously want to avoid writing my password in plaintext format in the config file.
Luckily enough msmtp offer the option passwordeval which can be used to obtain the password from the output of an an executable.
The question is: how should I use it?
I found here the following suggestion:
passwordeval gpg -d /some/path/to/.msmtp.password.gpg
That doesn't make much sense to me: if someone is able to access my config file he will certainly manage to run such a command and obtain the password from gpg.
So I believe I'm left with the only option of obfuscating the password within the binary executable even if I read almost everywhere that this is bad!
My impossible-to-hack implementation is: if the sendmail process is running output the correct pass, otherwise give a fake pass.
Your suggestions?
Other (more secure) tricks different from storing the pass in the binary file?
From Sukima's comment:
The reason gpg -d works is because it requires the private key of the person the file is encrypted to. So just placing that encrypted file in the public it is still encrypted an only one person (the one with the secret key) can decrypt it. It is assumed that the secret key is locked up on the user's machine and not leaked. It also assumes that they have not setup any agents which cache the unlock password while a hacker has direct access to the same machine. All of which is highly unlikely in 99% of all attacks.
There is not a standard solution on how to save credentials with the constraint of
having to use the credentials in plain text later
and in an unattended way
on a system which is not completely controlled by you (if it is you just set appropriate rights on the files holding the secrets)
You have several solutions, none solves perfectly your problem:
encrypt your credentials in a symmetric way: you need to input the key to decrypt them
encrypt in an asymmetric way: you need to provide your private key, which must be stored somewhere (unattended approach) or keyed in
obfuscate: as you mention, this only protects from some population
get it from somewhere else - you need to identify a way or another your system
You need to take into account which risk is acceptable and go from there.

pam_cracklib not seeing old password

I have enabled Linux PAM (version 1.1.4) and cracklib (version 2.8.22) and most things are working fine. All password complexity specified via the PAM configuration file are being adhered to (upper/lower case, digits, etc) but the 'difok' is NOT being adhered to. No matter what I set this option to, pam_cracklib will let any password through (provided it meets the other complexity requirements I've specified).
Long story short I had to modify the Linux PAM cracklib to add some debug and quickly found out that pam_cracklib FAILS to be able to retrieve the OLD password. It thinks the string is NULL so naturally there is nothing to compare the new password to.
Yet when the user changes their own password, it IS CORRECTLY authenticating the current (what will become the OLD) password so pam_unix is correctly seeing the old password. By the time it gets down to the pam_cracklib line of the PAM configuration the password appears to have been wiped out somehow.
I'm pulling my hair out trying to figure out how/where/why this is happening.
Here are the relevant password lines in my PAM configuration file:
password requisite pam_cracklib.so debug reject_username\
minlen=6 ucredit=-1 lcredit=-1 difok=4 maxrepeat=2
password required pam_unix.so debug md5 shadow
BY THE WAY: this is all being done programatically through a front end application. This is NOT something which can be done interactively in this environment.
Does anyone have any ideas on this?
Hashed versions of old passwords are stored in
/etc/security/opasswd
So I would check the perms on that file they normally should read:
-rw-------.
Also (and here is the crux of the issue I think) you have to ad the remember field to the pam_unix module:
pam_unix.so try_first_pass remember=3 use_authtok null debug md5 shadow

What is an effective solution to replay attacks on password storage files?

How can I effectively thwart a replay attack on a password file that contains usernames and their passwords hashed with salt (and/or pepper)? The attack I am interested in preventing is as follows:
Alice has password A.
Mallory comes to know password A.
Alice changes her password to B.
Mallory replaces the password file with the one that was used when Alice's password was A.
Mallory uses password A to authenticate as alice.
It clearly does not suffice to rely on OS read/write permissions or it would also suffice to store passwords unhashed as plaintext.
How do real systems do it? What if I replace my /etc/shadow with an older one?
The solution that I've arrived at is to store password timestamps alongside an audit log that records changes to the password file. The timestamps are integrity protected with an HMAC. Using an HMAC directly on the password is an alternate solution but the audit log was already present in the system so it seemed acceptable to leverage it.

How can we store password other than plain text?

I've found numerous posts on stackoverflow on how to store user passwords. However, I need to know what is the best way to store a password that my application needs to communicate with another application via the web? Currently, our web app needs to transmit data to a remote website. To upload the data, our web app reads the password from a text file and creates the header with payloads and submits via https.
This password in plain text on the file system is the issue. Is there any way to store the password more securely?
This is a linux os and the application is written in python and is not compiled.
Further clarification:
There are no users involved in this process at all. The password stored in the file system is used by the other web app to authenticate the web app that is making the request. To put it in the words of a commenter below:
"In this case, the application is the client to another remote application."
From the question it seems you need to store password in such a way, that it can be read and used in an automated transaction with another site. You could encrypt the password and store it encrypted in the file, then decrypt it using a key stored elsewhere in your system before using it. This makes difficulties to someone that gets access to the file from using the password, as they now have to find the key and encryption algorithm used, so they can decrypt it.
As defense, more lesser defense is always better than one strong defense that fails when breached. Moreover, I would also secure the file containing the password, rather than the password itself. Configure your webserver to disable possibility to serve the file containing the password, and try to set the process needing the file to run under a separate account, so you can restrict the access to the file to account running the process and admin accounts only.
I don't think you will find a foolproof way to do this. I would suggest a combination of things to achieve 'security by obscurity':
store the password file on a different computer than the one which will use it
store the file path in a separate config file on the app nachine
use permissions to limit access to the config and password files to your process only
audit file access if your system allows it (keep a log of who touched the files)
give the folders and files innocuous names (/usr/joe/kittens.txt?)
block physical access to the computer(s) (offsite hosting, or locked closet, or something)
You can use a two-way key encryption algorithms like RSA,
The password is stored encrypted (by a key, which is stored in the user's brain) on the filesystem, but to decode the password, the user must enter the key.
At the very least you should use permissions (if you are on a filesystem which supports them) to ensure that you are the only one able to read the file.
In addition, if your app is compiled, it would not be too difficult to encrypt the password with a hard-coded passphrase. If the code is not compiled this method wouldn't really be helpful, as a would-be attacker could just read the source and determine the encryption.
You can store it as a result of hash algorithm, this is one way algorithm (eg. MD5 or SHA). On authentication you calc MD5 of password typed by user and checking equality with your stored MD5 password hash for this user. If is equal password is ok.
For more information about hasing algorithms you can visit:
http://en.wikipedia.org/wiki/Secure_Hash_Algorithm
http://en.wikipedia.org/wiki/MD5
Is your web application hosted on a farm? If not then a technology such as DPAPI will allow you to encrypt the password so that it can only be decrypted on the machine it was encrypted on.
From memory there can be problems with using it on a web farm though, as you need to go and re-encrypt the value for each server.
If it is a web farm then you probably want to use some form of RSA encryption as has been suggested in other answers.
EDIT: DPAPI is only good if you are hosting on windows of course...
Protecting the Automatic Logon Password
The LsaStorePrivateData function can be used by server applications to store client and machine passwords.
Windows only
I don't think you are understanding the answers provided. You don't ever store a plain-text password anywhere, nor do you transmit it to another device.
You wrote: Sorry, but the issue is storing a
password on the file system... This
password is needed to authenticate by
the other web app.
You can't count on file system protections to keep plain-text safe which is why others have responded that you need SHA or similar. If you think that a hashed password can't be sufficient for authentication, you don't understand the relevant algorithm:
get password P from user
store encrypted (e.g. salted hash)
password Q someplace relatively
secure
forget P (even clear the buffer you
used to read it)
send Q to remote host H
H gets password P' from user when
needed
H computes Q' from P', compares Q'
to Q for equality

Do passwords used for .htaccess need to be encrypted?

I am using .htaccess files to control access to various Apache2 directories. I have a main "password" file that contains usernames and passwords. All the instructions I have found regarding .htaccess talk about how the passwords added are encrypted. The usernames and passwords are created using the following command line syntax ...
htpasswd -nb username password
What I am wondering is ... do the passwords always need to be encrypted? Could I store usernames and passwords in a plain-text form someonewhere on the system (above the web root)? This would allow me to easily edit user names and passwords via FTP without requiring access to the Shelll (which I do not always have). Thank you.
Uh, it's a really really really bad idea to store the passwords in plaintext, regardless of whether it's supported or not. You could always generate the hashed passwords with a local copy of the htpasswd(1) utility...

Resources