contrast-agent 6.6.4 → 6.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -2
- data/.gitmodules +0 -3
- data/.simplecov +0 -1
- data/Rakefile +0 -1
- data/ext/cs__assess_array/cs__assess_array.c +41 -10
- data/ext/cs__assess_array/cs__assess_array.h +4 -1
- data/ext/cs__scope/cs__scope.c +1 -1
- data/lib/contrast/agent/assess/contrast_event.rb +2 -24
- data/lib/contrast/agent/assess/events/source_event.rb +7 -61
- data/lib/contrast/agent/assess/finalizers/hash.rb +11 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +0 -55
- data/lib/contrast/agent/assess/policy/policy_node.rb +3 -3
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +0 -1
- data/lib/contrast/agent/assess/policy/propagation_node.rb +4 -4
- data/lib/contrast/agent/assess/policy/source_method.rb +24 -1
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +7 -5
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +6 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +40 -121
- data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -3
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -1
- data/lib/contrast/agent/assess/property/evented.rb +2 -12
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +42 -82
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +11 -27
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +1 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +77 -62
- data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +6 -1
- data/lib/contrast/agent/assess/rule/response/header_rule.rb +5 -5
- data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +1 -7
- data/lib/contrast/agent/at_exit_hook.rb +1 -7
- data/lib/contrast/agent/excluder.rb +224 -0
- data/lib/contrast/agent/exclusion_matcher.rb +25 -7
- data/lib/contrast/agent/inventory/database_config.rb +18 -23
- data/lib/contrast/agent/middleware.rb +4 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +146 -127
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +4 -0
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +20 -0
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -0
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
- data/lib/contrast/agent/protect/rule/base.rb +98 -66
- data/lib/contrast/agent/protect/rule/base_service.rb +49 -24
- data/lib/contrast/agent/protect/rule/bot_blocker/bot_blocker_input_classification.rb +98 -0
- data/lib/contrast/agent/protect/rule/bot_blocker.rb +81 -0
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +30 -99
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +132 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +169 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +69 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +68 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +2 -58
- data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
- data/lib/contrast/agent/protect/rule/deserialization.rb +10 -19
- data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +2 -2
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +0 -11
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +29 -34
- data/lib/contrast/agent/protect/rule/no_sqli.rb +25 -18
- data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_input_classification.rb +61 -0
- data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass.rb +114 -0
- data/lib/contrast/agent/protect/rule/path_traversal.rb +46 -18
- data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +49 -29
- data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +37 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -62
- data/lib/contrast/agent/protect/rule/sqli/sqli_semantic/sqli_dangerous_functions.rb +67 -0
- data/lib/contrast/agent/protect/rule/sqli.rb +67 -22
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +39 -63
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +6 -33
- data/lib/contrast/agent/protect/rule/xss/reflected_xss_input_classification.rb +58 -0
- data/lib/contrast/agent/protect/rule/xss.rb +14 -20
- data/lib/contrast/agent/protect/rule/xxe.rb +15 -30
- data/lib/contrast/agent/protect/rule.rb +3 -1
- data/lib/contrast/agent/reporting/attack_result/attack_result.rb +8 -0
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +70 -36
- data/lib/contrast/agent/reporting/attack_result/response_type.rb +9 -9
- data/lib/contrast/agent/reporting/attack_result/user_input.rb +11 -0
- data/lib/contrast/agent/reporting/details/bot_blocker_details.rb +29 -0
- data/lib/contrast/agent/reporting/details/cmd_injection_details.rb +30 -0
- data/lib/contrast/agent/reporting/details/details.rb +18 -0
- data/lib/contrast/agent/reporting/details/http_method_tempering_details.rb +27 -0
- data/lib/contrast/agent/reporting/details/ip_denylist_details.rb +35 -0
- data/lib/contrast/agent/reporting/details/no_sqli_details.rb +36 -0
- data/lib/contrast/agent/reporting/details/path_traversal_details.rb +24 -0
- data/lib/contrast/agent/reporting/details/path_traversal_semantic_analysis_details.rb +32 -0
- data/lib/contrast/agent/reporting/details/protect_rule_details.rb +17 -0
- data/lib/contrast/agent/reporting/details/sqli_dangerous_functions.rb +22 -0
- data/lib/contrast/agent/reporting/details/sqli_details.rb +36 -0
- data/lib/contrast/agent/reporting/details/untrusted_deserialization_details.rb +27 -0
- data/lib/contrast/agent/reporting/details/virtual_patch_details.rb +30 -0
- data/lib/contrast/agent/reporting/details/xss_details.rb +33 -0
- data/lib/contrast/agent/reporting/details/xss_match.rb +30 -0
- data/lib/contrast/agent/reporting/details/xxe_details.rb +36 -0
- data/lib/contrast/agent/reporting/details/xxe_match.rb +25 -0
- data/lib/contrast/agent/reporting/details/xxe_wrapper.rb +25 -0
- data/lib/contrast/agent/reporting/input_analysis/details/bot_blocker_details.rb +27 -0
- data/lib/contrast/agent/reporting/input_analysis/details/protect_rule_details.rb +15 -0
- data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +1 -2
- data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +17 -3
- data/lib/contrast/agent/reporting/masker/masker.rb +80 -65
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +1 -30
- data/lib/contrast/agent/reporting/reporter.rb +1 -15
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +2 -2
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +84 -15
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +13 -25
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +19 -24
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +46 -126
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +5 -16
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +10 -18
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +6 -14
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/application_update.rb +0 -2
- data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +7 -22
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +23 -53
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +12 -9
- data/lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +23 -21
- data/lib/contrast/agent/reporting/reporting_events/finding_event_stack.rb +5 -18
- data/lib/contrast/agent/reporting/reporting_events/finding_event_taint_range.rb +1 -0
- data/lib/contrast/{api/decorators/trace_taint_range_tags.rb → agent/reporting/reporting_events/finding_event_taint_range_tags.rb} +7 -6
- data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +40 -10
- data/lib/contrast/agent/reporting/reporting_events/library_discovery.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +2 -2
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +1 -11
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +10 -14
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +11 -0
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +3 -1
- data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +12 -25
- data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +8 -27
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +3 -3
- data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +4 -7
- data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +3 -3
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +0 -3
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +1 -0
- data/lib/contrast/agent/reporting/settings/code_exclusion.rb +6 -1
- data/lib/contrast/agent/reporting/settings/exclusion_base.rb +18 -0
- data/lib/contrast/agent/reporting/settings/exclusions.rb +2 -1
- data/lib/contrast/agent/reporting/settings/input_exclusion.rb +9 -3
- data/lib/contrast/agent/reporting/settings/protect.rb +15 -15
- data/lib/contrast/agent/request.rb +4 -14
- data/lib/contrast/agent/request_context.rb +18 -24
- data/lib/contrast/agent/request_context_extend.rb +23 -164
- data/lib/contrast/agent/request_handler.rb +1 -11
- data/lib/contrast/agent/response.rb +0 -18
- data/lib/contrast/agent/telemetry/events/event.rb +1 -1
- data/lib/contrast/agent/telemetry/events/metric_event.rb +1 -1
- data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +3 -3
- data/lib/contrast/agent/thread_watcher.rb +3 -18
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +0 -11
- data/lib/contrast/agent_lib/api/command_injection.rb +46 -0
- data/lib/contrast/agent_lib/api/init.rb +101 -0
- data/lib/contrast/agent_lib/api/input_tracing.rb +267 -0
- data/lib/contrast/agent_lib/api/method_tempering.rb +29 -0
- data/lib/contrast/agent_lib/api/panic.rb +87 -0
- data/lib/contrast/agent_lib/api/path_semantic_file_security_bypass.rb +40 -0
- data/lib/contrast/agent_lib/interface.rb +260 -0
- data/lib/contrast/agent_lib/interface_base.rb +118 -0
- data/lib/contrast/agent_lib/return_types/eval_result.rb +44 -0
- data/lib/contrast/agent_lib/test.rb +29 -0
- data/lib/contrast/api/communication/connection_status.rb +5 -5
- data/lib/contrast/components/agent.rb +13 -23
- data/lib/contrast/components/api.rb +10 -10
- data/lib/contrast/components/app_context.rb +9 -11
- data/lib/contrast/components/app_context_extend.rb +1 -26
- data/lib/contrast/components/assess.rb +92 -38
- data/lib/contrast/components/assess_rules.rb +36 -0
- data/lib/contrast/components/config.rb +49 -24
- data/lib/contrast/components/heap_dump.rb +1 -1
- data/lib/contrast/components/protect.rb +9 -6
- data/lib/contrast/components/ruby_component.rb +81 -0
- data/lib/contrast/components/sampling.rb +1 -1
- data/lib/contrast/components/security_logger.rb +23 -0
- data/lib/contrast/components/settings.rb +41 -85
- data/lib/contrast/config/base_configuration.rb +1 -1
- data/lib/contrast/config/protect_rule_configuration.rb +7 -7
- data/lib/contrast/config/protect_rules_configuration.rb +24 -48
- data/lib/contrast/config/server_configuration.rb +1 -1
- data/lib/contrast/config.rb +0 -6
- data/lib/contrast/configuration.rb +73 -18
- data/lib/contrast/extension/assess/array.rb +9 -0
- data/lib/contrast/extension/assess/exec_trigger.rb +3 -1
- data/lib/contrast/extension/assess/marshal.rb +3 -2
- data/lib/contrast/extension/assess/string.rb +0 -1
- data/lib/contrast/extension/delegator.rb +2 -0
- data/lib/contrast/extension/extension.rb +1 -1
- data/lib/contrast/framework/base_support.rb +0 -5
- data/lib/contrast/framework/grape/support.rb +1 -23
- data/lib/contrast/framework/manager.rb +3 -11
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -6
- data/lib/contrast/framework/rails/railtie.rb +0 -1
- data/lib/contrast/framework/rails/support.rb +5 -59
- data/lib/contrast/framework/sinatra/support.rb +2 -21
- data/lib/contrast/logger/cef_log.rb +21 -3
- data/lib/contrast/logger/log.rb +1 -11
- data/lib/contrast/tasks/config.rb +5 -10
- data/lib/contrast/utils/assess/event_limit_utils.rb +28 -12
- data/lib/contrast/utils/assess/trigger_method_utils.rb +10 -18
- data/lib/contrast/utils/duck_utils.rb +1 -0
- data/lib/contrast/utils/findings.rb +6 -5
- data/lib/contrast/utils/hash_digest.rb +9 -24
- data/lib/contrast/utils/hash_digest_extend.rb +6 -6
- data/lib/contrast/utils/input_classification_base.rb +156 -0
- data/lib/contrast/utils/invalid_configuration_util.rb +21 -58
- data/lib/contrast/utils/log_utils.rb +47 -17
- data/lib/contrast/utils/net_http_base.rb +2 -2
- data/lib/contrast/utils/os.rb +0 -20
- data/lib/contrast/utils/patching/policy/patch_utils.rb +3 -2
- data/lib/contrast/utils/response_utils.rb +0 -16
- data/lib/contrast/utils/stack_trace_utils.rb +3 -40
- data/lib/contrast/utils/string_utils.rb +19 -7
- data/lib/contrast/utils/telemetry_client.rb +13 -7
- data/lib/contrast.rb +7 -13
- data/resources/protect/policy.json +1 -2
- data/ruby-agent.gemspec +2 -5
- metadata +78 -137
- data/exe/contrast_service +0 -23
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +0 -64
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +0 -118
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +0 -45
- data/lib/contrast/agent/reaction_processor.rb +0 -47
- data/lib/contrast/agent/reporting/reporting_events/trace_event_source.rb +0 -30
- data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +0 -43
- data/lib/contrast/agent/service_heartbeat.rb +0 -35
- data/lib/contrast/api/communication/messaging_queue.rb +0 -129
- data/lib/contrast/api/communication/response_processor.rb +0 -90
- data/lib/contrast/api/communication/service_lifecycle.rb +0 -77
- data/lib/contrast/api/communication/socket.rb +0 -44
- data/lib/contrast/api/communication/socket_client.rb +0 -130
- data/lib/contrast/api/communication/speedracer.rb +0 -142
- data/lib/contrast/api/communication/tcp_socket.rb +0 -32
- data/lib/contrast/api/communication/unix_socket.rb +0 -28
- data/lib/contrast/api/communication.rb +0 -20
- data/lib/contrast/api/decorators/activity.rb +0 -33
- data/lib/contrast/api/decorators/address.rb +0 -59
- data/lib/contrast/api/decorators/agent_startup.rb +0 -57
- data/lib/contrast/api/decorators/application_settings.rb +0 -42
- data/lib/contrast/api/decorators/application_startup.rb +0 -56
- data/lib/contrast/api/decorators/architecture_component.rb +0 -36
- data/lib/contrast/api/decorators/bot_blocker.rb +0 -37
- data/lib/contrast/api/decorators/finding.rb +0 -29
- data/lib/contrast/api/decorators/http_request.rb +0 -137
- data/lib/contrast/api/decorators/input_analysis.rb +0 -18
- data/lib/contrast/api/decorators/instrumentation_mode.rb +0 -35
- data/lib/contrast/api/decorators/ip_denylist.rb +0 -37
- data/lib/contrast/api/decorators/message.rb +0 -71
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +0 -58
- data/lib/contrast/api/decorators/response_type.rb +0 -17
- data/lib/contrast/api/decorators/route_coverage.rb +0 -91
- data/lib/contrast/api/decorators/server_features.rb +0 -25
- data/lib/contrast/api/decorators/trace_event.rb +0 -120
- data/lib/contrast/api/decorators/trace_event_object.rb +0 -63
- data/lib/contrast/api/decorators/trace_event_signature.rb +0 -69
- data/lib/contrast/api/decorators/trace_taint_range.rb +0 -52
- data/lib/contrast/api/decorators/user_input.rb +0 -51
- data/lib/contrast/api/decorators/virtual_patch.rb +0 -34
- data/lib/contrast/api/decorators.rb +0 -28
- data/lib/contrast/api/dtm.pb.rb +0 -852
- data/lib/contrast/api/settings.pb.rb +0 -500
- data/lib/contrast/api.rb +0 -16
- data/lib/contrast/components/contrast_service.rb +0 -88
- data/lib/contrast/config/assess_configuration.rb +0 -93
- data/lib/contrast/config/assess_rules_configuration.rb +0 -32
- data/lib/contrast/config/root_configuration.rb +0 -90
- data/lib/contrast/config/ruby_configuration.rb +0 -81
- data/lib/contrast/config/service_configuration.rb +0 -49
- data/lib/contrast/tasks/service.rb +0 -84
- data/lib/contrast/utils/input_classification.rb +0 -73
- data/lib/contrast/utils/preflight_util.rb +0 -13
- data/lib/protobuf/code_generator.rb +0 -129
- data/lib/protobuf/decoder.rb +0 -28
- data/lib/protobuf/deprecation.rb +0 -117
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +0 -79
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +0 -360
- data/lib/protobuf/descriptors.rb +0 -3
- data/lib/protobuf/encoder.rb +0 -11
- data/lib/protobuf/enum.rb +0 -365
- data/lib/protobuf/exceptions.rb +0 -9
- data/lib/protobuf/field/base_field.rb +0 -380
- data/lib/protobuf/field/base_field_object_definitions.rb +0 -504
- data/lib/protobuf/field/bool_field.rb +0 -64
- data/lib/protobuf/field/bytes_field.rb +0 -67
- data/lib/protobuf/field/double_field.rb +0 -25
- data/lib/protobuf/field/enum_field.rb +0 -56
- data/lib/protobuf/field/field_array.rb +0 -102
- data/lib/protobuf/field/field_hash.rb +0 -122
- data/lib/protobuf/field/fixed32_field.rb +0 -25
- data/lib/protobuf/field/fixed64_field.rb +0 -28
- data/lib/protobuf/field/float_field.rb +0 -43
- data/lib/protobuf/field/int32_field.rb +0 -21
- data/lib/protobuf/field/int64_field.rb +0 -34
- data/lib/protobuf/field/integer_field.rb +0 -23
- data/lib/protobuf/field/message_field.rb +0 -51
- data/lib/protobuf/field/sfixed32_field.rb +0 -27
- data/lib/protobuf/field/sfixed64_field.rb +0 -28
- data/lib/protobuf/field/signed_integer_field.rb +0 -29
- data/lib/protobuf/field/sint32_field.rb +0 -21
- data/lib/protobuf/field/sint64_field.rb +0 -21
- data/lib/protobuf/field/string_field.rb +0 -51
- data/lib/protobuf/field/uint32_field.rb +0 -21
- data/lib/protobuf/field/uint64_field.rb +0 -21
- data/lib/protobuf/field/varint_field.rb +0 -77
- data/lib/protobuf/field.rb +0 -74
- data/lib/protobuf/generators/base.rb +0 -85
- data/lib/protobuf/generators/enum_generator.rb +0 -39
- data/lib/protobuf/generators/extension_generator.rb +0 -27
- data/lib/protobuf/generators/field_generator.rb +0 -193
- data/lib/protobuf/generators/file_generator.rb +0 -262
- data/lib/protobuf/generators/group_generator.rb +0 -122
- data/lib/protobuf/generators/message_generator.rb +0 -104
- data/lib/protobuf/generators/option_generator.rb +0 -17
- data/lib/protobuf/generators/printable.rb +0 -160
- data/lib/protobuf/generators/service_generator.rb +0 -50
- data/lib/protobuf/lifecycle.rb +0 -33
- data/lib/protobuf/logging.rb +0 -39
- data/lib/protobuf/message/fields.rb +0 -233
- data/lib/protobuf/message/serialization.rb +0 -85
- data/lib/protobuf/message.rb +0 -241
- data/lib/protobuf/optionable.rb +0 -72
- data/lib/protobuf/tasks/compile.rake +0 -80
- data/lib/protobuf/tasks.rb +0 -1
- data/lib/protobuf/varint.rb +0 -20
- data/lib/protobuf/varint_pure.rb +0 -31
- data/lib/protobuf/version.rb +0 -3
- data/lib/protobuf/wire_type.rb +0 -10
- data/lib/protobuf.rb +0 -91
- data/proto/dynamic_discovery.proto +0 -46
- data/proto/google/protobuf/compiler/plugin.proto +0 -183
- data/proto/google/protobuf/descriptor.proto +0 -911
- data/proto/rpc.proto +0 -71
- data/service_executables/.gitkeep +0 -0
- data/service_executables/VERSION +0 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
@@ -5,7 +5,7 @@
|
|
5
5
|
# state, indicating a successful attack using SQL or NoSQL Injection.
|
6
6
|
#
|
7
7
|
# @deprecated RUBY-356: this class and those that extend it are being phased out
|
8
|
-
# in favor of the more performant code in the
|
8
|
+
# in favor of the more performant code in the Agent Library.
|
9
9
|
class Contrast::Agent::Protect::Rule::DefaultScanner # rubocop:disable Style/ClassAndModuleChildren
|
10
10
|
OPERATOR_PATTERN = %r{[+=*^/%><!-]}.cs__freeze
|
11
11
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/protect/rule/base'
|
5
|
+
require 'contrast/agent/reporting/details/untrusted_deserialization_details'
|
5
6
|
require 'contrast/components/logger'
|
6
7
|
|
7
8
|
module Contrast
|
@@ -42,17 +43,6 @@ module Contrast
|
|
42
43
|
# Used to indicate to TeamServer the gadget is an Arel module
|
43
44
|
AREL = 'Arel'
|
44
45
|
|
45
|
-
class << self
|
46
|
-
# @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
|
47
|
-
# @return [Hash] the details for this specific rule
|
48
|
-
def extract_details attack_sample
|
49
|
-
{
|
50
|
-
command: attack_sample.untrusted_deserialization.command,
|
51
|
-
deserializer: attack_sample.untrusted_deserialization.deserializer
|
52
|
-
}
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
46
|
# Return the TeamServer understood id / name of this rule.
|
57
47
|
# @return [String] the TeamServer understood id / name of this rule.
|
58
48
|
def rule_name
|
@@ -68,9 +58,10 @@ module Contrast
|
|
68
58
|
# Per the spec, this rule applies regardless of input. Only the mode
|
69
59
|
# of the rule and code exclusions apply at this point.
|
70
60
|
# @return [Boolean] should the rule apply to this call.
|
71
|
-
def infilter?
|
61
|
+
def infilter? context
|
72
62
|
return false unless enabled?
|
73
63
|
return false if protect_excluded_by_code?
|
64
|
+
return false if protect_excluded_by_url?(context)
|
74
65
|
|
75
66
|
true
|
76
67
|
end
|
@@ -116,7 +107,7 @@ module Contrast
|
|
116
107
|
ia_result = build_evaluation(gadget_command)
|
117
108
|
result = build_attack_with_match(context, ia_result, nil, gadget_command, **kwargs)
|
118
109
|
append_to_activity(context, result)
|
119
|
-
cef_logging(result, :successful_attack, gadget_command)
|
110
|
+
cef_logging(result, :successful_attack, value: gadget_command)
|
120
111
|
raise(Contrast::SecurityException.new(self, BLOCK_MESSAGE)) if blocked?
|
121
112
|
end
|
122
113
|
|
@@ -125,7 +116,7 @@ module Contrast
|
|
125
116
|
# Build the RaspRuleSample for the detected Deserialization attack.
|
126
117
|
# @param context [Contrast::Agent::RequestContext] the request
|
127
118
|
# context in which this attack is occurring.
|
128
|
-
# @param input_analysis_result [Contrast::
|
119
|
+
# @param input_analysis_result [Contrast::Agent::Reporting::InputAnalysis]
|
129
120
|
# the result of the analysis done by this rule.
|
130
121
|
# @param _candidate_string [nil] unused.
|
131
122
|
# @param kwargs [Hash, nil] Hash of inputs used by this rule to flesh
|
@@ -135,13 +126,13 @@ module Contrast
|
|
135
126
|
# to render this attack event in TeamServer.
|
136
127
|
def build_sample context, input_analysis_result, _candidate_string, **kwargs
|
137
128
|
sample = build_base_sample(context, input_analysis_result)
|
138
|
-
sample.
|
129
|
+
sample.details = Contrast::Agent::Reporting::Details::UntrustedDeserializationDetails.new
|
139
130
|
|
140
131
|
deserializer = Contrast::Utils::StringUtils.protobuf_safe_string(kwargs[:GADGET_TYPE])
|
141
|
-
sample.
|
132
|
+
sample.details.deserializer = deserializer
|
142
133
|
|
143
134
|
command = !!kwargs[:COMMAND_SCOPE]
|
144
|
-
sample.
|
135
|
+
sample.details.cmd = command
|
145
136
|
|
146
137
|
sample
|
147
138
|
end
|
@@ -154,10 +145,10 @@ module Contrast
|
|
154
145
|
# @param gadget_string [String] the input to be deserialized in which
|
155
146
|
# the gadget exists or the command that resulted from deserializing
|
156
147
|
# an input not detected in the initial infilter.
|
157
|
-
# @return [Contrast::
|
148
|
+
# @return [Contrast::Agent::Reporting::InputAnalysisResult] the result
|
158
149
|
# of the analysis done by this rule.
|
159
150
|
def build_evaluation gadget_string
|
160
|
-
ia_result = Contrast::
|
151
|
+
ia_result = Contrast::Agent::Reporting::InputAnalysisResult.new
|
161
152
|
ia_result.rule_id = rule_name
|
162
153
|
ia_result.input_type = :UNKNOWN
|
163
154
|
ia_result.key = INPUT_NAME
|
@@ -5,7 +5,7 @@ require 'contrast/utils/object_share'
|
|
5
5
|
require 'contrast/agent/protect/input_analyzer/input_analyzer'
|
6
6
|
require 'contrast/agent/reporting/attack_result/attack_result'
|
7
7
|
require 'contrast/agent/reporting/attack_result/rasp_rule_sample'
|
8
|
-
require 'contrast/utils/
|
8
|
+
require 'contrast/utils/input_classification_base'
|
9
9
|
|
10
10
|
module Contrast
|
11
11
|
module Agent
|
@@ -36,7 +36,7 @@ module Contrast
|
|
36
36
|
#
|
37
37
|
# attack_result = build_attack_result ia_result, rule_id
|
38
38
|
#
|
39
|
-
# if
|
39
|
+
# if :BLOCK != Contrast::PROTECT.rule_mode(rule_id)
|
40
40
|
# attack_result.response = :EXPLOITED
|
41
41
|
# Contrast::Agent::EXPLOITS.push attack_result
|
42
42
|
# return input_analysis
|
@@ -20,17 +20,6 @@ module Contrast
|
|
20
20
|
# UNLOCK UPDATE VERSION-CONTROL
|
21
21
|
# ].cs__freeze
|
22
22
|
|
23
|
-
class << self
|
24
|
-
# @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
|
25
|
-
# @return [Hash] the details for this specific rule
|
26
|
-
def extract_details attack_sample
|
27
|
-
{
|
28
|
-
method: attack_sample.method_tampering.method, # rubocop:disable Security/Object/Method
|
29
|
-
responseCode: attack_sample.method_tampering.response_code
|
30
|
-
}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
23
|
def rule_name
|
35
24
|
NAME
|
36
25
|
end
|
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'contrast/utils/object_share'
|
5
5
|
require 'contrast/agent/protect/rule/no_sqli'
|
6
6
|
require 'contrast/agent/protect/input_analyzer/input_analyzer'
|
7
|
-
require 'contrast/utils/
|
7
|
+
require 'contrast/utils/input_classification_base'
|
8
8
|
|
9
9
|
module Contrast
|
10
10
|
module Agent
|
@@ -50,33 +50,26 @@ module Contrast
|
|
50
50
|
NOSQL_WORTH_WATCHING_THRESHOLD = 1
|
51
51
|
NOSQL_CONFIDENCE_THRESHOLD = 3
|
52
52
|
MAX_DISTANCE = 10
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
input_type,
|
74
|
-
v)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
input_analysis
|
79
|
-
end
|
53
|
+
DEFAULT_RULE_DEFINITIONS = [
|
54
|
+
{
|
55
|
+
keywords: [],
|
56
|
+
name: 'nosql-injection',
|
57
|
+
patterns: [
|
58
|
+
{
|
59
|
+
caseSensitive: false,
|
60
|
+
id: 'NO-SQLI-1',
|
61
|
+
score: 1,
|
62
|
+
value: '(?:\\{\\s*\".*\"\\s*:.*\\})'
|
63
|
+
},
|
64
|
+
{
|
65
|
+
id: 'NO-SQLI-2',
|
66
|
+
caseSensitive: true,
|
67
|
+
score: 3,
|
68
|
+
value: "(?:\"|')?\\$(?:gte|gt|lt|lte|eq|ne|in|nin|where|mod|all|size|exists|type|slice|or)(?:\"|')?\\s*:.*" # rubocop:disable Layout/LineLength
|
69
|
+
}
|
70
|
+
]
|
71
|
+
}
|
72
|
+
].cs__freeze
|
80
73
|
|
81
74
|
private
|
82
75
|
|
@@ -102,7 +95,7 @@ module Contrast
|
|
102
95
|
# @param value [String, Array<String>] the value of the input.
|
103
96
|
#
|
104
97
|
# @return res [Contrast::Agent::Reporting::InputAnalysisResult]
|
105
|
-
def
|
98
|
+
def create_new_input_result request, rule_id, input_type, value
|
106
99
|
score = evaluate_patterns(value)
|
107
100
|
score = evaluate_rules(value, score)
|
108
101
|
|
@@ -113,8 +106,9 @@ module Contrast
|
|
113
106
|
else
|
114
107
|
IGNORE
|
115
108
|
end
|
116
|
-
|
117
|
-
|
109
|
+
result = new_ia_result(rule_id, input_type, score_level, request.path, value)
|
110
|
+
add_needed_key(request, result, input_type, value)
|
111
|
+
result
|
118
112
|
end
|
119
113
|
|
120
114
|
# This method evaluates the patterns relevant to NoSQL Injection to check whether
|
@@ -125,7 +119,7 @@ module Contrast
|
|
125
119
|
# point is returned.
|
126
120
|
#
|
127
121
|
# @param value [String] the value of the input.
|
128
|
-
# @param
|
122
|
+
# @param total_score [Integer] the total score thus far.
|
129
123
|
#
|
130
124
|
# @return res [Integer]
|
131
125
|
def evaluate_patterns value, total_score = 0
|
@@ -159,7 +153,7 @@ module Contrast
|
|
159
153
|
# point is returned.
|
160
154
|
#
|
161
155
|
# @param value [String] the value of the input.
|
162
|
-
# @param
|
156
|
+
# @param total_score [Integer] the total score thus far.
|
163
157
|
#
|
164
158
|
# @return res [Integer]
|
165
159
|
def evaluate_rules value, total_score = 0
|
@@ -209,7 +203,8 @@ module Contrast
|
|
209
203
|
def nosqli_patterns
|
210
204
|
server_features = Contrast::Agent::Reporting::Settings::ServerFeatures.new
|
211
205
|
rule_definitions = server_features&.protect&.rule_definition_list
|
212
|
-
rule_definitions
|
206
|
+
rule_definitions = DEFAULT_RULE_DEFINITIONS if rule_definitions.empty?
|
207
|
+
rule_definitions.find { |r| r[:name] == Contrast::Agent::Protect::Rule::NoSqli::NAME }&.dig(:patterns)
|
213
208
|
end
|
214
209
|
|
215
210
|
def matches_by_position value, pattern
|
@@ -3,6 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'contrast/agent/protect/rule/base_service'
|
5
5
|
require 'contrast/agent/protect/rule/sql_sample_builder'
|
6
|
+
require 'contrast/agent/reporting/input_analysis/input_type'
|
6
7
|
|
7
8
|
module Contrast
|
8
9
|
module Agent
|
@@ -15,22 +16,16 @@ module Contrast
|
|
15
16
|
include SqlSampleBuilder::NoSqliSample
|
16
17
|
# Defining build_attack_with_match method
|
17
18
|
include SqlSampleBuilder::AttackBuilder
|
19
|
+
include Contrast::Agent::Reporting::InputType
|
18
20
|
|
19
21
|
NAME = 'nosql-injection'
|
20
22
|
BLOCK_MESSAGE = 'NoSQLi rule triggered. Response blocked.'
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end: attack_sample.no_sqli.end_idx,
|
28
|
-
boundaryOverrunIndex: attack_sample.no_sqli.boundary_overrun_idx,
|
29
|
-
inputBoundaryIndex: attack_sample.no_sqli.input_boundary_idx,
|
30
|
-
query: attack_sample.no_sqli.query
|
31
|
-
}
|
32
|
-
end
|
33
|
-
end
|
23
|
+
APPLICABLE_USER_INPUTS = [
|
24
|
+
BODY, COOKIE_NAME, COOKIE_VALUE, HEADER,
|
25
|
+
PARAMETER_NAME, PARAMETER_VALUE, JSON_VALUE,
|
26
|
+
MULTIPART_VALUE, MULTIPART_FIELD_NAME,
|
27
|
+
XML_VALUE, DWR_VALUE
|
28
|
+
].cs__freeze
|
34
29
|
|
35
30
|
def rule_name
|
36
31
|
NAME
|
@@ -40,6 +35,10 @@ module Contrast
|
|
40
35
|
BLOCK_MESSAGE
|
41
36
|
end
|
42
37
|
|
38
|
+
def applicable_user_inputs
|
39
|
+
APPLICABLE_USER_INPUTS
|
40
|
+
end
|
41
|
+
|
43
42
|
# @raise [Contrast::SecurityException] if the attack is blocked
|
44
43
|
# raised with BLOCK_MESSAGE
|
45
44
|
def infilter context, database, query_string
|
@@ -55,11 +54,7 @@ module Contrast
|
|
55
54
|
end
|
56
55
|
|
57
56
|
def build_attack_with_match context, input_analysis_result, result, candidate_string, **kwargs
|
58
|
-
if mode ==
|
59
|
-
mode == Contrast::Api::Settings::ProtectionRule::Mode::PERMIT
|
60
|
-
|
61
|
-
return result
|
62
|
-
end
|
57
|
+
return result if mode == :NO_ACTION || mode == :PERMIT
|
63
58
|
|
64
59
|
result ||= build_attack_result(context)
|
65
60
|
update_successful_attack_response(context, input_analysis_result, result, candidate_string)
|
@@ -67,6 +62,18 @@ module Contrast
|
|
67
62
|
result
|
68
63
|
end
|
69
64
|
|
65
|
+
# @param context [Contrast::Agent::RequestContext]
|
66
|
+
def infilter? context
|
67
|
+
return false unless enabled?
|
68
|
+
return false unless context&.agent_input_analysis&.results&.any? do |result|
|
69
|
+
result.rule_id == rule_name
|
70
|
+
end
|
71
|
+
|
72
|
+
return false if protect_excluded_by_code?
|
73
|
+
|
74
|
+
true
|
75
|
+
end
|
76
|
+
|
70
77
|
protected
|
71
78
|
|
72
79
|
def find_attacker context, potential_attack_string, **kwargs
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/input_classification_base'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module Protect
|
9
|
+
module Rule
|
10
|
+
# The Ruby implementation of the Protect Path Traversal rule
|
11
|
+
# Input classification
|
12
|
+
module PathTraversalInputClassification
|
13
|
+
PATH_TRAVERSAL_MATCH = 'path-traversal-input-tracing-v1'
|
14
|
+
WORTHWATCHING_MATCH = 'path-traversal-worth-watching-v2'
|
15
|
+
|
16
|
+
THRESHOLD = 90.cs__freeze
|
17
|
+
class << self
|
18
|
+
include InputClassificationBase
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
# This methods checks if input is tagged DEFINITEATTACK or IGNORE matches value with it's
|
23
|
+
# key if needed and Creates new isntance of InputAnalysisResult.
|
24
|
+
#
|
25
|
+
# @param request [Contrast::Agent::Request] the current request context.
|
26
|
+
# @param rule_id [String] The name of the Protect Rule.
|
27
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
28
|
+
# @param value [String, Array<String>] the value of the input.
|
29
|
+
#
|
30
|
+
# @return res [Contrast::Agent::Reporting::InputAnalysisResult]
|
31
|
+
def create_new_input_result request, rule_id, input_type, value
|
32
|
+
return unless Contrast::AGENT_LIB
|
33
|
+
|
34
|
+
input_eval = Contrast::AGENT_LIB.eval_input(value,
|
35
|
+
convert_input_type(input_type),
|
36
|
+
Contrast::AGENT_LIB.rule_set[rule_id],
|
37
|
+
Contrast::AGENT_LIB.eval_option[:WORTHWATCHING])
|
38
|
+
|
39
|
+
ia_result = new_ia_result(rule_id, input_type, request.path, value)
|
40
|
+
score = input_eval&.score || 0
|
41
|
+
if score >= THRESHOLD
|
42
|
+
ia_result.score_level = DEFINITEATTACK
|
43
|
+
ia_result.ids << PATH_TRAVERSAL_MATCH
|
44
|
+
elsif score == 10
|
45
|
+
# There is one pattern to match 10 and thus on its own will be reported as a probe.
|
46
|
+
# This rule can report WORTHWATCHING:
|
47
|
+
# https://protect-spec.prod.dotnet.contsec.com/rules/path-traversal.html#applicable-input-types
|
48
|
+
ia_result.score_level = WORTHWATCHING
|
49
|
+
ia_result.ids << WORTHWATCHING_MATCH
|
50
|
+
else
|
51
|
+
ia_result.score_level = IGNORE
|
52
|
+
end
|
53
|
+
add_needed_key(request, ia_result, input_type, value)
|
54
|
+
ia_result
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/agent/protect/rule/base_service'
|
5
|
+
require 'contrast/agent/reporting/details/path_traversal_semantic_analysis_details'
|
6
|
+
require 'contrast/agent/request_context'
|
7
|
+
require 'contrast/utils/string_utils'
|
8
|
+
require 'contrast/agent_lib/api/path_semantic_file_security_bypass'
|
9
|
+
require 'contrast/agent_lib/interface'
|
10
|
+
|
11
|
+
module Contrast
|
12
|
+
module Agent
|
13
|
+
module Protect
|
14
|
+
module Rule
|
15
|
+
# The Ruby implementation of the Protect Path Traversal Semantic
|
16
|
+
# Bypass sub-rule. This rule should report the attack result
|
17
|
+
class PathTraversalSemanticBypass < Contrast::Agent::Protect::Rule::BaseService
|
18
|
+
NAME = 'path-traversal-semantic-file-security-bypass'
|
19
|
+
# There paths here will eventually be moved
|
20
|
+
|
21
|
+
def rule_name
|
22
|
+
NAME
|
23
|
+
end
|
24
|
+
|
25
|
+
def infilter context, method, path
|
26
|
+
return unless rule_violated?(path)
|
27
|
+
|
28
|
+
result = find_vulnerability(context, path)
|
29
|
+
|
30
|
+
return unless result
|
31
|
+
|
32
|
+
append_to_activity(context, result)
|
33
|
+
return unless blocked?
|
34
|
+
|
35
|
+
result_rule_name = Contrast::Utils::StringUtils.transform_string(result.rule_id)
|
36
|
+
cef_logging(result, :successful_attack, value: path)
|
37
|
+
exception_messasge = "#{ result_rule_name } rule triggered. Call to File.#{ method } blocked."
|
38
|
+
raise(Contrast::SecurityException.new(self, exception_messasge))
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
# Check if semantic file security bypass is detected
|
44
|
+
#
|
45
|
+
# @param file_path [String] command to check.
|
46
|
+
# @param is_custom_code[String] whether the file is being accessed by custom (user) code,
|
47
|
+
# rather than framework code
|
48
|
+
# @return result[Integer, nil] returns:
|
49
|
+
# 1 => security bypass is detected.
|
50
|
+
# 0 => no security bypass is detected.
|
51
|
+
def file_security_bypassed? file_path, is_custom_code = nil
|
52
|
+
return false unless (agent_lib = Contrast::AGENT_LIB) || file_path
|
53
|
+
|
54
|
+
custom_call = is_custom_code.nil? ? 0 : 1
|
55
|
+
|
56
|
+
agent_lib.check_path_semantic_security_bypass(file_path, custom_call) == 1
|
57
|
+
end
|
58
|
+
|
59
|
+
def rule_violated? path
|
60
|
+
is_custom_code = custom_code_accessing_system_file?(path)
|
61
|
+
is_custom_code || file_security_bypassed?(path, is_custom_code)
|
62
|
+
end
|
63
|
+
|
64
|
+
def find_vulnerability context, path
|
65
|
+
build_attack_with_match(context, nil, nil, path)
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_sample context, _input_analysis_result, path, **_kwargs
|
69
|
+
sample = build_base_sample(context, nil)
|
70
|
+
sample.details = Contrast::Agent::Reporting::Details::PathTraversalSemanticAnalysisDetails.new
|
71
|
+
path = Contrast::Utils::StringUtils.protobuf_safe_string(path)
|
72
|
+
sample.details.path = path
|
73
|
+
|
74
|
+
is_custom_code = custom_code_accessing_system_file?(path)
|
75
|
+
# This should catch all the types of security breaches in that sub-rule scope
|
76
|
+
# but apparently it's not, because some of the system files is being skipped and not detected,
|
77
|
+
# but for our previous logic - it was expected for certain files to be detected and blocked
|
78
|
+
security_bypassed = file_security_bypassed?(path, is_custom_code)
|
79
|
+
|
80
|
+
# if agent lib sub-rule returns true and is custom code -> assign and report
|
81
|
+
if security_bypassed
|
82
|
+
if is_custom_code
|
83
|
+
sample.details.findings << :CUSTOM_CODE_ACCESSING_SYSTEM_FILES
|
84
|
+
sample.details.findings << :COMMON_FILE_EXPLOITS if common_file_exploits_enabled?
|
85
|
+
end
|
86
|
+
return sample
|
87
|
+
end
|
88
|
+
|
89
|
+
if is_custom_code
|
90
|
+
sample.details.findings << :CUSTOM_CODE_ACCESSING_SYSTEM_FILES
|
91
|
+
return sample
|
92
|
+
end
|
93
|
+
|
94
|
+
nil
|
95
|
+
end
|
96
|
+
|
97
|
+
def custom_code_accessing_system_file? input
|
98
|
+
system_file?(input) && Contrast::Utils::StackTraceUtils.custom_code_context?
|
99
|
+
end
|
100
|
+
|
101
|
+
def system_file? path
|
102
|
+
return false unless path
|
103
|
+
|
104
|
+
Contrast::Agent::Protect::Rule::PathTraversal::SYSTEM_PATHS.any? { |sys_path| sys_path.include?(path) }
|
105
|
+
end
|
106
|
+
|
107
|
+
def common_file_exploits_enabled?
|
108
|
+
false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -2,7 +2,13 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/agent/protect/rule/base_service'
|
5
|
+
require 'contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass'
|
6
|
+
require 'contrast/agent/reporting/input_analysis/input_type'
|
7
|
+
require 'contrast/agent/reporting/input_analysis/score_level'
|
5
8
|
require 'contrast/utils/stack_trace_utils'
|
9
|
+
require 'contrast/agent/reporting/details/path_traversal_details'
|
10
|
+
require 'contrast/agent/reporting/details/path_traversal_semantic_analysis_details'
|
11
|
+
require 'contrast/utils/string_utils'
|
6
12
|
|
7
13
|
module Contrast
|
8
14
|
module Agent
|
@@ -11,7 +17,13 @@ module Contrast
|
|
11
17
|
# This class handles our implementation of the Path Traversal
|
12
18
|
# Protect rule.
|
13
19
|
class PathTraversal < Contrast::Agent::Protect::Rule::BaseService
|
20
|
+
include Contrast::Agent::Reporting::InputType
|
21
|
+
|
14
22
|
NAME = 'path-traversal'
|
23
|
+
APPLICABLE_USER_INPUTS = [
|
24
|
+
BODY, COOKIE_NAME, COOKIE_VALUE, HEADER, PARAMETER_VALUE, PARAMETER_NAME,
|
25
|
+
JSON_VALUE, MULTIPART_VALUE, MULTIPART_FIELD_NAME, XML_VALUE, DWR_VALUE, URI
|
26
|
+
].cs__freeze
|
15
27
|
SYSTEM_PATHS = %w[
|
16
28
|
/proc/self
|
17
29
|
etc/passwd
|
@@ -25,20 +37,20 @@ module Contrast
|
|
25
37
|
/windows/repair/
|
26
38
|
].cs__freeze
|
27
39
|
|
28
|
-
|
29
|
-
# @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
|
30
|
-
# @return [Hash] the details for this specific rule
|
31
|
-
def extract_details attack_sample
|
32
|
-
{
|
33
|
-
path: attack_sample.path_traversal.path
|
34
|
-
}
|
35
|
-
end
|
36
|
-
end
|
40
|
+
SUB_RULES = [Contrast::Agent::Protect::Rule::PathTraversalSemanticBypass.new].cs__freeze
|
37
41
|
|
38
42
|
def rule_name
|
39
43
|
NAME
|
40
44
|
end
|
41
45
|
|
46
|
+
def sub_rules
|
47
|
+
SUB_RULES
|
48
|
+
end
|
49
|
+
|
50
|
+
def applicable_user_inputs
|
51
|
+
APPLICABLE_USER_INPUTS
|
52
|
+
end
|
53
|
+
|
42
54
|
def infilter context, method, path
|
43
55
|
return unless infilter?(context)
|
44
56
|
|
@@ -48,9 +60,10 @@ module Contrast
|
|
48
60
|
append_to_activity(context, result)
|
49
61
|
return unless blocked?
|
50
62
|
|
51
|
-
|
52
|
-
|
53
|
-
|
63
|
+
result_rule_name = Contrast::Utils::StringUtils.transform_string(result.rule_id)
|
64
|
+
cef_logging(result, :successful_attack, value: path)
|
65
|
+
exception_messasge = "#{ result_rule_name } rule triggered. Call to File.#{ method } blocked."
|
66
|
+
raise(Contrast::SecurityException.new(self, exception_messasge))
|
54
67
|
end
|
55
68
|
|
56
69
|
protected
|
@@ -65,28 +78,43 @@ module Contrast
|
|
65
78
|
# evaluation
|
66
79
|
def build_sample context, input_analysis_result, path, **_kwargs
|
67
80
|
sample = build_base_sample(context, input_analysis_result)
|
68
|
-
sample.
|
81
|
+
sample.details = Contrast::Agent::Reporting::Details::PathTraversalDetails.new
|
69
82
|
path ||= input_analysis_result.value
|
70
|
-
sample.
|
83
|
+
sample.details.path = Contrast::Utils::StringUtils.protobuf_safe_string(path)
|
71
84
|
sample
|
72
85
|
end
|
73
86
|
|
87
|
+
# @param context [Contrast::Agent::RequestContext]
|
88
|
+
def infilter? context
|
89
|
+
return false unless enabled?
|
90
|
+
return false unless context&.agent_input_analysis&.results&.any? do |result|
|
91
|
+
# When a file is being accessed, the agent should see if any of its worth-watching inputs appear in
|
92
|
+
# the file path. If so, the input is considered a confirmed attack and should be reported or blocked.
|
93
|
+
# If the score level is ignore we don't need to report it.
|
94
|
+
result.rule_id == rule_name && result.score_level != Contrast::Agent::Reporting::ScoreLevel::IGNORE
|
95
|
+
end
|
96
|
+
|
97
|
+
return false if protect_excluded_by_code?
|
98
|
+
|
99
|
+
true
|
100
|
+
end
|
101
|
+
|
74
102
|
private
|
75
103
|
|
76
104
|
# Build a subclass of the RaspRuleSample if the sample matches
|
77
105
|
def build_rep_sample context, path
|
78
106
|
sample = build_base_sample(context, nil)
|
79
|
-
sample.
|
107
|
+
sample.details = Contrast::Agent::Reporting::Details::PathTraversalSemanticAnalysisDetails.new
|
80
108
|
path = Contrast::Utils::StringUtils.protobuf_safe_string(path)
|
81
|
-
sample.
|
109
|
+
sample.details.path = path
|
82
110
|
|
83
111
|
if custom_code_access_sysfile_enabled? && custom_code_accessing_system_file?(path)
|
84
|
-
sample.
|
112
|
+
sample.details.findings << :CUSTOM_CODE_ACCESSING_SYSTEM_FILES
|
85
113
|
return sample
|
86
114
|
end
|
87
115
|
|
88
116
|
if common_file_exploits_enabled? && contains_known_attack_signatures?(path)
|
89
|
-
sample.
|
117
|
+
sample.details.findings << :COMMON_FILE_EXPLOITS
|
90
118
|
return sample
|
91
119
|
end
|
92
120
|
|