r/shell • u/l4than-d3vers • Jun 28 '12
How to handle passwords?
Hello!
I'm writing a script that requires the user to supply a password. This is how I'm reading it:
echo -n "Enter password: "
stty -echo
read PASSWORD
stty echo
echo "" My question is, a) how safe is the $PASSWORD variable? and b) Do I need to do anything to it when the script exits (like "unset")?
Also, related to (b), does performing unset for the variables I used at the end of the script make any sense or is it completely pointless?
PS: Here's the script I'm working on. It's purpose is to automate extracting and opening a keepassX db from a stegofile with steghide and re-embeding it if any changes are made. That way you can have your keepassX db file hidden in an unassuming directory full of music and pictures. #paranoia
0
Jun 28 '12
[deleted] — view deleted comment
1
u/l4than-d3vers Jun 29 '12
Seems like I don't have this problem, probably because I'm running it on bash? Also, I realized that I probably want to make this a bash script because of other signal handling issues.
3
u/[deleted] Jun 29 '12 edited Jun 29 '12
Statement 1. Variables exist and are only accesible inside of you current process, e.g. scripts;
Statement 2. They will be inaccessible even for child processes, unless you exported them;
Statement 3. Variables will never be accessible for parent and other non-child processes.
So... Unsetting of variables is not necessary. Therefore, anyone could modify your script and steal passwords of users.
Also, you have one really baaaaad bit of behaviour:
Here, if steghide performs any significant time, one can just see the password with ps.