|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit3 < Msf::Auxiliary |
| 9 | + include Msf::Exploit::Remote::Tcp |
| 10 | + include Msf::Auxiliary::Scanner |
| 11 | + include Msf::Auxiliary::Report |
| 12 | + |
| 13 | + # TODO: figure out what these do: |
| 14 | + # o: valid command, takes no args, does nothing |
| 15 | + # B, c, F, G, I, M, U, x: all require an "instance id" and possibly other args |
| 16 | + ALLOWED_COMMANDS = %w(a A i g l p t T u w Z) |
| 17 | + |
| 18 | + def initialize |
| 19 | + super( |
| 20 | + 'Name' => 'HP Operations Manager Perfd Environment Scanner', |
| 21 | + 'Description' => %q{ |
| 22 | + This module will enumerate the environment |
| 23 | + HP Operation Manager via daemon perfd. |
| 24 | + }, |
| 25 | + 'Author' => [ 'Roberto Soares Espreto <robertoespreto[at]gmail.com>' ], |
| 26 | + 'License' => MSF_LICENSE |
| 27 | + ) |
| 28 | + |
| 29 | + commands_help = ALLOWED_COMMANDS.join(',') |
| 30 | + register_options( |
| 31 | + [ |
| 32 | + Opt::RPORT(5227), |
| 33 | + OptString.new("COMMANDS", [true, "Command(s) to execute (one or more of #{commands_help})", commands_help]) |
| 34 | + ], self.class) |
| 35 | + end |
| 36 | + |
| 37 | + def commands |
| 38 | + datastore['COMMANDS'].split(/[, ]+/).map(&:strip) |
| 39 | + end |
| 40 | + |
| 41 | + def setup |
| 42 | + super |
| 43 | + if datastore['COMMANDS'] |
| 44 | + bad_commands = commands - ALLOWED_COMMANDS |
| 45 | + unless bad_commands.empty? |
| 46 | + fail ArgumentError, "Bad perfd command(s): #{bad_commands}" |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + def run_host(target_host) |
| 52 | + begin |
| 53 | + |
| 54 | + connect |
| 55 | + banner_resp = sock.get_once |
| 56 | + if banner_resp && banner_resp =~ /^Welcome to the perfd server/ |
| 57 | + banner_resp.strip! |
| 58 | + print_good("#{target_host}:#{rport}, Perfd server banner: #{banner_resp}") |
| 59 | + perfd_service = report_service(host: rhost, port: rport, name: "perfd", proto: "tcp", info: banner_resp) |
| 60 | + sock.puts("\n") |
| 61 | + |
| 62 | + commands.each do |command| |
| 63 | + sock.puts("#{command}\n") |
| 64 | + Rex.sleep(1) |
| 65 | + command_resp = sock.get_once |
| 66 | + |
| 67 | + loot_name = "HP Ops Agent perfd #{command}" |
| 68 | + path = store_loot( |
| 69 | + "hp.ops.agent.perfd.#{command}", |
| 70 | + 'text/plain', |
| 71 | + target_host, |
| 72 | + command_resp, |
| 73 | + nil, |
| 74 | + "HP Ops Agent perfd #{command}", |
| 75 | + perfd_service |
| 76 | + ) |
| 77 | + print_status("#{target_host}:#{rport} - #{loot_name} saved in: #{path}") |
| 78 | + end |
| 79 | + else |
| 80 | + print_error("#{target_host}:#{rport}, Perfd server banner detection failed!") |
| 81 | + end |
| 82 | + disconnect |
| 83 | + rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout |
| 84 | + rescue Timeout::Error => e |
| 85 | + print_error(e.message) |
| 86 | + end |
| 87 | + end |
| 88 | +end |
0 commit comments