wg-metasploit_data_models 4.1.4.01 → 4.1.4.02

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (440) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.github/workflows/verify.yml +68 -0
  4. data/.gitignore +29 -0
  5. data/.rspec +3 -0
  6. data/.simplecov +38 -0
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +6 -0
  9. data/CONTRIBUTING.md +133 -0
  10. data/Gemfile +46 -0
  11. data/LICENSE +27 -0
  12. data/README.md +65 -0
  13. data/RELEASING.md +82 -0
  14. data/Rakefile +72 -0
  15. data/UPGRADING.md +1 -0
  16. data/app/models/mdm/api_key.rb +61 -0
  17. data/app/models/mdm/async_callback.rb +64 -0
  18. data/app/models/mdm/client.rb +50 -0
  19. data/app/models/mdm/cred.rb +205 -0
  20. data/app/models/mdm/event.rb +83 -0
  21. data/app/models/mdm/exploit_attempt.rb +105 -0
  22. data/app/models/mdm/exploited_host.rb +42 -0
  23. data/app/models/mdm/host.rb +619 -0
  24. data/app/models/mdm/host_detail.rb +62 -0
  25. data/app/models/mdm/host_tag.rb +49 -0
  26. data/app/models/mdm/listener.rb +82 -0
  27. data/app/models/mdm/loot.rb +161 -0
  28. data/app/models/mdm/macro.rb +62 -0
  29. data/app/models/mdm/mod_ref.rb +24 -0
  30. data/app/models/mdm/module/action.rb +33 -0
  31. data/app/models/mdm/module/arch.rb +28 -0
  32. data/app/models/mdm/module/author.rb +34 -0
  33. data/app/models/mdm/module/detail.rb +388 -0
  34. data/app/models/mdm/module/mixin.rb +31 -0
  35. data/app/models/mdm/module/platform.rb +29 -0
  36. data/app/models/mdm/module/ref.rb +42 -0
  37. data/app/models/mdm/module/target.rb +37 -0
  38. data/app/models/mdm/nexpose_console.rb +121 -0
  39. data/app/models/mdm/note.rb +125 -0
  40. data/app/models/mdm/payload.rb +103 -0
  41. data/app/models/mdm/profile.rb +45 -0
  42. data/app/models/mdm/ref.rb +48 -0
  43. data/app/models/mdm/route.rb +28 -0
  44. data/app/models/mdm/service.rb +267 -0
  45. data/app/models/mdm/session.rb +203 -0
  46. data/app/models/mdm/session_event.rb +44 -0
  47. data/app/models/mdm/tag.rb +114 -0
  48. data/app/models/mdm/task.rb +168 -0
  49. data/app/models/mdm/task_cred.rb +45 -0
  50. data/app/models/mdm/task_host.rb +41 -0
  51. data/app/models/mdm/task_service.rb +41 -0
  52. data/app/models/mdm/task_session.rb +41 -0
  53. data/app/models/mdm/user.rb +230 -0
  54. data/app/models/mdm/vuln.rb +204 -0
  55. data/app/models/mdm/vuln_attempt.rb +76 -0
  56. data/app/models/mdm/vuln_detail.rb +156 -0
  57. data/app/models/mdm/vuln_ref.rb +21 -0
  58. data/app/models/mdm/web_form.rb +53 -0
  59. data/app/models/mdm/web_page.rb +92 -0
  60. data/app/models/mdm/web_site.rb +113 -0
  61. data/app/models/mdm/web_vuln.rb +193 -0
  62. data/app/models/mdm/wmap_request.rb +101 -0
  63. data/app/models/mdm/wmap_target.rb +56 -0
  64. data/app/models/mdm/workspace.rb +286 -0
  65. data/app/models/metasploit_data_models/automatic_exploitation/match.rb +43 -0
  66. data/app/models/metasploit_data_models/automatic_exploitation/match_result.rb +71 -0
  67. data/app/models/metasploit_data_models/automatic_exploitation/match_set.rb +40 -0
  68. data/app/models/metasploit_data_models/automatic_exploitation/run.rb +29 -0
  69. data/app/models/metasploit_data_models/ip_address/v4/cidr.rb +14 -0
  70. data/app/models/metasploit_data_models/ip_address/v4/nmap.rb +14 -0
  71. data/app/models/metasploit_data_models/ip_address/v4/range.rb +12 -0
  72. data/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list.rb +125 -0
  73. data/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range.rb +12 -0
  74. data/app/models/metasploit_data_models/ip_address/v4/segment/single.rb +123 -0
  75. data/app/models/metasploit_data_models/ip_address/v4/segmented.rb +200 -0
  76. data/app/models/metasploit_data_models/ip_address/v4/single.rb +53 -0
  77. data/app/models/metasploit_data_models/module_run.rb +213 -0
  78. data/app/models/metasploit_data_models/search/operation/ip_address.rb +60 -0
  79. data/app/models/metasploit_data_models/search/operation/port/number.rb +25 -0
  80. data/app/models/metasploit_data_models/search/operation/port/range.rb +79 -0
  81. data/app/models/metasploit_data_models/search/operation/range.rb +56 -0
  82. data/app/models/metasploit_data_models/search/operator/ip_address.rb +33 -0
  83. data/app/models/metasploit_data_models/search/operator/multitext.rb +73 -0
  84. data/app/models/metasploit_data_models/search/operator/port/list.rb +67 -0
  85. data/app/models/metasploit_data_models/search/visitor/attribute.rb +17 -0
  86. data/app/models/metasploit_data_models/search/visitor/includes.rb +47 -0
  87. data/app/models/metasploit_data_models/search/visitor/joins.rb +67 -0
  88. data/app/models/metasploit_data_models/search/visitor/method.rb +16 -0
  89. data/app/models/metasploit_data_models/search/visitor/relation.rb +91 -0
  90. data/app/models/metasploit_data_models/search/visitor/where.rb +128 -0
  91. data/config/initializers/arel_helper.rb +5 -0
  92. data/config/initializers/ipaddr.rb +29 -0
  93. data/config/locales/en.yml +94 -0
  94. data/console_db.yml +9 -0
  95. data/db/migrate/000_create_tables.rb +79 -0
  96. data/db/migrate/001_add_wmap_tables.rb +35 -0
  97. data/db/migrate/002_add_workspaces.rb +36 -0
  98. data/db/migrate/003_move_notes.rb +20 -0
  99. data/db/migrate/004_add_events_table.rb +16 -0
  100. data/db/migrate/005_expand_info.rb +58 -0
  101. data/db/migrate/006_add_timestamps.rb +26 -0
  102. data/db/migrate/007_add_loots.rb +20 -0
  103. data/db/migrate/008_create_users.rb +16 -0
  104. data/db/migrate/009_add_loots_ctype.rb +10 -0
  105. data/db/migrate/010_add_alert_fields.rb +16 -0
  106. data/db/migrate/011_add_reports.rb +19 -0
  107. data/db/migrate/012_add_tasks.rb +24 -0
  108. data/db/migrate/013_add_tasks_result.rb +10 -0
  109. data/db/migrate/014_add_loots_fields.rb +12 -0
  110. data/db/migrate/015_rename_user.rb +16 -0
  111. data/db/migrate/016_add_host_purpose.rb +10 -0
  112. data/db/migrate/017_expand_info2.rb +58 -0
  113. data/db/migrate/018_add_workspace_user_info.rb +29 -0
  114. data/db/migrate/019_add_workspace_desc.rb +23 -0
  115. data/db/migrate/020_add_user_preferences.rb +11 -0
  116. data/db/migrate/021_standardize_info_and_data.rb +18 -0
  117. data/db/migrate/022_enlarge_event_info.rb +10 -0
  118. data/db/migrate/023_add_report_downloaded_at.rb +10 -0
  119. data/db/migrate/024_convert_service_info_to_text.rb +12 -0
  120. data/db/migrate/025_add_user_admin.rb +19 -0
  121. data/db/migrate/026_add_creds_table.rb +19 -0
  122. data/db/migrate/20100819123300_migrate_cred_data.rb +154 -0
  123. data/db/migrate/20100824151500_add_exploited_table.rb +16 -0
  124. data/db/migrate/20100908001428_add_owner_to_workspaces.rb +9 -0
  125. data/db/migrate/20100911122000_add_report_templates.rb +18 -0
  126. data/db/migrate/20100916151530_require_admin_flag.rb +15 -0
  127. data/db/migrate/20100916175000_add_campaigns_and_templates.rb +61 -0
  128. data/db/migrate/20100920012100_add_generate_exe_column.rb +8 -0
  129. data/db/migrate/20100926214000_add_template_prefs.rb +11 -0
  130. data/db/migrate/20101001000000_add_web_tables.rb +57 -0
  131. data/db/migrate/20101002000000_add_query.rb +10 -0
  132. data/db/migrate/20101007000000_add_vuln_info.rb +15 -0
  133. data/db/migrate/20101008111800_add_clients_to_campaigns.rb +10 -0
  134. data/db/migrate/20101009023300_add_campaign_attachments.rb +15 -0
  135. data/db/migrate/20101104135100_add_imported_creds.rb +17 -0
  136. data/db/migrate/20101203000000_fix_web_tables.rb +34 -0
  137. data/db/migrate/20101203000001_expand_host_comment.rb +12 -0
  138. data/db/migrate/20101206212033_add_limit_to_network_to_workspaces.rb +9 -0
  139. data/db/migrate/20110112154300_add_module_uuid_to_tasks.rb +9 -0
  140. data/db/migrate/20110204112800_add_host_tags.rb +28 -0
  141. data/db/migrate/20110317144932_add_session_table.rb +110 -0
  142. data/db/migrate/20110414180600_add_local_id_to_session_table.rb +11 -0
  143. data/db/migrate/20110415175705_add_routes_table.rb +18 -0
  144. data/db/migrate/20110422000000_convert_binary.rb +73 -0
  145. data/db/migrate/20110425095900_add_last_seen_to_sessions.rb +8 -0
  146. data/db/migrate/20110513143900_track_successful_exploits.rb +31 -0
  147. data/db/migrate/20110517160800_rename_and_prune_nessus_vulns.rb +26 -0
  148. data/db/migrate/20110527000000_add_task_id_to_reports_table.rb +11 -0
  149. data/db/migrate/20110527000001_add_api_keys_table.rb +12 -0
  150. data/db/migrate/20110606000001_add_macros_table.rb +16 -0
  151. data/db/migrate/20110622000000_add_settings_to_tasks_table.rb +12 -0
  152. data/db/migrate/20110624000001_add_listeners_table.rb +19 -0
  153. data/db/migrate/20110625000001_add_macro_to_listeners_table.rb +12 -0
  154. data/db/migrate/20110630000001_add_nexpose_consoles_table.rb +21 -0
  155. data/db/migrate/20110630000002_add_name_to_nexpose_consoles_table.rb +12 -0
  156. data/db/migrate/20110717000001_add_profiles_table.rb +15 -0
  157. data/db/migrate/20110727163801_expand_cred_ptype_column.rb +9 -0
  158. data/db/migrate/20110730000001_add_initial_indexes.rb +85 -0
  159. data/db/migrate/20110812000001_prune_indexes.rb +23 -0
  160. data/db/migrate/20110922000000_expand_notes.rb +9 -0
  161. data/db/migrate/20110928101300_add_mod_ref_table.rb +17 -0
  162. data/db/migrate/20111011110000_add_display_name_to_reports_table.rb +24 -0
  163. data/db/migrate/20111203000000_inet_columns.rb +13 -0
  164. data/db/migrate/20111204000000_more_inet_columns.rb +17 -0
  165. data/db/migrate/20111210000000_add_scope_to_hosts.rb +9 -0
  166. data/db/migrate/20120126110000_add_virtual_host_to_hosts.rb +9 -0
  167. data/db/migrate/20120411173220_rename_workspace_members.rb +9 -0
  168. data/db/migrate/20120601152442_add_counter_caches_to_hosts.rb +21 -0
  169. data/db/migrate/20120625000000_add_vuln_details.rb +34 -0
  170. data/db/migrate/20120625000001_add_host_details.rb +16 -0
  171. data/db/migrate/20120625000002_expand_details.rb +16 -0
  172. data/db/migrate/20120625000003_expand_details2.rb +24 -0
  173. data/db/migrate/20120625000004_add_vuln_attempts.rb +19 -0
  174. data/db/migrate/20120625000005_add_vuln_and_host_counter_caches.rb +14 -0
  175. data/db/migrate/20120625000006_add_module_details.rb +118 -0
  176. data/db/migrate/20120625000007_add_exploit_attempts.rb +26 -0
  177. data/db/migrate/20120625000008_add_fail_message.rb +12 -0
  178. data/db/migrate/20120718202805_add_owner_and_payload_to_web_vulns.rb +13 -0
  179. data/db/migrate/20130228214900_change_required_columns_to_null_false_in_web_vulns.rb +19 -0
  180. data/db/migrate/20130412154159_change_foreign_key_in_module_actions.rb +25 -0
  181. data/db/migrate/20130412171844_change_foreign_key_in_module_archs.rb +25 -0
  182. data/db/migrate/20130412173121_change_foreign_key_in_module_authors.rb +25 -0
  183. data/db/migrate/20130412173640_change_foreign_key_in_module_mixins.rb +25 -0
  184. data/db/migrate/20130412174254_change_foreign_key_in_module_platforms.rb +25 -0
  185. data/db/migrate/20130412174719_change_foreign_key_in_module_refs.rb +25 -0
  186. data/db/migrate/20130412175040_change_foreign_key_in_module_targets.rb +25 -0
  187. data/db/migrate/20130423211152_add_creds_counter_cache.rb +24 -0
  188. data/db/migrate/20130430151353_change_required_columns_to_null_false_in_hosts.rb +11 -0
  189. data/db/migrate/20130430162145_enforce_address_uniqueness_in_workspace_in_hosts.rb +101 -0
  190. data/db/migrate/20130510021637_remove_campaigns.rb +11 -0
  191. data/db/migrate/20130515164311_change_web_vulns_confidence_to_integer.rb +48 -0
  192. data/db/migrate/20130515172727_valid_mdm_web_vuln_params.rb +30 -0
  193. data/db/migrate/20130516204810_making_vulns_refs_a_real_ar_model.rb +5 -0
  194. data/db/migrate/20130522001343_create_task_creds.rb +9 -0
  195. data/db/migrate/20130522032517_create_task_hosts.rb +9 -0
  196. data/db/migrate/20130522041110_create_task_services.rb +9 -0
  197. data/db/migrate/20130525015035_remove_campaign_id_from_clients.rb +9 -0
  198. data/db/migrate/20130525212420_drop_table_imported_creds.rb +14 -0
  199. data/db/migrate/20130531144949_making_host_tags_a_real_ar_model.rb +6 -0
  200. data/db/migrate/20130604145732_create_task_sessions.rb +9 -0
  201. data/db/migrate/20130717150737_remove_pname_validation.rb +7 -0
  202. data/db/migrate/20131002004641_create_automatic_exploitation_matches.rb +13 -0
  203. data/db/migrate/20131002164449_create_automatic_exploitation_match_sets.rb +12 -0
  204. data/db/migrate/20131008213344_create_automatic_exploitation_runs.rb +11 -0
  205. data/db/migrate/20131011184338_module_detail_on_automatic_exploitation_match.rb +10 -0
  206. data/db/migrate/20131017150735_create_automatic_exploitation_match_results.rb +11 -0
  207. data/db/migrate/20131021185657_make_match_polymorphic.rb +11 -0
  208. data/db/migrate/20140905031549_add_detected_arch_to_host.rb +5 -0
  209. data/db/migrate/20150112203945_remove_duplicate_services.rb +17 -0
  210. data/db/migrate/20150205192745_drop_service_uniqueness_index.rb +5 -0
  211. data/db/migrate/20150209195939_add_vuln_id_to_note.rb +6 -0
  212. data/db/migrate/20150212214222_remove_duplicate_services2.rb +17 -0
  213. data/db/migrate/20150219173821_create_module_runs.rb +23 -0
  214. data/db/migrate/20150219215039_add_module_run_to_session.rb +8 -0
  215. data/db/migrate/20150226151459_add_module_run_fk_to_loot.rb +8 -0
  216. data/db/migrate/20150312155312_add_module_full_name_to_match.rb +6 -0
  217. data/db/migrate/20150317145455_rename_module_indices.rb +29 -0
  218. data/db/migrate/20150326183742_add_missing_ae_indices.rb +13 -0
  219. data/db/migrate/20150421211719_rename_automatic_exploitation_index.rb +16 -0
  220. data/db/migrate/20150514182921_add_origin_to_mdm_vuln.rb +13 -0
  221. data/db/migrate/20160415153312_remove_not_null_from_web_vuln_p_arams.rb +5 -0
  222. data/db/migrate/20161004165612_add_fingerprinted_to_workspace.rb +5 -0
  223. data/db/migrate/20161227212223_add_os_family_to_hosts.rb +5 -0
  224. data/db/migrate/20180904120211_create_payloads.rb +21 -0
  225. data/db/migrate/20190308134512_create_async_callbacks.rb +13 -0
  226. data/db/migrate/20190507120211_remove_payload_workspaces.rb +5 -0
  227. data/lib/mdm/host/operating_system_normalization.rb +942 -0
  228. data/lib/mdm/module.rb +13 -0
  229. data/lib/mdm.rb +57 -0
  230. data/lib/metasploit_data_models/automatic_exploitation.rb +25 -0
  231. data/lib/metasploit_data_models/base64_serializer.rb +99 -0
  232. data/lib/metasploit_data_models/change_required_columns_to_null_false.rb +21 -0
  233. data/lib/metasploit_data_models/engine.rb +32 -0
  234. data/lib/metasploit_data_models/ip_address/cidr.rb +174 -0
  235. data/lib/metasploit_data_models/ip_address/range.rb +181 -0
  236. data/lib/metasploit_data_models/ip_address/v4/segment/nmap.rb +7 -0
  237. data/lib/metasploit_data_models/ip_address/v4/segment.rb +7 -0
  238. data/lib/metasploit_data_models/ip_address/v4.rb +11 -0
  239. data/lib/metasploit_data_models/ip_address.rb +9 -0
  240. data/lib/metasploit_data_models/match/child.rb +48 -0
  241. data/lib/metasploit_data_models/match/parent.rb +103 -0
  242. data/lib/metasploit_data_models/match.rb +8 -0
  243. data/lib/metasploit_data_models/search/operation/port.rb +9 -0
  244. data/lib/metasploit_data_models/search/operation.rb +9 -0
  245. data/lib/metasploit_data_models/search/operator/port.rb +6 -0
  246. data/lib/metasploit_data_models/search/operator.rb +8 -0
  247. data/lib/metasploit_data_models/search/visitor.rb +11 -0
  248. data/lib/metasploit_data_models/search.rb +8 -0
  249. data/lib/metasploit_data_models/serialized_prefs.rb +27 -0
  250. data/lib/metasploit_data_models/version.rb +13 -0
  251. data/lib/metasploit_data_models.rb +56 -0
  252. data/metasploit_data_models.gemspec +65 -0
  253. data/script/rails +8 -0
  254. data/spec/app/models/mdm/api_key_spec.rb +3 -0
  255. data/spec/app/models/mdm/client_spec.rb +43 -0
  256. data/spec/app/models/mdm/cred_spec.rb +346 -0
  257. data/spec/app/models/mdm/event_spec.rb +90 -0
  258. data/spec/app/models/mdm/exploit_attempt_spec.rb +59 -0
  259. data/spec/app/models/mdm/exploited_host_spec.rb +44 -0
  260. data/spec/app/models/mdm/host_detail_spec.rb +48 -0
  261. data/spec/app/models/mdm/host_spec.rb +1139 -0
  262. data/spec/app/models/mdm/host_tag_spec.rb +69 -0
  263. data/spec/app/models/mdm/listener_spec.rb +107 -0
  264. data/spec/app/models/mdm/loot_spec.rb +84 -0
  265. data/spec/app/models/mdm/macro_spec.rb +3 -0
  266. data/spec/app/models/mdm/mod_ref_spec.rb +3 -0
  267. data/spec/app/models/mdm/module/action_spec.rb +34 -0
  268. data/spec/app/models/mdm/module/arch_spec.rb +34 -0
  269. data/spec/app/models/mdm/module/author_spec.rb +52 -0
  270. data/spec/app/models/mdm/module/detail_spec.rb +746 -0
  271. data/spec/app/models/mdm/module/mixin_spec.rb +34 -0
  272. data/spec/app/models/mdm/module/platform_spec.rb +34 -0
  273. data/spec/app/models/mdm/module/ref_spec.rb +58 -0
  274. data/spec/app/models/mdm/module/target_spec.rb +36 -0
  275. data/spec/app/models/mdm/nexpose_console_spec.rb +146 -0
  276. data/spec/app/models/mdm/note_spec.rb +91 -0
  277. data/spec/app/models/mdm/profile_spec.rb +3 -0
  278. data/spec/app/models/mdm/ref_spec.rb +71 -0
  279. data/spec/app/models/mdm/route_spec.rb +35 -0
  280. data/spec/app/models/mdm/service_spec.rb +232 -0
  281. data/spec/app/models/mdm/session_event_spec.rb +42 -0
  282. data/spec/app/models/mdm/session_spec.rb +118 -0
  283. data/spec/app/models/mdm/tag_spec.rb +116 -0
  284. data/spec/app/models/mdm/task_cred_spec.rb +51 -0
  285. data/spec/app/models/mdm/task_host_spec.rb +50 -0
  286. data/spec/app/models/mdm/task_service_spec.rb +50 -0
  287. data/spec/app/models/mdm/task_session_spec.rb +46 -0
  288. data/spec/app/models/mdm/task_spec.rb +71 -0
  289. data/spec/app/models/mdm/user_spec.rb +50 -0
  290. data/spec/app/models/mdm/vuln_attempt_spec.rb +53 -0
  291. data/spec/app/models/mdm/vuln_detail_spec.rb +65 -0
  292. data/spec/app/models/mdm/vuln_ref_spec.rb +46 -0
  293. data/spec/app/models/mdm/vuln_spec.rb +299 -0
  294. data/spec/app/models/mdm/web_form_spec.rb +46 -0
  295. data/spec/app/models/mdm/web_page_spec.rb +101 -0
  296. data/spec/app/models/mdm/web_site_spec.rb +85 -0
  297. data/spec/app/models/mdm/web_vuln_spec.rb +312 -0
  298. data/spec/app/models/mdm/wmap_request_spec.rb +5 -0
  299. data/spec/app/models/mdm/wmap_target_spec.rb +5 -0
  300. data/spec/app/models/mdm/workspace_spec.rb +500 -0
  301. data/spec/app/models/metasploit_data_models/automatic_exploitation/match_result_spec.rb +86 -0
  302. data/spec/app/models/metasploit_data_models/automatic_exploitation/match_set_spec.rb +46 -0
  303. data/spec/app/models/metasploit_data_models/automatic_exploitation/match_spec.rb +37 -0
  304. data/spec/app/models/metasploit_data_models/automatic_exploitation/run_spec.rb +38 -0
  305. data/spec/app/models/metasploit_data_models/ip_address/v4/cidr_spec.rb +119 -0
  306. data/spec/app/models/metasploit_data_models/ip_address/v4/nmap_spec.rb +149 -0
  307. data/spec/app/models/metasploit_data_models/ip_address/v4/range_spec.rb +298 -0
  308. data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list_spec.rb +276 -0
  309. data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range_spec.rb +302 -0
  310. data/spec/app/models/metasploit_data_models/ip_address/v4/segment/segmented_spec.rb +27 -0
  311. data/spec/app/models/metasploit_data_models/ip_address/v4/segment/single_spec.rb +324 -0
  312. data/spec/app/models/metasploit_data_models/ip_address/v4/single_spec.rb +181 -0
  313. data/spec/app/models/metasploit_data_models/module_run_spec.rb +134 -0
  314. data/spec/app/models/metasploit_data_models/search/operation/ip_address_spec.rb +180 -0
  315. data/spec/app/models/metasploit_data_models/search/operation/port/number_spec.rb +39 -0
  316. data/spec/app/models/metasploit_data_models/search/operation/port/range_spec.rb +138 -0
  317. data/spec/app/models/metasploit_data_models/search/operation/range_spec.rb +233 -0
  318. data/spec/app/models/metasploit_data_models/search/operator/ip_address_spec.rb +17 -0
  319. data/spec/app/models/metasploit_data_models/search/operator/multitext_spec.rb +160 -0
  320. data/spec/app/models/metasploit_data_models/search/operator/port/list_spec.rb +162 -0
  321. data/spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb +96 -0
  322. data/spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb +175 -0
  323. data/spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb +396 -0
  324. data/spec/app/models/metasploit_data_models/search/visitor/method_spec.rb +49 -0
  325. data/spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb +925 -0
  326. data/spec/app/models/metasploit_data_models/search/visitor/where_spec.rb +187 -0
  327. data/spec/dummy/Rakefile +7 -0
  328. data/spec/dummy/app/assets/config/manifest.js +1 -0
  329. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  330. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  331. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  332. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  333. data/spec/dummy/app/mailers/.gitkeep +0 -0
  334. data/spec/dummy/app/models/.gitkeep +0 -0
  335. data/spec/dummy/app/models/application_record.rb +3 -0
  336. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  337. data/spec/dummy/bin/bundle +3 -0
  338. data/spec/dummy/bin/rails +4 -0
  339. data/spec/dummy/bin/rake +4 -0
  340. data/spec/dummy/config/application.rb +61 -0
  341. data/spec/dummy/config/boot.rb +4 -0
  342. data/spec/dummy/config/database.yml.example +22 -0
  343. data/spec/dummy/config/database.yml.github_actions +21 -0
  344. data/spec/dummy/config/environment.rb +5 -0
  345. data/spec/dummy/config/environments/development.rb +37 -0
  346. data/spec/dummy/config/environments/production.rb +78 -0
  347. data/spec/dummy/config/environments/test.rb +39 -0
  348. data/spec/dummy/config/initializers/active_record_migrations.rb +4 -0
  349. data/spec/dummy/config/initializers/assets.rb +8 -0
  350. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  351. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  352. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  353. data/spec/dummy/config/initializers/inflections.rb +16 -0
  354. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  355. data/spec/dummy/config/initializers/session_store.rb +3 -0
  356. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  357. data/spec/dummy/config/locales/en.yml +23 -0
  358. data/spec/dummy/config/routes.rb +2 -0
  359. data/spec/dummy/config.ru +4 -0
  360. data/spec/dummy/db/structure.sql +3430 -0
  361. data/spec/dummy/db/structure.sql.from_rails_3 +3403 -0
  362. data/spec/dummy/lib/assets/.gitkeep +0 -0
  363. data/spec/dummy/log/.gitkeep +0 -0
  364. data/spec/dummy/public/404.html +26 -0
  365. data/spec/dummy/public/422.html +26 -0
  366. data/spec/dummy/public/500.html +25 -0
  367. data/spec/dummy/public/favicon.ico +0 -0
  368. data/spec/dummy/script/rails +6 -0
  369. data/spec/factories/mdm/addresses.rb +12 -0
  370. data/spec/factories/mdm/clients.rb +8 -0
  371. data/spec/factories/mdm/creds.rb +17 -0
  372. data/spec/factories/mdm/events.rb +15 -0
  373. data/spec/factories/mdm/exploit_attempts.rb +8 -0
  374. data/spec/factories/mdm/exploited_hosts.rb +7 -0
  375. data/spec/factories/mdm/fingerprints/nessus_fingerprints.rb +6 -0
  376. data/spec/factories/mdm/fingerprints/nexpose_fingerprints.rb +6 -0
  377. data/spec/factories/mdm/fingerprints/nmap_fingerprints.rb +6 -0
  378. data/spec/factories/mdm/fingerprints/retina_fingerprints.rb +6 -0
  379. data/spec/factories/mdm/fingerprints/session_fingerprints.rb +6 -0
  380. data/spec/factories/mdm/host_details.rb +8 -0
  381. data/spec/factories/mdm/host_tags.rb +9 -0
  382. data/spec/factories/mdm/hosts.rb +85 -0
  383. data/spec/factories/mdm/listeners.rb +12 -0
  384. data/spec/factories/mdm/loots.rb +11 -0
  385. data/spec/factories/mdm/module/actions.rb +14 -0
  386. data/spec/factories/mdm/module/archs.rb +14 -0
  387. data/spec/factories/mdm/module/authors.rb +22 -0
  388. data/spec/factories/mdm/module/details.rb +73 -0
  389. data/spec/factories/mdm/module/mixins.rb +14 -0
  390. data/spec/factories/mdm/module/platforms.rb +14 -0
  391. data/spec/factories/mdm/module/refs.rb +14 -0
  392. data/spec/factories/mdm/module/targets.rb +19 -0
  393. data/spec/factories/mdm/nexpose_consoles.rb +15 -0
  394. data/spec/factories/mdm/notes.rb +12 -0
  395. data/spec/factories/mdm/refs.rb +9 -0
  396. data/spec/factories/mdm/routes.rb +36 -0
  397. data/spec/factories/mdm/services.rb +41 -0
  398. data/spec/factories/mdm/session_events.rb +8 -0
  399. data/spec/factories/mdm/sessions.rb +13 -0
  400. data/spec/factories/mdm/tags.rb +14 -0
  401. data/spec/factories/mdm/task.rb +16 -0
  402. data/spec/factories/mdm/task_creds.rb +9 -0
  403. data/spec/factories/mdm/task_hosts.rb +9 -0
  404. data/spec/factories/mdm/task_services.rb +8 -0
  405. data/spec/factories/mdm/task_sessions.rb +8 -0
  406. data/spec/factories/mdm/users.rb +22 -0
  407. data/spec/factories/mdm/vuln_attempts.rb +8 -0
  408. data/spec/factories/mdm/vuln_details.rb +8 -0
  409. data/spec/factories/mdm/vuln_refs.rb +4 -0
  410. data/spec/factories/mdm/vulns.rb +20 -0
  411. data/spec/factories/mdm/web_forms.rb +33 -0
  412. data/spec/factories/mdm/web_pages.rb +64 -0
  413. data/spec/factories/mdm/web_sites.rb +8 -0
  414. data/spec/factories/mdm/web_vulns.rb +64 -0
  415. data/spec/factories/mdm/workspaces.rb +23 -0
  416. data/spec/factories/metasploit_data_models/automatic_exploitation/match_results.rb +7 -0
  417. data/spec/factories/metasploit_data_models/automatic_exploitation/match_sets.rb +8 -0
  418. data/spec/factories/metasploit_data_models/automatic_exploitation/matches.rb +7 -0
  419. data/spec/factories/metasploit_data_models/automatic_exploitation/runs.rb +6 -0
  420. data/spec/factories/module_runs.rb +40 -0
  421. data/spec/lib/base64_serializer_spec.rb +172 -0
  422. data/spec/lib/ipaddr_spec.rb +29 -0
  423. data/spec/lib/metasploit_data_models/ip_address/cidr_spec.rb +356 -0
  424. data/spec/lib/metasploit_data_models/ip_address/range_spec.rb +75 -0
  425. data/spec/lib/metasploit_data_models/match/child_spec.rb +59 -0
  426. data/spec/lib/metasploit_data_models/match/parent_spec.rb +153 -0
  427. data/spec/lib/metasploit_data_models_spec.rb +13 -0
  428. data/spec/spec_helper.rb +148 -0
  429. data/spec/support/matchers/match_regex_exactly.rb +28 -0
  430. data/spec/support/shared/contexts/rex/text.rb +15 -0
  431. data/spec/support/shared/examples/coerces_inet_column_type_to_string.rb +15 -0
  432. data/spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb +20 -0
  433. data/spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb +36 -0
  434. data/spec/support/shared/examples/metasploit_data_models/search/operation/ipaddress/match.rb +109 -0
  435. data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb +38 -0
  436. data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb +26 -0
  437. data/spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record.rb +50 -0
  438. data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb +34 -0
  439. data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb +51 -0
  440. metadata +444 -6
