CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/tools/password/vxencrypt.rb
Views: 1904
1
#!/usr/bin/env ruby
2
3
#
4
# This script can be used to calculate hash values for VxWorks passwords.
5
#
6
7
def hashit(inp)
8
if inp.length < 8 or inp.length > 120
9
raise RuntimeError, "The password must be between 8 and 120 characters"
10
end
11
sum = 0
12
bytes = inp.unpack("C*")
13
bytes.each_index {|i| sum += (bytes[i] * (i + 1)) ^ (i + 1) }
14
hackit(sum)
15
end
16
17
def hackit(sum)
18
magic = 31695317
19
res = ((sum * magic) & 0xffffffff).to_s
20
res.unpack("C*").map{ |c|
21
c += 0x21 if c < 0x33
22
c += 0x2f if c < 0x37
23
c += 0x42 if c < 0x39
24
c
25
}.pack("C*")
26
end
27
28
input = ARGV.shift || "flintstone"
29
$stderr.puts "[*] Hash for password '#{input}' is #{hashit(input)}"
30
31