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
@@ -3,6 +3,8 @@
|
|
3
3
|
|
4
4
|
require 'contrast/agent/protect/rule/base'
|
5
5
|
require 'contrast/agent/protect/rule/base_service'
|
6
|
+
require 'contrast/agent/reporting/details/sqli_details'
|
7
|
+
require 'contrast/agent/reporting/details/no_sqli_details'
|
6
8
|
|
7
9
|
module Contrast
|
8
10
|
module Agent
|
@@ -13,21 +15,21 @@ module Contrast
|
|
13
15
|
# by TeamServer
|
14
16
|
#
|
15
17
|
# @param context [Contrast::Agent::RequestContext] the context for the current request
|
16
|
-
# @param input_analysis_result [Contrast::
|
18
|
+
# @param input_analysis_result [Contrast::Agent::Reporting, nil] previous attack result for this rule,
|
17
19
|
# if one exists, in the case of multiple inputs being found to violate the protection criteria
|
18
20
|
# @candidate_string [String] the value of the input which may be an attack
|
19
21
|
# @kwargs [Hash] key - value pairs of context individual rules need to build out details
|
20
|
-
# to send to
|
21
|
-
# @return [Contrast::
|
22
|
+
# to send to TeamServer to tell the story of the attack
|
23
|
+
# @return [Contrast::Agent::Reporting::RaspRuleSample] the sample from this attack
|
22
24
|
module SqliSample
|
23
25
|
def build_sample context, input_analysis_result, candidate_string, **kwargs
|
24
26
|
sqli_sample = build_base_sample(context, input_analysis_result)
|
25
|
-
sqli_sample.
|
26
|
-
sqli_sample.
|
27
|
-
sqli_sample.
|
28
|
-
sqli_sample.
|
29
|
-
sqli_sample.
|
30
|
-
sqli_sample.
|
27
|
+
sqli_sample.details = Contrast::Agent::Reporting::Details::SqliDetails.new
|
28
|
+
sqli_sample.details.query = Contrast::Utils::StringUtils.protobuf_safe_string(candidate_string)
|
29
|
+
sqli_sample.details.start_idx = kwargs[:start_idx]
|
30
|
+
sqli_sample.details.end_idx = kwargs[:end_idx]
|
31
|
+
sqli_sample.details.boundary_overrun_idx = kwargs[:boundary_overrun_idx].to_i
|
32
|
+
sqli_sample.details.input_boundary_idx = kwargs[:input_boundary_idx].to_i
|
31
33
|
sqli_sample
|
32
34
|
end
|
33
35
|
end
|
@@ -36,21 +38,21 @@ module Contrast
|
|
36
38
|
# by TeamServer
|
37
39
|
#
|
38
40
|
# @param context [Contrast::Agent::RequestContext] the context for the current request
|
39
|
-
# @param input_analysis_result [Contrast::
|
41
|
+
# @param input_analysis_result [Contrast::Agent::Reporting, nil] previous attack result for this rule,
|
40
42
|
# if one exists, in the case of multiple inputs being found to violate the protection criteria
|
41
43
|
# @candidate_string [String] the value of the input which may be an attack
|
42
44
|
# @kwargs [Hash] key - value pairs of context individual rules need to build out details
|
43
|
-
# to send to
|
44
|
-
# @return [Contrast::
|
45
|
+
# to send to TeamServer to tell the story of the attack
|
46
|
+
# @return [Contrast::Agent::Reporting::RaspRuleSample] the sample from this attack
|
45
47
|
module NoSqliSample
|
46
48
|
def build_sample context, input_analysis_result, candidate_string, **kwargs
|
47
49
|
no_sqli_sample = build_base_sample(context, input_analysis_result)
|
48
|
-
no_sqli_sample.
|
49
|
-
no_sqli_sample.
|
50
|
-
no_sqli_sample.
|
51
|
-
no_sqli_sample.
|
52
|
-
no_sqli_sample.
|
53
|
-
no_sqli_sample.
|
50
|
+
no_sqli_sample.details = Contrast::Agent::Reporting::Details::NoSqliDetails.new
|
51
|
+
no_sqli_sample.details.query = Contrast::Utils::StringUtils.protobuf_safe_string(candidate_string)
|
52
|
+
no_sqli_sample.details.start_idx = kwargs[:start_idx].to_i
|
53
|
+
no_sqli_sample.details.end_idx = kwargs[:end_idx].to_i
|
54
|
+
no_sqli_sample.details.boundary_overrun_idx = kwargs[:boundary_overrun_idx].to_i
|
55
|
+
no_sqli_sample.details.input_boundary_idx = kwargs[:input_boundary_idx].to_i
|
54
56
|
no_sqli_sample
|
55
57
|
end
|
56
58
|
end
|
@@ -61,24 +63,21 @@ module Contrast
|
|
61
63
|
# Set up an attack result and assigns Database scanner for the No-SQL and SQLI injection detection rules
|
62
64
|
#
|
63
65
|
# @param context [Contrast::Agent::RequestContext] the context for the current request
|
64
|
-
# @param input_analysis_result [Contrast::
|
66
|
+
# @param input_analysis_result [Contrast::Agent::Reporting, nil] previous attack result for this rule,
|
65
67
|
# if one exists, in the case of multiple inputs being found to violate the protection criteria
|
66
|
-
# @param result [Contrast::
|
68
|
+
# @param result [Contrast::Agent::Reporting, nil] previous attack result for this rule, if one exists,
|
67
69
|
# in the case of multiple inputs being found to violate the protection criteria
|
68
70
|
# @param query_string [String] the value of the input which may be an attack
|
69
71
|
# @param kwargs [Hash] key - value pairs of context individual rules need to build out details to send
|
70
|
-
# to
|
71
|
-
# @return [Contrast::
|
72
|
+
# to TeamServer to tell the story of the attack
|
73
|
+
# @return [Contrast::Agent::Reporting] the result from this attack
|
72
74
|
def build_attack_with_match context, input_analysis_result, result, query_string, **kwargs
|
73
|
-
if mode ==
|
74
|
-
mode == Contrast::Api::Settings::ProtectionRule::Mode::PERMIT
|
75
|
-
|
76
|
-
return result
|
77
|
-
end
|
75
|
+
return result if mode == :NO_ACTION || mode == :PERMIT
|
78
76
|
|
79
77
|
attack_string = input_analysis_result.value
|
80
78
|
regexp = Regexp.new(Regexp.escape(attack_string), Regexp::IGNORECASE)
|
81
|
-
|
79
|
+
# extract struct result from kwargs
|
80
|
+
agent_lib_struct_result = kwargs[:result_struct]
|
82
81
|
return unless query_string.match?(regexp)
|
83
82
|
|
84
83
|
database = kwargs[:database]
|
@@ -92,7 +91,14 @@ module Contrast
|
|
92
91
|
next unless last_boundary && boundary
|
93
92
|
|
94
93
|
result ||= build_attack_result(context)
|
95
|
-
|
94
|
+
|
95
|
+
# if the struct actually has the needed data in it - use it
|
96
|
+
if agent_lib_struct_result.cs__is_a?(Hash)
|
97
|
+
record_agent_lib_match(agent_lib_struct_result, length, kwargs)
|
98
|
+
else
|
99
|
+
record_match(idx, length, boundary, last_boundary, kwargs)
|
100
|
+
end
|
101
|
+
|
96
102
|
append_match(context, input_analysis_result, result, query_string, **kwargs)
|
97
103
|
end
|
98
104
|
|
@@ -122,6 +128,20 @@ module Contrast
|
|
122
128
|
kwargs[:input_boundary_idx] = last_boundary
|
123
129
|
end
|
124
130
|
|
131
|
+
# all the agent_lib checks methods needed
|
132
|
+
|
133
|
+
# @param struct[ResultingStruct] The struct including all the data from the agent_lib scan
|
134
|
+
def record_agent_lib_match struct, length, kwargs
|
135
|
+
kwargs[:start_idx] = struct[:start_index]
|
136
|
+
kwargs[:end_idx] = if (struct[:end_index]).zero?
|
137
|
+
struct[:start_index] + length
|
138
|
+
else
|
139
|
+
struct[:end_index]
|
140
|
+
end
|
141
|
+
kwargs[:boundary_overrun_idx] = struct[:boundary_overrun_index]
|
142
|
+
kwargs[:input_boundary_idx] = struct[:input_boundary_index]
|
143
|
+
end
|
144
|
+
|
125
145
|
def append_match context, input_analysis_result, result, query_string, **kwargs
|
126
146
|
input_analysis_result.attack_count = input_analysis_result.attack_count + 1
|
127
147
|
update_successful_attack_response(context, input_analysis_result, result, query_string)
|
@@ -0,0 +1,37 @@
|
|
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
|
+
module Contrast
|
5
|
+
module Agent
|
6
|
+
module Protect
|
7
|
+
module Rule
|
8
|
+
# This is the Base Rule
|
9
|
+
class SqliBaseRule < Contrast::Agent::Protect::Rule::BaseService
|
10
|
+
include Contrast::Components::Logger::InstanceMethods
|
11
|
+
include Contrast::Agent::Reporting::InputType
|
12
|
+
|
13
|
+
BLOCK_MESSAGE = 'SQLi rule triggered. Response blocked.'
|
14
|
+
|
15
|
+
APPLICABLE_USER_INPUTS = [
|
16
|
+
BODY, COOKIE_NAME, COOKIE_VALUE, HEADER,
|
17
|
+
PARAMETER_NAME, PARAMETER_VALUE, JSON_VALUE,
|
18
|
+
MULTIPART_VALUE, MULTIPART_FIELD_NAME,
|
19
|
+
XML_VALUE, DWR_VALUE
|
20
|
+
].cs__freeze
|
21
|
+
|
22
|
+
def infilter context, database, query_string
|
23
|
+
return unless infilter?(context)
|
24
|
+
|
25
|
+
result = find_attacker(context, query_string, database: database)
|
26
|
+
return unless result
|
27
|
+
|
28
|
+
append_to_activity(context, result)
|
29
|
+
|
30
|
+
cef_logging(result, :successful_attack)
|
31
|
+
raise(Contrast::SecurityException.new(self, BLOCK_MESSAGE)) if blocked?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -5,10 +5,8 @@ require 'contrast/utils/object_share'
|
|
5
5
|
require 'contrast/agent/reporting/input_analysis/input_type'
|
6
6
|
require 'contrast/agent/protect/rule/sqli'
|
7
7
|
require 'contrast/agent/reporting/input_analysis/score_level'
|
8
|
-
require 'contrast/agent/protect/rule/sqli/sqli_worth_watching'
|
9
8
|
require 'contrast/agent/protect/input_analyzer/input_analyzer'
|
10
|
-
require 'contrast/utils/
|
11
|
-
require 'contrast/components/logger'
|
9
|
+
require 'contrast/utils/input_classification_base'
|
12
10
|
|
13
11
|
module Contrast
|
14
12
|
module Agent
|
@@ -18,68 +16,10 @@ module Contrast
|
|
18
16
|
# as a result input would be marked as WORTHWATCHING or IGNORE,
|
19
17
|
# to be analyzed at the sink level.
|
20
18
|
module SqliInputClassification
|
19
|
+
WORTHWATCHING_MATCH = 'sqli-worth-watching-v2'.cs__freeze
|
21
20
|
class << self
|
22
21
|
include InputClassificationBase
|
23
|
-
include Contrast::Agent::Protect::Rule::SqliWorthWatching
|
24
22
|
include Contrast::Components::Logger::InstanceMethods
|
25
|
-
|
26
|
-
WORTHWATCHING_MATCH = 'sqli-worth-watching-v2'
|
27
|
-
SQLI_KEYS_NEEDED = [
|
28
|
-
COOKIE_VALUE, PARAMETER_VALUE, JSON_VALUE, MULTIPART_VALUE, XML_VALUE, DWR_VALUE
|
29
|
-
].cs__freeze
|
30
|
-
|
31
|
-
# Input Classification stage is done to determine if an user input is
|
32
|
-
# WORTHWATCHING or to be ignored.
|
33
|
-
#
|
34
|
-
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
35
|
-
# @param value [String, Array<String>] the value of the input.
|
36
|
-
# @param input_analysis [Contrast::Agent::Reporting::InputAnalysis] Holds all the results from the
|
37
|
-
# agent analysis from the current
|
38
|
-
# Request.
|
39
|
-
# @return ia [Contrast::Agent::Reporting::InputAnalysis] with updated results.
|
40
|
-
def classify input_type, value, input_analysis
|
41
|
-
return unless Contrast::Agent::Protect::Rule::Sqli::APPLICABLE_USER_INPUTS.include?(input_type)
|
42
|
-
return unless super
|
43
|
-
|
44
|
-
rule_id = Contrast::Agent::Protect::Rule::Sqli::NAME
|
45
|
-
|
46
|
-
# double check the input to avoid calling match? on array
|
47
|
-
Array(value).each do |val|
|
48
|
-
Array(val).each do |v|
|
49
|
-
input_analysis.results << sqli_create_new_input_result(input_analysis.request, rule_id, input_type, v)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
input_analysis
|
54
|
-
rescue StandardError => e
|
55
|
-
logger.debug('An Error was recorded in the input classification of the sqli.')
|
56
|
-
logger.debug(e)
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
# This methods checks if input is tagged WORTHWATCHING or IGNORE matches value with it's
|
62
|
-
# key if needed and Creates new isntance of InputAnalysisResult.
|
63
|
-
#
|
64
|
-
# @param request [Contrast::Agent::Request] the current request context.
|
65
|
-
# @param rule_id [String] The name of the Protect Rule.
|
66
|
-
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
67
|
-
# @param value [String, Array<String>] the value of the input.
|
68
|
-
#
|
69
|
-
# @return res [Contrast::Agent::Reporting::InputAnalysisResult]
|
70
|
-
def sqli_create_new_input_result request, rule_id, input_type, value
|
71
|
-
ia_result = new_ia_result(rule_id, input_type, request.path, value)
|
72
|
-
if sqli_worth_watching?(value)
|
73
|
-
ia_result.ids << WORTHWATCHING_MATCH
|
74
|
-
ia_result.score_level = WORTHWATCHING
|
75
|
-
ia_result
|
76
|
-
else
|
77
|
-
ia_result.score_level = IGNORE
|
78
|
-
end
|
79
|
-
|
80
|
-
add_needed_key(request, ia_result, input_type, value) if SQLI_KEYS_NEEDED.include?(input_type)
|
81
|
-
ia_result
|
82
|
-
end
|
83
23
|
end
|
84
24
|
end
|
85
25
|
end
|
@@ -0,0 +1,67 @@
|
|
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/reporting/details/sqli_dangerous_functions'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Agent
|
8
|
+
module Protect
|
9
|
+
module Rule
|
10
|
+
# This class will include the check for SQL Injection Semantic Dangerous Functions
|
11
|
+
class SqliDangerousFunctions < Contrast::Agent::Protect::Rule::SqliBaseRule
|
12
|
+
NAME = 'sql-injection-semantic-dangerous-functions'
|
13
|
+
BLOCK_MESSAGE = 'SQLi Semantic Dangerous Functions rule triggered. Response blocked.'
|
14
|
+
|
15
|
+
SQL_DANGEROUS_FUNCTIONS = %w[unhex waitfor xp_cmdshell exec].cs__freeze
|
16
|
+
|
17
|
+
def rule_name
|
18
|
+
NAME
|
19
|
+
end
|
20
|
+
|
21
|
+
def infilter context, query_string
|
22
|
+
return unless infilter?(context)
|
23
|
+
return unless violated?(query_string)
|
24
|
+
|
25
|
+
result = build_violation(context, query_string)
|
26
|
+
return unless result
|
27
|
+
|
28
|
+
append_to_activity(context, result)
|
29
|
+
|
30
|
+
cef_logging(result, :successful_attack)
|
31
|
+
raise(Contrast::SecurityException.new(self, BLOCK_MESSAGE)) if blocked?
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def violated? attack_string
|
37
|
+
SQL_DANGEROUS_FUNCTIONS.any? { |dang_func| attack_string.downcase.include?(dang_func) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_violation context, potential_attack_string
|
41
|
+
result = build_attack_result(context)
|
42
|
+
update_successful_attack_response(context, nil, result, potential_attack_string)
|
43
|
+
append_sample(context, nil, result, potential_attack_string)
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
# Override if rule can make use of the candidate string or kwargs to
|
48
|
+
# build rasp rule sample.
|
49
|
+
def build_sample context, ia_result, candidate_string, **_kwargs
|
50
|
+
sample = build_base_sample(context, nil)
|
51
|
+
sample.details = Contrast::Agent::Reporting::Details::SqliDangerousFunctions.new
|
52
|
+
sample.details.query = candidate_string
|
53
|
+
|
54
|
+
if ia_result.nil?
|
55
|
+
ui = Contrast::Agent::Reporting::UserInput.new
|
56
|
+
ui.input_type = :UNKNOWN
|
57
|
+
ui.value = candidate_string
|
58
|
+
sample.user_input = ui
|
59
|
+
end
|
60
|
+
|
61
|
+
sample
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -5,13 +5,15 @@ require 'contrast/agent/protect/rule/base_service'
|
|
5
5
|
require 'contrast/agent/protect/policy/applies_sqli_rule'
|
6
6
|
require 'contrast/agent/protect/rule/sql_sample_builder'
|
7
7
|
require 'contrast/agent/reporting/input_analysis/input_type'
|
8
|
+
require 'contrast/agent/protect/rule/sqli/sqli_base_rule'
|
9
|
+
require 'contrast/agent/protect/rule/sqli/sqli_semantic/sqli_dangerous_functions'
|
8
10
|
|
9
11
|
module Contrast
|
10
12
|
module Agent
|
11
13
|
module Protect
|
12
14
|
module Rule
|
13
15
|
# The Ruby implementation of the Protect SQL Injection rule.
|
14
|
-
class Sqli < Contrast::Agent::Protect::Rule::
|
16
|
+
class Sqli < Contrast::Agent::Protect::Rule::SqliBaseRule
|
15
17
|
# Generate a sample for the SQLI injection detection rule, allowing for reporting to and rendering
|
16
18
|
# by TeamServer
|
17
19
|
include SqlSampleBuilder::SqliSample
|
@@ -22,28 +24,9 @@ module Contrast
|
|
22
24
|
include Contrast::Agent::Reporting::InputType
|
23
25
|
end
|
24
26
|
|
25
|
-
APPLICABLE_USER_INPUTS = [
|
26
|
-
BODY, COOKIE_NAME, COOKIE_VALUE, HEADER,
|
27
|
-
PARAMETER_NAME, PARAMETER_VALUE, JSON_VALUE,
|
28
|
-
MULTIPART_VALUE, MULTIPART_FIELD_NAME,
|
29
|
-
XML_VALUE, DWR_VALUE
|
30
|
-
].cs__freeze
|
31
27
|
NAME = 'sql-injection'
|
32
|
-
BLOCK_MESSAGE = 'SQLi rule triggered. Response blocked.'
|
33
28
|
|
34
|
-
|
35
|
-
# @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
|
36
|
-
# @return [Hash] the details for this specific rule
|
37
|
-
def extract_details attack_sample
|
38
|
-
{
|
39
|
-
start: attack_sample.sqli.start_idx,
|
40
|
-
end: attack_sample.sqli.end_idx,
|
41
|
-
boundaryOverrunIndex: attack_sample.sqli.boundary_overrun_idx,
|
42
|
-
inputBoundaryIndex: attack_sample.sqli.input_boundary_idx,
|
43
|
-
query: attack_sample.sqli.query
|
44
|
-
}
|
45
|
-
end
|
46
|
-
end
|
29
|
+
SUB_RULES = [Contrast::Agent::Protect::Rule::SqliDangerousFunctions.new].cs__freeze
|
47
30
|
|
48
31
|
def rule_name
|
49
32
|
NAME
|
@@ -53,6 +36,14 @@ module Contrast
|
|
53
36
|
BLOCK_MESSAGE
|
54
37
|
end
|
55
38
|
|
39
|
+
def sub_rules
|
40
|
+
SUB_RULES
|
41
|
+
end
|
42
|
+
|
43
|
+
def applicable_user_inputs
|
44
|
+
APPLICABLE_USER_INPUTS
|
45
|
+
end
|
46
|
+
|
56
47
|
def infilter context, database, query_string
|
57
48
|
return unless infilter?(context)
|
58
49
|
|
@@ -61,9 +52,63 @@ module Contrast
|
|
61
52
|
|
62
53
|
append_to_activity(context, result)
|
63
54
|
|
64
|
-
cef_logging(result, :successful_attack, query_string)
|
55
|
+
cef_logging(result, :successful_attack, value: query_string)
|
65
56
|
raise(Contrast::SecurityException.new(self, BLOCK_MESSAGE)) if blocked?
|
66
57
|
end
|
58
|
+
|
59
|
+
# Allows for the InputAnalysis from Agent Library to be extracted early
|
60
|
+
# @param context [Contrast::Agent::RequestContext]
|
61
|
+
# @param potential_attack_string [String, nil]
|
62
|
+
# @param ia_results [Array<Contrast::Agent::Reporting::InputAnalysis>]
|
63
|
+
# @param **kwargs
|
64
|
+
# @return [Contrast::Agent::Reporting, nil]
|
65
|
+
def find_attacker_with_results context, potential_attack_string, ia_results, **kwargs
|
66
|
+
logger.trace('Checking vectors for attacks', rule: rule_name, input: potential_attack_string)
|
67
|
+
|
68
|
+
result = nil
|
69
|
+
ia_results.each do |ia_result|
|
70
|
+
if potential_attack_string
|
71
|
+
idx = potential_attack_string.index(ia_result.value)
|
72
|
+
next unless idx
|
73
|
+
|
74
|
+
database_type = kwargs[:database].to_sym
|
75
|
+
input_length = ia_result.value.length
|
76
|
+
lib_result = check_sql_input_with_agent(potential_attack_string, database_type, idx, input_length)
|
77
|
+
|
78
|
+
kwargs[:result_struct] = lib_result
|
79
|
+
result = build_attack_with_match(context, ia_result, result, potential_attack_string, **kwargs)
|
80
|
+
else
|
81
|
+
result = build_attack_without_match(context, ia_result, result, **kwargs)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
result
|
85
|
+
end
|
86
|
+
|
87
|
+
# We'll need a second place, where we need to check the token boundaries if are being crossed and
|
88
|
+
# worth-watching.
|
89
|
+
#
|
90
|
+
# @param sql[String] SQL coming from parameter
|
91
|
+
# @param database[String] Type of database
|
92
|
+
# @param input_index[String] index in the sqlQuery string where user input was found
|
93
|
+
# @param input_length[Number] length of the input value
|
94
|
+
# @return [Hash, Boolean]
|
95
|
+
def check_sql_input_with_agent sql, database, input_index, input_length
|
96
|
+
return false unless (agent_lib = Contrast::AGENT_LIB) && sql && database
|
97
|
+
|
98
|
+
agent_lib.check_sql_query(input_index, input_length, database, sql)
|
99
|
+
end
|
100
|
+
|
101
|
+
# @param context [Contrast::Agent::RequestContext]
|
102
|
+
def infilter? context
|
103
|
+
return false unless enabled?
|
104
|
+
return false unless context&.agent_input_analysis&.results&.any? do |result|
|
105
|
+
result.rule_id == rule_name
|
106
|
+
end
|
107
|
+
|
108
|
+
return false if protect_excluded_by_code?
|
109
|
+
|
110
|
+
true
|
111
|
+
end
|
67
112
|
end
|
68
113
|
end
|
69
114
|
end
|
data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
|
4
4
|
require 'contrast/utils/object_share'
|
5
5
|
require 'contrast/agent/protect/rule/unsafe_file_upload'
|
6
|
-
require 'contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher'
|
7
6
|
require 'contrast/agent/protect/input_analyzer/input_analyzer'
|
8
|
-
require 'contrast/utils/
|
7
|
+
require 'contrast/utils/input_classification_base'
|
9
8
|
|
10
9
|
module Contrast
|
11
10
|
module Agent
|
@@ -14,67 +13,44 @@ module Contrast
|
|
14
13
|
# This module will do the Input Classification stage of Unsafe File Upload
|
15
14
|
# rule. As a result input would be marked as DEFINITEATTACK or IGNORE.
|
16
15
|
module UnsafeFileUploadInputClassification
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# #
|
56
|
-
# # @param request [Contrast::Agent::Request] the current request context.
|
57
|
-
# # @param rule_id [String] The name of the Protect Rule.
|
58
|
-
# # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
59
|
-
# # @param value [String, Array<String>] the value of the input.
|
60
|
-
# #
|
61
|
-
# # @return res [Contrast::Agent::Reporting::InputAnalysisResult]
|
62
|
-
# def create_new_input_result request, rule_id, input_type, value
|
63
|
-
# ia_result = new_ia_result rule_id, input_type, request.path, value
|
64
|
-
# if unsafe_match? value
|
65
|
-
# ia_result.score_level = DEFINITEATTACK
|
66
|
-
# ia_result.ids << UNSAFE_UPLOAD_MATCH
|
67
|
-
# else
|
68
|
-
# ia_result.score_level = IGNORE
|
69
|
-
# end
|
70
|
-
# ia_result.key = if input_type == MULTIPART_FIELD_NAME
|
71
|
-
# Contrast::Agent::Protect::InputAnalyzer::DISPOSITION_FILENAME
|
72
|
-
# else
|
73
|
-
# Contrast::Agent::Protect::InputAnalyzer::DISPOSITION_NAME
|
74
|
-
# end
|
75
|
-
# ia_result
|
76
|
-
# end
|
77
|
-
# end
|
16
|
+
UNSAFE_UPLOAD_MATCH = 'unsafe-file-upload-input-tracing-v1'
|
17
|
+
|
18
|
+
class << self
|
19
|
+
include InputClassificationBase
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# This methods checks if input is tagged DEFINITEATTACK or IGNORE matches value with it's
|
24
|
+
# key if needed and Creates new isntance of InputAnalysisResult.
|
25
|
+
#
|
26
|
+
# @param request [Contrast::Agent::Request] the current request context.
|
27
|
+
# @param rule_id [String] The name of the Protect Rule.
|
28
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
29
|
+
# @param value [String, Array<String>] the value of the input.
|
30
|
+
#
|
31
|
+
# @return res [Contrast::Agent::Reporting::InputAnalysisResult]
|
32
|
+
def create_new_input_result request, rule_id, input_type, value
|
33
|
+
return unless Contrast::AGENT_LIB
|
34
|
+
return unless (input_eval = Contrast::AGENT_LIB.eval_input(value,
|
35
|
+
Contrast::AGENT_LIB.input_set[:MULTIPART_NAME],
|
36
|
+
Contrast::AGENT_LIB.rule_set[rule_id],
|
37
|
+
Contrast::AGENT_LIB.eval_option[:NONE]))
|
38
|
+
|
39
|
+
ia_result = new_ia_result(rule_id, input_type, request.path, value)
|
40
|
+
if input_eval.score >= THRESHOLD
|
41
|
+
ia_result.score_level = DEFINITEATTACK
|
42
|
+
ia_result.ids << UNSAFE_UPLOAD_MATCH
|
43
|
+
else
|
44
|
+
ia_result.score_level = IGNORE
|
45
|
+
end
|
46
|
+
ia_result.key = if input_type == MULTIPART_FIELD_NAME
|
47
|
+
Contrast::Agent::Protect::InputAnalyzer::DISPOSITION_FILENAME
|
48
|
+
else
|
49
|
+
Contrast::Agent::Protect::InputAnalyzer::DISPOSITION_NAME
|
50
|
+
end
|
51
|
+
ia_result
|
52
|
+
end
|
53
|
+
end
|
78
54
|
end
|
79
55
|
end
|
80
56
|
end
|
@@ -11,7 +11,7 @@ module Contrast
|
|
11
11
|
module Rule
|
12
12
|
# The Ruby implementation of the Protect Unsafe File Upload rule.
|
13
13
|
# The unsafe-file-upload rule can trigger the following results:
|
14
|
-
# BLOCKED in Blocking mode
|
14
|
+
# BLOCKED in Blocking mode and SUSPICIOUS in Monitor mode.
|
15
15
|
class UnsafeFileUpload < Contrast::Agent::Protect::Rule::BaseService
|
16
16
|
include Contrast::Agent::Reporting::InputType
|
17
17
|
|
@@ -23,40 +23,13 @@ module Contrast
|
|
23
23
|
NAME
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
# TODO: RUBY-1574
|
29
|
-
def enabled?
|
30
|
-
super && false
|
26
|
+
def applicable_user_inputs
|
27
|
+
APPLICABLE_USER_INPUTS
|
31
28
|
end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
#
|
37
|
-
# def prefilter context
|
38
|
-
# return unless prefilter?(context)
|
39
|
-
#
|
40
|
-
# ia_results = gather_ia_results context
|
41
|
-
#
|
42
|
-
# ia_results.each do |ia_result|
|
43
|
-
# result = build_attack_result(context)
|
44
|
-
# build_attack_without_match context, ia_result, result
|
45
|
-
# append_to_activity context, result
|
46
|
-
#
|
47
|
-
# cef_logging result, :successful_attack
|
48
|
-
# raise Contrast::SecurityException.new(self, BLOCK_MESSAGE) if blocked?
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
#
|
52
|
-
# private
|
53
|
-
#
|
54
|
-
# def prefilter? _context
|
55
|
-
# return false unless enabled?
|
56
|
-
# return false if protect_excluded_by_code?
|
57
|
-
#
|
58
|
-
# true
|
59
|
-
# end
|
30
|
+
def block_message
|
31
|
+
BLOCK_MESSAGE
|
32
|
+
end
|
60
33
|
end
|
61
34
|
end
|
62
35
|
end
|