|
|
Subscribe / Log in / New account

Wordpress Cookie Authentication Vulnerability

From:  "Steven J. Murdoch" <bugtraq+Steven.Murdoch-AT-cl.cam.ac.uk>
To:  bugtraq-AT-securityfocus.com
Subject:  Wordpress Cookie Authentication Vulnerability
Date:  Mon, 19 Nov 2007 18:44:43 +0000
Message-ID:  <20071119184443.GI1043@tern.cl.cam.ac.uk>

Wordpress Cookie Authentication Vulnerability

Original release date: 2007-11-19
Last revised: 2007-11-19
Latest version: http://www.cl.cam.ac.uk/users/sjm217/advisories/wordpress...
CVE ID: <pending>
Source: Steven J. Murdoch <http://www.cl.cam.ac.uk/users/sjm217/>


Systems Affected:

 Wordpress 1.5 -- 2.3.1 (including current version, as of 2007-11-19)


Overview:

 With read-only access to the Wordpress database, it is possible to
 generate a valid login cookie for any account, without resorting to a
 brute force attack. This allows a limited SQL injection vulnerability
 to be escalated into administrator access.

 This vulnerability is known to be actively exploited, hence the
 expedited public release.


I. Description

 For authentication, the Wordpress user database stores the MD5 hash
 of login passwords. A client is permitted access if they can present a
 password whose hash matches the stored one.

 $ mysql -u wordpress -p wordpress
   Enter password: ********

   mysql> SELECT ID, user_login, user_pass FROM wp_users;
   +----+-------------+----------------------------------+
   | ID | user_login  | user_pass                        |
   +----+-------------+----------------------------------+
   |  1 | admin       | 4cee2c84f6de6d89a4db4f2894d14e38 |
   ...

 Of course, entering your password after each action that requires
 authorization would be exceptionally tedious. So, after logging in,
 Wordpress presents the client with two cookies:

  wordpressuser_6092254072ca971c70b3ff302411aa5f=admin
  wordpresspass_6092254072ca971c70b3ff302411aa5f=813cadd8658c4776afbe5de8f304a684

 The cookie names contains the MD5 hash (6092...1a5f) of the blog URL.
 The value of wordpressuser_... is the login name, and the value of
 wordpresspass is the double-MD5 hash of the user password.

 Wordpress will permit access to a given user account if the
 wordpressuserpass_... cookie matches the hash of the specified user's
 wp_users.user_pass database entry.

 In other words, the database contains MD5(password) and the cookie
 contains MD5(MD5(password)). It is thus trivial to convert a database
 entry into an authentication cookie.

 At this point the vulnerability should be clear. If an attacker can
 gain read access to the wp_user table, for example due to a publicly
 visible backup or SQL injection vulnerability, a valid cookie can be
 generated for any account. 

 This applies even if the user's password is sufficiently complex to
 resist brute force and rainbow table attacks. While it should be
 computationally infeasible to go backwards from MD5(password) to
 password, the attacker needs only to go forwards.

 The exploitation steps are therefore:
  1) Find the hash of the blog URL: Either just look at the URL, or
     create an account to get a user cookie
  2) Read the user_pass entry from wp_users table: Look for
     backups, perform SQL injection, etc...
  3) Set the following cookies:
      wordpressuser_<MD5(url)>=admin
      wordpresspass_<MD5(url)>=MD5(user_pass)
  4) You have admin access to the blog


II. Impact

 A remote attacker, with read access to the password database can gain
 administrator rights. This may be used in conjunction with an SQL
 injection attack, or after locating a database backup.

 An attacker who has alternatively compromised the database of one
 Wordpress blog can also gain access to any other whose users have the
 same password on both.


