Clan x86

Member Forums => iago's forum => Topic started by: Sidoh on March 04, 2010, 06:23:45 pm

Title: blag
Post by: Sidoh on March 04, 2010, 06:23:45 pm
I liked your passwords blag.  :)
Title: Re: blag
Post by: iago on March 04, 2010, 07:03:26 pm
Thanks! :D
Title: Re: blag
Post by: Blaze on March 04, 2010, 07:40:22 pm
Me too, now that I've read it.  Need a second mirror for the passwords?  :D
Title: Re: blag
Post by: iago on March 04, 2010, 08:37:34 pm
Haha, I think I'm ok. Feel free to download them all, though, just in case I get asked to remove them at some point.
Title: Re: blag
Post by: rabbit on March 04, 2010, 10:07:08 pm
Er....what?
Title: Re: blag
Post by: iago on March 05, 2010, 12:05:17 am
http://www.skullsecurity.org/blog/?p=516
Title: Re: blag
Post by: Ender on March 05, 2010, 12:11:33 am
iago, I just wanted to use this opportunity to thank you so much for everything that you've done for me.
Title: Re: blag
Post by: rabbit on March 05, 2010, 12:39:10 am
http://www.skullsecurity.org/blog/?p=516

Read it....still don't get "blag"...
Title: Re: blag
Post by: Sidoh on March 05, 2010, 12:48:05 am
omg... WTF MAN??????  YOU MISSED AN XKCD REFERENCE. I HATE YOU FOREVER

(http://imgs.xkcd.com/comics/mispronouncing.png)
http://xkcd.com/148/
Title: Re: blag
Post by: iago on March 05, 2010, 08:28:44 am
Heh, when I hear 'blag' I think of a show that none of you (except Blaze) have ever heard of, probably: Corner Gas.
Title: Re: blag
Post by: Sidoh on March 05, 2010, 01:07:40 pm
Heh, when I hear 'blag' I think of a show that none of you (except Blaze) have ever heard of, probably: Corner Gas.


I think I've even watched an episode, but that's only because you made me. :)
Title: Re: blag
Post by: while1 on March 14, 2010, 11:32:45 pm
rabbot fails.
Title: Re: blag
Post by: Sidoh on March 15, 2011, 06:15:51 pm
I liked the last two posts on your blag.  They were cool.  I especially liked the Taco Bell programming bit.  I've never used xargs in that way, but I definitely will be doing so in the future.

This seems like a solid (ish) way to generate random salts in PHP. Thoughts?

Code: [Select]
$salt = md5(rand() . microtime())

It seems to me that this is about as good as it gets.  Some of the things people come up with are a lot more convoluted than this, which puzzles me.
Title: Re: blag
Post by: while1 on March 15, 2011, 11:10:22 pm
I liked the last two posts on your blag.  They were cool.  I especially liked the Taco Bell programming bit.  I've never used xargs in that way, but I definitely will be doing so in the future.

This seems like a solid (ish) way to generate random salts in PHP. Thoughts?

Code: [Select]
$salt = md5(rand() . microtime())

It seems to me that this is about as good as it gets.  Some of the things people come up with are a lot more convoluted than this, which puzzles me.

Shit, no wonder my salts always get cracked.

Code: [Select]
$salt = md5(rand() . $penisLen)
Title: Re: blag
Post by: Sidoh on March 15, 2011, 11:12:49 pm
That code is equivalent to

Code: [Select]
$salt = md5(rand() . 0);
Better than the nonsense code in iago's blog, but could be better.
Title: Re: blag
Post by: iago on March 16, 2011, 08:56:15 am
Heh. Salt doesn't have to be strongly random. In fact, salt can be equal to the username, the date, incremental, etc. The only trick with salt is to make sure it's distinct for every user.
Title: Re: blag
Post by: Sidoh on March 16, 2011, 04:10:00 pm
Heh. Salt doesn't have to be strongly random. In fact, salt can be equal to the username, the date, incremental, etc. The only trick with salt is to make sure it's distinct for every user.


Yes, of course, but I was more interested in the answer to the question "is that a good random salt?"
Title: Re: blag
Post by: iago on March 16, 2011, 04:23:52 pm
Yes, that's a decent way of generating a random value, and it's as good a salt as any! :)
Title: Re: blag
Post by: Sidoh on March 16, 2011, 04:38:08 pm
WWiD?
Title: Re: blag
Post by: iago on March 16, 2011, 06:19:56 pm
WWiD for what? For a salt value, just pick some kinda-random letters or sequential values. Like I said, as long as no two users have the same salt, there's no bad salting.
Title: Re: blag
Post by: Sidoh on March 16, 2011, 07:11:45 pm
WWiD for what? For a salt value, just pick some kinda-random letters or sequential values. Like I said, as long as no two users have the same salt, there's no bad salting.

Hehe... yeah.  I probably shouldn't have used the word "salt" anywhere.  It was misleading

Say you want to generate a random password or something.  How would you do it?  I'd probably just use the line I provided above (or something close to it).
Title: Re: blag
Post by: iago on March 17, 2011, 12:16:38 am
Honestly, I don't know what the right answer is. That's why I didn't say in the blog the "right" way.

I think as long as you have a reasonable source of entropy, and a decent RNG, you're okay.

btw, if you're using php, don't use rand(), use mt_rand(). It's better. Also, don't use srand() (I see that you aren't, but you might be using it elsewhere). PHP seeds itself.
Title: Re: blag
Post by: iago on March 17, 2011, 12:20:57 am
Btw, here's how smf generates it:

function generateValidationCode()
{
  global $modSettings;

  $request = db_query('
    SELECT RAND()', __FILE__, __LINE__);

  list ($dbRand) = mysql_fetch_row($request);
  mysql_free_result($request);

  return substr(preg_replace('/\W/', '', sha1(microtime() . mt_rand() . $dbRand . $modSettings['rand_seed'])), 0, 10);
}


It uses microtime, mt_rand(), a random value from mysql, and a random seed that's stored in the settings. That'd be extremely difficult to predict.
Title: Re: blag
Post by: iago on March 17, 2011, 12:27:17 am
Here's Wordpress:
function wp_rand( $min = 0, $max = 0 ) {
  global $rnd_value;

  // Reset $rnd_value after 14 uses
  // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
  if ( strlen($rnd_value) < 8 ) {
    if ( defined( 'WP_SETUP_CONFIG' ) )
      static $seed = '';
    else
      $seed = get_transient('random_seed');
    $rnd_value = md5( uniqid(microtime() . mt_rand(), true ) . $seed );
    $rnd_value .= sha1($rnd_value);
    $rnd_value .= sha1($rnd_value . $seed);
    $seed = md5($seed . $rnd_value);
    if ( ! defined( 'WP_SETUP_CONFIG' ) )
      set_transient('random_seed', $seed);
  }

  // Take the first 8 digits for our value
  $value = substr($rnd_value, 0, 8);

  // Strip the first eight, leaving the remainder for the next call to wp_rand().
  $rnd_value = substr($rnd_value, 8);

  $value = abs(hexdec($value));

  // Reduce the value to be within the min - max range
  // 4294967295 = 0xffffffff = max random number
  if ( $max != 0 )
    $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1)));

  return abs(intval($value));
}


I find you can tell when people don't know what they're doing by seeing that they throw a bunch of stuff in there that doesn't add any strength (for example, using both md5 and sha1, calling sha1 multiple times on the same value, etc).

In any case, the key to their security is, in part, that they save $seed across subsequent calls, so every call to the function uses a seed generated by the previous call.
Title: Re: blag
Post by: iago on March 17, 2011, 12:36:01 am
And finally, here's Mediawiki:
  static function randomPassword() {
    global $wgMinimalPasswordLength;
    $pwchars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz';
    $l = strlen( $pwchars ) - 1;

    $pwlength = max( 7, $wgMinimalPasswordLength );
    $digit = mt_rand( 0, $pwlength - 1 );
    $np = '';
    for ( $i = 0; $i < $pwlength; $i++ ) {
      $np .= $i == $digit ? chr( mt_rand( 48, 57 ) ) : $pwchars{ mt_rand( 0, $l ) };
    }
    return $np;
  }


It's much simpler, but I'm a little concerned about the strength. Unless a min password length is set, it does 7 characters - 6 letters and a number. That's 197,706,096,640 combinations. So yeah, that's pretty damn big, but not nearly as big as it ought to be. Why in the hell did they put a number in the middle and default it to 7 characters?

Losers. :)
Title: Re: blag
Post by: Sidoh on March 17, 2011, 02:27:02 am
Honestly, I don't know what the right answer is. That's why I didn't say in the blog the "right" way.

I think as long as you have a reasonable source of entropy, and a decent RNG, you're okay.

btw, if you're using php, don't use rand(), use mt_rand(). It's better. Also, don't use srand() (I see that you aren't, but you might be using it elsewhere). PHP seeds itself.


Aha, I recall reading that in the docs for rand().  I guess I forgot. :)

Yep, I know about srand.

Heh, mediawiki's is pretty terrible.  People are weird.
Title: Re: blag
Post by: iago on March 17, 2011, 08:58:09 am
I'm actually impressed at the effort they went to to intentionally weaken it. :)
Title: Re: blag
Post by: Sidoh on March 17, 2011, 02:03:46 pm
I'm actually impressed at the effort they went to to intentionally weaken it. :)

Yeah.  Very confusing.

I missed this before:

Unless a min password length is set, it does 7 characters - 6 letters and a number. That's 197,706,096,640 combinations.

Since the position of the digit isn't fixed, it's actually:

52^6 * 10 * 7 = 1,383,942,676,480
Title: Re: blag
Post by: iago on March 17, 2011, 02:53:08 pm
Good call, I forgot the 7.
Title: Re: blag
Post by: iago on March 20, 2011, 08:40:08 pm
I liked the last two posts on your blag.  They were cool.  I especially liked the Taco Bell programming bit.  I've never used xargs in that way, but I definitely will be doing so in the future.

This seems like a solid (ish) way to generate random salts in PHP. Thoughts?

Code: [Select]
$salt = md5(rand() . microtime())

It seems to me that this is about as good as it gets.  Some of the things people come up with are a lot more convoluted than this, which puzzles me.
So, it turns out that rand() and mt_rand() are both seeded by 32-bit values that are somewhat known. And microtime() is actually one of those values. That means that, in reality, due to PHP's crappy random number generator, that may not be especially secure. :)

(I'm going to post a blog on Tuesday (give or take) about this.
Title: Re: blag
Post by: Sidoh on March 20, 2011, 10:18:33 pm
Hm, that's pretty bad.

md5(`cat -c 1000 /dev/random`);

ENTROPY NOMNOMNOMNOM