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/spec/lib/metasploit/framework/hashes/identify_spec.rb
Views: 11788
require 'spec_helper'1require 'bcrypt'23=begin4#!/usr/bin/python5# bcrypts generated with python's passlib6from passlib import hash7print("MD5: %s") %(hash.md5_crypt.hash("password"))8print("BCrypt 2: %s") %(hash.bcrypt.using(ident="2").hash("password"))9print("BCrypt 2a: %s") %(hash.bcrypt.using(ident="2a").hash("password"))10print("BCrypt 2b: %s") %(hash.bcrypt.using(ident="2b").hash("password"))11print("BCrypt 2y: %s") %(hash.bcrypt.using(ident="2y").hash("password"))12# bcrypt.using(ident="2x").hash("password")13print("SHA256: %s") %(hash.sha256_crypt.hash("password"))14print("SHA512: %s") %(hash.sha512_crypt.hash("password"))15print("BSDi: %s") %(hash.bsdi_crypt.hash("password"))16print("DES: %s") %(hash.des_crypt.hash("password"))17=end1819RSpec.describe Metasploit::Framework::Hashes do20describe 'identify_md5' do21it 'returns md5' do22hash = described_class.identify_hash('$1$IEHUWAxH$nMC1edxSFa4SaKH7hi2.P1')23expect(hash).to match('md5')24end25end2627describe 'identify_blofish' do28it 'returns bf' do29hash = described_class.identify_hash('$2$12$YuKGRH4GwF0PoeS9ZGsxyucAw4ju7LUUm6zllt85HeleuKBRb0n5G')30expect(hash).to match('bf')31end32end3334describe 'identify_blofish_a' do35it 'returns bf' do36# looks like BCrypt can only generate 2a in ruby as of april 201937hash = described_class.identify_hash(BCrypt::Password.create('password'))38expect(hash).to match('bf')39end40end4142describe 'identify_blofish_b' do43it 'returns bf' do44hash = described_class.identify_hash('$2b$12$LQRJHRdK8ubs.dOWBFc/6uhNNeuwMNzEBxjG5YSFu3swmnk2pMtSq')45expect(hash).to match('bf')46end47end4849describe 'identify_blofish_x' do50it 'returns bf' do51hash = described_class.identify_hash('$2x$12$LQRJHRdK8ubs.dOWBFc/6uhNNeuwMNzEBxjG5YSFu3swmnk2pMtSq')52expect(hash).to match('bf')53end54end5556describe 'identify_blofish_y' do57it 'returns bf' do58hash = described_class.identify_hash('$2y$12$EMrTs6wKK3Qj4u7jPL59Bug9JHBGhZKnZxTYKQAE9CEFBq9mDmfL2')59expect(hash).to match('bf')60end61end6263describe 'identify_sha256_rounds' do64it 'returns sha256,crypt' do65hash = described_class.identify_hash('$5$rounds=535000$28N3kN/W4y.z/VwS$jpaW4.rR/57IlqhJRpZDu9FoZu/jr.ksbRJJZjJSZN7')66expect(hash).to match('sha256,crypt')67end68end6970describe 'identify_sha512_rounds' do71it 'returns sha512,crypt' do72hash = described_class.identify_hash('$6$rounds=656000$bnopPiXhQ2jjaa9h$H9.hNSwpg5PaUTtEEgTAjoZFsUKmONplIXLFe1nd0/QTyw/DMQhHuyChA2glT.BbYe9gJjE5RD.yog8Z5tACA/')73expect(hash).to match('sha512,crypt')74end75end7677describe 'identify_sha512_norounds' do78it 'returns sha512,crypt' do79hash = described_class.identify_hash('$6$52450745$k5ka2p8bFuSmoVT1tzOyyuaREkkKBcCNqoDKzYiJL9RaE8yMnPgh2XzzF0NDrUhgrcLwg78xs1w5pJiypEdFX/')80expect(hash).to match('sha512,crypt')81end82end8384describe 'identify_qnx_sha256' do85it 'returns qnx,sha256' do86hash = described_class.identify_hash('@s@0b365cab7e17ee1e7e1a90078501cc1aa85888d6da34e2f5b04f5c614b882a93@5498317092471604')87expect(hash).to match('qnx,sha256')88end89end9091describe 'identify_qnx_sha512' do92it 'returns qnx,sha512' do93hash = described_class.identify_hash('@S@715df9e94c097805dd1e13c6a40f331d02ce589765a2100ec7435e76b978d5efc364ce10870780622cee003c9951bd92ec1020c924b124cfff7e0fa1f73e3672@2257314490293159')94expect(hash).to match('qnx,sha512')95end96end9798describe 'identify_qnx_md5' do99it 'returns qnx,md5' do100hash = described_class.identify_hash('@m@75f6f129f9c9e77b6b1b78f791ed764a@8741857532330050')101expect(hash).to match('qnx,md5')102end103end104105describe 'identify_bsdi' do106it 'returns des,bsdi,crypt' do107hash = described_class.identify_hash('_7C/.WncdBNA9AL2CyaM')108expect(hash).to match('des,bsdi,crypt')109end110end111112describe 'identify_des' do113it 'returns des,crypt' do114hash = described_class.identify_hash('ItkroId4UAOF.')115expect(hash).to match('des,crypt')116end117end118119describe 'identify_pbkdf2_osx' do120it 'returns pbkdf2-hmac-sha512,osx' do121hash = described_class.identify_hash('$ml$49504$0dba6246bd38266b2e827ff7e7271380757c71d653893aa361d5902398302369$c5f198639915a101c99af326dffe13e8f14456be8fd2312a39a777b92178804e204ca4fee12a8667871440eff4288e811d86d746c6d96a60c919c3418dfebba42f329f5d73c0372d636d61d5dfda1add61af36c70e4acd771276107209e643ae92a0f43e95a452744e50fb4540d9bdf4e0b701725d7db488fbe18c1ab7737c6b')122expect(hash).to match('pbkdf2-hmac-sha512,osx')123end124end125126describe 'identify_sha_osx' do127it 'returns xsha,osx' do128hash = described_class.identify_hash('1430823483d07626ef8be3fda2ff056d0dfd818dbfe47683')129expect(hash).to match('xsha,osx')130end131end132133describe 'identify_mssql05' do134it 'returns mssql05' do135hash = described_class.identify_hash('0x01004086CEB6BF932BC4151A1AF1F13CD17301D70816A8886908')136expect(hash).to match('mssql05')137end138end139140describe 'identify_mssql' do141it 'returns mssql' do142hash = described_class.identify_hash('0x0100A607BA7C54A24D17B565C59F1743776A10250F581D482DA8B6D6261460D3F53B279CC6913CE747006A2E3254')143expect(hash).to match('mssql')144end145end146147describe 'identify_mssql12' do148it 'returns mssql12' do149hash = described_class.identify_hash('0x0200F733058A07892C5CACE899768F89965F6BD1DED7955FE89E1C9A10E27849B0B213B5CE92CC9347ECCB34C3EFADAF2FD99BFFECD8D9150DD6AACB5D409A9D2652A4E0AF16')150expect(hash).to match('mssql12')151end152end153154describe 'identify_mysql' do155it 'returns mysql' do156hash = described_class.identify_hash('6f8c114b58f2ce9e')157expect(hash).to match('mysql')158end159end160161describe 'identify_mysql_sha1' do162it 'returns mysql_sha1' do163hash = described_class.identify_hash('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4')164expect(hash).to match('mysql-sha1')165end166end167168describe 'identify_lanman' do169it 'returns lm' do170hash = described_class.identify_hash('E52CAC67419A9A224A3B108F3FA6CB6D:8846F7EAEE8FB117AD06BDD830B7586C')171expect(hash).to match('lm')172end173end174175describe 'identify_ntlm' do176it 'returns nt' do177hash = described_class.identify_hash('AAD3B435B51404EEAAD3B435B51404EE:8846F7EAEE8FB117AD06BDD830B7586C')178expect(hash).to match('nt')179end180end181182describe 'identify_postgres' do183it 'returns postgres' do184hash = described_class.identify_hash('md5be86a79bf2043622d58d5453c47d4860')185expect(hash).to match('postgres')186end187end188189describe 'identify_oracle_des' do190it 'returns des,oracle' do191hash = described_class.identify_hash('4F8BC1809CB2AF77')192expect(hash).to match('des,oracle')193end194end195196describe 'identify_oracle11_S' do197it 'returns raw-sha1,oracle' do198hash = described_class.identify_hash('S:BFAF1ED5A8D39CC10D07DAF03A175C65198359874DAD92F081BE09B89162')199expect(hash).to match('raw-sha1,oracle')200end201end202203describe 'identify_oracle_SHT' do204it 'returns raw-sha1,oracle' do205hash = described_class.identify_hash('S:8F2D65FB5547B71C8DA3760F10960428CD307B1C6271691FC55C1F56554A;H:DC9894A01797D91D92ECA1DA66242209;T:23D1F8CAC9001F69630ED2DD8DF67DD3BE5C470B5EA97B622F757FE102D8BF14BEDC94A3CC046D10858D885DB656DC0CBF899A79CD8C76B788744844CADE54EEEB4FDEC478FB7C7CBFBBAC57BA3EF22C')206expect(hash).to match('raw-sha1,oracle')207end208end209210describe 'identify_oracle_HT' do211it 'returns ' do212hash = described_class.identify_hash('H:DC9894A01797D91D92ECA1DA66242209;T:23D1F8CAC9001F69630ED2DD8DF67DD3BE5C470B5EA97B622F757FE102D8BF14BEDC94A3CC046D10858D885DB656DC0CBF899A79CD8C76B788744844CADE54EEEB4FDEC478FB7C7CBFBBAC57BA3EF22C')213expect(hash).to match('pbkdf2,oracle12c')214end215end216217describe 'identify_phpass_P' do218it 'returns phpass' do219hash = described_class.identify_hash('$P$984478476IagS59wHZvyQMArzfx58u.')220expect(hash).to match('phpass')221end222end223224describe 'identify_phpass_H' do225it 'returns phpass' do226hash = described_class.identify_hash('$H$984478476IagS59wHZvyQMArzfx58u.')227expect(hash).to match('phpass')228end229end230231describe 'identify_PBKDF2-HMAC-SHA512' do232it 'returns PBKDF2-HMAC-SHA512' do233hash = described_class.identify_hash('$ml$35460$93a94bd24b5de64d79a5e49fa372827e739f4d7b6975c752c9a0ff1e5cf72e05$752351df64dd2ce9dc9c64a72ad91de6581a15c19176266b44d98919dfa81f0f96cbcb20a1ffb400718c20382030f637892f776627d34e021bad4f81b7de8222')234expect(hash).to match('PBKDF2-HMAC-SHA512')235end236end237238describe 'identify_PBKDF2-HMAC-SHA1' do239it 'returns PBKDF2-HMAC-SHA1' do240hash = described_class.identify_hash('{PKCS5S2}8WEZjkCbLWysbcbZ5PRgMbdJgJOhkzRT3y1jxOqke2z1Zr79q8ypugFQEYaMoIZt')241expect(hash).to match('PBKDF2-HMAC-SHA1')242end243end244245describe 'identify_mediawiki' do246it 'returns mediawiki' do247hash = described_class.identify_hash('$B$113$de2874e33da25313d808d2a8cbf31485')248expect(hash).to match('mediawiki')249end250end251252describe 'identify_android_sha1' do253it 'returns android-sha1' do254hash = described_class.identify_hash('EA8457DE97836C955082AE77DBE2CD86A4E8BC0E:4aafc54dc502e88b')255expect(hash).to match('android-sha1')256end257end258259describe 'identify_hmac_md5' do260it 'returns hmac-md5' do261hash = described_class.identify_hash('<[email protected]>#332b463fcf3baac718c63860a7093df4')262expect(hash).to match('hmac-md5')263end264end265266describe 'identify_f5_secure_value' do267it 'returns F5-Secure-Vault' do268hash = described_class.identify_hash('$M$iE$cIdy72xi7Xbk3kazSrpdfscd+oD1pdsXJbwhvhMPiss4Iw0RKIJQS/CuSReZl/+kseKpPCNpBWNWOOaBCwlQ0v4sl7ZUkxCymh5pfFNAjhc=')269expect(hash).to match('F5-Secure-Vault')270end271end272273describe 'identify_mscash' do274it 'returns mscash' do275hash = described_class.identify_hash('M$3060147285011#4dd8965d1d476fa0d026722989a6b772:::')276expect(hash).to match('mscash')277end278end279280describe 'identify_mscash2' do281it 'returns mscash2' do282hash = described_class.identify_hash('$DCC2$10240#username#5f9d79a71fa6d92c31cf16d6eaa23435:::')283expect(hash).to match('mscash2')284end285end286287describe 'identify_netntlm' do288it 'returns netntlm' do289hash = described_class.identify_hash('u4-netntlm::kNS:338d08f8e26de93300000000000000000000000000000000:9526fb8c23a90751cdd619b6cea564742e1e4bf33006ba41:cb8086049ec4736c')290expect(hash).to match('netntlm')291end292end293294describe 'identify_netntlmv2' do295it 'returns netntlmv2' do296hash = described_class.identify_hash('admin::N46iSNekpT:08ca45b7d7ea58ee:88dcbe4446168966a153a0064958dac6:5c7830315c7830310000000000000b45c67103d07d7b95acd12ffa11230e0000000052920b85f78d013c31cdb3b92f5d765c783030')297expect(hash).to match('netntlmv2')298end299end300301describe 'identify_vnc' do302it 'returns vnc' do303hash = described_class.identify_hash('*00112233445566778899aabbccddeeff*6feb3cb1f07b66151656b5832341f223')304expect(hash).to match('vnc')305end306it 'returns vnc on uppercase' do307hash = described_class.identify_hash('*00112233445566778899aabbccddeeff*6feb3cb1f07b66151656b5832341f223'.upcase)308expect(hash).to match('vnc')309end310it 'returns vnc on no leading star' do311hash = described_class.identify_hash('00112233445566778899aabbccddeeff*6feb3cb1f07b66151656b5832341f223')312expect(hash).to match('vnc')313end314end315316describe 'identify_pbkdf2-sha256' do317it 'returns pbkdf2-sha256' do318hash = described_class.identify_hash('$pbkdf2-sha256$260000$Q1hzYjU5dFNMWm05QUJCTg$s.vmjGlIV0ZKV1Sp3dTdrcn/i9CTqxPZ0klve4HreeU')319expect(hash).to match('pbkdf2-sha256')320end321end322323describe 'identify_empty_string' do324it 'returns empty string' do325hash = described_class.identify_hash('')326expect(hash).to match('')327end328end329330describe 'identify_nil' do331it 'returns empty string' do332hash = described_class.identify_hash(nil)333expect(hash).to match('')334end335end336337describe 'identify_shadow_line' do338it 'returns empty string' do339hash = described_class.identify_hash('root:$1$TDQFedzX$.kv51AjM.FInu0lrH1dY30:15045:0:99999:7:::')340expect(hash).to match('')341end342end343344describe 'identify_un_pass' do345it 'returns empty string' do346hash = described_class.identify_hash('root:$1$TDQFedzX$.kv51AjM.FInu0lrH1dY30')347expect(hash).to match('')348end349end350351describe 'identify_ascii_as_nothing' do352it 'returns empty string' do353hash = described_class.identify_hash('This is just some words')354expect(hash).to match('')355end356end357end358359360