diff --git a/lib/metasploit/framework/jtr/cracker.rb b/lib/metasploit/framework/jtr/cracker.rb index a5e3a331dc..69ae6808a6 100644 --- a/lib/metasploit/framework/jtr/cracker.rb +++ b/lib/metasploit/framework/jtr/cracker.rb @@ -102,7 +102,7 @@ module Metasploit cmd_string = binary_path raise JohnNotFoundError, 'No suitable John binary was found on the system' if cmd_string.blank? - cmd = [ cmd_string, '--session=' + john_session_id, '--nolog' ] + cmd = [ cmd_string, '--session=' + john_session_id, '--nolog', '--dupe-suppression' ] if config.present? cmd << ( "--config=" + config ) @@ -148,6 +148,36 @@ module Metasploit @session_id ||= ::Rex::Text.rand_text_alphanumeric(8) end + # This method builds the command to show the cracked passwords. + # + # @raise [JohnNotFoundError] if a suitable John binary was never found + # @return [Array] An array set up for {::IO.popen} to use + def show_command + cmd_string = binary_path + raise JohnNotFoundError, 'No suitable John binary was found on the system' if cmd_string.blank? + + pot_file = pot || john_pot_file + cmd = [cmd_string, "--show", "--pot=#{pot_file}", "--format=#{format}" ] + + if config + cmd << "--config=#{config}" + end + + cmd << hash_path + end + + # This runs the show command in john to show cracked passwords. + # + # @yield [String] the output lines from the command + # @return [void] + def show_passwords + ::IO.popen(show_command, "rb") do |fd| + fd.each_line do |line| + yield line + end + end + end + private # This method tries to identify the correct version of the pre-shipped diff --git a/spec/lib/metasploit/framework/jtr/cracker_spec.rb b/spec/lib/metasploit/framework/jtr/cracker_spec.rb index 57b2f6dae6..784ee44691 100644 --- a/spec/lib/metasploit/framework/jtr/cracker_spec.rb +++ b/spec/lib/metasploit/framework/jtr/cracker_spec.rb @@ -116,4 +116,38 @@ describe Metasploit::Framework::JtR::Cracker do end end + + describe '#show_command' do + before(:each) do + expect(cracker).to receive(:binary_path).and_return john_path + end + + it 'starts with the john binary path' do + expect(cracker.show_command[0]).to eq john_path + end + + it 'has the --show flag' do + expect(cracker.show_command).to include '--show' + end + + it 'uses the user supplied john.pot if there is one' do + cracker.pot = pot + expect(cracker.show_command).to include "--pot=#{pot}" + end + + it 'uses default john.pot if the user did not supply one' do + expect(cracker).to receive(:john_pot_file).and_return other_pot + expect(cracker.show_command).to include "--pot=#{other_pot}" + end + + it 'uses the user supplied format directive' do + cracker.format = nt_format + expect(cracker.show_command).to include "--format=#{nt_format}" + end + + it 'puts the path to the has file at the end' do + cracker.hash_path = hash_path + expect(cracker.show_command.last).to eq hash_path + end + end end \ No newline at end of file