Skip to content

Commit b11d041

Browse files
committed
Describe bad choice for passwords storage in README
Ref: anxolerd#4 #1
1 parent 21238f2 commit b11d041

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

Dockerfile.db

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM postgres:alpine
1+
FROM postgres:9.6.15-alpine
22

33
ENV POSTGRES_DB sqli
44
COPY ./migrations/* /docker-entrypoint-initdb.d/

README.rst

+52-1
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,59 @@ engine (Jinja2) in ``sqli/app.py``.
197197
You can also sanitize text, when users input it and prohibit different kinds of
198198
code injection.
199199

200+
Bad choice for storing passwords
201+
--------------------------------
202+
203+
Description
204+
~~~~~~~~~~~
205+
206+
As per `check_paswword function
207+
<https://github.com/anxolerd/dvpwa/blob/master/sqli/dao/user.py#L40-L41>`_ and
208+
`database initialization script
209+
<https://github.com/anxolerd/dvpwa/blob/master/sqli/dao/user.py#L40-L41>`_,
210+
passwords are not stored in the database themselves, but their md5 hashes.
211+
212+
Here are the problems with such approach:
213+
214+
- As hash function produces same output for same input, same passwords will
215+
produce the same hash. Passwords are vulnerable to statistical analysis: it
216+
is possible to determine how many people use the same password, how popular
217+
the password is, etc:
218+
219+
.. code-block :: sql
220+
221+
sqli=# select pwd_hash, array_agg(username), count(*)
222+
sqli-# from "users"
223+
sqli-# group by pwd_hash
224+
sqli-# order by count(*) desc;
225+
pwd_hash | array_agg | count
226+
----------------------------------+----------------+-------
227+
5f4dcc3b5aa765d61d8327deb882cf99 | {j.doe,s.king} | 2
228+
1da0bac388e8e0409a83e121e1af6ef4 | {p.parker} | 1
229+
17c4520f6cfd1ab53d8745e84681eb49 | {superadmin} | 1
230+
(3 rows)
231+
232+
233+
- Md5 is considered quite a weak hash, thus collisions can be easily found.
234+
Moreover, this hash is easy to bruteforce, as well as a lot of rainbow tables
235+
exists for md5. For example, `CrackStation website
236+
<https://crackstation.net/>`_ can be used for such purposes.
237+
238+
Mitigation
239+
~~~~~~~~~~
240+
241+
Password themselves should never be stored in database. Special hash functions
242+
for passwords exist, such as argon2, bcrypt, pbkdf2. These functions should be
243+
used instead of plain text passwords or weak hashes like md5, or fast hash
244+
functions like sha1, sha2. For examples, see `password hashing
245+
<https://pynacl.readthedocs.io/en/stable/password_hashing/>`_ section on PyNaCL
246+
documentation.
247+
248+
Cross-site request forgery
249+
--------------------------
250+
200251
TBA
201-
---
252+
202253

203254

204255
.. _`dvwa`: http://dvwa.co.uk

0 commit comments

Comments
 (0)