Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/tools/password/halflm_second.rb
Views: 11767
#!/usr/bin/env ruby12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67#8# This script cracks a half-lm challenge/response hash that uses a9# a static challenge key. The idea is you use rainbow tables to10# crack the first 7 chars and this script to complete a few remaining.11# If the password is longer than 10 characters, this script will fail.12#1314msfbase = __FILE__15while File.symlink?(msfbase)16msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))17end1819$:.unshift(File.expand_path(File.join(File.dirname(msfbase), '..', '..', 'lib')))20require 'msfenv'2122$:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']23require 'rex'2425def usage26$stderr.puts("\n" + " Usage: #{$0} <options>\n" + $args.usage)27exit28end2930def try(word,challenge)31buf = ::Rex::Proto::NTLM::Crypt.lanman_des(word, challenge)32buf.unpack("H*")[0]33end3435hash = pass = chall = nil3637$args = Rex::Parser::Arguments.new(38"-n" => [ true, "The encrypted LM hash to crack" ],39"-p" => [ true, "The decrypted LANMAN password for bytes 1-7" ],40"-s" => [ true, "The server challenge (default value 1122334455667788)" ],41"-h" => [ false, "Display this help information" ])4243$args.parse(ARGV) { |opt, idx, val|44case opt45when "-n"46hash = val47when "-p"48pass = val49when "-s"50chall = val51when "-h"52usage53else54usage55end56}5758if (not (hash and pass))59usage60end6162if (not chall)63chall = ["1122334455667788"].pack("H*")64else65if not chall =~ /^([a-fA-F0-9]{16})$/66$stderr.puts "[*] Server challenge must be exactly 16 bytes of hexadecimal"67exit68else69chall = [chall].pack("H*")70end71end727374if(hash.length != 48)75$stderr.puts "[*] LANMAN should be exactly 48 bytes of hexadecimal"76exit77end7879if(pass.length != 7)80$stderr.puts "[*] Cracked LANMAN password should be exactly 7 characters"81exit82end8384pass = pass.upcase85hash = hash.downcase8687cset = [*(1..255)].pack("C*").upcase.unpack("C*").uniq8889stime = Time.now.to_f90puts "[*] Trying one character..."910.upto(cset.length-1) do |c1|92test = pass + cset[c1].chr93if(try(test, chall) == hash)94puts "[*] Cracked: #{test}"95exit96end97end98etime = Time.now.to_f - stime99100puts "[*] Trying two characters (eta: #{etime * cset.length} seconds)..."1010.upto(cset.length-1) do |c1|1020.upto(cset.length-1) do |c2|103test = pass + cset[c1].chr + cset[c2].chr104if(try(test, chall) == hash)105puts "[*] Cracked: #{test}"106exit107end108end109end110111puts "[*] Trying three characters (eta: #{etime * cset.length * cset.length} seconds)..."1120.upto(cset.length-1) do |c1|1130.upto(cset.length-1) do |c2|1140.upto(cset.length-1) do |c3|115test = pass + cset[c1].chr + cset[c2].chr + cset[c3].chr116if(try(test, chall) == hash)117puts "[*] Cracked: #{test}"118exit119end120end121end122end123124puts "[*] Trying four characters (eta: #{etime * cset.length * cset.length * cset.length} seconds)..."1250.upto(cset.length-1) do |c1|1260.upto(cset.length-1) do |c2|1270.upto(cset.length-1) do |c3|1280.upto(cset.length-1) do |c4|129test = pass + cset[c1].chr + cset[c2].chr + cset[c3].chr + cset[c4].chr130if(try(test, chall) == hash)131puts "[*] Cracked: #{test}"132exit133end134end135end136end137end138139140