Skip to content

Instantly share code, notes, and snippets.

@phikshun
Created April 23, 2012 17:39
Show Gist options
  • Save phikshun/2472555 to your computer and use it in GitHub Desktop.
Save phikshun/2472555 to your computer and use it in GitHub Desktop.
John passwd file to mschapv2acc file converter
#!/usr/bin/ruby
require 'digest/sha1'
if !ARGV[0] || !ARGV[1]
puts "Usage: accgen.rb <john-style-passfile.txt> <mschapv2acc-bin-output>"
puts ""
puts "Takes a John-sytle passwd file as input, separated as follows:"
puts "username:::AUTH_HASH:RESPONSE_HASH:PEER_HASH"
puts "The output file is ready for mschapv2acc cracking."
puts ""
exit
end
def hex2bin(s)
s.scan(/../).map { |x| x.hex.chr }.join
end
input = File.read(ARGV[0])
out = File.open(ARGV[1], 'wb')
input = input.split("\n")[0] if input =~ /\n/
input_array = input.split(":")
user = input_array[0]
auth = hex2bin(input_array[3])
resp = hex2bin(input_array[4])
peer = hex2bin(input_array[5])
digest = Digest::SHA1.new
digest.update(peer)
digest.update(auth)
digest.update(user)
challenge = digest.digest[0..7]
out.write user.length.chr + "\x00\x00\x00" + user + auth + peer + challenge + resp
out.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment