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.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.github/workflows/verify.yml +68 -0
- data/.gitignore +29 -0
- data/.rspec +3 -0
- data/.simplecov +38 -0
- data/.yardopts +4 -0
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +133 -0
- data/Gemfile +46 -0
- data/LICENSE +27 -0
- data/README.md +65 -0
- data/RELEASING.md +82 -0
- data/Rakefile +72 -0
- data/UPGRADING.md +1 -0
- data/app/models/mdm/api_key.rb +61 -0
- data/app/models/mdm/async_callback.rb +64 -0
- data/app/models/mdm/client.rb +50 -0
- data/app/models/mdm/cred.rb +205 -0
- data/app/models/mdm/event.rb +83 -0
- data/app/models/mdm/exploit_attempt.rb +105 -0
- data/app/models/mdm/exploited_host.rb +42 -0
- data/app/models/mdm/host.rb +619 -0
- data/app/models/mdm/host_detail.rb +62 -0
- data/app/models/mdm/host_tag.rb +49 -0
- data/app/models/mdm/listener.rb +82 -0
- data/app/models/mdm/loot.rb +161 -0
- data/app/models/mdm/macro.rb +62 -0
- data/app/models/mdm/mod_ref.rb +24 -0
- data/app/models/mdm/module/action.rb +33 -0
- data/app/models/mdm/module/arch.rb +28 -0
- data/app/models/mdm/module/author.rb +34 -0
- data/app/models/mdm/module/detail.rb +388 -0
- data/app/models/mdm/module/mixin.rb +31 -0
- data/app/models/mdm/module/platform.rb +29 -0
- data/app/models/mdm/module/ref.rb +42 -0
- data/app/models/mdm/module/target.rb +37 -0
- data/app/models/mdm/nexpose_console.rb +121 -0
- data/app/models/mdm/note.rb +125 -0
- data/app/models/mdm/payload.rb +103 -0
- data/app/models/mdm/profile.rb +45 -0
- data/app/models/mdm/ref.rb +48 -0
- data/app/models/mdm/route.rb +28 -0
- data/app/models/mdm/service.rb +267 -0
- data/app/models/mdm/session.rb +203 -0
- data/app/models/mdm/session_event.rb +44 -0
- data/app/models/mdm/tag.rb +114 -0
- data/app/models/mdm/task.rb +168 -0
- data/app/models/mdm/task_cred.rb +45 -0
- data/app/models/mdm/task_host.rb +41 -0
- data/app/models/mdm/task_service.rb +41 -0
- data/app/models/mdm/task_session.rb +41 -0
- data/app/models/mdm/user.rb +230 -0
- data/app/models/mdm/vuln.rb +204 -0
- data/app/models/mdm/vuln_attempt.rb +76 -0
- data/app/models/mdm/vuln_detail.rb +156 -0
- data/app/models/mdm/vuln_ref.rb +21 -0
- data/app/models/mdm/web_form.rb +53 -0
- data/app/models/mdm/web_page.rb +92 -0
- data/app/models/mdm/web_site.rb +113 -0
- data/app/models/mdm/web_vuln.rb +193 -0
- data/app/models/mdm/wmap_request.rb +101 -0
- data/app/models/mdm/wmap_target.rb +56 -0
- data/app/models/mdm/workspace.rb +286 -0
- data/app/models/metasploit_data_models/automatic_exploitation/match.rb +43 -0
- data/app/models/metasploit_data_models/automatic_exploitation/match_result.rb +71 -0
- data/app/models/metasploit_data_models/automatic_exploitation/match_set.rb +40 -0
- data/app/models/metasploit_data_models/automatic_exploitation/run.rb +29 -0
- data/app/models/metasploit_data_models/ip_address/v4/cidr.rb +14 -0
- data/app/models/metasploit_data_models/ip_address/v4/nmap.rb +14 -0
- data/app/models/metasploit_data_models/ip_address/v4/range.rb +12 -0
- data/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list.rb +125 -0
- data/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range.rb +12 -0
- data/app/models/metasploit_data_models/ip_address/v4/segment/single.rb +123 -0
- data/app/models/metasploit_data_models/ip_address/v4/segmented.rb +200 -0
- data/app/models/metasploit_data_models/ip_address/v4/single.rb +53 -0
- data/app/models/metasploit_data_models/module_run.rb +213 -0
- data/app/models/metasploit_data_models/search/operation/ip_address.rb +60 -0
- data/app/models/metasploit_data_models/search/operation/port/number.rb +25 -0
- data/app/models/metasploit_data_models/search/operation/port/range.rb +79 -0
- data/app/models/metasploit_data_models/search/operation/range.rb +56 -0
- data/app/models/metasploit_data_models/search/operator/ip_address.rb +33 -0
- data/app/models/metasploit_data_models/search/operator/multitext.rb +73 -0
- data/app/models/metasploit_data_models/search/operator/port/list.rb +67 -0
- data/app/models/metasploit_data_models/search/visitor/attribute.rb +17 -0
- data/app/models/metasploit_data_models/search/visitor/includes.rb +47 -0
- data/app/models/metasploit_data_models/search/visitor/joins.rb +67 -0
- data/app/models/metasploit_data_models/search/visitor/method.rb +16 -0
- data/app/models/metasploit_data_models/search/visitor/relation.rb +91 -0
- data/app/models/metasploit_data_models/search/visitor/where.rb +128 -0
- data/config/initializers/arel_helper.rb +5 -0
- data/config/initializers/ipaddr.rb +29 -0
- data/config/locales/en.yml +94 -0
- data/console_db.yml +9 -0
- data/db/migrate/000_create_tables.rb +79 -0
- data/db/migrate/001_add_wmap_tables.rb +35 -0
- data/db/migrate/002_add_workspaces.rb +36 -0
- data/db/migrate/003_move_notes.rb +20 -0
- data/db/migrate/004_add_events_table.rb +16 -0
- data/db/migrate/005_expand_info.rb +58 -0
- data/db/migrate/006_add_timestamps.rb +26 -0
- data/db/migrate/007_add_loots.rb +20 -0
- data/db/migrate/008_create_users.rb +16 -0
- data/db/migrate/009_add_loots_ctype.rb +10 -0
- data/db/migrate/010_add_alert_fields.rb +16 -0
- data/db/migrate/011_add_reports.rb +19 -0
- data/db/migrate/012_add_tasks.rb +24 -0
- data/db/migrate/013_add_tasks_result.rb +10 -0
- data/db/migrate/014_add_loots_fields.rb +12 -0
- data/db/migrate/015_rename_user.rb +16 -0
- data/db/migrate/016_add_host_purpose.rb +10 -0
- data/db/migrate/017_expand_info2.rb +58 -0
- data/db/migrate/018_add_workspace_user_info.rb +29 -0
- data/db/migrate/019_add_workspace_desc.rb +23 -0
- data/db/migrate/020_add_user_preferences.rb +11 -0
- data/db/migrate/021_standardize_info_and_data.rb +18 -0
- data/db/migrate/022_enlarge_event_info.rb +10 -0
- data/db/migrate/023_add_report_downloaded_at.rb +10 -0
- data/db/migrate/024_convert_service_info_to_text.rb +12 -0
- data/db/migrate/025_add_user_admin.rb +19 -0
- data/db/migrate/026_add_creds_table.rb +19 -0
- data/db/migrate/20100819123300_migrate_cred_data.rb +154 -0
- data/db/migrate/20100824151500_add_exploited_table.rb +16 -0
- data/db/migrate/20100908001428_add_owner_to_workspaces.rb +9 -0
- data/db/migrate/20100911122000_add_report_templates.rb +18 -0
- data/db/migrate/20100916151530_require_admin_flag.rb +15 -0
- data/db/migrate/20100916175000_add_campaigns_and_templates.rb +61 -0
- data/db/migrate/20100920012100_add_generate_exe_column.rb +8 -0
- data/db/migrate/20100926214000_add_template_prefs.rb +11 -0
- data/db/migrate/20101001000000_add_web_tables.rb +57 -0
- data/db/migrate/20101002000000_add_query.rb +10 -0
- data/db/migrate/20101007000000_add_vuln_info.rb +15 -0
- data/db/migrate/20101008111800_add_clients_to_campaigns.rb +10 -0
- data/db/migrate/20101009023300_add_campaign_attachments.rb +15 -0
- data/db/migrate/20101104135100_add_imported_creds.rb +17 -0
- data/db/migrate/20101203000000_fix_web_tables.rb +34 -0
- data/db/migrate/20101203000001_expand_host_comment.rb +12 -0
- data/db/migrate/20101206212033_add_limit_to_network_to_workspaces.rb +9 -0
- data/db/migrate/20110112154300_add_module_uuid_to_tasks.rb +9 -0
- data/db/migrate/20110204112800_add_host_tags.rb +28 -0
- data/db/migrate/20110317144932_add_session_table.rb +110 -0
- data/db/migrate/20110414180600_add_local_id_to_session_table.rb +11 -0
- data/db/migrate/20110415175705_add_routes_table.rb +18 -0
- data/db/migrate/20110422000000_convert_binary.rb +73 -0
- data/db/migrate/20110425095900_add_last_seen_to_sessions.rb +8 -0
- data/db/migrate/20110513143900_track_successful_exploits.rb +31 -0
- data/db/migrate/20110517160800_rename_and_prune_nessus_vulns.rb +26 -0
- data/db/migrate/20110527000000_add_task_id_to_reports_table.rb +11 -0
- data/db/migrate/20110527000001_add_api_keys_table.rb +12 -0
- data/db/migrate/20110606000001_add_macros_table.rb +16 -0
- data/db/migrate/20110622000000_add_settings_to_tasks_table.rb +12 -0
- data/db/migrate/20110624000001_add_listeners_table.rb +19 -0
- data/db/migrate/20110625000001_add_macro_to_listeners_table.rb +12 -0
- data/db/migrate/20110630000001_add_nexpose_consoles_table.rb +21 -0
- data/db/migrate/20110630000002_add_name_to_nexpose_consoles_table.rb +12 -0
- data/db/migrate/20110717000001_add_profiles_table.rb +15 -0
- data/db/migrate/20110727163801_expand_cred_ptype_column.rb +9 -0
- data/db/migrate/20110730000001_add_initial_indexes.rb +85 -0
- data/db/migrate/20110812000001_prune_indexes.rb +23 -0
- data/db/migrate/20110922000000_expand_notes.rb +9 -0
- data/db/migrate/20110928101300_add_mod_ref_table.rb +17 -0
- data/db/migrate/20111011110000_add_display_name_to_reports_table.rb +24 -0
- data/db/migrate/20111203000000_inet_columns.rb +13 -0
- data/db/migrate/20111204000000_more_inet_columns.rb +17 -0
- data/db/migrate/20111210000000_add_scope_to_hosts.rb +9 -0
- data/db/migrate/20120126110000_add_virtual_host_to_hosts.rb +9 -0
- data/db/migrate/20120411173220_rename_workspace_members.rb +9 -0
- data/db/migrate/20120601152442_add_counter_caches_to_hosts.rb +21 -0
- data/db/migrate/20120625000000_add_vuln_details.rb +34 -0
- data/db/migrate/20120625000001_add_host_details.rb +16 -0
- data/db/migrate/20120625000002_expand_details.rb +16 -0
- data/db/migrate/20120625000003_expand_details2.rb +24 -0
- data/db/migrate/20120625000004_add_vuln_attempts.rb +19 -0
- data/db/migrate/20120625000005_add_vuln_and_host_counter_caches.rb +14 -0
- data/db/migrate/20120625000006_add_module_details.rb +118 -0
- data/db/migrate/20120625000007_add_exploit_attempts.rb +26 -0
- data/db/migrate/20120625000008_add_fail_message.rb +12 -0
- data/db/migrate/20120718202805_add_owner_and_payload_to_web_vulns.rb +13 -0
- data/db/migrate/20130228214900_change_required_columns_to_null_false_in_web_vulns.rb +19 -0
- data/db/migrate/20130412154159_change_foreign_key_in_module_actions.rb +25 -0
- data/db/migrate/20130412171844_change_foreign_key_in_module_archs.rb +25 -0
- data/db/migrate/20130412173121_change_foreign_key_in_module_authors.rb +25 -0
- data/db/migrate/20130412173640_change_foreign_key_in_module_mixins.rb +25 -0
- data/db/migrate/20130412174254_change_foreign_key_in_module_platforms.rb +25 -0
- data/db/migrate/20130412174719_change_foreign_key_in_module_refs.rb +25 -0
- data/db/migrate/20130412175040_change_foreign_key_in_module_targets.rb +25 -0
- data/db/migrate/20130423211152_add_creds_counter_cache.rb +24 -0
- data/db/migrate/20130430151353_change_required_columns_to_null_false_in_hosts.rb +11 -0
- data/db/migrate/20130430162145_enforce_address_uniqueness_in_workspace_in_hosts.rb +101 -0
- data/db/migrate/20130510021637_remove_campaigns.rb +11 -0
- data/db/migrate/20130515164311_change_web_vulns_confidence_to_integer.rb +48 -0
- data/db/migrate/20130515172727_valid_mdm_web_vuln_params.rb +30 -0
- data/db/migrate/20130516204810_making_vulns_refs_a_real_ar_model.rb +5 -0
- data/db/migrate/20130522001343_create_task_creds.rb +9 -0
- data/db/migrate/20130522032517_create_task_hosts.rb +9 -0
- data/db/migrate/20130522041110_create_task_services.rb +9 -0
- data/db/migrate/20130525015035_remove_campaign_id_from_clients.rb +9 -0
- data/db/migrate/20130525212420_drop_table_imported_creds.rb +14 -0
- data/db/migrate/20130531144949_making_host_tags_a_real_ar_model.rb +6 -0
- data/db/migrate/20130604145732_create_task_sessions.rb +9 -0
- data/db/migrate/20130717150737_remove_pname_validation.rb +7 -0
- data/db/migrate/20131002004641_create_automatic_exploitation_matches.rb +13 -0
- data/db/migrate/20131002164449_create_automatic_exploitation_match_sets.rb +12 -0
- data/db/migrate/20131008213344_create_automatic_exploitation_runs.rb +11 -0
- data/db/migrate/20131011184338_module_detail_on_automatic_exploitation_match.rb +10 -0
- data/db/migrate/20131017150735_create_automatic_exploitation_match_results.rb +11 -0
- data/db/migrate/20131021185657_make_match_polymorphic.rb +11 -0
- data/db/migrate/20140905031549_add_detected_arch_to_host.rb +5 -0
- data/db/migrate/20150112203945_remove_duplicate_services.rb +17 -0
- data/db/migrate/20150205192745_drop_service_uniqueness_index.rb +5 -0
- data/db/migrate/20150209195939_add_vuln_id_to_note.rb +6 -0
- data/db/migrate/20150212214222_remove_duplicate_services2.rb +17 -0
- data/db/migrate/20150219173821_create_module_runs.rb +23 -0
- data/db/migrate/20150219215039_add_module_run_to_session.rb +8 -0
- data/db/migrate/20150226151459_add_module_run_fk_to_loot.rb +8 -0
- data/db/migrate/20150312155312_add_module_full_name_to_match.rb +6 -0
- data/db/migrate/20150317145455_rename_module_indices.rb +29 -0
- data/db/migrate/20150326183742_add_missing_ae_indices.rb +13 -0
- data/db/migrate/20150421211719_rename_automatic_exploitation_index.rb +16 -0
- data/db/migrate/20150514182921_add_origin_to_mdm_vuln.rb +13 -0
- data/db/migrate/20160415153312_remove_not_null_from_web_vuln_p_arams.rb +5 -0
- data/db/migrate/20161004165612_add_fingerprinted_to_workspace.rb +5 -0
- data/db/migrate/20161227212223_add_os_family_to_hosts.rb +5 -0
- data/db/migrate/20180904120211_create_payloads.rb +21 -0
- data/db/migrate/20190308134512_create_async_callbacks.rb +13 -0
- data/db/migrate/20190507120211_remove_payload_workspaces.rb +5 -0
- data/lib/mdm/host/operating_system_normalization.rb +942 -0
- data/lib/mdm/module.rb +13 -0
- data/lib/mdm.rb +57 -0
- data/lib/metasploit_data_models/automatic_exploitation.rb +25 -0
- data/lib/metasploit_data_models/base64_serializer.rb +99 -0
- data/lib/metasploit_data_models/change_required_columns_to_null_false.rb +21 -0
- data/lib/metasploit_data_models/engine.rb +32 -0
- data/lib/metasploit_data_models/ip_address/cidr.rb +174 -0
- data/lib/metasploit_data_models/ip_address/range.rb +181 -0
- data/lib/metasploit_data_models/ip_address/v4/segment/nmap.rb +7 -0
- data/lib/metasploit_data_models/ip_address/v4/segment.rb +7 -0
- data/lib/metasploit_data_models/ip_address/v4.rb +11 -0
- data/lib/metasploit_data_models/ip_address.rb +9 -0
- data/lib/metasploit_data_models/match/child.rb +48 -0
- data/lib/metasploit_data_models/match/parent.rb +103 -0
- data/lib/metasploit_data_models/match.rb +8 -0
- data/lib/metasploit_data_models/search/operation/port.rb +9 -0
- data/lib/metasploit_data_models/search/operation.rb +9 -0
- data/lib/metasploit_data_models/search/operator/port.rb +6 -0
- data/lib/metasploit_data_models/search/operator.rb +8 -0
- data/lib/metasploit_data_models/search/visitor.rb +11 -0
- data/lib/metasploit_data_models/search.rb +8 -0
- data/lib/metasploit_data_models/serialized_prefs.rb +27 -0
- data/lib/metasploit_data_models/version.rb +13 -0
- data/lib/metasploit_data_models.rb +56 -0
- data/metasploit_data_models.gemspec +65 -0
- data/script/rails +8 -0
- data/spec/app/models/mdm/api_key_spec.rb +3 -0
- data/spec/app/models/mdm/client_spec.rb +43 -0
- data/spec/app/models/mdm/cred_spec.rb +346 -0
- data/spec/app/models/mdm/event_spec.rb +90 -0
- data/spec/app/models/mdm/exploit_attempt_spec.rb +59 -0
- data/spec/app/models/mdm/exploited_host_spec.rb +44 -0
- data/spec/app/models/mdm/host_detail_spec.rb +48 -0
- data/spec/app/models/mdm/host_spec.rb +1139 -0
- data/spec/app/models/mdm/host_tag_spec.rb +69 -0
- data/spec/app/models/mdm/listener_spec.rb +107 -0
- data/spec/app/models/mdm/loot_spec.rb +84 -0
- data/spec/app/models/mdm/macro_spec.rb +3 -0
- data/spec/app/models/mdm/mod_ref_spec.rb +3 -0
- data/spec/app/models/mdm/module/action_spec.rb +34 -0
- data/spec/app/models/mdm/module/arch_spec.rb +34 -0
- data/spec/app/models/mdm/module/author_spec.rb +52 -0
- data/spec/app/models/mdm/module/detail_spec.rb +746 -0
- data/spec/app/models/mdm/module/mixin_spec.rb +34 -0
- data/spec/app/models/mdm/module/platform_spec.rb +34 -0
- data/spec/app/models/mdm/module/ref_spec.rb +58 -0
- data/spec/app/models/mdm/module/target_spec.rb +36 -0
- data/spec/app/models/mdm/nexpose_console_spec.rb +146 -0
- data/spec/app/models/mdm/note_spec.rb +91 -0
- data/spec/app/models/mdm/profile_spec.rb +3 -0
- data/spec/app/models/mdm/ref_spec.rb +71 -0
- data/spec/app/models/mdm/route_spec.rb +35 -0
- data/spec/app/models/mdm/service_spec.rb +232 -0
- data/spec/app/models/mdm/session_event_spec.rb +42 -0
- data/spec/app/models/mdm/session_spec.rb +118 -0
- data/spec/app/models/mdm/tag_spec.rb +116 -0
- data/spec/app/models/mdm/task_cred_spec.rb +51 -0
- data/spec/app/models/mdm/task_host_spec.rb +50 -0
- data/spec/app/models/mdm/task_service_spec.rb +50 -0
- data/spec/app/models/mdm/task_session_spec.rb +46 -0
- data/spec/app/models/mdm/task_spec.rb +71 -0
- data/spec/app/models/mdm/user_spec.rb +50 -0
- data/spec/app/models/mdm/vuln_attempt_spec.rb +53 -0
- data/spec/app/models/mdm/vuln_detail_spec.rb +65 -0
- data/spec/app/models/mdm/vuln_ref_spec.rb +46 -0
- data/spec/app/models/mdm/vuln_spec.rb +299 -0
- data/spec/app/models/mdm/web_form_spec.rb +46 -0
- data/spec/app/models/mdm/web_page_spec.rb +101 -0
- data/spec/app/models/mdm/web_site_spec.rb +85 -0
- data/spec/app/models/mdm/web_vuln_spec.rb +312 -0
- data/spec/app/models/mdm/wmap_request_spec.rb +5 -0
- data/spec/app/models/mdm/wmap_target_spec.rb +5 -0
- data/spec/app/models/mdm/workspace_spec.rb +500 -0
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_result_spec.rb +86 -0
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_set_spec.rb +46 -0
- data/spec/app/models/metasploit_data_models/automatic_exploitation/match_spec.rb +37 -0
- data/spec/app/models/metasploit_data_models/automatic_exploitation/run_spec.rb +38 -0
- data/spec/app/models/metasploit_data_models/ip_address/v4/cidr_spec.rb +119 -0
- data/spec/app/models/metasploit_data_models/ip_address/v4/nmap_spec.rb +149 -0
- data/spec/app/models/metasploit_data_models/ip_address/v4/range_spec.rb +298 -0
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/list_spec.rb +276 -0
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/nmap/range_spec.rb +302 -0
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/segmented_spec.rb +27 -0
- data/spec/app/models/metasploit_data_models/ip_address/v4/segment/single_spec.rb +324 -0
- data/spec/app/models/metasploit_data_models/ip_address/v4/single_spec.rb +181 -0
- data/spec/app/models/metasploit_data_models/module_run_spec.rb +134 -0
- data/spec/app/models/metasploit_data_models/search/operation/ip_address_spec.rb +180 -0
- data/spec/app/models/metasploit_data_models/search/operation/port/number_spec.rb +39 -0
- data/spec/app/models/metasploit_data_models/search/operation/port/range_spec.rb +138 -0
- data/spec/app/models/metasploit_data_models/search/operation/range_spec.rb +233 -0
- data/spec/app/models/metasploit_data_models/search/operator/ip_address_spec.rb +17 -0
- data/spec/app/models/metasploit_data_models/search/operator/multitext_spec.rb +160 -0
- data/spec/app/models/metasploit_data_models/search/operator/port/list_spec.rb +162 -0
- data/spec/app/models/metasploit_data_models/search/visitor/attribute_spec.rb +96 -0
- data/spec/app/models/metasploit_data_models/search/visitor/includes_spec.rb +175 -0
- data/spec/app/models/metasploit_data_models/search/visitor/joins_spec.rb +396 -0
- data/spec/app/models/metasploit_data_models/search/visitor/method_spec.rb +49 -0
- data/spec/app/models/metasploit_data_models/search/visitor/relation_spec.rb +925 -0
- data/spec/app/models/metasploit_data_models/search/visitor/where_spec.rb +187 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/config/manifest.js +1 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/application_record.rb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +61 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/database.yml.example +22 -0
- data/spec/dummy/config/database.yml.github_actions +21 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +78 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/active_record_migrations.rb +4 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/structure.sql +3430 -0
- data/spec/dummy/db/structure.sql.from_rails_3 +3403 -0
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +25 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/factories/mdm/addresses.rb +12 -0
- data/spec/factories/mdm/clients.rb +8 -0
- data/spec/factories/mdm/creds.rb +17 -0
- data/spec/factories/mdm/events.rb +15 -0
- data/spec/factories/mdm/exploit_attempts.rb +8 -0
- data/spec/factories/mdm/exploited_hosts.rb +7 -0
- data/spec/factories/mdm/fingerprints/nessus_fingerprints.rb +6 -0
- data/spec/factories/mdm/fingerprints/nexpose_fingerprints.rb +6 -0
- data/spec/factories/mdm/fingerprints/nmap_fingerprints.rb +6 -0
- data/spec/factories/mdm/fingerprints/retina_fingerprints.rb +6 -0
- data/spec/factories/mdm/fingerprints/session_fingerprints.rb +6 -0
- data/spec/factories/mdm/host_details.rb +8 -0
- data/spec/factories/mdm/host_tags.rb +9 -0
- data/spec/factories/mdm/hosts.rb +85 -0
- data/spec/factories/mdm/listeners.rb +12 -0
- data/spec/factories/mdm/loots.rb +11 -0
- data/spec/factories/mdm/module/actions.rb +14 -0
- data/spec/factories/mdm/module/archs.rb +14 -0
- data/spec/factories/mdm/module/authors.rb +22 -0
- data/spec/factories/mdm/module/details.rb +73 -0
- data/spec/factories/mdm/module/mixins.rb +14 -0
- data/spec/factories/mdm/module/platforms.rb +14 -0
- data/spec/factories/mdm/module/refs.rb +14 -0
- data/spec/factories/mdm/module/targets.rb +19 -0
- data/spec/factories/mdm/nexpose_consoles.rb +15 -0
- data/spec/factories/mdm/notes.rb +12 -0
- data/spec/factories/mdm/refs.rb +9 -0
- data/spec/factories/mdm/routes.rb +36 -0
- data/spec/factories/mdm/services.rb +41 -0
- data/spec/factories/mdm/session_events.rb +8 -0
- data/spec/factories/mdm/sessions.rb +13 -0
- data/spec/factories/mdm/tags.rb +14 -0
- data/spec/factories/mdm/task.rb +16 -0
- data/spec/factories/mdm/task_creds.rb +9 -0
- data/spec/factories/mdm/task_hosts.rb +9 -0
- data/spec/factories/mdm/task_services.rb +8 -0
- data/spec/factories/mdm/task_sessions.rb +8 -0
- data/spec/factories/mdm/users.rb +22 -0
- data/spec/factories/mdm/vuln_attempts.rb +8 -0
- data/spec/factories/mdm/vuln_details.rb +8 -0
- data/spec/factories/mdm/vuln_refs.rb +4 -0
- data/spec/factories/mdm/vulns.rb +20 -0
- data/spec/factories/mdm/web_forms.rb +33 -0
- data/spec/factories/mdm/web_pages.rb +64 -0
- data/spec/factories/mdm/web_sites.rb +8 -0
- data/spec/factories/mdm/web_vulns.rb +64 -0
- data/spec/factories/mdm/workspaces.rb +23 -0
- data/spec/factories/metasploit_data_models/automatic_exploitation/match_results.rb +7 -0
- data/spec/factories/metasploit_data_models/automatic_exploitation/match_sets.rb +8 -0
- data/spec/factories/metasploit_data_models/automatic_exploitation/matches.rb +7 -0
- data/spec/factories/metasploit_data_models/automatic_exploitation/runs.rb +6 -0
- data/spec/factories/module_runs.rb +40 -0
- data/spec/lib/base64_serializer_spec.rb +172 -0
- data/spec/lib/ipaddr_spec.rb +29 -0
- data/spec/lib/metasploit_data_models/ip_address/cidr_spec.rb +356 -0
- data/spec/lib/metasploit_data_models/ip_address/range_spec.rb +75 -0
- data/spec/lib/metasploit_data_models/match/child_spec.rb +59 -0
- data/spec/lib/metasploit_data_models/match/parent_spec.rb +153 -0
- data/spec/lib/metasploit_data_models_spec.rb +13 -0
- data/spec/spec_helper.rb +148 -0
- data/spec/support/matchers/match_regex_exactly.rb +28 -0
- data/spec/support/shared/contexts/rex/text.rb +15 -0
- data/spec/support/shared/examples/coerces_inet_column_type_to_string.rb +15 -0
- data/spec/support/shared/examples/mdm/module/detail/does_not_support_stance_with_mtype.rb +20 -0
- data/spec/support/shared/examples/mdm/module/detail/supports_stance_with_mtype.rb +36 -0
- data/spec/support/shared/examples/metasploit_data_models/search/operation/ipaddress/match.rb +109 -0
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_children.rb +38 -0
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/includes/visit/with_metasploit_model_search_operation_base.rb +26 -0
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/relation/visit/matching_record.rb +50 -0
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_equality.rb +34 -0
- data/spec/support/shared/examples/metasploit_data_models/search/visitor/where/visit/with_metasploit_model_search_group_base.rb +51 -0
- metadata +444 -6
data/lib/mdm/module.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Namespace for all models dealing with module caching.
|
2
|
+
module Mdm::Module
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
autoload :Action
|
6
|
+
autoload :Arch
|
7
|
+
autoload :Author
|
8
|
+
autoload :Detail
|
9
|
+
autoload :Mixin
|
10
|
+
autoload :Platform
|
11
|
+
autoload :Ref
|
12
|
+
autoload :Target
|
13
|
+
end
|
data/lib/mdm.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Namespace for models
|
2
|
+
module Mdm
|
3
|
+
extend ActiveSupport::Autoload
|
4
|
+
|
5
|
+
autoload :ApiKey
|
6
|
+
autoload :AsyncCallback
|
7
|
+
autoload :Client
|
8
|
+
autoload :Cred
|
9
|
+
autoload :Event
|
10
|
+
autoload :ExploitAttempt
|
11
|
+
autoload :ExploitedHost
|
12
|
+
autoload :Host
|
13
|
+
autoload :HostDetail
|
14
|
+
autoload :HostTag
|
15
|
+
autoload :Listener
|
16
|
+
autoload :Loot
|
17
|
+
autoload :Macro
|
18
|
+
autoload :ModRef
|
19
|
+
autoload :Module
|
20
|
+
autoload :NexposeConsole
|
21
|
+
autoload :Note
|
22
|
+
autoload :Payload
|
23
|
+
autoload :Profile
|
24
|
+
autoload :Ref
|
25
|
+
autoload :Route
|
26
|
+
autoload :Service
|
27
|
+
autoload :Session
|
28
|
+
autoload :SessionEvent
|
29
|
+
autoload :Tag
|
30
|
+
autoload :Task
|
31
|
+
autoload :TaskCred
|
32
|
+
autoload :TaskHost
|
33
|
+
autoload :TaskService
|
34
|
+
autoload :TaskSession
|
35
|
+
autoload :User
|
36
|
+
autoload :Vuln
|
37
|
+
autoload :VulnAttempt
|
38
|
+
autoload :VulnDetail
|
39
|
+
autoload :VulnRef
|
40
|
+
autoload :WebForm
|
41
|
+
autoload :WebPage
|
42
|
+
autoload :WebSite
|
43
|
+
autoload :WebVuln
|
44
|
+
autoload :WmapRequest
|
45
|
+
autoload :WmapTarget
|
46
|
+
autoload :Workspace
|
47
|
+
|
48
|
+
# Causes the model_name for all Mdm modules to not include the Mdm:: prefix in their name.
|
49
|
+
#
|
50
|
+
# This has been supported since ActiveSupport 3.2.1. In ActiveSupport 3.1.0, it checked for _railtie. Before that
|
51
|
+
# there was no way to do relative naming without manually overriding model_name in each class.
|
52
|
+
#
|
53
|
+
# @return [true]
|
54
|
+
def self.use_relative_model_naming?
|
55
|
+
true
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Namespace for automatic exploitation. Automatic exploitation
|
2
|
+
# {MetasploitDataModels::AutomaticExploitation::Match matches}
|
3
|
+
# {MetasploitDataModels::AutomaticExploitation::Match#matchable services or vulnerbatility} with the
|
4
|
+
# {MetasploitDataModels::AutomaticExploitation::Match#module_detail Metasploit Module} that can exploit the service or
|
5
|
+
# vulnerability. These matches are grouped into a {MetasploitDataModels::AutomaticExploitation::MatchSet a set} that
|
6
|
+
# can be {MetasploitDataModels::AutomaticExploitation::Run run} multiple times.
|
7
|
+
module MetasploitDataModels::AutomaticExploitation
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
|
10
|
+
autoload :Match
|
11
|
+
autoload :MatchResult
|
12
|
+
autoload :MatchSet
|
13
|
+
autoload :Run
|
14
|
+
|
15
|
+
#
|
16
|
+
# Module Methods
|
17
|
+
#
|
18
|
+
|
19
|
+
# The prefix of the `ApplicationRecord#table_name` of subclasses in this namespace.
|
20
|
+
#
|
21
|
+
# @return [String]
|
22
|
+
def self.table_name_prefix
|
23
|
+
'automatic_exploitation_'
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Provides ActiveRecord 3.1x-friendly serialization for descendants of
|
2
|
+
# ApplicationRecord. Backwards compatible with older YAML methods and
|
3
|
+
# will fall back to string decoding in the worst case
|
4
|
+
#
|
5
|
+
# @example Using default default of {}
|
6
|
+
# serialize :foo, MetasploitDataModels::Base64Serializer.new
|
7
|
+
#
|
8
|
+
# @example Overriding default to []
|
9
|
+
# serialize :bar, MetasploitDataModels::Base64Serializer.new(:default => [])
|
10
|
+
#
|
11
|
+
class MetasploitDataModels::Base64Serializer
|
12
|
+
#
|
13
|
+
# CONSTANTS
|
14
|
+
#
|
15
|
+
|
16
|
+
# The default for {#default}
|
17
|
+
DEFAULT = {}
|
18
|
+
# Deserializers for {#load}
|
19
|
+
# 1. Base64 decoding and then unmarshalling the value.
|
20
|
+
# 2. Parsing the value as YAML.
|
21
|
+
# 3. The raw value.
|
22
|
+
LOADERS = [
|
23
|
+
lambda { |serialized|
|
24
|
+
marshaled = serialized.unpack('m').first
|
25
|
+
# Load the unpacked Marshal object first
|
26
|
+
Marshal.load(marshaled)
|
27
|
+
},
|
28
|
+
lambda { |serialized|
|
29
|
+
# Support legacy YAML encoding for existing data
|
30
|
+
YAML.load(serialized)
|
31
|
+
},
|
32
|
+
lambda { |serialized|
|
33
|
+
# Fall back to string decoding
|
34
|
+
serialized
|
35
|
+
}
|
36
|
+
]
|
37
|
+
|
38
|
+
#
|
39
|
+
# Methods
|
40
|
+
#
|
41
|
+
|
42
|
+
# Creates a duplicate of default value
|
43
|
+
#
|
44
|
+
# @return
|
45
|
+
def default
|
46
|
+
@default.dup
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_writer :default
|
50
|
+
|
51
|
+
# Serializes the value by marshalling the value and then base64 encodes the marshaled value.
|
52
|
+
#
|
53
|
+
# @param value [Object] value to serialize
|
54
|
+
# @return [String]
|
55
|
+
def dump(value)
|
56
|
+
# Always store data back in the Marshal format
|
57
|
+
marshalled = Marshal.dump(value)
|
58
|
+
base64_encoded = [ marshalled ].pack('m')
|
59
|
+
|
60
|
+
base64_encoded
|
61
|
+
end
|
62
|
+
|
63
|
+
# @param attributes [Hash] attributes
|
64
|
+
# @option attributes [Object] :default ({}) Value to use for {#default}.
|
65
|
+
def initialize(attributes={})
|
66
|
+
attributes.assert_valid_keys(:default)
|
67
|
+
|
68
|
+
@default = attributes.fetch(:default, DEFAULT)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Deserializes the value by either
|
72
|
+
# 1. Base64 decoding and then unmarshalling the value.
|
73
|
+
# 2. Parsing the value as YAML.
|
74
|
+
# 3. Returns the raw value.
|
75
|
+
#
|
76
|
+
# @param value [String] serialized value
|
77
|
+
# @return [Object]
|
78
|
+
#
|
79
|
+
# @see #default
|
80
|
+
def load(value)
|
81
|
+
loaded = nil
|
82
|
+
|
83
|
+
if value.blank?
|
84
|
+
loaded = default
|
85
|
+
else
|
86
|
+
LOADERS.each do |loader|
|
87
|
+
begin
|
88
|
+
loaded = loader.call(value)
|
89
|
+
rescue
|
90
|
+
next
|
91
|
+
else
|
92
|
+
break
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
loaded
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Changes all the COLUMNS in the table with TABLE_NAME that are required from the table's mode, but were previously
|
2
|
+
# `:null => true`, to `:null => false`.
|
3
|
+
#
|
4
|
+
# @abstract Subclass and define COLUMNS as Array<Symbol> and TABLE_NAME as Symbol.
|
5
|
+
class MetasploitDataModels::ChangeRequiredColumnsToNullFalse < ActiveRecord::Migration[4.2]
|
6
|
+
# Marks all the COLUMNS as `:null => true`
|
7
|
+
def down
|
8
|
+
# Use self.class:: so constants are resolved in subclasses instead of this class.
|
9
|
+
self.class::COLUMNS.each do |column|
|
10
|
+
change_column_null(self.class::TABLE_NAME, column, true)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Marks all the COLUMNS as `:null => false`
|
15
|
+
def up
|
16
|
+
# Use self.class:: so constants are resolved in subclasses instead of this class.
|
17
|
+
self.class::COLUMNS.each do |column|
|
18
|
+
change_column_null(self.class::TABLE_NAME, column, false)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
# `Rails::Engine` that exposes MetasploitDataModel's `ApplicationRecord` subclasses and automatically loads its
|
4
|
+
# `FactoryBot` factories, sequences, and traits.
|
5
|
+
class MetasploitDataModels::Engine < Rails::Engine
|
6
|
+
# @see http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
|
7
|
+
config.generators do |g|
|
8
|
+
g.assets false
|
9
|
+
g.fixture_replacement :factory_bot, :dir => 'spec/factories'
|
10
|
+
g.helper false
|
11
|
+
g.test_framework :rspec, :fixture => false
|
12
|
+
end
|
13
|
+
|
14
|
+
# Remove ActiveSupport::Dependencies loading paths to save time during constant resolution and to ensure that
|
15
|
+
# metasploit_data_models is properly declaring all autoloads and not falling back on ActiveSupport::Dependencies
|
16
|
+
config.paths.values.each do |path|
|
17
|
+
path.skip_autoload!
|
18
|
+
path.skip_autoload_once!
|
19
|
+
path.skip_eager_load!
|
20
|
+
path.skip_load_path!
|
21
|
+
end
|
22
|
+
|
23
|
+
initializer 'metasploit_data_models.prepend_factory_path', :after => 'factory_bot.set_factory_paths' do
|
24
|
+
if defined? FactoryBot
|
25
|
+
relative_definition_file_path = config.generators.options[:factory_bot][:dir]
|
26
|
+
definition_file_path = root.join(relative_definition_file_path)
|
27
|
+
|
28
|
+
# unshift so that Pro can modify mdm factories
|
29
|
+
FactoryBot.definition_file_paths.unshift definition_file_path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,174 @@
|
|
1
|
+
# Common behavior for Class-InterDomain Routing (`<address>/<prefix-length>`) notation under
|
2
|
+
# {MetasploitDataModels::IPAddress},
|
3
|
+
module MetasploitDataModels::IPAddress::CIDR
|
4
|
+
# so that translations for errors messages can be filed under metasploit_data_models/ip_address/cidr
|
5
|
+
extend ActiveModel::Naming
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
#
|
9
|
+
# CONSTANTS
|
10
|
+
#
|
11
|
+
|
12
|
+
# Separator between the {#address} and {#prefix_length}
|
13
|
+
SEPARATOR = '/'
|
14
|
+
|
15
|
+
#
|
16
|
+
# Attributes
|
17
|
+
#
|
18
|
+
|
19
|
+
# @!attribute address
|
20
|
+
# The IP address being masked by {#prefix_length} `1` bits.
|
21
|
+
#
|
22
|
+
# @return [Object] an instance of {address_class}
|
23
|
+
attr_reader :address
|
24
|
+
|
25
|
+
# @!attribute prefix_length
|
26
|
+
# The significant number of bits in {#address}.
|
27
|
+
#
|
28
|
+
# @return [Integer] number of `1` bits in the netmask of {#address}
|
29
|
+
attr_reader :prefix_length
|
30
|
+
|
31
|
+
included do
|
32
|
+
include ActiveModel::Validations
|
33
|
+
|
34
|
+
#
|
35
|
+
#
|
36
|
+
# Validations
|
37
|
+
#
|
38
|
+
#
|
39
|
+
|
40
|
+
#
|
41
|
+
# Validation Methods
|
42
|
+
#
|
43
|
+
|
44
|
+
validate :address_valid
|
45
|
+
|
46
|
+
#
|
47
|
+
# Attribute Validations
|
48
|
+
#
|
49
|
+
|
50
|
+
validates :address,
|
51
|
+
presence: true
|
52
|
+
end
|
53
|
+
|
54
|
+
# Class methods added to the including `Class`.
|
55
|
+
module ClassMethods
|
56
|
+
include MetasploitDataModels::Match::Child
|
57
|
+
|
58
|
+
#
|
59
|
+
# Attributes
|
60
|
+
#
|
61
|
+
|
62
|
+
# @!attribute address_class
|
63
|
+
# The Class` whose instance are usd for {MetasploitDataModels::IPAddress::CIDR#address}.
|
64
|
+
#
|
65
|
+
# @return [Class]
|
66
|
+
attr_reader :address_class
|
67
|
+
|
68
|
+
#
|
69
|
+
# Methods
|
70
|
+
#
|
71
|
+
|
72
|
+
# @note `address_class` must respond to `#segment_class` and `#segment_count` so {#maximum_prefix_length} can be
|
73
|
+
# calculated.
|
74
|
+
#
|
75
|
+
# Sets up the address class and allowed {#maximum_prefix_length} for the including `Class`.
|
76
|
+
#
|
77
|
+
# @param options [Hash{Symbol => Class}]
|
78
|
+
# @option options [Class, #segment_class, #segment_count] :address_class The `Class` whose instances will be used
|
79
|
+
# for {#address}.
|
80
|
+
def cidr(options={})
|
81
|
+
options.assert_valid_keys(:address_class)
|
82
|
+
|
83
|
+
@address_class = options.fetch(:address_class)
|
84
|
+
|
85
|
+
#
|
86
|
+
# Validations
|
87
|
+
#
|
88
|
+
|
89
|
+
validates :prefix_length,
|
90
|
+
numericality: {
|
91
|
+
only_integer: true,
|
92
|
+
greater_than_or_equal_to: 0,
|
93
|
+
less_than_or_equal_to: maximum_prefix_length
|
94
|
+
}
|
95
|
+
end
|
96
|
+
|
97
|
+
# Regular expression that matches a string that contains only a CIDR IP address.
|
98
|
+
#
|
99
|
+
# @return [Regexp]
|
100
|
+
def match_regexp
|
101
|
+
@match_regexp ||= /\A#{regexp}\z/
|
102
|
+
end
|
103
|
+
|
104
|
+
# The maximum number of bits in a prefix for the {#address_class}.
|
105
|
+
#
|
106
|
+
# @return [Integer] the number of bits across all segments of {#address_class}.
|
107
|
+
def maximum_prefix_length
|
108
|
+
@maximum_prefix_length ||= address_class.segment_count * address_class.segment_class.bits
|
109
|
+
end
|
110
|
+
|
111
|
+
# Regular expression that matches a portion of string that contains a CIDR IP address.
|
112
|
+
#
|
113
|
+
# @return [Regexp]
|
114
|
+
def regexp
|
115
|
+
@regexp ||= /(?<address>#{address_class.regexp})#{Regexp.escape(SEPARATOR)}(?<prefix_length>\d+)/
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
#
|
120
|
+
# Instance Methods
|
121
|
+
#
|
122
|
+
|
123
|
+
# Set {#address}.
|
124
|
+
#
|
125
|
+
# @param formatted_address [#to_s]
|
126
|
+
def address=(formatted_address)
|
127
|
+
@address = self.class.address_class.new(value: formatted_address)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Set {#prefix_length}.
|
131
|
+
#
|
132
|
+
# @param formatted_prefix_length [#to_s]
|
133
|
+
def prefix_length=(formatted_prefix_length)
|
134
|
+
@prefix_length_before_type_cast = formatted_prefix_length
|
135
|
+
|
136
|
+
begin
|
137
|
+
# use Integer() instead of String#to_i as String#to_i will ignore trailing letters (i.e. '1two' -> 1) and turn all
|
138
|
+
# string without an integer in it to 0.
|
139
|
+
@prefix_length = Integer(formatted_prefix_length.to_s)
|
140
|
+
rescue ArgumentError
|
141
|
+
@prefix_length = formatted_prefix_length
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# The formatted_prefix_length passed to {#prefix_length=}
|
146
|
+
#
|
147
|
+
# @return [#to_s]
|
148
|
+
def prefix_length_before_type_cast
|
149
|
+
@prefix_length_before_type_cast
|
150
|
+
end
|
151
|
+
|
152
|
+
# Parses the `formatted_value` into an {#address} and {#prefix_length}.
|
153
|
+
#
|
154
|
+
# @param formatted_value [#to_s]
|
155
|
+
def value=(formatted_value)
|
156
|
+
formatted_address, formatted_prefix_length = formatted_value.to_s.split(SEPARATOR, 2)
|
157
|
+
|
158
|
+
self.address = formatted_address
|
159
|
+
self.prefix_length = formatted_prefix_length
|
160
|
+
|
161
|
+
[address, prefix_length]
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
# Validates that {#address} is valid.
|
167
|
+
#
|
168
|
+
# @return [void]
|
169
|
+
def address_valid
|
170
|
+
if address && !address.valid?
|
171
|
+
errors.add(:address, :invalid)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
@@ -0,0 +1,181 @@
|
|
1
|
+
# Common behavior for ranges under {MetasploitDataModels::IPAddress}, including ranges of addresses and segments.
|
2
|
+
module MetasploitDataModels::IPAddress::Range
|
3
|
+
# so that translations for error messages can be filed under metasploit_data_models/ip_address/range
|
4
|
+
extend ActiveModel::Naming
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
#
|
8
|
+
# CONSTANTS
|
9
|
+
#
|
10
|
+
|
11
|
+
# Separator between the {#begin} and {#end} in the formatted value.
|
12
|
+
SEPARATOR = '-'
|
13
|
+
|
14
|
+
#
|
15
|
+
# Attributes
|
16
|
+
#
|
17
|
+
|
18
|
+
# @!attribute value
|
19
|
+
# The range.
|
20
|
+
#
|
21
|
+
# @return [Range<Object, Objectr>] Range with {ClassMethods#extreme_class} instances for `Range#begin` and
|
22
|
+
# `Range#end`.
|
23
|
+
# @return [String] if `formatted_value` cannot be parsed into a Range.
|
24
|
+
attr_reader :value
|
25
|
+
|
26
|
+
included do
|
27
|
+
include ActiveModel::Validations
|
28
|
+
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# Validations
|
32
|
+
#
|
33
|
+
#
|
34
|
+
|
35
|
+
#
|
36
|
+
# Validation Methods
|
37
|
+
#
|
38
|
+
|
39
|
+
validate :extremes_valid
|
40
|
+
validate :order
|
41
|
+
|
42
|
+
#
|
43
|
+
# Validation Attributes
|
44
|
+
#
|
45
|
+
|
46
|
+
validates :begin,
|
47
|
+
presence: true
|
48
|
+
validates :end,
|
49
|
+
presence: true
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
# Class methods added to the including `Class`.
|
55
|
+
module ClassMethods
|
56
|
+
# @note Call {#extremes} first to set {#extreme_class_name}.
|
57
|
+
#
|
58
|
+
# Regular expression that matches a string exactly when it contains an IP address range with the correct
|
59
|
+
# {#extreme_class}.
|
60
|
+
#
|
61
|
+
# @return [Regexp] {#regexp} pinned with `'\A'` and `'\z'` to the whole `String`.
|
62
|
+
def match_regexp
|
63
|
+
@match_regexp ||= /\A#{regexp}\z/
|
64
|
+
end
|
65
|
+
|
66
|
+
# @note Call {#extremes} first to set {#extreme_class_name}.
|
67
|
+
#
|
68
|
+
# The `Class` for each extreme (`Range#begin` and `Range#end`) of the range.
|
69
|
+
#
|
70
|
+
# @return [Class]
|
71
|
+
def extreme_class
|
72
|
+
@extreme_class ||= extreme_class_name.constantize
|
73
|
+
end
|
74
|
+
|
75
|
+
# The name of {#extreme_class}.
|
76
|
+
#
|
77
|
+
# @return [String] `Class#name` passed to :class_name key when {#extremes} was called.
|
78
|
+
# @return [nil] if {#extremes} has not been called.
|
79
|
+
def extreme_class_name
|
80
|
+
@extreme_class_name
|
81
|
+
end
|
82
|
+
|
83
|
+
# Sets {#extreme_class_name}.
|
84
|
+
#
|
85
|
+
# @example Setting extremes class name
|
86
|
+
# extremes class_name: 'MetasploitDataModels::IPAddress::V4::Single'
|
87
|
+
#
|
88
|
+
# @param options [Hash{Symbol => String}]
|
89
|
+
# @option options [String] :class_name {#extreme_class_name}.
|
90
|
+
# @return [void]
|
91
|
+
def extremes(options={})
|
92
|
+
options.assert_valid_keys(:class_name)
|
93
|
+
|
94
|
+
@extreme_class_name = options.fetch(:class_name)
|
95
|
+
end
|
96
|
+
|
97
|
+
# @note Call {#extremes} first to set {#extreme_class_name}.
|
98
|
+
#
|
99
|
+
# Regular expression match a {SEPARATOR} separated range with {#extreme_class} parseable `Range#begin` and
|
100
|
+
# `Range#end`.
|
101
|
+
#
|
102
|
+
# @return [Regexp]
|
103
|
+
def regexp
|
104
|
+
@regexp ||= /#{extreme_class.regexp}#{SEPARATOR}#{extreme_class.regexp}/
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
#
|
109
|
+
# Instance Methods
|
110
|
+
#
|
111
|
+
|
112
|
+
# Begin of segment range.
|
113
|
+
#
|
114
|
+
# @return [MetasploitDataModels::IPAddress::V4::NMAP::Segment::Number] if {#value} is a `Range`.
|
115
|
+
# @return [nil] if {#value} is not a `Range`.
|
116
|
+
def begin
|
117
|
+
if value.respond_to? :begin
|
118
|
+
value.begin
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# End of segment range.
|
123
|
+
#
|
124
|
+
# @return [MetasploitDataModels::IPAddress::V4::NMAP::Segment::Number] if {#value} is a `Range`.
|
125
|
+
# @return [nil] if {#value} is not a `Range`.
|
126
|
+
def end
|
127
|
+
if value.respond_to? :end
|
128
|
+
value.end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# This range as a string. Equivalent to the original `formatted_value` passed to {#value}.
|
133
|
+
#
|
134
|
+
# @return [String]
|
135
|
+
def to_s
|
136
|
+
"#{self.begin}#{SEPARATOR}#{self.end}"
|
137
|
+
end
|
138
|
+
|
139
|
+
# Sets {#value} by breaking up the range into its begin and end Integers.
|
140
|
+
#
|
141
|
+
# @param formatted_value [#to_s]
|
142
|
+
# @return [Range<Integer, Integer>] if {SEPARATOR} is used and both extremes are Integers.
|
143
|
+
# @return [#to_s] `formatted_value` if it could not be converted
|
144
|
+
def value=(formatted_value)
|
145
|
+
formatted_extremes = formatted_value.to_s.split(SEPARATOR, 2)
|
146
|
+
|
147
|
+
extremes = formatted_extremes.map { |formatted_extreme|
|
148
|
+
self.class.extreme_class.new(value: formatted_extreme)
|
149
|
+
}
|
150
|
+
|
151
|
+
begin
|
152
|
+
@value = Range.new(*extremes)
|
153
|
+
rescue ArgumentError
|
154
|
+
@value = formatted_value
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
private
|
159
|
+
|
160
|
+
# Validates that {#begin} and {#end} are valid.
|
161
|
+
#
|
162
|
+
# @return [void]
|
163
|
+
def extremes_valid
|
164
|
+
[:begin, :end].each do |extreme_name|
|
165
|
+
extreme_value = send(extreme_name)
|
166
|
+
|
167
|
+
unless extreme_value.respond_to?(:valid?) && extreme_value.valid?
|
168
|
+
errors.add(extreme_name, :invalid)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# Validates that {#begin} is `<=` {#end}.
|
174
|
+
#
|
175
|
+
# @return [void]
|
176
|
+
def order
|
177
|
+
if self.begin && self.end && self.begin > self.end
|
178
|
+
errors.add(:value, :order, begin: self.begin, end: self.end)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# Adds a {#match match class method} to the extending class. The extending class must define `MATCH_REGEXP`.
|
2
|
+
#
|
3
|
+
# @example Define `match` class method
|
4
|
+
# class MetasploitDataModels::Format
|
5
|
+
# extend MetasploitDataModels::Match::Child
|
6
|
+
#
|
7
|
+
# #
|
8
|
+
# # CONSTANTS
|
9
|
+
# #
|
10
|
+
#
|
11
|
+
# # Regular expression {MetasploitDataModels::Match#match} must match against.
|
12
|
+
# MATCH_REGEXP = /\A...\z/
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# # a `MetasploitDataModels::Format` because `'123'` matches `MetasploitDataModels::Format::MATCH_REGEXP`
|
16
|
+
# instance = MetapsloitDataModels::Format.match('123')
|
17
|
+
# # `nil` because string `'12'` doesn't match `MetasploitDataModels::Format::MATCH_REGEXP`
|
18
|
+
# no_instance = MetasploitDataModels::Format.match('12')
|
19
|
+
#
|
20
|
+
module MetasploitDataModels::Match::Child
|
21
|
+
# Creates a new instance of the extending class if `MATCH_REGEXP`, defined on the extending class, matches
|
22
|
+
# `formatted_value`.
|
23
|
+
#
|
24
|
+
# @param formatted_value [#to_s]
|
25
|
+
def match(formatted_value)
|
26
|
+
instance = nil
|
27
|
+
|
28
|
+
if match_regexp.match(formatted_value)
|
29
|
+
instance = new(value: formatted_value)
|
30
|
+
end
|
31
|
+
|
32
|
+
instance
|
33
|
+
end
|
34
|
+
|
35
|
+
# Regular expression to match against for {#match}.
|
36
|
+
#
|
37
|
+
# @return [Regexp] Defaults to {#regexp} pinned with `\A` and `\z`.
|
38
|
+
def match_regexp
|
39
|
+
@match_regexp ||= /\A#{regexp}\z/
|
40
|
+
end
|
41
|
+
|
42
|
+
# Regular expression to match child as part of {MetasploitDataModels::Match::Parent}.
|
43
|
+
#
|
44
|
+
# @return [Regexp] Default to `REGEXP` from the extending `Class`.
|
45
|
+
def regexp
|
46
|
+
self::REGEXP
|
47
|
+
end
|
48
|
+
end
|