contrast-agent 6.7.0 → 6.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- 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/lib/contrast/agent/assess/policy/trigger_method.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 +11 -11
- data/lib/contrast/agent/assess.rb +0 -1
- data/lib/contrast/agent/excluder.rb +53 -35
- data/lib/contrast/agent/exclusion_matcher.rb +21 -9
- data/lib/contrast/agent/middleware.rb +12 -6
- 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/input_analyzer/worth_watching_analyzer.rb +116 -0
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +20 -0
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
- data/lib/contrast/agent/protect/rule/base.rb +47 -55
- data/lib/contrast/agent/protect/rule/base_service.rb +48 -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 +20 -2
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +8 -5
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +22 -22
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +64 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +63 -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 +3 -14
- 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 +40 -13
- data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +33 -15
- data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +0 -14
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -62
- data/lib/contrast/agent/protect/rule/sqli.rb +74 -3
- 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 +15 -20
- data/lib/contrast/agent/protect/rule/xxe.rb +4 -24
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +19 -40
- data/lib/contrast/agent/reporting/attack_result/response_type.rb +9 -9
- data/lib/contrast/agent/reporting/details/ip_denylist_details.rb +10 -2
- data/lib/contrast/agent/reporting/details/virtual_patch_details.rb +8 -2
- 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 +16 -2
- data/lib/contrast/agent/reporting/masker/masker.rb +2 -0
- data/lib/contrast/agent/reporting/report.rb +1 -0
- data/lib/contrast/agent/reporting/reporter.rb +35 -14
- data/lib/contrast/agent/reporting/reporter_heartbeat.rb +3 -9
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +16 -13
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +12 -7
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +3 -3
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +6 -1
- data/lib/contrast/agent/reporting/reporting_events/application_update.rb +0 -2
- data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +6 -6
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +239 -93
- data/lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb +10 -23
- data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +10 -9
- data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +0 -5
- data/lib/contrast/agent/reporting/reporting_events/library_discovery.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +12 -0
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +1 -11
- data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +8 -0
- data/lib/contrast/agent/reporting/reporting_events/server_settings.rb +40 -0
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +2 -2
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +43 -1
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +8 -4
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +58 -4
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +4 -6
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +77 -16
- data/lib/contrast/agent/reporting/server_settings_worker.rb +44 -0
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +14 -2
- 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/helpers.rb +7 -0
- 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/reporting/settings/protect_server_feature.rb +39 -2
- data/lib/contrast/agent/reporting/settings/rule_definition.rb +3 -0
- data/lib/contrast/agent/reporting/settings/security_logger.rb +77 -0
- data/lib/contrast/agent/reporting/settings/server_features.rb +9 -0
- data/lib/contrast/agent/reporting/settings/syslog.rb +34 -5
- data/lib/contrast/agent/request.rb +3 -14
- data/lib/contrast/agent/request_context.rb +6 -9
- data/lib/contrast/agent/request_context_extend.rb +9 -148
- data/lib/contrast/agent/request_handler.rb +5 -10
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +37 -18
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +6 -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 +20 -5
- data/lib/contrast/components/agent.rb +34 -14
- data/lib/contrast/components/api.rb +23 -0
- data/lib/contrast/components/app_context.rb +23 -5
- data/lib/contrast/components/app_context_extend.rb +0 -25
- data/lib/contrast/components/assess.rb +34 -4
- data/lib/contrast/components/assess_rules.rb +18 -0
- data/lib/contrast/components/base.rb +40 -0
- data/lib/contrast/components/config/sources.rb +95 -0
- data/lib/contrast/components/config.rb +19 -19
- data/lib/contrast/components/heap_dump.rb +10 -0
- data/lib/contrast/components/inventory.rb +15 -2
- data/lib/contrast/components/logger.rb +18 -0
- data/lib/contrast/components/polling.rb +36 -0
- data/lib/contrast/components/protect.rb +52 -2
- data/lib/contrast/components/ruby_component.rb +16 -1
- data/lib/contrast/components/sampling.rb +70 -13
- data/lib/contrast/components/security_logger.rb +13 -0
- data/lib/contrast/components/settings.rb +105 -90
- data/lib/contrast/config/certification_configuration.rb +14 -0
- data/lib/contrast/config/config.rb +46 -0
- data/lib/contrast/config/diagnostics.rb +114 -0
- data/lib/contrast/config/diagnostics_tools.rb +98 -0
- data/lib/contrast/config/effective_config.rb +65 -0
- data/lib/contrast/config/effective_config_value.rb +32 -0
- data/lib/contrast/config/exception_configuration.rb +12 -0
- data/lib/contrast/config/protect_rule_configuration.rb +8 -8
- data/lib/contrast/config/protect_rules_configuration.rb +23 -60
- data/lib/contrast/config/request_audit_configuration.rb +13 -0
- data/lib/contrast/config/server_configuration.rb +41 -2
- data/lib/contrast/configuration.rb +29 -12
- data/lib/contrast/extension/assess/array.rb +9 -0
- data/lib/contrast/extension/assess/erb.rb +1 -1
- data/lib/contrast/extension/delegator.rb +2 -0
- data/lib/contrast/framework/manager.rb +3 -1
- data/lib/contrast/framework/rails/railtie.rb +0 -1
- data/lib/contrast/framework/rails/support.rb +0 -1
- data/lib/contrast/tasks/config.rb +1 -8
- data/lib/contrast/utils/assess/event_limit_utils.rb +31 -9
- data/lib/contrast/utils/assess/trigger_method_utils.rb +5 -4
- data/lib/contrast/utils/duck_utils.rb +1 -0
- data/lib/contrast/utils/hash_digest.rb +2 -2
- data/lib/contrast/utils/input_classification_base.rb +155 -0
- data/lib/contrast/utils/os.rb +0 -20
- data/lib/contrast/utils/reporting/application_activity_batch_utils.rb +81 -0
- data/lib/contrast/utils/response_utils.rb +0 -16
- data/lib/contrast/utils/routes_sent.rb +60 -0
- data/lib/contrast/utils/stack_trace_utils.rb +3 -15
- data/lib/contrast/utils/string_utils.rb +10 -7
- data/lib/contrast/utils/telemetry_client.rb +1 -2
- data/lib/contrast/utils/timer.rb +16 -0
- data/lib/contrast.rb +5 -4
- data/resources/protect/policy.json +1 -2
- data/ruby-agent.gemspec +7 -6
- metadata +69 -130
- data/exe/contrast_service +0 -23
- data/lib/contrast/agent/assess/contrast_event.rb +0 -157
- data/lib/contrast/agent/assess/events/event_factory.rb +0 -34
- data/lib/contrast/agent/assess/events/source_event.rb +0 -46
- 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/server_activity.rb +0 -36
- data/lib/contrast/agent/service_heartbeat.rb +0 -35
- data/lib/contrast/api/communication/messaging_queue.rb +0 -128
- 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 -138
- 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/address.rb +0 -59
- data/lib/contrast/api/decorators/agent_startup.rb +0 -56
- data/lib/contrast/api/decorators/application_settings.rb +0 -43
- data/lib/contrast/api/decorators/application_startup.rb +0 -56
- data/lib/contrast/api/decorators/bot_blocker.rb +0 -37
- 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 -67
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +0 -52
- data/lib/contrast/api/decorators/response_type.rb +0 -17
- data/lib/contrast/api/decorators/server_features.rb +0 -25
- 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 -22
- data/lib/contrast/api/dtm.pb.rb +0 -363
- 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/components/service.rb +0 -55
- data/lib/contrast/tasks/service.rb +0 -84
- data/lib/contrast/utils/input_classification.rb +0 -73
- 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
@@ -4,7 +4,7 @@
|
|
4
4
|
require 'contrast/components/logger'
|
5
5
|
require 'contrast/components/scope'
|
6
6
|
require 'contrast/utils/object_share'
|
7
|
-
require 'contrast/
|
7
|
+
require 'contrast/agent/reporting/attack_result/response_type'
|
8
8
|
|
9
9
|
module Contrast
|
10
10
|
module Agent
|
@@ -18,26 +18,18 @@ module Contrast
|
|
18
18
|
include Contrast::Components::Logger::InstanceMethods
|
19
19
|
include Contrast::Components::Scope::InstanceMethods
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
BLOCKING_MODES = Set.new([
|
26
|
-
Contrast::Api::Settings::ProtectionRule::Mode::BLOCK,
|
27
|
-
Contrast::Api::Settings::ProtectionRule::Mode::BLOCK_AT_PERIMETER
|
28
|
-
]).cs__freeze
|
29
|
-
POSTFILTER_MODES = Set.new([
|
30
|
-
Contrast::Api::Settings::ProtectionRule::Mode::BLOCK,
|
31
|
-
Contrast::Api::Settings::ProtectionRule::Mode::PERMIT,
|
32
|
-
Contrast::Api::Settings::ProtectionRule::Mode::MONITOR
|
33
|
-
]).cs__freeze
|
21
|
+
BLOCKING_MODES = Set.new(%i[BLOCK BLOCK_AT_PERIMETER]).cs__freeze
|
22
|
+
POSTFILTER_MODES = Set.new(%i[BLOCK MONITOR]).cs__freeze
|
34
23
|
STACK_COLLECTION_RESULTS = Set.new([
|
35
|
-
Contrast::
|
36
|
-
Contrast::
|
24
|
+
Contrast::Agent::Reporting::ResponseType::BLOCKED,
|
25
|
+
Contrast::Agent::Reporting::ResponseType::MONITORED
|
37
26
|
]).cs__freeze
|
38
27
|
SUSPICIOUS_REPORTING_RULES = %w[
|
39
28
|
unsafe-file-upload
|
40
29
|
reflected-xss
|
30
|
+
cmd-injection-semantic-dangerous-paths
|
31
|
+
cmd-injection-semantic-chained-commands
|
32
|
+
path-traversal-semantic-file-security-bypass
|
41
33
|
sql-injection-semantic-dangerous-functions
|
42
34
|
].cs__freeze
|
43
35
|
|
@@ -68,7 +60,7 @@ module Contrast
|
|
68
60
|
return false if ::Contrast::PROTECT.rule_config&.disabled_rules&.include?(rule_name)
|
69
61
|
|
70
62
|
# 3. it is enabled so long as its mode is not NO_ACTION
|
71
|
-
@mode !=
|
63
|
+
@mode != :NO_ACTION
|
72
64
|
end
|
73
65
|
|
74
66
|
def excluded? exclusions
|
@@ -127,22 +119,22 @@ module Contrast
|
|
127
119
|
# A given input, candidate_string, was determined to violate a
|
128
120
|
# protect rule and did exploit the application, or at least made it
|
129
121
|
# to exploitable code in the case where we blocked the attack. As
|
130
|
-
# such, we need to build a result to report this violation to
|
131
|
-
#
|
122
|
+
# such, we need to build a result to report this violation to
|
123
|
+
# TeamServer.
|
132
124
|
#
|
133
125
|
# @param context [Contrast::Agent::RequestContext] the context of the
|
134
126
|
# request in which this input is evaluated.
|
135
|
-
# @param ia_result [Contrast::
|
127
|
+
# @param ia_result [Contrast::Agent::Reporting::InputAnalysis] the
|
136
128
|
# analysis of the input that was determined to be an attack
|
137
|
-
# @param result [Contrast::
|
129
|
+
# @param result [Contrast::Agent::Reporting::AttackResult, nil] previous
|
138
130
|
# attack result for this rule, if one exists, in the case of
|
139
131
|
# multiple inputs being found to violate the protection criteria
|
140
132
|
# @param candidate_string [String] the value of the input which may
|
141
133
|
# be an attack
|
142
134
|
# @param kwargs [Hash] key - value pairs of context individual rules
|
143
|
-
# need to build out details to send to the
|
135
|
+
# need to build out details to send to the TeamServer to tell the
|
144
136
|
# story of the attack
|
145
|
-
# @return [Contrast::
|
137
|
+
# @return [Contrast::Agent::Reporting::AttackResult] the attack result from
|
146
138
|
# this input
|
147
139
|
def build_attack_with_match context, ia_result, result, candidate_string, **kwargs
|
148
140
|
result ||= build_attack_result(context)
|
@@ -154,19 +146,19 @@ module Contrast
|
|
154
146
|
|
155
147
|
# A given input, candidate_string, was determined to violate a
|
156
148
|
# protect rule but did not exploit the application. As such, we need
|
157
|
-
# to build a result to report this violation to
|
149
|
+
# to build a result to report this violation to TeamServer.
|
158
150
|
#
|
159
|
-
# @param context [Contrast::Agent::RequestContext] the context of the
|
151
|
+
# @param context [Contrast::Agent::RequestContext, nil] the context of the
|
160
152
|
# request in which this input is evaluated.
|
161
|
-
# @param ia_result [Contrast::
|
153
|
+
# @param ia_result [Contrast::Agent::Reporting::InputAnalysis] the
|
162
154
|
# analysis of the input that was determined to be an attack
|
163
|
-
# @param result [Contrast::
|
155
|
+
# @param result [Contrast::Agent::Reporting::AttackResult, nil] previous
|
164
156
|
# attack result for this rule, if one exists, in the case of
|
165
157
|
# multiple inputs being found to violate the protection criteria
|
166
|
-
# @param kwargs [Hash] key - value pairs of context individual rules
|
167
|
-
# need to build out details to send to
|
158
|
+
# @param kwargs [Hash, nil] key - value pairs of context individual rules
|
159
|
+
# need to build out details to send to TeamServer to tell the
|
168
160
|
# story of the attack
|
169
|
-
# @return [Contrast::
|
161
|
+
# @return [Contrast::Agent::Reporting::AttackResult] the attack result from
|
170
162
|
# this input
|
171
163
|
def build_attack_without_match context, ia_result, result, **kwargs
|
172
164
|
result ||= build_attack_result(context)
|
@@ -177,7 +169,7 @@ module Contrast
|
|
177
169
|
end
|
178
170
|
|
179
171
|
# Attach the given result to the current request's context to report
|
180
|
-
# it to
|
172
|
+
# it to TeamServer
|
181
173
|
#
|
182
174
|
# @param context [Contrast::Agent::RequestContext] the context of the
|
183
175
|
# request in which this input is evaluated.
|
@@ -188,7 +180,7 @@ module Contrast
|
|
188
180
|
|
189
181
|
# With this we log to CEF
|
190
182
|
#
|
191
|
-
# @param result [Contrast::
|
183
|
+
# @param result [Contrast::Agent::Reporting::AttackResult]
|
192
184
|
# @param attack [Symbol] the type of message we want to send
|
193
185
|
# @param value [String] the input value we want to log
|
194
186
|
def cef_logging result, attack = :ineffective_attack, value: nil
|
@@ -251,14 +243,14 @@ module Contrast
|
|
251
243
|
|
252
244
|
def update_successful_attack_response context, ia_result, result, attack_string = nil
|
253
245
|
case mode
|
254
|
-
when
|
246
|
+
when :MONITOR
|
255
247
|
# We are checking the result as the ia_result would not contain the sub-rules.
|
256
248
|
result.response = if SUSPICIOUS_REPORTING_RULES.include?(result&.rule_id)
|
257
249
|
Contrast::Agent::Reporting::ResponseType::SUSPICIOUS
|
258
250
|
else
|
259
251
|
Contrast::Agent::Reporting::ResponseType::MONITORED
|
260
252
|
end
|
261
|
-
when
|
253
|
+
when :BLOCK
|
262
254
|
result.response = Contrast::Agent::Reporting::ResponseType::BLOCKED
|
263
255
|
end
|
264
256
|
|
@@ -270,13 +262,13 @@ module Contrast
|
|
270
262
|
|
271
263
|
# @param context [Contrast::Agent::RequestContext] the context of the
|
272
264
|
# request in which this input is evaluated.
|
273
|
-
# @param ia_result [Contrast::
|
265
|
+
# @param ia_result [Contrast::Agent::Reporting::InputAnalysis] the
|
274
266
|
# analysis of the input that was determined to be an attack
|
275
|
-
# @param result [Contrast::
|
267
|
+
# @param result [Contrast::Agent::Reporting::AttackResult] previous
|
276
268
|
# attack result for this rule, if one exists, in the case of
|
277
269
|
# multiple inputs being found to violate the protection criteria
|
278
270
|
def update_perimeter_attack_response context, ia_result, result
|
279
|
-
if mode ==
|
271
|
+
if mode == :BLOCK_AT_PERIMETER
|
280
272
|
result.response = if blocked_rule?(ia_result)
|
281
273
|
Contrast::Agent::Reporting::ResponseType::BLOCKED
|
282
274
|
else
|
@@ -303,27 +295,27 @@ module Contrast
|
|
303
295
|
end
|
304
296
|
|
305
297
|
# @param sample [Contrast::Agent::Reporting::RaspRuleSample]
|
306
|
-
# @param result [Contrast::
|
307
|
-
# in the case of multiple inputs being found to violate the protection criteria
|
298
|
+
# @param result [Contrast::Agent::Reporting::AttackResult, nil] previous attack result for this rule, if one
|
299
|
+
# exists, in the case of multiple inputs being found to violate the protection criteria
|
308
300
|
def append_stack sample, result
|
309
301
|
return unless sample
|
310
302
|
return unless STACK_COLLECTION_RESULTS.include?(result&.response)
|
311
303
|
|
312
|
-
stack = Contrast::Utils::StackTraceUtils.
|
304
|
+
stack = Contrast::Utils::StackTraceUtils.build_protect_report_stack_array
|
313
305
|
return unless stack
|
314
306
|
|
315
|
-
sample.
|
307
|
+
sample.stack.concat(stack)
|
316
308
|
end
|
317
309
|
|
318
310
|
# @param context [Contrast::Agent::RequestContext] the context of the request in which this input is
|
319
311
|
# evaluated.
|
320
|
-
# @param ia_result [Contrast::
|
321
|
-
# determined to be an attack
|
322
|
-
# @param result [Contrast::
|
323
|
-
# in the case of multiple inputs being found to violate the protection criteria
|
312
|
+
# @param ia_result [Contrast::Agent::Reporting::Settings::InputAnalysisResult] the analysis of the input that
|
313
|
+
# was determined to be an attack
|
314
|
+
# @param result [Contrast::Agent::Reporting::AttackResult, nil] previous attack result for this rule, if one
|
315
|
+
# exists, in the case of multiple inputs being found to violate the protection criteria
|
324
316
|
# @param candidate_string [String] the value of the input which may be an attack
|
325
317
|
# @param kwargs [Hash] key - value pairs of context individual rules
|
326
|
-
# need to build out details to send to
|
318
|
+
# need to build out details to send to TeamServer to tell the
|
327
319
|
# story of the attack
|
328
320
|
def append_sample context, ia_result, result, candidate_string, **kwargs
|
329
321
|
return unless result
|
@@ -340,8 +332,8 @@ module Contrast
|
|
340
332
|
# build rasp rule sample.
|
341
333
|
#
|
342
334
|
# @param context [Contrast::Agent::RequestContext]
|
343
|
-
# @param ia_result [Contrast::
|
344
|
-
# determined to be an attack
|
335
|
+
# @param ia_result [Contrast::Agent::Reporting::Settings::InputAnalysisResult] the analysis of the input that
|
336
|
+
# was determined to be an attack
|
345
337
|
# @param _candidate_string [String] potential attack value/ input containing attack value
|
346
338
|
# @param _kwargs [Hash]
|
347
339
|
# @return [Contrast::Agent::Reporting::RaspRuleSample]
|
@@ -350,8 +342,8 @@ module Contrast
|
|
350
342
|
end
|
351
343
|
|
352
344
|
# @param context [Contrast::Agent::RequestContext]
|
353
|
-
# @param ia_result [Contrast::
|
354
|
-
# determined to be an attack
|
345
|
+
# @param ia_result [Contrast::Agent::Reporting::Settings::InputAnalysisResult] the analysis of the input that
|
346
|
+
# was determined to be an attack
|
355
347
|
# @return [Contrast::Agent::Reporting::RaspRuleSample]
|
356
348
|
def build_base_sample context, ia_result
|
357
349
|
Contrast::Agent::Reporting::RaspRuleSample.build(context, ia_result)
|
@@ -360,9 +352,9 @@ module Contrast
|
|
360
352
|
def log_rule_matched _context, ia_result, response, _matched_string = nil
|
361
353
|
logger.debug('A successful attack was detected',
|
362
354
|
rule: rule_name,
|
363
|
-
type: ia_result&.input_type,
|
364
|
-
name: ia_result&.key,
|
365
|
-
input: ia_result&.value,
|
355
|
+
type: ia_result&.input_type || '',
|
356
|
+
name: ia_result&.key || '',
|
357
|
+
input: ia_result&.value || '',
|
366
358
|
result: response)
|
367
359
|
end
|
368
360
|
|
@@ -402,10 +394,10 @@ module Contrast
|
|
402
394
|
# Handles the Response type for different Protect rules. Some rules need to report SUSPICIOUS over PROBED in
|
403
395
|
# MONITORED mode.
|
404
396
|
#
|
405
|
-
# @param ia_result [Contrast::
|
397
|
+
# @param ia_result [Contrast::Agent::Reporting::InputAnalysis] the analysis of the input that was
|
406
398
|
# determined to be an attack
|
407
399
|
def assign_reporter_response_type ia_result
|
408
|
-
if suspicious_rule?(ia_result)
|
400
|
+
if suspicious_rule?(ia_result)
|
409
401
|
Contrast::Agent::Reporting::ResponseType::SUSPICIOUS
|
410
402
|
else
|
411
403
|
Contrast::Agent::Reporting::ResponseType::PROBED
|
@@ -8,8 +8,7 @@ module Contrast
|
|
8
8
|
module Agent
|
9
9
|
module Protect
|
10
10
|
module Rule
|
11
|
-
# Encapsulate common code for protect rules that do their
|
12
|
-
# input analysis on Speedracer rather in ruby code
|
11
|
+
# Encapsulate common code for protect rules that do their input analysis on agent-lib rather in ruby code
|
13
12
|
class BaseService < Contrast::Agent::Protect::Rule::Base
|
14
13
|
include Contrast::Components::Logger::InstanceMethods
|
15
14
|
|
@@ -21,12 +20,43 @@ module Contrast
|
|
21
20
|
'Contrast Security Protect Rule Triggered. Response blocked.'
|
22
21
|
end
|
23
22
|
|
23
|
+
def prefilter context
|
24
|
+
return unless prefilter?(context)
|
25
|
+
|
26
|
+
ia_results = gather_ia_results(context)
|
27
|
+
|
28
|
+
ia_results.each do |ia_result|
|
29
|
+
result = build_attack_result(context)
|
30
|
+
build_attack_without_match(context, ia_result, result)
|
31
|
+
append_to_activity(context, result)
|
32
|
+
|
33
|
+
cef_logging(result, :successful_attack)
|
34
|
+
raise(Contrast::SecurityException.new(self, block_message)) if blocked?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
24
38
|
# @param context [Contrast::Agent::RequestContext]
|
39
|
+
# @return [Boolean]
|
25
40
|
def infilter? context
|
26
41
|
return false unless enabled?
|
27
|
-
return false unless context
|
28
|
-
|
29
|
-
|
42
|
+
return false unless gather_ia_results(context).any?
|
43
|
+
return false if protect_excluded_by_code?
|
44
|
+
return false if protect_excluded_by_url?(context)
|
45
|
+
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
# Base method for prefilter check. Extend if rule needs more
|
50
|
+
# specific conditioning.
|
51
|
+
#
|
52
|
+
# @param context [Contrast::Agent::RequestContext]
|
53
|
+
# @return [Boolean]
|
54
|
+
def prefilter? context
|
55
|
+
return false unless context
|
56
|
+
return false unless enabled?
|
57
|
+
return false unless context.agent_input_analysis&.results&.any? do |result|
|
58
|
+
result.rule_id == rule_name && result.score_level != Contrast::Agent::Reporting::ScoreLevel::IGNORE
|
59
|
+
end
|
30
60
|
|
31
61
|
return false if protect_excluded_by_code?
|
32
62
|
return false if protect_excluded_by_url?(context)
|
@@ -41,11 +71,7 @@ module Contrast
|
|
41
71
|
# @raise [Contrast::SecurityException]
|
42
72
|
def postfilter context
|
43
73
|
return unless enabled? && POSTFILTER_MODES.include?(mode)
|
44
|
-
if mode ==
|
45
|
-
mode == Contrast::Api::Settings::ProtectionRule::Mode::PERMIT
|
46
|
-
|
47
|
-
return
|
48
|
-
end
|
74
|
+
return if mode == :NO_ACTION || mode == :PERMIT
|
49
75
|
|
50
76
|
result = find_postfilter_attacker(context, nil)
|
51
77
|
return unless result&.samples&.any?
|
@@ -60,28 +86,31 @@ module Contrast
|
|
60
86
|
protected
|
61
87
|
|
62
88
|
# @param context [Contrast::Agent::RequestContext]
|
63
|
-
# @return [Array<Contrast::
|
89
|
+
# @return [Array<Contrast::Agent::Reporting::InputAnalysis>]
|
64
90
|
def gather_ia_results context
|
65
|
-
context
|
66
|
-
|
91
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless context&.agent_input_analysis&.results
|
92
|
+
|
93
|
+
context.agent_input_analysis.results.select do |ia_result|
|
94
|
+
ia_result.rule_id == rule_name &&
|
95
|
+
ia_result.score_level != Contrast::Agent::Reporting::ScoreLevel::IGNORE
|
67
96
|
end
|
68
97
|
end
|
69
98
|
|
70
99
|
# @param context [Contrast::Agent::RequestContext]
|
71
100
|
# @param potential_attack_string [String, nil]
|
72
101
|
# @param **kwargs
|
73
|
-
# @return [Contrast::
|
102
|
+
# @return [Contrast::Agent::Reporting]
|
74
103
|
def find_attacker context, potential_attack_string, **kwargs
|
75
104
|
ia_results = gather_ia_results(context)
|
76
105
|
find_attacker_with_results(context, potential_attack_string, ia_results, **kwargs)
|
77
106
|
end
|
78
107
|
|
79
|
-
# Allows for the InputAnalysis from
|
108
|
+
# Allows for the InputAnalysis from Agent Library to be extracted early
|
80
109
|
# @param context [Contrast::Agent::RequestContext]
|
81
110
|
# @param potential_attack_string [String, nil]
|
82
|
-
# @param ia_results [Array<Contrast::
|
111
|
+
# @param ia_results [Array<Contrast::Agent::Reporting::InputAnalysis>]
|
83
112
|
# @param **kwargs
|
84
|
-
# @return [Contrast::
|
113
|
+
# @return [Contrast::Agent::Reporting, nil]
|
85
114
|
def find_attacker_with_results context, potential_attack_string, ia_results, **kwargs
|
86
115
|
logger.trace('Checking vectors for attacks', rule: rule_name, input: potential_attack_string)
|
87
116
|
|
@@ -103,16 +132,11 @@ module Contrast
|
|
103
132
|
|
104
133
|
# @param context [Contrast::Agent::RequestContext]
|
105
134
|
# @param potential_attack_string [String, nil]
|
106
|
-
# @return [Contrast::
|
135
|
+
# @return [Contrast::Agent::Reporting, nil]
|
107
136
|
def find_postfilter_attacker context, potential_attack_string, **kwargs
|
108
137
|
ia_results = gather_ia_results(context)
|
109
138
|
ia_results.select! do |ia_result|
|
110
|
-
|
111
|
-
Contrast::Api::Settings::InputAnalysisResult::ScoreLevel::DEFINITEATTACK
|
112
|
-
else
|
113
|
-
Contrast::Agent::Reporting::ScoreLevel::DEFINITEATTACK
|
114
|
-
end
|
115
|
-
ia_result.score_level == required_level
|
139
|
+
ia_result.score_level == Contrast::Agent::Reporting::ScoreLevel::DEFINITEATTACK
|
116
140
|
end
|
117
141
|
find_attacker_with_results(context, potential_attack_string, ia_results, **kwargs)
|
118
142
|
end
|
@@ -0,0 +1,98 @@
|
|
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/input_analysis/input_type'
|
5
|
+
require 'contrast/agent/reporting/input_analysis/score_level'
|
6
|
+
require 'contrast/agent/reporting/input_analysis/details/bot_blocker_details'
|
7
|
+
require 'contrast/utils/input_classification_base'
|
8
|
+
require 'contrast/utils/object_share'
|
9
|
+
|
10
|
+
module Contrast
|
11
|
+
module Agent
|
12
|
+
module Protect
|
13
|
+
module Rule
|
14
|
+
# This module will do the Input Classification stage of CMD Injection rule
|
15
|
+
# as a result input would be marked as WORTHWATCHING or IGNORE,
|
16
|
+
# to be analyzed at the sink level.
|
17
|
+
module BotBlockerInputClassification
|
18
|
+
USER_AGENT = 'USER_AGENT'
|
19
|
+
AGENT_LIB_HEADER_NAME = 'user-agent'
|
20
|
+
BOT_BLOCKER_MATCH = 'bot-blocker-input-tracing-v1'
|
21
|
+
|
22
|
+
class << self
|
23
|
+
include InputClassificationBase
|
24
|
+
|
25
|
+
# Input Classification stage is done to determine if an user input is
|
26
|
+
# DEFINITEATTACK or to be ignored.
|
27
|
+
#
|
28
|
+
# @param rule_id [String] Name of the protect rule.
|
29
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
30
|
+
# @param value [Hash<String>] the value of the input.
|
31
|
+
# @param input_analysis [Contrast::Agent::Reporting::InputAnalysis] Holds all the results from the
|
32
|
+
# agent analysis from the current
|
33
|
+
# Request.
|
34
|
+
# @return ia [Contrast::Agent::Reporting::InputAnalysis, nil] with updated results.
|
35
|
+
def classify rule_id, input_type, value, input_analysis
|
36
|
+
return unless (rule = Contrast::PROTECT.rule(rule_id))
|
37
|
+
return unless rule.applicable_user_inputs.include?(input_type)
|
38
|
+
return unless input_analysis.request
|
39
|
+
|
40
|
+
value.each_value do |val|
|
41
|
+
result = create_new_input_result(input_analysis.request, rule.rule_name, input_type, val)
|
42
|
+
input_analysis.results << result if result
|
43
|
+
end
|
44
|
+
|
45
|
+
input_analysis
|
46
|
+
rescue StandardError => e
|
47
|
+
logger.debug("An Error was recorded in the input classification of the #{ rule_id }", error: e)
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# This methods checks if input is tagged WORTHWATCHING or IGNORE matches value with it's
|
53
|
+
# key if needed and Creates new instance of InputAnalysisResult.
|
54
|
+
#
|
55
|
+
# @param request [Contrast::Agent::Request] the current request context.
|
56
|
+
# @param rule_id [String] The name of the Protect Rule.
|
57
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
58
|
+
# @param value [String, Array<String>] the value of the input.
|
59
|
+
#
|
60
|
+
# @return res [Contrast::Agent::Reporting::InputAnalysisResult]
|
61
|
+
def create_new_input_result request, rule_id, input_type, value
|
62
|
+
return unless request.headers.key(value) == USER_AGENT
|
63
|
+
return unless Contrast::AGENT_LIB
|
64
|
+
|
65
|
+
# If there is no match this would return nil.
|
66
|
+
header_eval = Contrast::AGENT_LIB.eval_header(AGENT_LIB_HEADER_NAME,
|
67
|
+
value,
|
68
|
+
Contrast::AGENT_LIB.rule_set[rule_id],
|
69
|
+
Contrast::AGENT_LIB.eval_option[:NONE])
|
70
|
+
|
71
|
+
ia_result = new_ia_result(rule_id, input_type, request.path, value)
|
72
|
+
score = header_eval&.score || 0
|
73
|
+
if score >= THRESHOLD
|
74
|
+
ia_result.score_level = DEFINITEATTACK
|
75
|
+
ia_result.ids << BOT_BLOCKER_MATCH
|
76
|
+
ia_result.details = Contrast::Agent::Reporting::BotBlockerDetails.new
|
77
|
+
# details:
|
78
|
+
add_details(ia_result, value)
|
79
|
+
else
|
80
|
+
ia_result.score_level = IGNORE
|
81
|
+
end
|
82
|
+
add_needed_key(request, ia_result, input_type, value)
|
83
|
+
ia_result
|
84
|
+
end
|
85
|
+
|
86
|
+
def add_details ia_result, value
|
87
|
+
ia_result.details.bot = value.downcase
|
88
|
+
if value.include?(Contrast::Utils::ObjectShare::CARROT)
|
89
|
+
ia_result.details.bot.delete!(Contrast::Utils::ObjectShare::CARROT)
|
90
|
+
end
|
91
|
+
ia_result.details.user_agent = value
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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/components/logger'
|
6
|
+
require 'contrast/agent/reporting/input_analysis/input_type'
|
7
|
+
require 'contrast/agent/reporting/input_analysis/score_level'
|
8
|
+
require 'contrast/agent_lib/interface'
|
9
|
+
|
10
|
+
module Contrast
|
11
|
+
module Agent
|
12
|
+
module Protect
|
13
|
+
module Rule
|
14
|
+
# The Ruby implementation of the Protect BotBlocker rule.
|
15
|
+
class BotBlocker < Contrast::Agent::Protect::Rule::BaseService
|
16
|
+
include Contrast::Components::Logger::InstanceMethods
|
17
|
+
include Contrast::Agent::Reporting::InputType
|
18
|
+
|
19
|
+
NAME = 'bot-blocker'
|
20
|
+
APPLICABLE_USER_INPUTS = [HEADER].cs__freeze
|
21
|
+
|
22
|
+
def rule_name
|
23
|
+
NAME
|
24
|
+
end
|
25
|
+
|
26
|
+
def applicable_user_inputs
|
27
|
+
APPLICABLE_USER_INPUTS
|
28
|
+
end
|
29
|
+
|
30
|
+
# BotBlocker prefilter:
|
31
|
+
#
|
32
|
+
# @param context [Contrast::Agent::RequestContext] current request contest
|
33
|
+
# @raise [Contrast::SecurityException] if the rule mode ise set
|
34
|
+
# to BLOCK and valid bot is detected.
|
35
|
+
def prefilter context
|
36
|
+
return unless prefilter?(context)
|
37
|
+
# We expect only one result per request since the user-agent Header is one.
|
38
|
+
# And the IA analysis explicitly searches for the key match before starting
|
39
|
+
# the analysis.
|
40
|
+
return unless (ia_result = gather_ia_results(context)[0]) &&
|
41
|
+
ia_result.score_level == Contrast::Agent::Reporting::ScoreLevel::DEFINITEATTACK
|
42
|
+
|
43
|
+
result = build_attack_without_match(context, ia_result, nil)
|
44
|
+
append_to_activity(context, result) if result
|
45
|
+
cef_logging(result, :successful_attack) if result
|
46
|
+
return unless blocked?
|
47
|
+
|
48
|
+
# Raise BotBlocker error
|
49
|
+
exception_message = "#{ rule_name } rule triggered. Unsafe Bot blocked."
|
50
|
+
raise(Contrast::SecurityException.new(self, exception_message))
|
51
|
+
end
|
52
|
+
|
53
|
+
# @param context [Contrast::Agent::RequestContext]
|
54
|
+
# @return [Array<Contrast::Agent::Reporting::InputAnalysis>]
|
55
|
+
def gather_ia_results context
|
56
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless context&.agent_input_analysis&.results
|
57
|
+
|
58
|
+
context.agent_input_analysis.results.select do |ia_result|
|
59
|
+
ia_result.rule_id == rule_name
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# Adding bot blocker details
|
64
|
+
#
|
65
|
+
# @param context [Contrast::Agent::RequestContext]
|
66
|
+
# @param ia_result [Contrast::Agent::Reporting::InputAnalysisResult]
|
67
|
+
# @param _candidate_string
|
68
|
+
# @param **_kwargs
|
69
|
+
# @return [Contrast::Agent::Reporting::RaspRuleSample]
|
70
|
+
def build_sample context, ia_result, _candidate_string, **_kwargs
|
71
|
+
sample = build_base_sample(context, ia_result)
|
72
|
+
sample.details = Contrast::Agent::Reporting::BotBlockerDetails.new
|
73
|
+
sample.details.bot = ia_result.value
|
74
|
+
sample.details.user_agent = context&.request&.user_agent
|
75
|
+
sample
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -6,6 +6,9 @@ require 'contrast/utils/stack_trace_utils'
|
|
6
6
|
require 'contrast/utils/object_share'
|
7
7
|
require 'contrast/components/logger'
|
8
8
|
require 'contrast/agent/reporting/input_analysis/input_type'
|
9
|
+
require 'contrast/agent_lib/interface'
|
10
|
+
require 'contrast/agent/protect/rule/cmdi/cmdi_chained_command'
|
11
|
+
require 'contrast/agent/protect/rule/cmdi/cmdi_dangerous_path'
|
9
12
|
require 'contrast/agent/protect/rule/cmdi/cmdi_base_rule'
|
10
13
|
require 'contrast/agent/protect/rule/cmdi/cmdi_backdoors'
|
11
14
|
|
@@ -18,14 +21,29 @@ module Contrast
|
|
18
21
|
include Contrast::Components::Logger::InstanceMethods
|
19
22
|
include Contrast::Agent::Reporting::InputType
|
20
23
|
NAME = 'cmd-injection'
|
21
|
-
|
24
|
+
APPLICABLE_USER_INPUTS = [
|
25
|
+
BODY, COOKIE_VALUE, HEADER, PARAMETER_NAME,
|
26
|
+
PARAMETER_VALUE, JSON_VALUE, MULTIPART_VALUE,
|
27
|
+
MULTIPART_FIELD_NAME, XML_VALUE, DWR_VALUE
|
28
|
+
].cs__freeze
|
22
29
|
|
23
30
|
def rule_name
|
24
31
|
NAME
|
25
32
|
end
|
26
33
|
|
34
|
+
# Array of sub_rules:
|
35
|
+
#
|
36
|
+
# @return [Array]
|
27
37
|
def sub_rules
|
28
|
-
|
38
|
+
@_sub_rules ||= [
|
39
|
+
Contrast::Agent::Protect::Rule::CmdiBackdoors.new,
|
40
|
+
Contrast::Agent::Protect::Rule::CmdiChainedCommand.new,
|
41
|
+
Contrast::Agent::Protect::Rule::CmdiDangerousPath.new
|
42
|
+
].cs__freeze
|
43
|
+
end
|
44
|
+
|
45
|
+
def applicable_user_inputs
|
46
|
+
APPLICABLE_USER_INPUTS
|
29
47
|
end
|
30
48
|
|
31
49
|
# CMDI infilter:
|
@@ -52,7 +52,7 @@ module Contrast
|
|
52
52
|
return false unless enabled?
|
53
53
|
# This rule does not have input tracing stage so we need to check the results of
|
54
54
|
# the main rule instead.
|
55
|
-
return false unless context&.
|
55
|
+
return false unless context&.agent_input_analysis&.results&.any? do |result|
|
56
56
|
result.rule_id == Contrast::Agent::Protect::Rule::CmdInjection::NAME
|
57
57
|
end
|
58
58
|
|
@@ -103,9 +103,9 @@ module Contrast
|
|
103
103
|
# the applicable input type is already checked before input
|
104
104
|
# classification. Only thing left is the match check.
|
105
105
|
#
|
106
|
-
# @param ia_results [Contrast::
|
106
|
+
# @param ia_results [Contrast::Agent::Reporting::Settings::InputAnalysisResult] gathered results
|
107
107
|
# @param cmd [String] potential attack vector
|
108
|
-
# @return [Contrast::
|
108
|
+
# @return [Contrast::Agent::Reporting::Settings::InputAnalysisResult, nil] matched input_type
|
109
109
|
def match_applicable_input_type ia_results, cmd
|
110
110
|
ia_results.each do |ia_result|
|
111
111
|
return ia_result if ia_result.value == cmd
|
@@ -118,8 +118,11 @@ module Contrast
|
|
118
118
|
#
|
119
119
|
# @param context [Contrast::Agent::RequestContext]
|
120
120
|
def gather_ia_results context
|
121
|
-
context
|
122
|
-
|
121
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless context&.agent_input_analysis&.results
|
122
|
+
|
123
|
+
context.agent_input_analysis.results.select do |ia_result|
|
124
|
+
ia_result.rule_id == Contrast::Agent::Protect::Rule::CmdInjection::NAME &&
|
125
|
+
ia_result.score_level != Contrast::Agent::Reporting::ScoreLevel::IGNORE
|
123
126
|
end
|
124
127
|
end
|
125
128
|
end
|