Should hardcoded passwords be salted / hashed?

StackOverflow has many questions about simple systems without entering the database. I was about to propose a salted hash approach on a recent one when I thought, "does it really make sense to do this?"

I have stored salted hashes in databases for many years, and I understand why it is more secure: if the database is compromised, the information contained in it will not allow anyone to enter my system (as opposed to passwords in db).

But in a setting that is not database related, does hashing + salting have any security benefits? The only reason I can think of is because if an attacker gets read-only access to my server code, it will not be possible to determine any passwords. Is this a likely scenario? Because, as soon as an attacker gains access to files, he can do anything.

So my question is: when setting up very simple systems without entering the database, should the passwords be salted / hashed or just saved in plain text?

+4
source share
3 answers

I think they will answer the question if you can figure out the answer, "is my source code much less likely to be read by an attacker than a database?"

I would suggest that this is not the case - perhaps your source is somewhat less prone to leak, depending on how something is backed up, etc. Despite this, I doubt that it is so less likely that you can neglect the risk, given that you do not neglect the same risk for the database. The reason that the passwords in the database must be salted / hashed is not because there is some special property of the databases, which means that attackers can view their contents [*], because attackers can either look differently at all kinds of things.

In fact, the source code may be even more likely to leak than the database, given that anyone who works on the system may need access to the source, while not everyone on the system needs access to the contents of the live database. It's not that I thought your developers were dishonest (if you have them, you have worse problems than a password leak), just so that the logistics around the exchange source can introduce more (or just different) ways that it can accidentally flow than logistics around db backup.

Personally, in your situation, I would create a small file on the server containing a hashed / salty password, and about nothing. Users installing different instances of the application can create their own versions of this file containing their own password, separately from the actual application code. They should block it with the same write restrictions as the source code.

Calling this file “read-only database” or “part of the server code” does not affect how easy it is for an attacker to view it, although it can affect whether you refer to the password as “hard”.

[*], of course, there are potential flaws specific to specific databases, SQL injection attacks, or something else. This is not a decisive reason why passwords in databases should be salted and hashed.

+2
source

Yes, it still provides the advantage of hashing and salt . If the source code of the script leaked, otherwise people could just use a hard-coded password or google for the hash and possibly find the input value. With a salty hash is not possible.

+3
source

Well, as Steve Jessop said. The source code may leak or most likely fall into some hands. If you hardcode the password (which I understand), then why not save it as a two-part data structure => the salt used and the hashed password. You know this, but never appears in the source code. This is also what people do with DB connection strings or similar. Encrypt it with the key lying in the variable below it. Thus, it never appears in the source code. maybe not even in a memory dump, unless you crossed it.

+1
source

Source: https://habr.com/ru/post/1413571/


All Articles