metasploit-model 0.24.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +27 -0
- data/.rspec +4 -0
- data/.simplecov +38 -0
- data/.travis.yml +6 -0
- data/.yardopts +5 -0
- data/Gemfile +43 -0
- data/LICENSE +27 -0
- data/README.md +33 -0
- data/Rakefile +52 -0
- data/app/models/metasploit/model/association/reflection.rb +46 -0
- data/app/models/metasploit/model/module/ancestor/spec/template.rb +125 -0
- data/app/models/metasploit/model/module/class/spec/template.rb +92 -0
- data/app/models/metasploit/model/module/instance/spec/template.rb +97 -0
- data/app/models/metasploit/model/search/group/base.rb +21 -0
- data/app/models/metasploit/model/search/group/intersection.rb +4 -0
- data/app/models/metasploit/model/search/group/union.rb +4 -0
- data/app/models/metasploit/model/search/operation/base.rb +39 -0
- data/app/models/metasploit/model/search/operation/boolean.rb +36 -0
- data/app/models/metasploit/model/search/operation/date.rb +37 -0
- data/app/models/metasploit/model/search/operation/integer.rb +14 -0
- data/app/models/metasploit/model/search/operation/null.rb +26 -0
- data/app/models/metasploit/model/search/operation/set.rb +34 -0
- data/app/models/metasploit/model/search/operation/set/integer.rb +5 -0
- data/app/models/metasploit/model/search/operation/set/string.rb +5 -0
- data/app/models/metasploit/model/search/operation/string.rb +11 -0
- data/app/models/metasploit/model/search/operation/union.rb +59 -0
- data/app/models/metasploit/model/search/operator/association.rb +43 -0
- data/app/models/metasploit/model/search/operator/attribute.rb +60 -0
- data/app/models/metasploit/model/search/operator/base.rb +34 -0
- data/app/models/metasploit/model/search/operator/delegation.rb +40 -0
- data/app/models/metasploit/model/search/operator/deprecated/app.rb +27 -0
- data/app/models/metasploit/model/search/operator/deprecated/author.rb +33 -0
- data/app/models/metasploit/model/search/operator/deprecated/authority.rb +43 -0
- data/app/models/metasploit/model/search/operator/deprecated/platform.rb +45 -0
- data/app/models/metasploit/model/search/operator/deprecated/ref.rb +50 -0
- data/app/models/metasploit/model/search/operator/deprecated/text.rb +32 -0
- data/app/models/metasploit/model/search/operator/null.rb +44 -0
- data/app/models/metasploit/model/search/operator/single.rb +98 -0
- data/app/models/metasploit/model/search/operator/union.rb +33 -0
- data/app/models/metasploit/model/search/query.rb +171 -0
- data/app/models/metasploit/model/spec/template.rb +273 -0
- data/app/models/metasploit/model/visitation/visitor.rb +69 -0
- data/app/validators/derivation_validator.rb +17 -0
- data/app/validators/dynamic_length_validator.rb +45 -0
- data/app/validators/ip_format_validator.rb +31 -0
- data/app/validators/nil_validator.rb +16 -0
- data/app/validators/parameters_validator.rb +147 -0
- data/app/validators/password_is_strong_validator.rb +115 -0
- data/config/locales/en.yml +209 -0
- data/lib/metasploit/model.rb +38 -0
- data/lib/metasploit/model/architecture.rb +346 -0
- data/lib/metasploit/model/association.rb +49 -0
- data/lib/metasploit/model/association/error.rb +40 -0
- data/lib/metasploit/model/author.rb +58 -0
- data/lib/metasploit/model/authority.rb +134 -0
- data/lib/metasploit/model/authority/bid.rb +10 -0
- data/lib/metasploit/model/authority/cve.rb +10 -0
- data/lib/metasploit/model/authority/msb.rb +10 -0
- data/lib/metasploit/model/authority/osvdb.rb +10 -0
- data/lib/metasploit/model/authority/pmasa.rb +10 -0
- data/lib/metasploit/model/authority/secunia.rb +10 -0
- data/lib/metasploit/model/authority/us_cert_vu.rb +10 -0
- data/lib/metasploit/model/authority/waraxe.rb +31 -0
- data/lib/metasploit/model/authority/zdi.rb +10 -0
- data/lib/metasploit/model/base.rb +25 -0
- data/lib/metasploit/model/configuration.rb +72 -0
- data/lib/metasploit/model/configuration/autoload.rb +109 -0
- data/lib/metasploit/model/configuration/child.rb +12 -0
- data/lib/metasploit/model/configuration/error.rb +4 -0
- data/lib/metasploit/model/configuration/i18n.rb +54 -0
- data/lib/metasploit/model/configuration/parent.rb +50 -0
- data/lib/metasploit/model/configured.rb +46 -0
- data/lib/metasploit/model/derivation.rb +110 -0
- data/lib/metasploit/model/derivation/full_name.rb +25 -0
- data/lib/metasploit/model/email_address.rb +128 -0
- data/lib/metasploit/model/engine.rb +34 -0
- data/lib/metasploit/model/error.rb +7 -0
- data/lib/metasploit/model/file.rb +49 -0
- data/lib/metasploit/model/invalid.rb +17 -0
- data/lib/metasploit/model/module.rb +8 -0
- data/lib/metasploit/model/module/action.rb +58 -0
- data/lib/metasploit/model/module/ancestor.rb +494 -0
- data/lib/metasploit/model/module/architecture.rb +40 -0
- data/lib/metasploit/model/module/author.rb +47 -0
- data/lib/metasploit/model/module/class.rb +406 -0
- data/lib/metasploit/model/module/handler.rb +35 -0
- data/lib/metasploit/model/module/instance.rb +626 -0
- data/lib/metasploit/model/module/path.rb +165 -0
- data/lib/metasploit/model/module/platform.rb +38 -0
- data/lib/metasploit/model/module/rank.rb +91 -0
- data/lib/metasploit/model/module/reference.rb +38 -0
- data/lib/metasploit/model/module/stance.rb +22 -0
- data/lib/metasploit/model/module/target.rb +80 -0
- data/lib/metasploit/model/module/target/architecture.rb +42 -0
- data/lib/metasploit/model/module/target/platform.rb +42 -0
- data/lib/metasploit/model/module/type.rb +44 -0
- data/lib/metasploit/model/nilify_blanks.rb +53 -0
- data/lib/metasploit/model/platform.rb +250 -0
- data/lib/metasploit/model/real_pathname.rb +18 -0
- data/lib/metasploit/model/reference.rb +108 -0
- data/lib/metasploit/model/search.rb +63 -0
- data/lib/metasploit/model/search/association.rb +32 -0
- data/lib/metasploit/model/search/attribute.rb +51 -0
- data/lib/metasploit/model/search/operation.rb +31 -0
- data/lib/metasploit/model/search/operation/integer/value.rb +33 -0
- data/lib/metasploit/model/search/operation/string/value.rb +14 -0
- data/lib/metasploit/model/search/operator.rb +10 -0
- data/lib/metasploit/model/search/operator/help.rb +47 -0
- data/lib/metasploit/model/search/with.rb +40 -0
- data/lib/metasploit/model/spec.rb +140 -0
- data/lib/metasploit/model/spec/error.rb +9 -0
- data/lib/metasploit/model/spec/i18n_exception_handler.rb +19 -0
- data/lib/metasploit/model/spec/pathname_collision.rb +28 -0
- data/lib/metasploit/model/spec/template/write.rb +42 -0
- data/lib/metasploit/model/spec/temporary_pathname.rb +59 -0
- data/lib/metasploit/model/translation.rb +31 -0
- data/lib/metasploit/model/version.rb +31 -0
- data/lib/metasploit/model/visitation.rb +9 -0
- data/lib/metasploit/model/visitation/visit.rb +103 -0
- data/lib/tasks/yard.rake +30 -0
- data/metasploit-model.gemspec +39 -0
- data/script/rails +9 -0
- data/spec/app/models/metasploit/model/association/reflection_spec.rb +48 -0
- data/spec/app/models/metasploit/model/module/ancestor/spec/template_spec.rb +174 -0
- data/spec/app/models/metasploit/model/module/class/spec/template_spec.rb +222 -0
- data/spec/app/models/metasploit/model/module/instance/spec/template_spec.rb +201 -0
- data/spec/app/models/metasploit/model/search/group/base_spec.rb +5 -0
- data/spec/app/models/metasploit/model/search/group/intersection_spec.rb +5 -0
- data/spec/app/models/metasploit/model/search/group/union_spec.rb +5 -0
- data/spec/app/models/metasploit/model/search/operation/base_spec.rb +70 -0
- data/spec/app/models/metasploit/model/search/operation/boolean_spec.rb +56 -0
- data/spec/app/models/metasploit/model/search/operation/date_spec.rb +89 -0
- data/spec/app/models/metasploit/model/search/operation/integer_spec.rb +9 -0
- data/spec/app/models/metasploit/model/search/operation/null_spec.rb +64 -0
- data/spec/app/models/metasploit/model/search/operation/set/integer_spec.rb +7 -0
- data/spec/app/models/metasploit/model/search/operation/set/string_spec.rb +7 -0
- data/spec/app/models/metasploit/model/search/operation/set_spec.rb +126 -0
- data/spec/app/models/metasploit/model/search/operation/string_spec.rb +9 -0
- data/spec/app/models/metasploit/model/search/operation/union_spec.rb +124 -0
- data/spec/app/models/metasploit/model/search/operator/association_spec.rb +108 -0
- data/spec/app/models/metasploit/model/search/operator/attribute_spec.rb +104 -0
- data/spec/app/models/metasploit/model/search/operator/base_spec.rb +34 -0
- data/spec/app/models/metasploit/model/search/operator/delegation_spec.rb +108 -0
- data/spec/app/models/metasploit/model/search/operator/deprecated/app_spec.rb +62 -0
- data/spec/app/models/metasploit/model/search/operator/deprecated/author_spec.rb +161 -0
- data/spec/app/models/metasploit/model/search/operator/deprecated/authority_spec.rb +123 -0
- data/spec/app/models/metasploit/model/search/operator/deprecated/platform_spec.rb +112 -0
- data/spec/app/models/metasploit/model/search/operator/deprecated/ref_spec.rb +327 -0
- data/spec/app/models/metasploit/model/search/operator/deprecated/text_spec.rb +357 -0
- data/spec/app/models/metasploit/model/search/operator/null_spec.rb +41 -0
- data/spec/app/models/metasploit/model/search/operator/single_spec.rb +327 -0
- data/spec/app/models/metasploit/model/search/operator/union_spec.rb +92 -0
- data/spec/app/models/metasploit/model/search/query_spec.rb +742 -0
- data/spec/app/models/metasploit/model/spec/template_spec.rb +23 -0
- data/spec/app/models/metasploit/model/visitation/visitor_spec.rb +45 -0
- data/spec/app/validators/derivation_validator_spec.rb +92 -0
- data/spec/app/validators/dynamic_length_validator_spec.rb +293 -0
- data/spec/app/validators/ip_format_validator_spec.rb +124 -0
- data/spec/app/validators/nil_validator_spec.rb +69 -0
- data/spec/app/validators/parameters_validator_spec.rb +342 -0
- data/spec/app/validators/password_is_strong_validator_spec.rb +250 -0
- data/spec/dummy/Rakefile +7 -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/dummy/architecture.rb +92 -0
- data/spec/dummy/app/models/dummy/author.rb +15 -0
- data/spec/dummy/app/models/dummy/authority.rb +130 -0
- data/spec/dummy/app/models/dummy/email_address.rb +27 -0
- data/spec/dummy/app/models/dummy/module/action.rb +25 -0
- data/spec/dummy/app/models/dummy/module/ancestor.rb +67 -0
- data/spec/dummy/app/models/dummy/module/architecture.rb +19 -0
- data/spec/dummy/app/models/dummy/module/author.rb +28 -0
- data/spec/dummy/app/models/dummy/module/class.rb +69 -0
- data/spec/dummy/app/models/dummy/module/instance.rb +209 -0
- data/spec/dummy/app/models/dummy/module/path.rb +64 -0
- data/spec/dummy/app/models/dummy/module/platform.rb +19 -0
- data/spec/dummy/app/models/dummy/module/rank.rb +44 -0
- data/spec/dummy/app/models/dummy/module/reference.rb +19 -0
- data/spec/dummy/app/models/dummy/module/target.rb +62 -0
- data/spec/dummy/app/models/dummy/module/target/architecture.rb +19 -0
- data/spec/dummy/app/models/dummy/module/target/platform.rb +19 -0
- data/spec/dummy/app/models/dummy/platform.rb +58 -0
- data/spec/dummy/app/models/dummy/reference.rb +31 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +43 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +27 -0
- data/spec/dummy/config/environments/production.rb +63 -0
- data/spec/dummy/config/environments/test.rb +29 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +15 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +9 -0
- data/spec/dummy/config/locales/en.yml +1 -0
- data/spec/dummy/config/routes.rb +2 -0
- data/spec/dummy/db/schema.rb +707 -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/dummy/spec/factories/dummy/architectures.rb +13 -0
- data/spec/dummy/spec/factories/dummy/authorities.rb +32 -0
- data/spec/dummy/spec/factories/dummy/authors.rb +8 -0
- data/spec/dummy/spec/factories/dummy/email_addresses.rb +8 -0
- data/spec/dummy/spec/factories/dummy/module/actions.rb +13 -0
- data/spec/dummy/spec/factories/dummy/module/ancestors.rb +45 -0
- data/spec/dummy/spec/factories/dummy/module/architectures.rb +35 -0
- data/spec/dummy/spec/factories/dummy/module/authors.rb +10 -0
- data/spec/dummy/spec/factories/dummy/module/classes.rb +40 -0
- data/spec/dummy/spec/factories/dummy/module/instances.rb +86 -0
- data/spec/dummy/spec/factories/dummy/module/paths.rb +16 -0
- data/spec/dummy/spec/factories/dummy/module/platforms.rb +35 -0
- data/spec/dummy/spec/factories/dummy/module/ranks.rb +14 -0
- data/spec/dummy/spec/factories/dummy/module/references.rb +17 -0
- data/spec/dummy/spec/factories/dummy/module/target/architectures.rb +40 -0
- data/spec/dummy/spec/factories/dummy/module/target/platforms.rb +41 -0
- data/spec/dummy/spec/factories/dummy/module/targets.rb +46 -0
- data/spec/dummy/spec/factories/dummy/platforms.rb +3 -0
- data/spec/dummy/spec/factories/dummy/references.rb +26 -0
- data/spec/factories/metasploit/model/architectures.rb +6 -0
- data/spec/factories/metasploit/model/association/reflections.rb +9 -0
- data/spec/factories/metasploit/model/authorities.rb +28 -0
- data/spec/factories/metasploit/model/authors.rb +9 -0
- data/spec/factories/metasploit/model/bases.rb +10 -0
- data/spec/factories/metasploit/model/email_addresses.rb +14 -0
- data/spec/factories/metasploit/model/module/actions.rb +9 -0
- data/spec/factories/metasploit/model/module/ancestors.rb +180 -0
- data/spec/factories/metasploit/model/module/architectures.rb +15 -0
- data/spec/factories/metasploit/model/module/classes.rb +47 -0
- data/spec/factories/metasploit/model/module/handlers.rb +3 -0
- data/spec/factories/metasploit/model/module/instances.rb +83 -0
- data/spec/factories/metasploit/model/module/paths.rb +51 -0
- data/spec/factories/metasploit/model/module/platforms.rb +15 -0
- data/spec/factories/metasploit/model/module/ranks.rb +9 -0
- data/spec/factories/metasploit/model/module/references.rb +11 -0
- data/spec/factories/metasploit/model/module/stances.rb +3 -0
- data/spec/factories/metasploit/model/module/targets.rb +22 -0
- data/spec/factories/metasploit/model/module/types.rb +5 -0
- data/spec/factories/metasploit/model/references.rb +88 -0
- data/spec/factories/metasploit/model/search/operator/associations.rb +5 -0
- data/spec/factories/metasploit/model/search/operator/attributes.rb +7 -0
- data/spec/factories/metasploit/model/search/operator/bases.rb +5 -0
- data/spec/lib/metasploit/model/architecture_spec.rb +52 -0
- data/spec/lib/metasploit/model/association/error_spec.rb +48 -0
- data/spec/lib/metasploit/model/association_spec.rb +145 -0
- data/spec/lib/metasploit/model/author_spec.rb +6 -0
- data/spec/lib/metasploit/model/authority/bid_spec.rb +17 -0
- data/spec/lib/metasploit/model/authority/cve_spec.rb +17 -0
- data/spec/lib/metasploit/model/authority/msb_spec.rb +17 -0
- data/spec/lib/metasploit/model/authority/osvdb_spec.rb +17 -0
- data/spec/lib/metasploit/model/authority/pmasa_spec.rb +17 -0
- data/spec/lib/metasploit/model/authority/secunia_spec.rb +17 -0
- data/spec/lib/metasploit/model/authority/us_cert_vu_spec.rb +17 -0
- data/spec/lib/metasploit/model/authority/waraxe_spec.rb +51 -0
- data/spec/lib/metasploit/model/authority/zdi_spec.rb +21 -0
- data/spec/lib/metasploit/model/authority_spec.rb +10 -0
- data/spec/lib/metasploit/model/base_spec.rb +58 -0
- data/spec/lib/metasploit/model/configuration/autoload_spec.rb +165 -0
- data/spec/lib/metasploit/model/configuration/child_spec.rb +24 -0
- data/spec/lib/metasploit/model/configuration/error_spec.rb +5 -0
- data/spec/lib/metasploit/model/configuration/i18n_spec.rb +103 -0
- data/spec/lib/metasploit/model/configuration_spec.rb +106 -0
- data/spec/lib/metasploit/model/configured_spec.rb +41 -0
- data/spec/lib/metasploit/model/derivation/full_name_spec.rb +75 -0
- data/spec/lib/metasploit/model/derivation_spec.rb +217 -0
- data/spec/lib/metasploit/model/email_address_spec.rb +19 -0
- data/spec/lib/metasploit/model/engine_spec.rb +84 -0
- data/spec/lib/metasploit/model/file_spec.rb +43 -0
- data/spec/lib/metasploit/model/invalid_spec.rb +54 -0
- data/spec/lib/metasploit/model/module/action_spec.rb +6 -0
- data/spec/lib/metasploit/model/module/ancestor_spec.rb +6 -0
- data/spec/lib/metasploit/model/module/architecture_spec.rb +9 -0
- data/spec/lib/metasploit/model/module/author_spec.rb +6 -0
- data/spec/lib/metasploit/model/module/class_spec.rb +19 -0
- data/spec/lib/metasploit/model/module/handler_spec.rb +61 -0
- data/spec/lib/metasploit/model/module/instance_spec.rb +183 -0
- data/spec/lib/metasploit/model/module/path_spec.rb +6 -0
- data/spec/lib/metasploit/model/module/platform_spec.rb +9 -0
- data/spec/lib/metasploit/model/module/rank_spec.rb +29 -0
- data/spec/lib/metasploit/model/module/reference_spec.rb +9 -0
- data/spec/lib/metasploit/model/module/stance_spec.rb +30 -0
- data/spec/lib/metasploit/model/module/target/architecture_spec.rb +9 -0
- data/spec/lib/metasploit/model/module/target/platform_spec.rb +9 -0
- data/spec/lib/metasploit/model/module/target_spec.rb +9 -0
- data/spec/lib/metasploit/model/module/type_spec.rb +125 -0
- data/spec/lib/metasploit/model/nilify_blanks_spec.rb +156 -0
- data/spec/lib/metasploit/model/platform_spec.rb +100 -0
- data/spec/lib/metasploit/model/reference_spec.rb +21 -0
- data/spec/lib/metasploit/model/search/association_spec.rb +33 -0
- data/spec/lib/metasploit/model/search/attribute_spec.rb +99 -0
- data/spec/lib/metasploit/model/search/operation/integer/value_spec.rb +20 -0
- data/spec/lib/metasploit/model/search/operation/string/value_spec.rb +20 -0
- data/spec/lib/metasploit/model/search/operation_spec.rb +144 -0
- data/spec/lib/metasploit/model/search/operator/help_spec.rb +41 -0
- data/spec/lib/metasploit/model/search/with_spec.rb +81 -0
- data/spec/lib/metasploit/model/search_spec.rb +230 -0
- data/spec/lib/metasploit/model/spec/error_spec.rb +5 -0
- data/spec/lib/metasploit/model/spec/i18n_exception_handler_spec.rb +42 -0
- data/spec/lib/metasploit/model/spec/pathname_collision_spec.rb +55 -0
- data/spec/lib/metasploit/model/spec_spec.rb +114 -0
- data/spec/lib/metasploit/model/translation_spec.rb +82 -0
- data/spec/lib/metasploit/model/version_spec.rb +141 -0
- data/spec/lib/metasploit/model/visitation/visit_spec.rb +316 -0
- data/spec/lib/metasploit/model_spec.rb +68 -0
- data/spec/spec_helper.rb +48 -0
- data/spec/support/shared/contexts/metasploit/model/configuration.rb +11 -0
- data/spec/support/shared/contexts/metasploit/model/module/ancestor/contents/metasploit_module.rb +12 -0
- data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents.rb +10 -0
- data/spec/support/shared/contexts/metasploit/model/module/ancestor/factory/contents/metasploit_module.rb +15 -0
- data/spec/support/shared/contexts/metasploit/model/search/operator/union/children.rb +13 -0
- data/spec/support/shared/examples/derives.rb +115 -0
- data/spec/support/shared/examples/metasploit/model/architecture.rb +425 -0
- data/spec/support/shared/examples/metasploit/model/architecture/seed.rb +25 -0
- data/spec/support/shared/examples/metasploit/model/author.rb +27 -0
- data/spec/support/shared/examples/metasploit/model/authority.rb +124 -0
- data/spec/support/shared/examples/metasploit/model/authority/seed.rb +49 -0
- data/spec/support/shared/examples/metasploit/model/configuration/parent/child.rb +60 -0
- data/spec/support/shared/examples/metasploit/model/email_address.rb +220 -0
- data/spec/support/shared/examples/metasploit/model/module/action.rb +26 -0
- data/spec/support/shared/examples/metasploit/model/module/ancestor.rb +2004 -0
- data/spec/support/shared/examples/metasploit/model/module/ancestor/payload_factory.rb +63 -0
- data/spec/support/shared/examples/metasploit/model/module/architecture.rb +36 -0
- data/spec/support/shared/examples/metasploit/model/module/author.rb +29 -0
- data/spec/support/shared/examples/metasploit/model/module/class.rb +1514 -0
- data/spec/support/shared/examples/metasploit/model/module/handler.rb +21 -0
- data/spec/support/shared/examples/metasploit/model/module/instance.rb +1384 -0
- data/spec/support/shared/examples/metasploit/model/module/instance/class_methods.rb +537 -0
- data/spec/support/shared/examples/metasploit/model/module/instance/is_not_stanced_with_module_type.rb +22 -0
- data/spec/support/shared/examples/metasploit/model/module/instance/is_stanced_with_module_type.rb +38 -0
- data/spec/support/shared/examples/metasploit/model/module/instance/validates/dynamic_length_of.rb +131 -0
- data/spec/support/shared/examples/metasploit/model/module/path.rb +493 -0
- data/spec/support/shared/examples/metasploit/model/module/platform.rb +36 -0
- data/spec/support/shared/examples/metasploit/model/module/rank.rb +92 -0
- data/spec/support/shared/examples/metasploit/model/module/reference.rb +16 -0
- data/spec/support/shared/examples/metasploit/model/module/target.rb +29 -0
- data/spec/support/shared/examples/metasploit/model/module/target/architecture.rb +56 -0
- data/spec/support/shared/examples/metasploit/model/module/target/platform.rb +56 -0
- data/spec/support/shared/examples/metasploit/model/platform.rb +213 -0
- data/spec/support/shared/examples/metasploit/model/real_pathname.rb +29 -0
- data/spec/support/shared/examples/metasploit/model/reference.rb +410 -0
- data/spec/support/shared/examples/metasploit/model/search/operation/integer/value.rb +79 -0
- data/spec/support/shared/examples/metasploit/model/search/operation/string/value.rb +53 -0
- data/spec/support/shared/examples/metasploit/model/search/operator/help.rb +134 -0
- data/spec/support/shared/examples/metasploit/model/translation.rb +37 -0
- data/spec/support/shared/examples/search/query.rb +43 -0
- data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/app.rb +44 -0
- data/spec/support/shared/examples/search/query/metasploit/model/search/operator/deprecated/authority.rb +60 -0
- data/spec/support/shared/examples/search_association.rb +13 -0
- data/spec/support/shared/examples/search_attribute.rb +27 -0
- data/spec/support/shared/examples/search_with.rb +36 -0
- data/spec/support/shared/matchers/allow_attribute.rb +17 -0
- data/spec/support/templates/metasploit/model/module/ancestors/_attributes.rb.erb +9 -0
- data/spec/support/templates/metasploit/model/module/ancestors/_methods.rb.erb +8 -0
- data/spec/support/templates/metasploit/model/module/ancestors/_validations.rb.erb +6 -0
- data/spec/support/templates/metasploit/model/module/ancestors/base.rb.erb +3 -0
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_auxiliary.rb.erb +1 -0
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_encoder.rb.erb +1 -0
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_exploit.rb.erb +1 -0
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_non_payload.rb.erb +5 -0
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_nop.rb.erb +1 -0
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_payload.rb.erb +4 -0
- data/spec/support/templates/metasploit/model/module/ancestors/module_types/_post.rb.erb +1 -0
- data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_handled.rb.erb +20 -0
- data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_single.rb.erb +1 -0
- data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stage.rb.erb +0 -0
- data/spec/support/templates/metasploit/model/module/ancestors/payload_types/_stager.rb.erb +1 -0
- data/spec/support/templates/metasploit/model/module/classes/_methods.rb.erb +9 -0
- metadata +747 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'rails'
|
3
|
+
# Metasploit::Model.configuration.autoload.eager_load! will load this file, but if rails is not available, it should not
|
4
|
+
# break the caller of eager_load! (i.e. metasploit-framework)
|
5
|
+
rescue LoadError => error
|
6
|
+
warn "rails could not be loaded, so Metasploit::Model::Engine will not be defined: #{error}"
|
7
|
+
else
|
8
|
+
module Metasploit
|
9
|
+
module Model
|
10
|
+
# Rails engine for Metasploit::Model. Will automatically be used if `Rails` is defined when
|
11
|
+
# 'metasploit/model' is required, as should be the case in any normal Rails application Gemfile where
|
12
|
+
# gem 'rails' is the first gem in the Gemfile.
|
13
|
+
class Engine < Rails::Engine
|
14
|
+
# @see http://viget.com/extend/rails-engine-testing-with-rspec-capybara-and-factorygirl
|
15
|
+
config.generators do |g|
|
16
|
+
g.assets false
|
17
|
+
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
|
18
|
+
g.helper false
|
19
|
+
g.test_framework :rspec, :fixture => false
|
20
|
+
end
|
21
|
+
|
22
|
+
initializer 'metasploit-model.prepend_factory_path', :after => 'factory_girl.set_factory_paths' do
|
23
|
+
if defined? FactoryGirl
|
24
|
+
relative_definition_file_path = config.generators.options[:factory_girl][:dir]
|
25
|
+
definition_file_path = root.join(relative_definition_file_path)
|
26
|
+
|
27
|
+
# unshift so that dependent gems can modify metasploit-model's factories
|
28
|
+
FactoryGirl.definition_file_paths.unshift definition_file_path
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
if RUBY_PLATFORM =~ /java/
|
2
|
+
require 'java'
|
3
|
+
end
|
4
|
+
|
5
|
+
module Metasploit
|
6
|
+
module Model
|
7
|
+
# Re-implement methods on ruby's File that are buggy in JRuby so that the platform specific logic can be in this
|
8
|
+
# module instead of everywhere these methods are used.
|
9
|
+
module File
|
10
|
+
if RUBY_PLATFORM =~ /java/
|
11
|
+
# On JRuby, File.realpath does not resolve symlinks, so need to drop to Java to get the real path.
|
12
|
+
#
|
13
|
+
# @param path [String] a path that may contain `'.'`, `'..'`, or symlinks
|
14
|
+
# @return [String] canonical path
|
15
|
+
# @see https://github.com/jruby/jruby/issues/538
|
16
|
+
def self.realpath(path)
|
17
|
+
file = java.io.File.new(path)
|
18
|
+
|
19
|
+
file.canonical_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class << self
|
24
|
+
# Delegates to `::File` if `::File` supports the method when {Metasploit::Model::File} does not implement an
|
25
|
+
# override to fix different platform incompatibilities.
|
26
|
+
#
|
27
|
+
# @param method_name [Symbol] name of method.
|
28
|
+
# @param args [Array] arguments passed to method with name `method_name`.
|
29
|
+
# @param block [Proc] block to pass after `args` to method with name `method_name`.
|
30
|
+
def method_missing(method_name, *args, &block)
|
31
|
+
if ::File.respond_to?(method_name)
|
32
|
+
::File.public_send(method_name, *args, &block)
|
33
|
+
else
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Whether this module or `::File` responds to `method_name`.
|
39
|
+
#
|
40
|
+
# @param method_name [Symbol] name of method.
|
41
|
+
# @param include_private [Boolean] whether to include private methods.
|
42
|
+
# @return [Boolean]
|
43
|
+
def respond_to?(method_name, include_private=false)
|
44
|
+
::File.respond_to?(method_name, include_private) || super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Metasploit
|
2
|
+
module Model
|
3
|
+
# Error raised if a {Metasploit::Model} ActiveModel is invalid.
|
4
|
+
class Invalid < Metasploit::Model::Error
|
5
|
+
def initialize(model)
|
6
|
+
@model = model
|
7
|
+
|
8
|
+
errors = @model.errors.full_messages.join(', ')
|
9
|
+
# Must be called model_invalid so it doesn't alias errors.messages.invalid
|
10
|
+
translated_message = ::I18n.translate('metasploit.model.errors.messages.model_invalid', :errors => errors)
|
11
|
+
super(translated_message)
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :model
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Metasploit
|
2
|
+
module Model
|
3
|
+
# Namespace that maps to `Mdm::Module` and `Metasploit::Framework::Module` and contains constants and mixins to
|
4
|
+
# DRY the implementation of the in-memory and in-database models in those namespaces.
|
5
|
+
module Module
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Metasploit
|
2
|
+
module Model
|
3
|
+
module Module
|
4
|
+
# Code shared between `Mdm::Module::Action` and `Metasploit::Framework::Module::Action`.
|
5
|
+
module Action
|
6
|
+
extend ActiveModel::Naming
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
include Metasploit::Model::Translation
|
10
|
+
|
11
|
+
included do
|
12
|
+
include ActiveModel::MassAssignmentSecurity
|
13
|
+
include ActiveModel::Validations
|
14
|
+
include Metasploit::Model::Search
|
15
|
+
|
16
|
+
#
|
17
|
+
# Mass Assignment Security
|
18
|
+
#
|
19
|
+
|
20
|
+
attr_accessible :name
|
21
|
+
|
22
|
+
#
|
23
|
+
# Search Attributes
|
24
|
+
#
|
25
|
+
|
26
|
+
search_attribute :name, :type => :string
|
27
|
+
|
28
|
+
#
|
29
|
+
# Validations
|
30
|
+
#
|
31
|
+
|
32
|
+
validates :module_instance,
|
33
|
+
:presence => true
|
34
|
+
validates :name,
|
35
|
+
:presence => true
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# Associations
|
40
|
+
#
|
41
|
+
|
42
|
+
# @!attribute [rw] module_instance
|
43
|
+
# Module that has this action.
|
44
|
+
#
|
45
|
+
# @return [Metasploit::Model::Module::Instance]
|
46
|
+
|
47
|
+
#
|
48
|
+
# Attributes
|
49
|
+
#
|
50
|
+
|
51
|
+
# @!attribute [rw] name
|
52
|
+
# The name of this action.
|
53
|
+
#
|
54
|
+
# @return [String]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,494 @@
|
|
1
|
+
module Metasploit
|
2
|
+
module Model
|
3
|
+
module Module
|
4
|
+
# Code shared between `Mdm::Module::Ancestor` and `Metasploit::Framework::Module::Ancestor`.
|
5
|
+
module Ancestor
|
6
|
+
extend ActiveModel::Naming
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
include Metasploit::Model::Translation
|
10
|
+
|
11
|
+
#
|
12
|
+
# CONSTANTS
|
13
|
+
#
|
14
|
+
|
15
|
+
# The directory for a given {#module_type} is a not always the pluralization of #module_type, so this maps the
|
16
|
+
# #module_type to the type directory that is used to generate the #real_path from the #module_type and
|
17
|
+
# #reference_name.
|
18
|
+
DIRECTORY_BY_MODULE_TYPE = {
|
19
|
+
Metasploit::Model::Module::Type::AUX => Metasploit::Model::Module::Type::AUX,
|
20
|
+
Metasploit::Model::Module::Type::ENCODER => Metasploit::Model::Module::Type::ENCODER.pluralize,
|
21
|
+
Metasploit::Model::Module::Type::EXPLOIT => Metasploit::Model::Module::Type::EXPLOIT.pluralize,
|
22
|
+
Metasploit::Model::Module::Type::NOP => Metasploit::Model::Module::Type::NOP.pluralize,
|
23
|
+
Metasploit::Model::Module::Type::PAYLOAD => Metasploit::Model::Module::Type::PAYLOAD.pluralize,
|
24
|
+
Metasploit::Model::Module::Type::POST => Metasploit::Model::Module::Type::POST
|
25
|
+
}
|
26
|
+
|
27
|
+
# File extension used for metasploit modules.
|
28
|
+
EXTENSION = '.rb'
|
29
|
+
|
30
|
+
# The {#payload_type payload types} that require {#handler_type}.
|
31
|
+
HANDLED_TYPES = [
|
32
|
+
'single',
|
33
|
+
'stager'
|
34
|
+
]
|
35
|
+
|
36
|
+
# Maps directory to {#module_type} for converting a {#real_path} into a {#module_type} and {#reference_name}
|
37
|
+
MODULE_TYPE_BY_DIRECTORY = DIRECTORY_BY_MODULE_TYPE.invert
|
38
|
+
|
39
|
+
# Valid values for {#payload_type} if {#payload?} is `true`.
|
40
|
+
PAYLOAD_TYPES = [
|
41
|
+
'single',
|
42
|
+
'stage',
|
43
|
+
'stager'
|
44
|
+
]
|
45
|
+
|
46
|
+
# Regexp to keep '\' out of reference names
|
47
|
+
REFERENCE_NAME_REGEXP = /\A[\-0-9A-Z_a-z]+(?:\/[\-0-9A-Z_a-z]+)*\Z/
|
48
|
+
|
49
|
+
# Separator used to join names in {#reference_name}. It is always '/', even on Windows, where '\' is a valid
|
50
|
+
# file separator.
|
51
|
+
REFERENCE_NAME_SEPARATOR = '/'
|
52
|
+
|
53
|
+
# Regular expression matching a full SHA-1 hex digest.
|
54
|
+
SHA1_HEX_DIGEST_REGEXP = /\A[0-9a-z]{40}\Z/
|
55
|
+
|
56
|
+
included do
|
57
|
+
include ActiveModel::MassAssignmentSecurity
|
58
|
+
include ActiveModel::Validations
|
59
|
+
include ActiveModel::Validations::Callbacks
|
60
|
+
include Metasploit::Model::Derivation
|
61
|
+
include Metasploit::Model::Derivation::FullName
|
62
|
+
include Metasploit::Model::RealPathname
|
63
|
+
|
64
|
+
#
|
65
|
+
# Derivations
|
66
|
+
#
|
67
|
+
|
68
|
+
#
|
69
|
+
# Module Cache Construction derivation of {#module_type} and {#reference_name} from {#real_path} and
|
70
|
+
# {Metasploit::Model::Module::Path#real_path}.
|
71
|
+
#
|
72
|
+
|
73
|
+
derives :module_type, :validate => false
|
74
|
+
derives :reference_name, :validate => false
|
75
|
+
|
76
|
+
#
|
77
|
+
# Normal derivation from setting {#module_type} and {#reference_name}
|
78
|
+
#
|
79
|
+
|
80
|
+
derives :full_name, :validate => true
|
81
|
+
derives :payload_type, :validate => true
|
82
|
+
derives :real_path, :validate => true
|
83
|
+
|
84
|
+
# Don't validate attributes that require accessing file system to derive value
|
85
|
+
derives :real_path_modified_at, :validate => false
|
86
|
+
derives :real_path_sha1_hex_digest, :validate => false
|
87
|
+
|
88
|
+
#
|
89
|
+
# Mass Assignment Security
|
90
|
+
#
|
91
|
+
|
92
|
+
# full_name is NOT accessible since it's derived and must match {#derived_full_name} so there's no reason for a
|
93
|
+
# user to set it.
|
94
|
+
# handler_type is accessible because it's needed to derive {Metasploit::Model::Module::Class#reference_name}.
|
95
|
+
attr_accessible :handler_type
|
96
|
+
# module_type is accessible because it's needed to derive {#full_name} and {#real_path}.
|
97
|
+
attr_accessible :module_type
|
98
|
+
# payload_type is NOT accessible since it's derived and must match {#derived_payload_type}.
|
99
|
+
# reference_name is accessible because it's needed to derive {#full_name} and {#real_path}.
|
100
|
+
attr_accessible :reference_name
|
101
|
+
# real_path is accessible since {#module_type} and {#reference_name} can be derived from real_path.
|
102
|
+
attr_accessible :real_path
|
103
|
+
# real_path_modified_at is NOT accessible since it's derived
|
104
|
+
# real_path_sha1_hex_digest is NOT accessible since it's derived
|
105
|
+
|
106
|
+
#
|
107
|
+
# Validations
|
108
|
+
#
|
109
|
+
|
110
|
+
validates :handler_type,
|
111
|
+
:unless => :loading_context?,
|
112
|
+
:nil => {
|
113
|
+
:unless => :handled?
|
114
|
+
},
|
115
|
+
:presence => {
|
116
|
+
:if => :handled?
|
117
|
+
}
|
118
|
+
validates :module_type,
|
119
|
+
:inclusion => {
|
120
|
+
:in => Metasploit::Model::Module::Type::ALL
|
121
|
+
}
|
122
|
+
validates :parent_path,
|
123
|
+
:presence => true
|
124
|
+
validates :payload_type,
|
125
|
+
:inclusion => {
|
126
|
+
:if => :payload?,
|
127
|
+
:in => PAYLOAD_TYPES
|
128
|
+
},
|
129
|
+
:nil => {
|
130
|
+
:unless => :payload?
|
131
|
+
}
|
132
|
+
validates :real_path_modified_at,
|
133
|
+
:presence => true
|
134
|
+
validates :real_path_sha1_hex_digest,
|
135
|
+
:format => {
|
136
|
+
:with => SHA1_HEX_DIGEST_REGEXP
|
137
|
+
}
|
138
|
+
validates :reference_name,
|
139
|
+
:format => {
|
140
|
+
:with => REFERENCE_NAME_REGEXP
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
# Defines class methods added to classes that include {Metasploit::Model::Module::Ancestor}.
|
145
|
+
module ClassMethods
|
146
|
+
# Returns whether {#handler_type} is required or must be `nil` for the given payload_type.
|
147
|
+
#
|
148
|
+
# @param options [Hash{Symbol => String,nil}]
|
149
|
+
# @option options [String, nil] module_type (nil) `nil` or an element of
|
150
|
+
# `Metasploit::Model::Module::Ancestor::MODULE_TYPES`.
|
151
|
+
# @option options [String, nil] payload_type (nil) `nil` or an element of {PAYLOAD_TYPES}.
|
152
|
+
# @return [true] if {#handler_type} must be present.
|
153
|
+
# @return [false] if {#handler_type} must be `nil`.
|
154
|
+
def handled?(options={})
|
155
|
+
options.assert_valid_keys(:module_type, :payload_type)
|
156
|
+
|
157
|
+
handled = false
|
158
|
+
module_type = options[:module_type]
|
159
|
+
payload_type = options[:payload_type]
|
160
|
+
|
161
|
+
if module_type == 'payload' and HANDLED_TYPES.include? payload_type
|
162
|
+
handled = true
|
163
|
+
end
|
164
|
+
|
165
|
+
handled
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# Associations
|
171
|
+
#
|
172
|
+
|
173
|
+
# @!attribute [rw] parent_path
|
174
|
+
# Path under which this ancestor exists on-disk.
|
175
|
+
#
|
176
|
+
# @return [Metasploit::Model::Module::Path]
|
177
|
+
|
178
|
+
#
|
179
|
+
# Attributes
|
180
|
+
#
|
181
|
+
|
182
|
+
# @!attribute [rw] full_name
|
183
|
+
# The full name of the module. The full name is `"#{module_type}/#{reference_name}"`.
|
184
|
+
#
|
185
|
+
# @return [String]
|
186
|
+
|
187
|
+
# @!attribute [rw] handler_type
|
188
|
+
# The handler type (in the case of singles) or (in the case of stagers) the handler type alias. Handler type is
|
189
|
+
# appended to the end of the single's or stage's {#reference_name} to get the
|
190
|
+
# {Metasploit::Model::Module::Class#reference_name}.
|
191
|
+
#
|
192
|
+
# @return [String] if {Metasploit::Model::Module::Ancestor#handled?} is `true`.
|
193
|
+
# @return [nil] if {Metasploit::Model::Module::Ancestor#handled?} is `false`.
|
194
|
+
|
195
|
+
# @!attribute [rw] module_type
|
196
|
+
# The type of the module. This would be called #type, but #type is reserved for ActiveRecord's single table
|
197
|
+
# inheritance.
|
198
|
+
#
|
199
|
+
# @return [String] key in {Metasploit::Model::Module::Ancestor::DIRECTORY_BY_MODULE_TYPE}.
|
200
|
+
|
201
|
+
# @!attribute [rw] payload_type
|
202
|
+
# For payload modules, the type of payload, either 'single', 'stage', or 'stager'.
|
203
|
+
#
|
204
|
+
# @return ['single', 'stage', 'stager'] if `Metasploit::Model::Module::Ancestor#payload?` is `true`.
|
205
|
+
# @return [nil] if `Metasploit::Model::Module::Ancestor#payload?` is `false`
|
206
|
+
# @see Metasploit::Model::Module::Ancestor::PAYLOAD_TYPES
|
207
|
+
|
208
|
+
# @!attribute [rw] real_path
|
209
|
+
# The real (absolute) path to module file on-disk.
|
210
|
+
#
|
211
|
+
# @return [String]
|
212
|
+
|
213
|
+
# @!attribute [rw] real_path_modified_at
|
214
|
+
# The modification time of the module {#real_path file on-disk}.
|
215
|
+
#
|
216
|
+
# @return [DateTime]
|
217
|
+
|
218
|
+
# @!attribute [rw] real_path_sha1_hex_digest
|
219
|
+
# The SHA1 hexadecimal digest of contents of the file at {#real_path}. Stored as a string because postgres does not
|
220
|
+
# have support for a 160 bit numerical type and the hexdigest format is more recognizable when using SQL directly.
|
221
|
+
#
|
222
|
+
# @see Digest::SHA1#hexdigest
|
223
|
+
# @return [String]
|
224
|
+
|
225
|
+
# @!attribute [rw] reference_name
|
226
|
+
# The reference name of the module. The name of the module under its {#module_type type}.
|
227
|
+
#
|
228
|
+
# @return [String]
|
229
|
+
|
230
|
+
#
|
231
|
+
# Instance Methods
|
232
|
+
#
|
233
|
+
|
234
|
+
# The contents of {#real_path}.
|
235
|
+
#
|
236
|
+
# @return [String] contents of file at {#real_path}.
|
237
|
+
# @return [nil] if {#real_path} is `nil`.
|
238
|
+
# @return [nil] if {#real_path} does not exist on-disk.
|
239
|
+
def contents
|
240
|
+
contents = nil
|
241
|
+
|
242
|
+
if real_path
|
243
|
+
# rescue around both File calls since file could be deleted before size or after size and before read
|
244
|
+
begin
|
245
|
+
size = File.size(real_path)
|
246
|
+
# Specify full size of file for faster read on Windows (less chance of context switching mid-read).
|
247
|
+
# Open in binary mode in Windows to handle non-text content embedded in file.
|
248
|
+
contents = File.read(real_path, size, 0, mode: 'rb')
|
249
|
+
rescue Errno::ENOENT
|
250
|
+
contents = nil
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
contents
|
255
|
+
end
|
256
|
+
|
257
|
+
# Derives {#module_type} from {#real_path} and {Metasploit::Model::Module::Path#real_path}.
|
258
|
+
#
|
259
|
+
# @return [String]
|
260
|
+
# @return [nil] if {#real_path} is `nil`
|
261
|
+
# @return [nil] if {#relative_file_names} does not start with a module type directory.
|
262
|
+
def derived_module_type
|
263
|
+
module_type_directory = relative_file_names.first
|
264
|
+
derived = MODULE_TYPE_BY_DIRECTORY[module_type_directory]
|
265
|
+
|
266
|
+
derived
|
267
|
+
end
|
268
|
+
|
269
|
+
# Derives {#payload_type} from {#reference_name}.
|
270
|
+
#
|
271
|
+
# @return [String]
|
272
|
+
# @return [nil] if {#payload_type_directory} is `nil`
|
273
|
+
def derived_payload_type
|
274
|
+
derived = nil
|
275
|
+
directory = payload_type_directory
|
276
|
+
|
277
|
+
if directory
|
278
|
+
derived = directory.singularize
|
279
|
+
end
|
280
|
+
|
281
|
+
derived
|
282
|
+
end
|
283
|
+
|
284
|
+
# Derives {#real_path} by combining {Metasploit::Model::Module::Path#real_path parent_path.real_path},
|
285
|
+
# {#module_type_directory}, and {#reference_path} in the same way the module loader does in
|
286
|
+
# metasploit-framework.
|
287
|
+
#
|
288
|
+
# @return [String] the real path to the file holding the ruby Module or ruby Class represented by this ancestor.
|
289
|
+
# @return [nil] if {#parent_path} is `nil`.
|
290
|
+
# @return [nil] if {Metasploit::Model::Module::Path#real_path parent_path.real_path} is `nil`.
|
291
|
+
# @return [nil] if {#module_type_directory} is `nil`.
|
292
|
+
# @return [nil] if {#reference_name} is `nil`.
|
293
|
+
def derived_real_path
|
294
|
+
derived_real_path = nil
|
295
|
+
|
296
|
+
if parent_path and parent_path.real_path and module_type_directory and reference_path
|
297
|
+
derived_real_path = File.join(
|
298
|
+
parent_path.real_path,
|
299
|
+
module_type_directory,
|
300
|
+
reference_path
|
301
|
+
)
|
302
|
+
end
|
303
|
+
|
304
|
+
derived_real_path
|
305
|
+
end
|
306
|
+
|
307
|
+
# Derives {#real_path_modified_at} by getting the modification time of the file on-disk.
|
308
|
+
#
|
309
|
+
# @return [Time] modification time of {#real_path} if {#real_path} exists on disk and modification time can be
|
310
|
+
# queried by user.
|
311
|
+
# @return [nil] if {#real_path} does not exist or user cannot query the file's modification time.
|
312
|
+
def derived_real_path_modified_at
|
313
|
+
real_path_string = real_path.to_s
|
314
|
+
|
315
|
+
begin
|
316
|
+
mtime = File.mtime(real_path_string)
|
317
|
+
rescue Errno::ENOENT
|
318
|
+
nil
|
319
|
+
else
|
320
|
+
mtime.utc
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
# Derives {#real_path_sha1_hex_digest} by running the contents of {#real_path} through Digest::SHA1.hexdigest.
|
325
|
+
#
|
326
|
+
# @return [String] 40 character SHA1 hex digest if {#real_path} can be read.
|
327
|
+
# @return [nil] if {#real_path} cannot be read.
|
328
|
+
def derived_real_path_sha1_hex_digest
|
329
|
+
begin
|
330
|
+
sha1 = Digest::SHA1.file(real_path.to_s)
|
331
|
+
rescue Errno::ENOENT
|
332
|
+
hex_digest = nil
|
333
|
+
else
|
334
|
+
hex_digest = sha1.hexdigest
|
335
|
+
end
|
336
|
+
|
337
|
+
hex_digest
|
338
|
+
end
|
339
|
+
|
340
|
+
# Derives {#reference_name} from {#real_path} and {Metasploit::Model::Module::Path#real_path}.
|
341
|
+
#
|
342
|
+
# @return [String]
|
343
|
+
# @return [nil] if {#real_path} is `nil`.
|
344
|
+
def derived_reference_name
|
345
|
+
derived = nil
|
346
|
+
reference_name_file_names = relative_file_names.drop(1)
|
347
|
+
reference_name_base_name = reference_name_file_names[-1]
|
348
|
+
|
349
|
+
if reference_name_base_name
|
350
|
+
if File.extname(reference_name_base_name) == EXTENSION
|
351
|
+
reference_name_file_names[-1] = File.basename(reference_name_base_name, EXTENSION)
|
352
|
+
derived = reference_name_file_names.join(REFERENCE_NAME_SEPARATOR)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
derived
|
357
|
+
end
|
358
|
+
|
359
|
+
# Returns whether {#handler_type} is required or must be `nil`.
|
360
|
+
#
|
361
|
+
# @return (see handled?)
|
362
|
+
# @see handled?
|
363
|
+
def handled?
|
364
|
+
self.class.handled?(
|
365
|
+
:module_type => module_type,
|
366
|
+
:payload_type => payload_type
|
367
|
+
)
|
368
|
+
end
|
369
|
+
|
370
|
+
# The directory for {#module_type} under {Metasploit::Model::Module::Path parent_path.real_path}.
|
371
|
+
#
|
372
|
+
# @return [String]
|
373
|
+
# @see Metasploit::Model::Module::Ancestor::DIRECTORY_BY_MODULE_TYPE
|
374
|
+
def module_type_directory
|
375
|
+
Metasploit::Model::Module::Ancestor::DIRECTORY_BY_MODULE_TYPE[module_type]
|
376
|
+
end
|
377
|
+
|
378
|
+
# Return whether this forms part of a payload (either a single, stage, or stager).
|
379
|
+
#
|
380
|
+
# @return [true] if {#module_type} == 'payload'
|
381
|
+
# @return [false] if {#module_type} != 'payload'
|
382
|
+
def payload?
|
383
|
+
if module_type == Metasploit::Model::Module::Type::PAYLOAD
|
384
|
+
true
|
385
|
+
else
|
386
|
+
false
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
# The name used to forming the {Metasploit::Model::Module::Class#reference_name} for payloads.
|
391
|
+
#
|
392
|
+
# @return [String] The {#reference_name} without the {#payload_type_directory} if {#payload_type} is `'single'`
|
393
|
+
# or `'stage'`
|
394
|
+
# @return [String] The {#handler_type} if {#payload_type} is `'stager'`
|
395
|
+
# @return [nil] if {#module_type} is not `'payload'`
|
396
|
+
def payload_name
|
397
|
+
payload_name = nil
|
398
|
+
|
399
|
+
if module_type == Metasploit::Model::Module::Type::PAYLOAD
|
400
|
+
case payload_type
|
401
|
+
when 'single', 'stage'
|
402
|
+
if reference_name && payload_type_directory
|
403
|
+
escaped_payload_type_directory = Regexp.escape(payload_type_directory)
|
404
|
+
payload_type_directory_regexp = /^#{escaped_payload_type_directory}\//
|
405
|
+
payload_name = reference_name.gsub(payload_type_directory_regexp, '')
|
406
|
+
end
|
407
|
+
when 'stager'
|
408
|
+
payload_name = handler_type
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
payload_name
|
413
|
+
end
|
414
|
+
|
415
|
+
# The directory for {#payload_type} under {#module_type_directory} in {#real_path}.
|
416
|
+
#
|
417
|
+
# @return [String] first directory in reference_name
|
418
|
+
# @return [nil] if {#payload?} is `false`.
|
419
|
+
# @return [nil] if {#reference_name} is `nil`.
|
420
|
+
def payload_type_directory
|
421
|
+
directory = nil
|
422
|
+
|
423
|
+
if payload? and reference_name
|
424
|
+
head, _tail = reference_name.split(REFERENCE_NAME_SEPARATOR, 2)
|
425
|
+
directory = head
|
426
|
+
end
|
427
|
+
|
428
|
+
directory
|
429
|
+
end
|
430
|
+
|
431
|
+
# File names on {#relative_pathname}.
|
432
|
+
#
|
433
|
+
# @return [Enumerator<String>]
|
434
|
+
def relative_file_names
|
435
|
+
relative_pathname = self.relative_pathname
|
436
|
+
|
437
|
+
if relative_pathname
|
438
|
+
relative_pathname.each_filename
|
439
|
+
else
|
440
|
+
# empty enumerator
|
441
|
+
Enumerator.new { }
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
# {#real_path} relative to {Metasploit::Model::Module::Path#real_path}
|
446
|
+
#
|
447
|
+
# @return [Pathname]
|
448
|
+
def relative_pathname
|
449
|
+
relative_pathname = nil
|
450
|
+
real_pathname = self.real_pathname
|
451
|
+
|
452
|
+
if real_pathname
|
453
|
+
parent_path = self.parent_path
|
454
|
+
|
455
|
+
if parent_path
|
456
|
+
parent_path_real_pathname = parent_path.real_pathname
|
457
|
+
|
458
|
+
if parent_path_real_pathname
|
459
|
+
relative_pathname = real_pathname.relative_path_from parent_path_real_pathname
|
460
|
+
end
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
relative_pathname
|
465
|
+
end
|
466
|
+
|
467
|
+
# The path relative to the {#module_type_directory} under the {Metasploit::Model::Module::Path
|
468
|
+
# parent_path.real_path}, including the file {EXTENSION extension}.
|
469
|
+
#
|
470
|
+
# @return [String] {#reference_name} + {EXTENSION}
|
471
|
+
# @return [nil] if {#reference_name} is `nil`.
|
472
|
+
def reference_path
|
473
|
+
path = nil
|
474
|
+
|
475
|
+
if reference_name
|
476
|
+
path = "#{reference_name}#{EXTENSION}"
|
477
|
+
end
|
478
|
+
|
479
|
+
path
|
480
|
+
end
|
481
|
+
|
482
|
+
private
|
483
|
+
|
484
|
+
# Whether this ancestor is being validated for loading.
|
485
|
+
#
|
486
|
+
# @return [true] if `#validation_context` is `:loading`
|
487
|
+
# @return [false] otherwise
|
488
|
+
def loading_context?
|
489
|
+
validation_context == :loading
|
490
|
+
end
|
491
|
+
end
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|