@@ -0,0 +1,619 @@
1
+ # A system with an {#address IP address} on the network that has been discovered in some way.
2
+ class Mdm::Host < ApplicationRecord
3
+ extend ActiveSupport::Autoload
4
+
5
+ autoload :OperatingSystemNormalization
6
+
7
+ include Mdm::Host::OperatingSystemNormalization
8
+ include Metasploit::Model::Search
9
+
10
+ #
11
+ # CONSTANTS
12
+ #
13
+
14
+ # Special {#arch} value to indicate we should look at {#detected_arch}
15
+ # instead
16
+ UNKNOWN_ARCHITECTURE = 'Unknown'
17
+
18
+ # Either the CPU architecture for native code or the programming language
19
+ # name for exploits that run code in the programming language's virtual
20
+ # machine.
21
+ ARCHITECTURES = [
22
+ 'armbe',
23
+ 'armle',
24
+ 'cbea',
25
+ 'cbea64',
26
+ 'cmd',
27
+ 'java',
28
+ 'mips',
29
+ 'mipsbe',
30
+ 'mipsle',
31
+ 'php',
32
+ 'ppc',
33
+ 'ppc64',
34
+ 'ruby',
35
+ 'sparc',
36
+ 'tty',
37
+ # To be used for compatability with 'X86_64'
38
+ 'x64',
39
+ 'x86',
40
+ 'x86_64',
41
+ '',
42
+ UNKNOWN_ARCHITECTURE
43
+ ]
44
+
45
+ # Fields searched for the search scope
46
+ SEARCH_FIELDS = [
47
+ 'address::text',
48
+ 'comments',
49
+ 'mac',
50
+ 'name',
51
+ 'os_flavor',
52
+ 'os_name',
53
+ 'os_sp',
54
+ 'purpose'
55
+ ]
56
+
57
+ # Valid values for {#state}.
58
+ STATES = [
59
+ 'alive',
60
+ 'down',
61
+ 'unknown'
62
+ ]
63
+
64
+ # Valid MAC address value
65
+ #hyphen-separated: 1a-2B-3c-4D-5e-6f
66
+ MAC_ADDRESS_HYPHEN_REGEX = /\A(?:[A-F0-9]{2}[-]){5}[A-F0-9]{2}\z/i
67
+
68
+ #colon-separated: 1a:2B:3c:4D:5e:6f
69
+ MAC_ADDRESS_COLON_REGEX = /\A(?:[A-F0-9]{2}[:]){5}[A-F0-9]{2}\z/i
70
+
71
+ #XXX for now, allow en empty MAC so as not to break things that exist with
72
+ # empty MACs.
73
+ MAC_ADDRESS_EMPTY_REGEX = /\A\z/
74
+
75
+ # 6-tuple of hex (case-insensitive) doublets (or empty)
76
+ MAC_ADDRESS_REGEX = Regexp.union(MAC_ADDRESS_HYPHEN_REGEX, MAC_ADDRESS_COLON_REGEX,
77
+ MAC_ADDRESS_EMPTY_REGEX)
78
+
79
+ #
80
+ # Aggregations
81
+ #
82
+
83
+ # @!attribute [rw] address
84
+ # The IP address of this host. Necessary to avoid coercion to an `IPAddr` object.
85
+ #
86
+ # @return [String]
87
+ def address
88
+ self[:address].to_s
89
+ end
90
+
91
+ #
92
+ # Associations
93
+ #
94
+
95
+ # @!attribute [rw] clients
96
+ # Users connected to this host
97
+ #
98
+ # @return [ActiveRecord::Relation<Mdm::Client>]
99
+ has_many :clients,
100
+ class_name: 'Mdm::Client',
101
+ dependent: :destroy,
102
+ inverse_of: :host
103
+
104
+ # @!attribute events
105
+ # Events that occurred on this host.
106
+ #
107
+ # @return [ActiveRecord::Relation<Mdm::Event>]
108
+ has_many :events,
109
+ class_name: 'Mdm::Event',
110
+ dependent: :delete_all,
111
+ inverse_of: :host
112
+
113
+ # @!attribute [rw] task_hosts
114
+ # Details about what Tasks touched this host
115
+ #
116
+ # @return [ActiveRecord::Relation<Mdm::TaskHost>]
117
+ has_many :task_hosts,
118
+ class_name: 'Mdm::TaskHost',
119
+ dependent: :destroy,
120
+ inverse_of: :host
121
+
122
+ # @!attribute [rw] exploit_attempts
123
+ # Attempts to run exploits against this host.
124
+ #
125
+ # @return [ActiveRecord::Relation<Mdm::ExploitAttempt]
126
+ has_many :exploit_attempts,
127
+ class_name: 'Mdm::ExploitAttempt',
128
+ dependent: :destroy,
129
+ inverse_of: :host
130
+
131
+ # @!attribute exploited_hosts
132
+ # @todo MSP-2732
133
+ # @return [ActiveRecord::Relation<Mdm::ExploitedHost>]
134
+ has_many :exploited_hosts,
135
+ class_name: 'Mdm::ExploitedHost',
136
+ dependent: :destroy,
137
+ inverse_of: :host
138
+
139
+ # @!attribute [rw] host_details
140
+ # @return [ActiveRecord::Relation<Mdm::HostDetail>]
141
+ has_many :host_details,
142
+ class_name: 'Mdm::HostDetail',
143
+ dependent: :destroy,
144
+ inverse_of: :host
145
+
146
+ # @!attribute hosts_tags
147
+ # A join model between {Mdm::Tag} and {Mdm::Host}. Use {#tags} to get the actual {Mdm::Tag Mdm::Tags} on this host.
148
+ #
149
+ # @todo MSP-2723
150
+ # @return [ActiveRecord::Relation<Mdm::HostTag>]
151
+ has_many :hosts_tags,
152
+ class_name: 'Mdm::HostTag',
153
+ dependent: :destroy,
154
+ inverse_of: :host
155
+
156
+ # @!attribute loots
157
+ # Loot gathered from the host with {Mdm::Loot#created_at newest loot} first.
158
+ #
159
+ # @todo MSP-3065
160
+ # @return [ActiveRecord::Relation<Mdm::Loot>]
161
+ has_many :loots,
162
+ -> { order('loots.created_at DESC')},
163
+ class_name: 'Mdm::Loot',
164
+ dependent: :destroy,
165
+ inverse_of: :host
166
+
167
+ # @!attribute [rw] notes
168
+ # Notes about the host entered by a user with {Mdm::Note#created_at oldest notes} first.
169
+ #
170
+ # @return [ActiveRecord::Relation<Mdm::Note>]
171
+ has_many :notes,
172
+ -> { order('notes.created_at') },
173
+ class_name: 'Mdm::Note',
174
+ inverse_of: :host,
175
+ dependent: :delete_all
176
+
177
+ # @!attribute [rw] services
178
+ # The services running on {Mdm::Service#port ports} on the host with services ordered by {Mdm::Service#port port}
179
+ # and {Mdm::Service#proto protocol}.
180
+ #
181
+ # @return [ActiveRecord::Relation<Mdm::Service>]
182
+ has_many :services,
183
+ -> { order('services.port, services.proto') },
184
+ class_name: 'Mdm::Service',
185
+ dependent: :destroy,
186
+ inverse_of: :host
187
+
188
+ # @!attribute [rw] sessions
189
+ # Sessions that are open or previously were open on the host ordered by {Mdm::Session#opened_at when the session was
190
+ # opened}
191
+ #
192
+ # @return [ActiveRecord::Relation<Mdm::Session]
193
+ has_many :sessions,
194
+ -> { order('sessions.opened_at') },
195
+ class_name: 'Mdm::Session',
196
+ dependent: :destroy,
197
+ inverse_of: :host
198
+
199
+ # @!attribute [rw] vulns
200
+ # Vulnerabilities found on the host.
201
+ #
202
+ # @return [ActiveRecord::Relation<Mdm::Vuln>]
203
+ has_many :vulns,
204
+ class_name: 'Mdm::Vuln',
205
+ dependent: :delete_all,
206
+ inverse_of: :host
207
+
208
+ # @!attribute [rw] workspace
209
+ # The workspace in which this host was found.
210
+ #
211
+ # @return [Mdm::Workspace]
212
+ belongs_to :workspace,
213
+ class_name: 'Mdm::Workspace',
214
+ inverse_of: :hosts
215
+
216
+ #
217
+ # Through host_tags
218
+ #
219
+
220
+ # @!attribute [r] tags
221
+ # The tags on this host. Tags are used to filter hosts.
222
+ #
223
+ # @return [ActiveRecord::Relation<Mdm::Tag>]
224
+ # @see #hosts_tags
225
+ has_many :tags, :class_name => 'Mdm::Tag', :through => :hosts_tags
226
+
227
+ #
228
+ # Through services
229
+ #
230
+
231
+ # @!attribute [r] creds
232
+ # Credentials captured from {#services}.
233
+ #
234
+ # @return [ActiveRecord::Relation<Mdm::Cred>]
235
+ # @see #services
236
+ has_many :creds, :class_name => 'Mdm::Cred', :through => :services
237
+
238
+ # @!attribute [r] service_notes
239
+ # {Mdm::Note Notes} about {#services} running on this host.
240
+ #
241
+ # @return [ActiveRecord::Relation<Mdm::Note>]
242
+ # @see #services
243
+ has_many :service_notes,
244
+ class_name: 'Mdm::Note',
245
+ source: :notes,
246
+ through: :services
247
+
248
+ # @!attribute [r] web_sites
249
+ # {Mdm::WebSite Web sites} running on top of {#services} on this host.
250
+ #
251
+ # @return [ActiveRecord::Relation<Mdm::WebSite>]
252
+ # @see services
253
+ has_many :web_sites, :class_name => 'Mdm::WebSite', :through => :services
254
+
255
+ # @!attribute [r] module_runs
256
+ # Records of Metasploit modules being run on/against this {Mdm::Host}
257
+ #
258
+ # @return [ActiveRecord::Relation<MetasploitDataModels::ModuleRun>]
259
+ # @see services
260
+ has_many :module_runs,
261
+ class_name: 'MetasploitDataModels::ModuleRun',
262
+ as: :trackable
263
+
264
+
265
+ #
266
+ # through: :task_hosts
267
+ #
268
+
269
+ # @!attribute tasks
270
+ # Tasks that touched this service
271
+ #
272
+ # @return [ActiveRecord::Relation<Mdm::Task>]
273
+ has_many :tasks,
274
+ class_name: 'Mdm::Task',
275
+ through: :task_hosts
276
+
277
+ #
278
+ # Through vulns
279
+ #
280
+
281
+ # @!attribute [r] vuln_refs
282
+ # Join model between {#vulns} and {#refs}. Use either of those asssociations instead of this join model.
283
+ #
284
+ # @todo https://www.pivotaltracker.com/story/show/49004623
285
+ # @return [ActiveRecord::Relation<Mdm::VulnRef>]
286
+ # @see #refs
287
+ # @see #vulns
288
+ has_many :vuln_refs, :class_name => 'Mdm::VulnRef', :source => :vulns_refs, :through => :vulns
289
+
290
+ #
291
+ # Through vuln_refs
292
+ #
293
+
294
+ # @!attribute [r] refs
295
+ # External references, such as CVE, to vulnerabilities found on this host.
296
+ #
297
+ # @return [ActiveRecord::Relation<Mdm::Ref>]
298
+ # @see #vuln_refs
299
+ has_many :refs, :class_name => 'Mdm::Ref', :through => :vuln_refs
300
+
301
+ #
302
+ # Through refs
303
+ #
304
+
305
+ # @!attribute [r] module_refs
306
+ # {Mdm::Module::Ref References for modules} for {Mdm::Ref references for vulnerabilities}.
307
+ #
308
+ # @return [ActiveRecord::Relation<Mdm::Module::Ref>]
309
+ has_many :module_refs, :class_name => 'Mdm::Module::Ref', :through => :refs
310
+
311
+ #
312
+ # Through module_refs
313
+ #
314
+
315
+ # @!attribute [r] module_details
316
+ # {Mdm::Module::Detail Details about modules} that were used to find {#vulns vulnerabilities} on this host.
317
+ #
318
+ # @return [ActiveRecord::Relation<Mdm::Module::Detail]
319
+ has_many :module_details, -> { distinct } ,
320
+ :class_name => 'Mdm::Module::Detail',
321
+ :source =>:detail,
322
+ :through => :module_refs
323
+
324
+
325
+ #
326
+ # Attributes
327
+ #
328
+
329
+ # @!attribute [rw] address
330
+ # The IP address of this host.
331
+ #
332
+ # @return [String]
333
+
334
+ # @!attribute [rw] arch
335
+ # The architecture of the host's CPU OR the programming language for virtual machine programming language like
336
+ # Ruby, PHP, and Java.
337
+ #
338
+ # @return [String] an element of {ARCHITECTURES}
339
+
340
+ # @!attribute [rw] comm
341
+ # @todo https://www.pivotaltracker.com/story/show/49722411
342
+ #
343
+ # @return [String]
344
+
345
+ # @!attribute [rw] comments
346
+ # User supplied comments about host.
347
+ #
348
+ # @return [String]
349
+
350
+ # @!attribute [rw] created_at
351
+ # When this host was created in the database.
352
+ #
353
+ # @return [DateTime]
354
+
355
+ # @!attribute [rw] cred_count
356
+ # Counter cache for {#creds}.
357
+ #
358
+ # @return [Integer]
359
+
360
+ # @!attribute [rw] detected_arch
361
+ # The architecture of the host's CPU as detected by `Recog`. If {#arch} is
362
+ # not {UNKNOWN_ARCHITECTURE}, this is undefined.
363
+ #
364
+ # @return [String] a free-form string most likely from network data
365
+
366
+ # @!attribute [rw] exploit_attempt_count
367
+ # Counter cache for {#exploit_attempts}.
368
+ #
369
+ # @return [Integer]
370
+
371
+ # @!attribute [rw] host_detail_count
372
+ # Counter cache for {#host_details}.
373
+ #
374
+ # @return [Integer]
375
+
376
+ # @!attribute [rw] info
377
+ # Information about this host gathered from the host.
378
+ #
379
+ # @return [String]
380
+
381
+ # @!attribute [rw] mac
382
+ # The MAC address of this host.
383
+ #
384
+ # @return [String]
385
+ # @see http://en.wikipedia.org/wiki/Mac_address
386
+
387
+ # @!attribute [rw] name
388
+ # The name of the host. If the host name is not available, then it will just be the IP address.
389
+ #
390
+ # @return [String]
391
+
392
+ # @!attribute [rw] note_count
393
+ # Counter cache for {#notes}.
394
+ #
395
+ # @return [Integer]
396
+
397
+ # @!attribute [rw] os_flavor
398
+ # The flavor of {#os_name}.
399
+ #
400
+ # @example Windows XP
401
+ # host.os_name = 'Windows'
402
+ # host.os_flavor = 'XP'
403
+ #
404
+ # @return [String]
405
+
406
+ # @!attribute [rw] os_lang
407
+ # Free-form language of operating system. Usually either spelled out like 'English' or an
408
+ # {http://en.wikipedia.org/wiki/IETF_language_tag IETF language tag} like 'en' or 'en-US'.
409
+ #
410
+ # @return [String]
411
+
412
+ # @!attribute [rw] os_name
413
+ # The name of the operating system.
414
+ #
415
+ # @return [String]
416
+
417
+ # @!attribute [rw] os_sp
418
+ # The service pack of the {#os_flavor} of the {#os_name}.
419
+ #
420
+ # @example Windows XP SP2
421
+ # host.os_name = 'Windows'
422
+ # host.os_flavor = 'XP'
423
+ # host.os_sp = 'SP2'
424
+ #
425
+ # @return [String]
426
+
427
+ # @!attribute [rw] purpose
428
+ # The purpose of the host on the network, such as 'client' or 'firewall'.
429
+ #
430
+ # @return [String]
431
+
432
+ # @!attribute [rw] scope
433
+ # Interface identifier for link-local IPv6
434
+ #
435
+ # @return [String]
436
+ # @see http://en.wikipedia.org/wiki/IPv6_address#Link-local_addresses_and_zone_indices
437
+
438
+ # @!attribute [rw] service_count
439
+ # Counter cache for {#services}.
440
+ #
441
+ # @return [Integer]
442
+
443
+ # @!attribute [rw] state
444
+ # Whether the host is alive, down, or in an unknown state.
445
+ #
446
+ # @return [String] element of {STATES}.
447
+
448
+ # @!attribute [rw] updated_at
449
+ # The last time this host was updated in the database.
450
+ #
451
+ # @return [DateTime]
452
+
453
+ # @!attribute [rw] virtual_host
454
+ # The name of the virtual machine host software, such as 'VMWare', 'QEMU', 'XEN', etc.
455
+ #
456
+ # @return [String]
457
+
458
+ # @!attribute [rw] vuln_count
459
+ # Counter cache for {#vulns}.
460
+ #
461
+ # @return [Integer]
462
+
463
+ #
464
+ # Callbacks
465
+ #
466
+
467
+ before_validation :normalize_arch
468
+
469
+ #
470
+ # Nested Attributes
471
+ # @note Must be declared after relations being referenced.
472
+ #
473
+
474
+ accepts_nested_attributes_for :services, :reject_if => lambda { |s| s[:port].blank? }, :allow_destroy => true
475
+
476
+ #
477
+ # Validations
478
+ #
479
+
480
+ validates :address,
481
+ :ip_format => true,
482
+ :presence => true,
483
+ :uniqueness => {
484
+ :scope => :workspace_id,
485
+ :unless => :ip_address_invalid?
486
+ }
487
+ validates :arch,
488
+ :allow_blank => true,
489
+ :inclusion => {
490
+ :in => ARCHITECTURES
491
+ }
492
+
493
+ validates :mac,
494
+ :format => {
495
+ :with => MAC_ADDRESS_REGEX,
496
+ :message => 'must be a valid MAC address'
497
+ }
498
+
499
+ validates :state,
500
+ :allow_nil => true,
501
+ :inclusion => {
502
+ :in => STATES
503
+ }
504
+ validates :workspace, :presence => true
505
+
506
+ #
507
+ # Scopes
508
+ #
509
+
510
+ scope :alive, -> { where({'hosts.state' => 'alive'}) }
511
+ scope :flagged, -> { where('notes.critical = true AND notes.seen = false').includes(:notes).references(:notes) }
512
+ scope :search,
513
+ lambda { |*args|
514
+ # @todo replace with AREL
515
+ terms = SEARCH_FIELDS.collect { |field|
516
+ "#{self.table_name}.#{field} ILIKE ?"
517
+ }
518
+ disjunction = terms.join(' OR ')
519
+ formatted_parameter = "%#{args[0]}%"
520
+ parameters = [formatted_parameter] * SEARCH_FIELDS.length
521
+ conditions = [disjunction] + parameters
522
+
523
+ where(*conditions)
524
+ }
525
+ scope :tag_search,
526
+ lambda { |*args| where("tags.name" => args[0]).includes(:tags).references(:tags) }
527
+
528
+ #
529
+ #
530
+ # Search
531
+ #
532
+ #
533
+
534
+ #
535
+ # Search Associations
536
+ #
537
+
538
+ search_association :services
539
+
540
+ #
541
+ # Search Attributes
542
+ #
543
+
544
+ search_attribute :name,
545
+ type: :string
546
+ search_attribute :os_flavor,
547
+ type: :string
548
+ search_attribute :os_name,
549
+ type: :string
550
+ search_attribute :os_sp,
551
+ type: :string
552
+
553
+ #
554
+ # Search Withs
555
+ #
556
+
557
+ search_with MetasploitDataModels::Search::Operator::Multitext,
558
+ name: :os,
559
+ operator_names: [
560
+ :os_name,
561
+ :os_flavor,
562
+ :os_sp
563
+ ]
564
+
565
+ search_with MetasploitDataModels::Search::Operator::IPAddress,
566
+ attribute: :address
567
+
568
+ #
569
+ # Instance Methods
570
+ #
571
+
572
+ # Returns whether 'host.updated.<attr>' {#notes note} is {Mdm::Note#data locked}.
573
+ #
574
+ # @return [true] if Mdm::Note with 'host.updated.<attr>' as {Mdm::Note#name} exists and data[:locked] is `true`.
575
+ # @return [false] otherwise.
576
+ def attribute_locked?(attr)
577
+ n = notes.find_by_ntype("host.updated.#{attr}")
578
+ n && n.data[:locked]
579
+ end
580
+
581
+ # This is replicated by the IpAddressValidator class. Had to put it here as well to avoid
582
+ # SQL errors when checking address uniqueness.
583
+ #
584
+ # @return [void]
585
+ def ip_address_invalid?
586
+ begin
587
+ if address.is_a? IPAddr
588
+ potential_ip = address.dup
589
+ else
590
+ potential_ip = IPAddr.new(address)
591
+ end
592
+
593
+ return true unless potential_ip.ipv4? || potential_ip.ipv6?
594
+ rescue ArgumentError
595
+ return true
596
+ end
597
+ end
598
+
599
+ # Returns whether this host is a virtual machine.
600
+ #
601
+ # @return [true] unless {#virtual_host} is `nil`.
602
+ # @return [false] otherwise.
603
+ def is_vm?
604
+ !!self.virtual_host
605
+ end
606
+
607
+ private
608
+
609
+ def normalize_arch
610
+ if attribute_present?(:arch) && !ARCHITECTURES.include?(self.arch)
611
+ self.detected_arch = arch
612
+ self.arch = UNKNOWN_ARCHITECTURE
613
+ end
614
+ end
615
+
616
+ public
617
+
618
+ Metasploit::Concern.run(self)
619
+ end
@@ -0,0 +1,62 @@
1
+ # Details supplied by Nexpose about a {Mdm::Host host}.
2
+ class Mdm::HostDetail < ApplicationRecord
3
+ #
4
+ # Associations
5
+ #
6
+
7
+ # Host that this detail is about.
8
+ belongs_to :host,
9
+ class_name: 'Mdm::Host',
10
+ counter_cache: :host_detail_count,
11
+ inverse_of: :host_details
12
+
13
+ #
14
+ # Attributes
15
+ #
16
+
17
+ # @!attribute host_id
18
+ # The foreign key used to look up {#host}.
19
+ #
20
+ # @return [Integer]
21
+
22
+ # @!attribute nx_console_id
23
+ # The ID of the Nexpose console.
24
+ #
25
+ # @return [Integer]
26
+
27
+ # @!attribute nx_device_id
28
+ # The ID of the Device in Nexpose.
29
+ #
30
+ # @return [Integer]
31
+
32
+ # @!attribute nx_risk_score
33
+ # Risk score assigned by Nexpose. Useful to ordering hosts to determine which host to target first in metasploit.
34
+ #
35
+ # @return [Float]
36
+
37
+ # @!attribute nx_scan_template
38
+ # The template used by Nexpose to perform the scan on the {#nx_site_name site} on {#host}.
39
+ #
40
+ # @return [String]
41
+
42
+ # @!attribute nx_site_importance
43
+ # The importance of scanning the {#nx_site_name site} running on {#host} according to Nexpose.
44
+ #
45
+ # @return [String]
46
+
47
+ # @!attribute nx_site_name
48
+ # Name of site running on {#host} according to Nexpose.
49
+ #
50
+ # @return [String]
51
+
52
+ # @!attribute src
53
+ # @return [String]
54
+
55
+ #
56
+ # Validations
57
+ #
58
+
59
+ validates :host_id, :presence => true
60
+
61
+ Metasploit::Concern.run(self)
62
+ end
@@ -0,0 +1,49 @@
1
+ # Join model between {Mdm::Host} and {Mdm::Tag}.
2
+ class Mdm::HostTag < ApplicationRecord
3
+ self.table_name = "hosts_tags"
4
+
5
+ #
6
+ # Associations
7
+ #
8
+
9
+ # Host with {#tag}.
10
+ #
11
+ # @todo MSP-2723
12
+ belongs_to :host,
13
+ class_name: 'Mdm::Host',
14
+ inverse_of: :hosts_tags
15
+
16
+ # Tag on {#host}.
17
+ #
18
+ # @todo MSP-2723
19
+ belongs_to :tag,
20
+ class_name: 'Mdm::Tag',
21
+ inverse_of: :hosts_tags
22
+
23
+ #
24
+ # Callbacks
25
+ #
26
+
27
+ # @see http://stackoverflow.com/a/11694704
28
+ after_destroy :destroy_orphan_tag
29
+
30
+ #
31
+ # Instance Methods
32
+ #
33
+
34
+ private
35
+
36
+ # Destroys {#tag} if it is orphaned
37
+ #
38
+ # @see http://stackoverflow.com/a/11694704
39
+ # @return [void]
40
+ def destroy_orphan_tag
41
+ tag.destroy_if_orphaned
42
+ end
43
+
44
+ # switch back to public for load hooks
45
+ public
46
+
47
+ Metasploit::Concern.run(self)
48
+ end
49
+