PageRenderTime 64ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/msf/core/exploit/remote/http/nagios_xi/rce_check.rb

https://github.com/rapid7/metasploit-framework
Ruby | 93 lines | 67 code | 9 blank | 17 comment | 6 complexity | a347ddf455cfc4e212b568c8d1ce0529 MD5 | raw file
  1. # -*- coding: binary -*-
  2. # Scans a Nagios XI target and suggests exploit modules to use
  3. module Msf::Exploit::Remote::HTTP::NagiosXi::RceCheck
  4. # Uses the Nagios XI version to check which CVEs and related exploit modules the target is vulnerable to, if any
  5. #
  6. # @param version [Rex::Version] Nagios XI version
  7. # @return [Hash], Hash mapping CVE numbers to exploit module names if the target is vulnerable, empty hash otherwise
  8. def nagios_xi_rce_check(version)
  9. matching_exploits = {}
  10. # Storage area for known exploits that affect versions prior to the one in the hash key
  11. nagios_rce_version_prior = {
  12. '5.2.8' => [
  13. ['NO CVE AVAILABLE', 'nagios_xi_chained_rce']
  14. ]
  15. }
  16. nagios_rce_version_prior.each do |fixed_version, info|
  17. if version < Rex::Version.new(fixed_version)
  18. matching_exploits = add_cve_module_to_hash(matching_exploits, info)
  19. end
  20. end
  21. # Storage area for known exploits that affect only the version in the hash key
  22. nagios_rce_version_equals = {}
  23. unless nagios_rce_version_equals.empty?
  24. nagios_rce_version_equals.each do |fixed_version, info|
  25. if version == Rex::Version.new(fixed_version)
  26. matching_exploits = add_cve_module_to_hash(matching_exploits, info)
  27. end
  28. end
  29. end
  30. # Storage area for known exploits that affect version ranges (inclusive).
  31. # Each hash key should be two versions separated by a hyphen, eg `5.6.0-5.8.5`
  32. nagios_rce_version_range = {
  33. '5.2.0-5.5.6' => [
  34. ['CVE-2018-15708, CVE-2018-15710', 'nagios_xi_magpie_debug']
  35. ],
  36. '5.2.0-5.6.5' => [
  37. ['CVE-2019-15949', 'nagios_xi_plugins_check_plugin_authenticated_rce']
  38. ],
  39. '5.2.6-5.4.12' => [
  40. ['CVE-2018-8733, CVE-2018-8734, CVE-2018-8735, CVE-2018-8736', 'nagios_xi_chained_rce_2_electric_boogaloo']
  41. ],
  42. '5.3.0-5.7.9' => [
  43. ['CVE-2020-35578', 'nagios_xi_plugins_filename_authenticated_rce']
  44. ],
  45. '5.5.0-5.7.3' => [
  46. ['CVE-2020-5792', 'nagios_xi_snmptrap_authenticated_rce']
  47. ],
  48. '5.6.0-5.7.3' => [
  49. ['CVE-2020-5791', 'nagios_xi_mibs_authenticated_rce']
  50. ],
  51. '5.2.0-5.8.4' => [
  52. ['CVE-2021-37343', 'nagios_xi_autodiscovery_webshell']
  53. ]
  54. }
  55. nagios_rce_version_range.each do |fixed_version, info|
  56. lower, higher = fixed_version.split('-')
  57. lower = Rex::Version.new(lower)
  58. higher = Rex::Version.new(higher)
  59. if version >= lower && version <= higher
  60. matching_exploits = add_cve_module_to_hash(matching_exploits, info)
  61. end
  62. end
  63. matching_exploits
  64. end
  65. # Helper function that populates the matching_exploits hash with the contents
  66. # of cve_module_array by setting index 0 of each array as the key and index 1 as the value.
  67. #
  68. # @param matching_exploits [Hash] maps CVE numbers to exploit module names
  69. # @param cve_module_array [Array] contains arrays with a CVE number at index 0 and a matching exploit at index 1
  70. # @return [Hash] updated list of matching exploits, mapping CVE numbers to exploit module names
  71. def add_cve_module_to_hash(matching_exploits, cve_module_array)
  72. # Account for version numbers for which we have multiple exploits
  73. if cve_module_array.length > 1
  74. cve_module_array.each do |cma|
  75. cve, msf_module = cma
  76. matching_exploits[cve] = msf_module
  77. end
  78. else
  79. cve, msf_module = cve_module_array.flatten
  80. matching_exploits[cve] = msf_module
  81. end
  82. matching_exploits
  83. end
  84. end