Module: Msf::Ui::Console::CommandDispatcher::Analyze

Included in:
Db
Defined in:
lib/msf/ui/console/command_dispatcher/db/analyze.rb

Instance Method Summary collapse

Instance Method Details

#cmd_analyze(*args) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/msf/ui/console/command_dispatcher/db/analyze.rb', line 8

def cmd_analyze(*args)
  unless active?
    print_error "Not currently connected to a data service for analysis."
    return []
  end

  host_ranges = []

  while (arg = args.shift)
    case arg
      when '-h','help'
        cmd_analyze_help
        return
      else
        (arg_host_range(arg, host_ranges))
    end
  end

  host_ranges.push(nil) if host_ranges.empty?

  host_ids = []
  suggested_modules = {}
  each_host_range_chunk(host_ranges) do |host_search|
    next if host_search && host_search.empty?
    eval_hosts_ids = framework.db.hosts(address: host_search).map(&:id)
    if eval_hosts_ids
      eval_hosts_ids.each do |eval_id|
        host_ids.push(eval_id)
      end
    end
  end

  if host_ids.empty?
    print_status("No existing hosts stored to analyze.")
  else

    host_ids.each do |id|
      eval_host = framework.db.hosts(id: id).first
      next unless eval_host
      print_status("Analyzing #{eval_host.address}...")
      unless eval_host.vulns
        print_status("No suggestions for #{eval_host.address}.")
        next
      end

      reported_module = false
      host_result = framework.analyze.host(eval_host)
      found_modules = host_result[:modules]
      found_modules.each do |fnd_mod|
        print_status(fnd_mod.fullname)
        reported_module = true
      end

      suggested_modules[eval_host.address] = found_modules

      print_status("No suggestions for #{eval_host.address}.") unless reported_module
    end
  end
  suggested_modules
end

#cmd_analyze_helpObject


3
4
5
6
# File 'lib/msf/ui/console/command_dispatcher/db/analyze.rb', line 3

def cmd_analyze_help
  print_line "Usage: analyze [addr1 addr2 ...]"
  print_line
end

#cmd_analyze_tabs(_str, words) ⇒ Object


69
70
71
72
73
74
75
76
77
78
# File 'lib/msf/ui/console/command_dispatcher/db/analyze.rb', line 69

def cmd_analyze_tabs(_str, words)
  return [] unless framework.db.active

  hosts = framework.db.hosts.map(&:address)

  # Limit completion to supplied host if it's the only one
  return [] if words.length > 1 && hosts.length == 1

  hosts
end