III. Solution

 No vendor patch is available.
 No timeline for a vendor patch has been announced.

 Workarounds:

 - Protect the Wordpress database, and do not allow backups to be
   released.
 - Keep your Wordpress installation up to date. This should reduce the
   risk that your database will be compromised.
 - Do not share passwords across different sites.
 - If you suspect a database to be compromised, change all passwords
   to different ones. It is not adequate to change the passwords to
   the same ones, since Wordpress does not "salt" [1] the password
   database.
 - Remove write permissions on the Wordpress files for the system
   account that the webserver runs as. This will disable the theme
   editor, but make it more difficult to escalate Wordpress
   administrator access into the capability to execute arbitrary code
 - Configure the webserver to not execute files in any directory
   writable by the webserver system account (e.g. the upload
   directory).

 Potential fixes:

  The problem occurs because it is easy to go from the password hash
  in the database to a cookie (i.e the application of MD5 is the wrong
  way around). The simplest fix is to store MD5(MD5(password)) in the
  database, and make the cookie MD5(password). This still makes it
  infeasible to retrieve the password from a cookie, but means that it
  is also infeasible to generate a valid cookie from the database
  entry.

  However, there are other vulnerabilities in the Wordpress cookie and
  password handling, which should be resolved too:

  - Passwords are unsalted [2], leaving them open to brute force, rainbow
    table and other attacks [3].
  - It is impossible to revoke a cookie without changing the user's
    password.
  - Cookies do not contain an expiry time, so are always valid (until
    the user's password changes)
  - There ought to be an option to limit cookies to a particular
    IP address or range.


References:

  [1] http://en.wikipedia.org/wiki/Salt_(cryptography)
  [2] http://trac.wordpress.org/ticket/2394
  [3] http://www.lightbluetouchpaper.org/2007/11/16/google-as-a...


Timeline:

 2007-10-29: security@wordpress.org notified; no response
 2007-11-02: security@wordpress.org notified;
             Confirmation of active exploitation requested by Wordpress
 2007-11-02: Confirmation sent; no response
 2007-11-19: Advisory released to full-disclosure and BugTraq

-- 
w: http://www.cl.cam.ac.uk/users/sjm217/




to post comments

Wordpress Cookie Authentication Vulnerability

Posted Nov 19, 2007 21:29 UTC (Mon) by jwb (guest, #15467) [Link] (3 responses)

Oh boy!  As a system administrator there's nothing I like better than yet another mediocre PHP
hack with its own half-baked authentication and authorization system.  I have a version of
wordpress kicking around here somewhere but a few months back I ripped out the auth/authz code
and made it respect the authenticated user coming from Apache, which is IMHO the only sane way
to do things.

Wordpress Cookie Authentication Vulnerability

Posted Nov 19, 2007 23:03 UTC (Mon) by tobor (guest, #36736) [Link] (1 responses)

Don't blame the language for this worse-than-failure design decision.

Wordpress Cookie Authentication Vulnerability

Posted Nov 21, 2007 21:21 UTC (Wed) by judas_iscariote (guest, #47386) [Link]

not only the authentication system design is horrible...wordpress is a great example of a cool
blog user interface but an horrible, messy, insecure code. 

Apache security

Posted Nov 20, 2007 3:08 UTC (Tue) by ccyoung (guest, #16340) [Link]

if you do not trust app security, then apache security is a savior.

nonetheless apache security is not cheap, requiring extra transmission bytes, extra
processing, and (frequently many) extra db reads per page access.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 0:10 UTC (Tue) by lutchann (subscriber, #8872) [Link] (10 responses)

I don't get it.  If an attacker already has access to your SQL database, what more does it get
them to have administrator permissions in the web interface?

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 0:25 UTC (Tue) by drag (guest, #31333) [Link] (9 responses)

Well if you use a code injection vunerability you can display tables and such without actually
having login access to the database. Finding a input feild (say URL or text input box) without
correct input validation can provide this level of access.

Since Wordpress then, effectively thru cookies, uses MD5 hashes of passwords as passwords then
it's stupid simple to gain access to any account. 


To look at it this way...

A similar example would be on old Unix boxes without shadow passwords. Say you get access to a
FTP accound all you have to do is then download the /etc/passwd file. This is very easy to do
since everything uses that file for doing such mundane things as mapping a username to uid.
Any network service, any user program, any user account can allow access to /etc/passwd. You
don't need to be root to do that.

It appears to me that password table in the sql database is pretty much equivelent to
/etc/passwd.

Well in those old Unix/Linux systems the passwords would be encrypted in some manner. The
attacker would then have to run a brute force program to find passwords that match the hashes.

However.. Wordpress is so badly designed that the attacker does not have to even do that. Once
they obtain the hash of the password they can actually use the hash _as_the_password_. It's
very bad.

So this vunerability is a combination of a attacker finding bad input validation and badly
designed Single-Sign-On authentication systems based on browser cookies.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 3:37 UTC (Tue) by lutchann (subscriber, #8872) [Link] (8 responses)

I'm not very familiar with SQL/PHP security issues, but if you discovered an SQL injection
vulnerability in Wordpress, couldn't you just use it to add a new user to the authentication
table?

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 3:39 UTC (Tue) by lutchann (subscriber, #8872) [Link] (7 responses)

And by "new user" I mean "new administrator".  In other words, how does having administrator
access to the web site give you more power than the SQL injection vulnerability itself?

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 3:53 UTC (Tue) by drag (guest, #31333) [Link] (6 responses)

I donno. Good point.

I just figured being able to display a table requires less rights then being able to modify it
and since it's needed by the authentication stuff then it would be accessable to parts of the
website accessable by anonymous people.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 6:09 UTC (Tue) by Ross (guest, #4065) [Link] (5 responses)

For one thing, this type of problem would allow access to continue long after the broken code
is fixed, without the user knowing about it.  Also, because of the way the password is stored,
it would easy allow offline cracking of passwords, and users tend to reuse the same password
on different sites.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 6:41 UTC (Tue) by lutchann (subscriber, #8872) [Link] (4 responses)

That's true of pretty much any authentication system, except those based on asymmetric
cryptography.  Wordpress is far from unusual in storing password equivalents on disk.  So
unless Wordpress somehow encouraged making the user table accessible to attackers, I still
don't see why this is a big deal.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 9:15 UTC (Tue) by Ross (guest, #4065) [Link] (3 responses)

It's true that any encrypted password can be attacked offline if you have the hash, but if the
passwords were properly salted, it would be much more expensive to crack them because an
attacker couldn't build a pre-encrypted dictionary.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 16:10 UTC (Tue) by drag (guest, #31333) [Link] (2 responses)

Ya..

Google around for 'Rainbow tables'. There are ones you can download for free and ones you can
pay for. 

Just going out to pirate bay and doing a quick search I found downloads for MD5, SHA1, and NT
Lan manager tables.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 18:21 UTC (Tue) by Los__D (guest, #15263) [Link] (1 responses)

The main purpose of salts is to combat things like rainbow tables.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 19:12 UTC (Tue) by jengelh (guest, #33263) [Link]

The main purpose of rainbow tables is to combat unsalted web apps ;-)

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 9:45 UTC (Tue) by Velmont (guest, #46433) [Link] (6 responses)

Hmm. In my own CMS (before I went over to use WordPress), I salted the extra md5 in the cookie, like this:

cookie_pass = md5( md5(password) + config['salt'] + userid )

Wouldn't that be safer if every user must define config['salt'] in their config file?

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 11:41 UTC (Tue) by Los__D (guest, #15263) [Link] (4 responses)

AFAIK, normally you generate a random salt, and store that salt with the password.

Salts are only there to avoid dictionary attacks.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 11:41 UTC (Tue) by Los__D (guest, #15263) [Link] (3 responses)

Ehm, that would be the password hash

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 13:40 UTC (Tue) by drag (guest, #31333) [Link] (2 responses)

Because anybody can use the md5sum of the md5sum of the password to gain access to any account
there isn't any point to cracking the password. Effectively Wordpress found a way to defete
the whole point of using hashes to secure passwords. They could of used all the salt in the
world and it wouldn't of mattered.

Maybe using 'md5sum[ salt + md5sum[ password ]]' to make the token would of made a difference.
But then it would matter exactly how the cookie-based auth token is generated. For instance if
the salt was stored in the same database as the password hashes it wouldn't do much good.. if
the salt was time based it wouldn't do much good. 


This sort of thing is a very difficult problem and is why most of the time it's better to use
some method that has been developed by security researchers and has been audited by third
parties rather then try to make up your own auth systems.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 14:49 UTC (Tue) by Los__D (guest, #15263) [Link]

This was in response to making the salt a configured value.

Of course, when nobody really needs to care about testing the sums, they could have stored the
passwords bit flipped, and have Wordpress no more unsafe than it is now...

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 16:28 UTC (Tue) by zlynx (guest, #2285) [Link]

What they need to do is either use SSL client certificates, which would be a great idea since
they do exactly what is desired: authenticate the client, or:

Use Javascript.  Have the server provide a random value, then in Javascript MD5 or otherwise
hash the password or password MD5 + random value and return the result to the server.

In either case, the secret is never sent over the network.

Wordpress Cookie Authentication Vulnerability

Posted Nov 20, 2007 18:03 UTC (Tue) by Max.Hyre (subscriber, #1054) [Link]

Wouldn't that be safer if every user must define config['salt'] in their config file?
No. Anything the user adds to the authentication process weakens it: witness passwords. If you want to use salt, generate it yourself; otherwise you'd get config['mh'] all over the place. (Where ``mh'' is the user's initials.)


Copyright © 2007, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds