what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

Laravel 2.1 Hash::make() bcrypt Truncation

Laravel 2.1 Hash::make() bcrypt Truncation
Posted Sep 16, 2014
Authored by Pichaya Morimoto

Laravel version 2.1 fails to check length prior to password hash creation allowing for possible hash collisions for secrets over 72 characters.

tags | exploit
SHA-256 | c326cc304eeacde84a1ea946f533f0c9f4c6ce9cfb4ff9339cbc8e8cbada6457

Laravel 2.1 Hash::make() bcrypt Truncation

Change Mirror Download
######################################################################
# _ ___ _ _ ____ ____ _ _____
# | | / _ \| \ | |/ ___|/ ___| / \|_ _|
# | | | | | | \| | | _| | / _ \ | |
# | |__| |_| | |\ | |_| | |___ / ___ \| |
# |_____\___/|_| \_|\____|\____/_/ \_\_|
#
# Laravel 2.1 Hash::make() bcrypt truncation
# Website : http://laravel.com/
# Author : @u0x (Pichaya Morimoto)
# Release dates : September 16, 2014
#
# Special Thanks to 2600 Thailand group
# https://www.facebook.com/groups/2600Thailand/ , http://2600.in.th/
#
########################################################################

[+] Laravel
============================================================
Laravel is a free, open source PHP web application framework, designed for
the development of model–view–controller (MVC) web applications. According
to a December 2013 developers survey on PHP frameworks popularity, Laravel
is listed as the most popular PHP framework in 2013. At the same time, as
of August 2014 Laravel is the most popular and watched PHP project on
GitHub.
https://en.wikipedia.org/wiki/Laravel

[+] Description
============================================================
By using Laravel Security mechanism,
http://laravel.com/docs/security#storing-passwords
The passwords will be hashed using Laravel's Hash::make() function.
This function internally call PHP 's password_hash() without checking the
length.

Why do we need to check length? as PHP manual said,
"Using the PASSWORD_BCRYPT for the algo parameter,
will result in the password parameter being truncated
to a maximum length of 72 characters."
http://php.net/manual/en/function.password-hash.php

The problem occurs if users enter password longer than 72 characters
then the password will be truncated to be 72 characters.

This will result in pseudo hash collision.

[+] Proof-of-Concept
============================================================
// user input password
$input = str_repeat('A',72);
// plaintext password
$pass1 =
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.'mysupersecretpassword';
$pass2 =
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA.'longcatishere';
// hashed password
$hash1 = Hash::make($pass1);
$hash2 = Hash::make($pass2);
// match?
$status1 = Hash::check($input, $hash1)?'Yes':'No';
$status2 = Hash::check($input, $hash2)?'Yes':'No';

User 1
Desc. Value
$input
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
$pass1
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAmysupersecretpassword
Hash::make($pass1)
$2y$10$9oMcpTwHgTzR5ZUMqlnMMOx/P18QZ5e9054lq.pwxw1O9urX3JHHu
Hash::check($input, $hash1) Yes

User 2
Desc. Value
$input
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
$pass2
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlongcatishere
Hash::make($pass2)
$2y$10$W7wwB4nLmFjrenJGmx1uauqhjzikZNZA0qzxH8wkbiSmVatCYrAUm
Hash::check($input, $hash2) Yes

[+] Vulnerable Code
============================================================
/vendor/laravel/framework/src/Illuminate/Hashing/BcryptHasher.php

...
public function make($value, array $options = array())
{
...
$hash = password_hash($value, PASSWORD_BCRYPT, array('cost' => $cost));
...
return $hash;

[+] How to fix this?
============================================================
In Django project, they solved this problem by applying SHA256 before using
bcrypt
"BCryptSHA256PasswordHasher fixes this by first hashing the password using
sha256.
This prevents the password truncation"
https://docs.djangoproject.com/en/dev/topics/auth/passwords/#using-bcrypt-with-django


Login or Register to add favorites

File Archive:

August 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Aug 1st
    15 Files
  • 2
    Aug 2nd
    22 Files
  • 3
    Aug 3rd
    0 Files
  • 4
    Aug 4th
    0 Files
  • 5
    Aug 5th
    15 Files
  • 6
    Aug 6th
    11 Files
  • 7
    Aug 7th
    43 Files
  • 8
    Aug 8th
    42 Files
  • 9
    Aug 9th
    36 Files
  • 10
    Aug 10th
    0 Files
  • 11
    Aug 11th
    0 Files
  • 12
    Aug 12th
    27 Files
  • 13
    Aug 13th
    18 Files
  • 14
    Aug 14th
    50 Files
  • 15
    Aug 15th
    33 Files
  • 16
    Aug 16th
    23 Files
  • 17
    Aug 17th
    0 Files
  • 18
    Aug 18th
    0 Files
  • 19
    Aug 19th
    43 Files
  • 20
    Aug 20th
    29 Files
  • 21
    Aug 21st
    42 Files
  • 22
    Aug 22nd
    26 Files
  • 23
    Aug 23rd
    0 Files
  • 24
    Aug 24th
    0 Files
  • 25
    Aug 25th
    0 Files
  • 26
    Aug 26th
    0 Files
  • 27
    Aug 27th
    0 Files
  • 28
    Aug 28th
    0 Files
  • 29
    Aug 29th
    0 Files
  • 30
    Aug 30th
    0 Files
  • 31
    Aug 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close