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/lib/metasploit/framework/hashes.rb
Views: 11779
module Metasploit1module Framework2# This module contains utilities for hashes, including one to identify them3# Resource list:4# https://code.google.com/archive/p/hash-identifier/5# https://github.com/psypanda/hashID6# https://hashcat.net/wiki/doku.php?id=example_hashes7# http://pentestmonkey.net/cheat-sheet/john-the-ripper-hash-formats8# https://openwall.info/wiki/john/sample-hashes9# QNX formats -> https://moar.so/blog/qnx-password-hash-formats.html10# rubocop:disable Metrics/ModuleLength11module Hashes12JTR_NTLMV1 = 'netntlm'.freeze13JTR_NTLMV2 = 'netntlmv2'.freeze14def self.identify_hash(hash)15# @param [str] a string of a hashed password16# @return [String] the jtr type or empty string on no match17hash = hash.to_s.strip18case19# operating systems20when hash.start_with?('$1$') && hash.length == 3421return 'md5'22when hash.start_with?('$2$') && hash.length == 59,23hash.start_with?('$2a$') && hash.length == 60,24hash.start_with?('$2b$') && hash.length == 60,25hash.start_with?('$2x$') && hash.length == 60,26hash.start_with?('$2y$') && hash.length == 6027return 'bf' # bcrypt28when hash.start_with?('$5$') && hash.split('$').last.length == 4329# we dont check full length since it may have 'rounds=' in the [1] area or not with an arbitrary length number30return 'sha256,crypt'31when hash.start_with?('$6$') && hash.split('$').last.length == 8632# we dont check full length since it may have 'rounds=' in the [1] area or not with an arbitrary length number33return 'sha512,crypt'34when hash.start_with?('@S@') && hash.length == 14835return 'qnx,sha512'36when hash.start_with?('@s@') && hash.length == 8437return 'qnx,sha256'38when hash.start_with?('@m@') && hash.length == 5239return 'qnx,md5'40when hash.start_with?('$y$') && hash.split('$').last.length == 4341return 'yescrypt'42when hash.start_with?('_') && hash.length == 2043return 'des,bsdi,crypt'44when hash =~ %r{^[./\dA-Za-z]{13}$} # hash.length == 1345return 'des,crypt'46when hash =~ /^\$dynamic_82\$[\da-f]{128}\$HEX\$[\da-f]{32}$/ # jtr vmware ldap https://github.com/rapid7/metasploit-framework/pull/13865#issuecomment-66071810847return 'dynamic_82'48when hash.start_with?(/{SSHA}/i)49return 'ssha'50when hash.start_with?(/{SHA512}/i)51return 'raw-sha512'52when hash.start_with?(/{SHA256}/i)53return 'raw-sha256'54when hash.start_with?(/{SHA}/i)55return 'raw-sha1'56when hash.start_with?(/{MD5}/i)57return 'raw-md5'58when hash.start_with?(/{SMD5}/i)59return 'smd5'60when hash.start_with?(/{SSHA256}/i)61return 'ssha256'62when hash.start_with?(/{SSHA512}/i)63return 'ssha512'64# windows65when hash.length == 65 && hash =~ /^[\da-fA-F]{32}:[\da-fA-F]{32}$/ && hash.split(':').first.upcase == 'AAD3B435B51404EEAAD3B435B51404EE'66return 'nt'67when hash.length == 65 && hash =~ /^[\da-fA-F]{32}:[\da-fA-F]{32}$/68return 'lm'69when hash =~ /^[^\\\/:*?"<>|]{1,20}[:]{2,3}([^\\\/:*?"<>|]{1,20})?:[a-f0-9]{48}:[a-f0-9]{48}:[a-f0-9]{16}$/70return 'netntlm'71when hash =~ /^([^\\\/:*?"<>|]{1,20}\\)?[^\\\/:*?"<>|]{1,20}[:]{2,3}([^\\\/:*?"<>|]{1,20}:)?[^\\\/:*?"<>|]{1,20}:[a-f0-9]{32}:[a-f0-9]+$/72return 'netntlmv2'73# OSX74when hash.start_with?('$ml$') && hash.split('$').last.length == 25675return 'pbkdf2-hmac-sha512,osx' # 10.8+76when hash =~ /^[\da-fA-F]{48}$/ # hash.length == 4877return 'xsha,osx' # 10.4-10.678# databases79when hash.start_with?('0x0100') && hash.length == 5480return 'mssql05'81when hash.start_with?('0x0100') && hash.length == 9482return 'mssql'83when hash.start_with?('0x0200') && hash.length == 14284return 'mssql12'85when hash =~ /^[\da-f]{16}$/ # hash.length == 1686return 'mysql' # mysql323 (pre 4.1)87when hash.start_with?('*') && hash.length == 4188return 'mysql-sha1' # mysql 4.1+89when hash.start_with?('md5') && hash.length == 3590return 'postgres'91when hash =~ /^[\da-fA-F]{16}$/92return 'des,oracle' # pre 11g93when hash =~ /^S:[\dA-F]{60}$/94return 'raw-sha1,oracle11'95when hash =~ /^S:[\dA-F]{60};H:[\dA-F]{32};T:[\dA-F]{160}$/96return 'raw-sha1,oracle'97when hash =~ /^H:[\dA-F]{32};T:[\dA-F]{160}$/98return 'pbkdf2,oracle12c'99# webapps100when hash.start_with?('$P$') && hash.length == 34,101hash.start_with?('$H$') && hash.length == 34102return 'phpass' # wordpress, drupal, phpbb3 (H not P)103when hash.start_with?('$ml$') && hash.length == 203104return 'PBKDF2-HMAC-SHA512'105when hash.start_with?('{PKCS5S2}') && hash.length == 73106return 'PBKDF2-HMAC-SHA1'107when hash.start_with?('$B$') && hash.split('$').last.length == 32108return 'mediawiki'109# mobile110when hash =~ /^[A-F0-9]{40}:[a-f0-9]{16}$/111return 'android-sha1'112when hash =~ /^[A-F0-9]{32}:[a-f0-9]{16}$/113return 'android-md5'114# other115when hash =~ /^<\d+@.+?>#\w{32}$/116return 'hmac-md5'117when hash.length == 114 && hash.start_with?('$M$')118return 'F5-Secure-Vault'119when hash =~ /^M\$[[:print:]]+#[\da-fA-F]{32}(?:(?::[[:print:]]*$)|$)/120return 'mscash'121when hash =~ /^\$DCC2\$\d+#[[:print:]]+#[\da-fA-F]{32}(?:(?::[[:print:]]*$)|$)/122return 'mscash2'123when hash =~ /^\*?[\da-fA-F]{32}\*[\da-fA-F]{32}$/124# we accept the beginning star as optional125return 'vnc'126when hash =~ /^\$pbkdf2-sha256\$[0-9]+\$[a-z0-9\/.]+\$[a-z0-9\/.]{43}$/i127return 'pbkdf2-sha256'128end129''130end131# rubocop:enable Metrics/ModuleLength132end133end134end135136137