2017-09-14 14:09:31 +00:00
|
|
|
#!/usr/bin/env ruby
|
2018-04-02 04:26:42 +00:00
|
|
|
|
2010-08-09 22:06:26 +00:00
|
|
|
#
|
|
|
|
# This script can be used to calculate hash values for VxWorks passwords.
|
|
|
|
#
|
|
|
|
|
|
|
|
def hashit(inp)
|
2013-09-30 18:47:53 +00:00
|
|
|
if inp.length < 8 or inp.length > 120
|
|
|
|
raise RuntimeError, "The password must be between 8 and 120 characters"
|
|
|
|
end
|
|
|
|
sum = 0
|
|
|
|
bytes = inp.unpack("C*")
|
|
|
|
bytes.each_index {|i| sum += (bytes[i] * (i + 1)) ^ (i + 1) }
|
|
|
|
hackit(sum)
|
2010-08-09 22:06:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def hackit(sum)
|
2013-09-30 18:47:53 +00:00
|
|
|
magic = 31695317
|
|
|
|
res = ((sum * magic) & 0xffffffff).to_s
|
|
|
|
res.unpack("C*").map{ |c|
|
|
|
|
c += 0x21 if c < 0x33
|
|
|
|
c += 0x2f if c < 0x37
|
|
|
|
c += 0x42 if c < 0x39
|
|
|
|
c
|
|
|
|
}.pack("C*")
|
2010-08-09 22:06:26 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
input = ARGV.shift || "flintstone"
|
|
|
|
$stderr.puts "[*] Hash for password '#{input}' is #{hashit(input)}"
|