Last active
June 28, 2019 06:16
-
-
Save mjy9088/015cf2342b9f44f9b2a16c9f7cdadd17 to your computer and use it in GitHub Desktop.
Migrating password LDAP SSHA hash to new one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var readline = require('readline'); | |
var crypto = require('crypto'); | |
var kdf2 = require('pbkdf2-password'); | |
var hasher = kdf2({digest: 'sha256', iterations: 1000, keyLength: 64}); | |
var r = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
r.prompt(); | |
r.on('line', function(line) { | |
var buf = new Buffer(line.substring(6), 'base64'); | |
var old_hash = buf.slice(0, 20); | |
var old_salt = buf.slice(20, 24); | |
crypto.randomBytes(60, function(err, tmp_salt) { | |
if(err) throw err; | |
var new_salt = Buffer.concat([old_salt, tmp_salt]); | |
old_salt.copy(new_salt, 0, 4); | |
hasher({password: old_hash.toString('base64'), salt: new_salt.toString('base64')}, function(err, pass, salt, new_hash) { | |
if(err) throw err; | |
console.log('new hash : ' + new_hash.toString('base64') + ', new salt : ' + new_salt.toString('base64')); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var readline = require('readline'); | |
var crypto = require('crypto'); | |
var kdf2 = require('pbkdf2-password'); | |
var hasher = kdf2({digest: 'sha256', iterations: 1000, keyLength: 64}); | |
var r = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
r.prompt(); | |
r.on('line', function(line) { | |
var data = line.split('\\\\'); | |
var new_salt = new Buffer(data[1], 'base64'); | |
var old_salt = new_salt.slice(0, 4); | |
var tmp_hash = crypto.createHash('sha1').update(Buffer.concat([new Buffer(data[0]), old_salt])).digest('base64'); | |
hasher({password: tmp_hash, salt: new_salt.toString('base64')}, function(err, pass, salt, result) { | |
if(err) throw err; | |
console.log(result); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$lines = file_get_contents('php://stdin'); | |
foreach(explode("\n", $lines) as $line) | |
{ | |
if(!$data = trim($line)) break; | |
$data = explode("\\\\", $data); | |
$data[1] = base64_decode($data[1]); | |
$old_salt = substr($data[1], 0, 4); | |
echo base64_encode(hash_pbkdf2('sha256', base64_encode(sha1($data[0].$old_salt, true)), $data[1], 1000, 64, true)) . PHP_EOL; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment