contrast-agent 3.12.1 → 3.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +0 -1
- data/.gitignore +1 -1
- data/.simplecov +1 -1
- data/Rakefile +31 -0
- data/exe/contrast_service +1 -7
- data/ext/build_funchook.rb +0 -2
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
- data/ext/cs__assess_array/cs__assess_array.c +6 -5
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -9
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
- data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
- data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +4 -5
- data/ext/cs__assess_module/cs__assess_module.c +6 -6
- data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
- data/ext/cs__assess_string/cs__assess_string.c +20 -4
- data/ext/cs__assess_string/cs__assess_string.h +4 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -7
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +3 -7
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
- data/ext/cs__common/cs__common.c +59 -28
- data/ext/cs__common/cs__common.h +18 -20
- data/ext/cs__common/extconf.rb +0 -14
- data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
- data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
- data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
- data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
- data/ext/extconf_common.rb +0 -28
- data/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +15 -23
- data/lib/contrast/agent.rb +51 -39
- data/lib/contrast/agent/assess.rb +11 -12
- data/lib/contrast/agent/assess/contrast_event.rb +39 -176
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
- data/lib/contrast/agent/assess/events/source_event.rb +5 -9
- data/lib/contrast/agent/assess/finalizers/finalize.rb +21 -0
- data/lib/contrast/agent/assess/finalizers/freeze.rb +13 -0
- data/lib/contrast/agent/assess/finalizers/hash.rb +53 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +2 -2
- data/lib/contrast/agent/assess/policy/patcher.rb +5 -5
- data/lib/contrast/agent/assess/policy/policy.rb +9 -9
- data/lib/contrast/agent/assess/policy/policy_node.rb +5 -99
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -3
- data/lib/contrast/agent/assess/policy/preshift.rb +15 -5
- data/lib/contrast/agent/assess/policy/propagation_method.rb +26 -24
- data/lib/contrast/agent/assess/policy/propagation_node.rb +6 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +12 -3
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +5 -0
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +6 -11
- data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/split.rb +5 -5
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +8 -7
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +6 -16
- data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +7 -15
- data/lib/contrast/agent/assess/policy/trigger_node.rb +18 -6
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
- data/lib/contrast/agent/assess/properties.rb +13 -383
- data/lib/contrast/agent/assess/property/evented.rb +78 -0
- data/lib/contrast/agent/assess/property/tagged.rb +339 -0
- data/lib/contrast/agent/assess/rule.rb +2 -2
- data/lib/contrast/agent/assess/rule/base.rb +3 -4
- data/lib/contrast/agent/assess/rule/provider.rb +3 -3
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +4 -22
- data/lib/contrast/agent/assess/tag.rb +27 -12
- data/lib/contrast/agent/at_exit_hook.rb +4 -2
- data/lib/contrast/agent/class_reopener.rb +7 -6
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
- data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
- data/lib/contrast/agent/disable_reaction.rb +1 -1
- data/lib/contrast/agent/exclusion_matcher.rb +3 -3
- data/lib/contrast/agent/inventory/policy/datastores.rb +2 -3
- data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
- data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/middleware.rb +37 -48
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -5
- data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
- data/lib/contrast/agent/patching/policy/patch.rb +16 -16
- data/lib/contrast/agent/patching/policy/patcher.rb +30 -22
- data/lib/contrast/agent/patching/policy/policy.rb +9 -9
- data/lib/contrast/agent/patching/policy/policy_node.rb +3 -3
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/policy.rb +8 -8
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +3 -3
- data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/rule.rb +18 -18
- data/lib/contrast/agent/protect/rule/base.rb +21 -32
- data/lib/contrast/agent/protect/rule/base_service.rb +2 -2
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
- data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +3 -8
- data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
- data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
- data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
- data/lib/contrast/agent/protect/rule/xss.rb +1 -1
- data/lib/contrast/agent/protect/rule/xxe.rb +4 -5
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
- data/lib/contrast/agent/railtie.rb +1 -1
- data/lib/contrast/agent/reaction_processor.rb +5 -5
- data/lib/contrast/agent/request.rb +103 -340
- data/lib/contrast/agent/request_context.rb +25 -21
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +8 -20
- data/lib/contrast/agent/rewriter.rb +5 -6
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +8 -10
- data/lib/contrast/agent/static_analysis.rb +4 -4
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +49 -0
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +24 -0
- data/lib/contrast/api.rb +4 -6
- data/lib/contrast/api/communication.rb +20 -0
- data/lib/contrast/api/communication/connection_status.rb +41 -0
- data/lib/contrast/api/communication/messaging_queue.rb +79 -0
- data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +10 -19
- data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
- data/lib/contrast/api/communication/socket.rb +45 -0
- data/lib/contrast/api/communication/socket_client.rb +76 -0
- data/lib/contrast/api/communication/speedracer.rb +111 -0
- data/lib/contrast/api/communication/tcp_socket.rb +31 -0
- data/lib/contrast/api/communication/unix_socket.rb +27 -0
- data/lib/contrast/api/decorators.rb +14 -4
- data/lib/contrast/api/decorators/address.rb +61 -0
- data/lib/contrast/api/decorators/application_settings.rb +10 -5
- data/lib/contrast/api/decorators/application_update.rb +5 -13
- data/lib/contrast/api/decorators/http_request.rb +140 -0
- data/lib/contrast/api/decorators/input_analysis.rb +3 -2
- data/lib/contrast/api/decorators/message.rb +76 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +29 -0
- data/lib/contrast/api/decorators/route_coverage.rb +58 -0
- data/lib/contrast/api/decorators/server_features.rb +3 -2
- data/lib/contrast/api/decorators/trace_event.rb +100 -0
- data/lib/contrast/api/decorators/trace_event_object.rb +58 -0
- data/lib/contrast/api/decorators/trace_event_signature.rb +47 -0
- data/lib/contrast/api/decorators/trace_taint_range.rb +52 -0
- data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
- data/lib/contrast/api/decorators/user_input.rb +40 -0
- data/lib/contrast/common_agent_configuration.rb +2 -2
- data/lib/contrast/components/agent.rb +2 -2
- data/lib/contrast/components/app_context.rb +1 -8
- data/lib/contrast/components/config.rb +7 -12
- data/lib/contrast/components/contrast_service.rb +1 -1
- data/lib/contrast/components/interface.rb +16 -16
- data/lib/contrast/components/logger.rb +1 -1
- data/lib/contrast/components/scope.rb +3 -3
- data/lib/contrast/components/settings.rb +0 -6
- data/lib/contrast/config.rb +18 -18
- data/lib/contrast/config/base_configuration.rb +2 -2
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/configuration.rb +5 -5
- data/lib/contrast/extension/assess.rb +22 -22
- data/lib/contrast/extension/assess/array.rb +4 -4
- data/lib/contrast/extension/assess/assess_extension.rb +28 -31
- data/lib/contrast/extension/assess/eval_trigger.rb +3 -3
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
- data/lib/contrast/extension/assess/fiber.rb +3 -3
- data/lib/contrast/extension/assess/hash.rb +5 -3
- data/lib/contrast/extension/assess/kernel.rb +7 -6
- data/lib/contrast/extension/assess/marshal.rb +62 -0
- data/lib/contrast/extension/assess/regexp.rb +3 -3
- data/lib/contrast/extension/assess/string.rb +6 -6
- data/lib/contrast/extension/inventory.rb +4 -5
- data/lib/contrast/extension/kernel.rb +1 -1
- data/lib/contrast/extension/module.rb +1 -1
- data/lib/contrast/extension/protect.rb +3 -3
- data/lib/contrast/extension/protect/kernel.rb +2 -2
- data/lib/contrast/extension/protect/psych.rb +2 -2
- data/lib/contrast/framework/base_support.rb +0 -23
- data/lib/contrast/framework/manager.rb +7 -17
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- data/lib/contrast/framework/rack/patch/support.rb +1 -1
- data/lib/contrast/framework/rack/support.rb +2 -2
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -3
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -6
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/support.rb +3 -3
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +2 -2
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +2 -2
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -2
- data/lib/contrast/framework/rails/support.rb +56 -37
- data/lib/contrast/framework/sinatra/patch/base.rb +2 -2
- data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +13 -24
- data/lib/contrast/funchook/funchook.rb +45 -0
- data/lib/contrast/logger/application.rb +3 -3
- data/lib/contrast/logger/format.rb +64 -0
- data/lib/contrast/logger/log.rb +17 -9
- data/lib/contrast/logger/request.rb +30 -0
- data/lib/contrast/tasks/config.rb +1 -1
- data/lib/contrast/tasks/service.rb +2 -2
- data/lib/contrast/utils/assess/sampling_util.rb +2 -2
- data/lib/contrast/utils/assess/tracking_util.rb +46 -21
- data/lib/contrast/utils/boolean_util.rb +1 -1
- data/lib/contrast/utils/class_util.rb +5 -3
- data/lib/contrast/utils/freeze_util.rb +1 -1
- data/lib/contrast/utils/gemfile_reader.rb +5 -5
- data/lib/contrast/utils/hash_digest.rb +13 -3
- data/lib/contrast/utils/heap_dump_util.rb +2 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -18
- data/lib/contrast/utils/inventory_util.rb +6 -11
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/object_share.rb +0 -1
- data/lib/contrast/utils/os.rb +16 -4
- data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -2
- data/lib/contrast/utils/stack_trace_utils.rb +2 -3
- data/lib/contrast/utils/string_utils.rb +1 -1
- data/lib/contrast/utils/tag_util.rb +1 -1
- data/lib/contrast/utils/thread_tracker.rb +1 -14
- data/lib/contrast/utils/timer.rb +1 -17
- data/resources/deadzone/policy.json +5 -0
- data/ruby-agent.gemspec +9 -9
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +60 -79
- data/funchook/Makefile +0 -29
- data/funchook/autom4te.cache/output.0 +0 -4976
- data/funchook/autom4te.cache/requests +0 -78
- data/funchook/autom4te.cache/traces.0 +0 -364
- data/funchook/config.log +0 -490
- data/funchook/config.status +0 -1016
- data/funchook/configure +0 -4976
- data/funchook/src/Makefile +0 -70
- data/funchook/src/config.h +0 -101
- data/funchook/src/config.h.in +0 -100
- data/funchook/src/decoder.o +0 -0
- data/funchook/src/distorm.o +0 -0
- data/funchook/src/funchook.o +0 -0
- data/funchook/src/funchook_io.o +0 -0
- data/funchook/src/funchook_syscall.o +0 -0
- data/funchook/src/funchook_unix.o +0 -0
- data/funchook/src/funchook_x86.o +0 -0
- data/funchook/src/instructions.o +0 -0
- data/funchook/src/insts.o +0 -0
- data/funchook/src/libfunchook.so +0 -0
- data/funchook/src/mnemonics.o +0 -0
- data/funchook/src/operands.o +0 -0
- data/funchook/src/os_func.o +0 -0
- data/funchook/src/os_func_unix.o +0 -0
- data/funchook/src/prefix.o +0 -0
- data/funchook/src/printf_base.o +0 -0
- data/funchook/src/textdefs.o +0 -0
- data/funchook/src/wstring.o +0 -0
- data/funchook/test/Makefile +0 -43
- data/funchook/test/funchook_test +0 -0
- data/funchook/test/libfunchook_test.so +0 -0
- data/funchook/test/test_main.o +0 -0
- data/funchook/test/x86_64_test.o +0 -0
- data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
- data/lib/contrast/agent/assess/insulator.rb +0 -49
- data/lib/contrast/agent/require_state.rb +0 -61
- data/lib/contrast/agent/socket_client.rb +0 -134
- data/lib/contrast/api/connection_status.rb +0 -49
- data/lib/contrast/api/socket.rb +0 -43
- data/lib/contrast/api/speedracer.rb +0 -188
- data/lib/contrast/api/tcp_socket.rb +0 -29
- data/lib/contrast/api/unix_socket.rb +0 -25
- data/lib/contrast/framework/sinatra/application_helper.rb +0 -51
- data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
- data/lib/contrast/internal_exception.rb +0 -8
- data/lib/contrast/utils/cache.rb +0 -58
- data/lib/contrast/utils/service_sender_util.rb +0 -167
- data/lib/contrast/utils/sinatra_helper.rb +0 -49
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/string_utils'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Api
|
8
|
+
module Decorators
|
9
|
+
# Used to decorate the {Contrast::Api::Dtm::RouteCoverage} protobuf model
|
10
|
+
# to handle conversion between framework route classes and the dtm.
|
11
|
+
module RouteCoverage
|
12
|
+
def self.included klass
|
13
|
+
klass.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Class methods for RouteCoverage
|
17
|
+
module ClassMethods
|
18
|
+
def source_or_string obj
|
19
|
+
if obj.cs__is_a?(Regexp)
|
20
|
+
obj.source
|
21
|
+
elsif obj.cs__respond_to?(:safe_string)
|
22
|
+
obj.safe_string
|
23
|
+
else
|
24
|
+
obj.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Convert ActionDispatch::Journey::Route to Contrast::Api::Dtm::RouteCoverage
|
29
|
+
# @param journey_obj [ActionDispatch::Journey::Route] a rails route
|
30
|
+
# @return [Contrast::Api::Dtm::RouteCoverage]
|
31
|
+
def from_action_dispatch_journey journey_obj
|
32
|
+
msg = new
|
33
|
+
msg.route = "#{ journey_obj.defaults[:controller] }##{ journey_obj.defaults[:action] }"
|
34
|
+
|
35
|
+
verb = source_or_string(journey_obj.verb)
|
36
|
+
msg.verb = Contrast::Utils::StringUtils.force_utf8(verb)
|
37
|
+
|
38
|
+
url = source_or_string(journey_obj.path.spec)
|
39
|
+
msg.url = Contrast::Utils::StringUtils.force_utf8(url)
|
40
|
+
msg
|
41
|
+
end
|
42
|
+
|
43
|
+
def from_sinatra_route clazz, method, pattern
|
44
|
+
safe_pattern = source_or_string(pattern)
|
45
|
+
|
46
|
+
msg = new
|
47
|
+
msg.route = "#{ clazz }##{ method } #{ safe_pattern }"
|
48
|
+
msg.verb = Contrast::Utils::StringUtils.force_utf8(method)
|
49
|
+
msg.url = Contrast::Utils::StringUtils.force_utf8(safe_pattern)
|
50
|
+
msg
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Contrast::Api::Dtm::RouteCoverage.include(Contrast::Api::Decorators::RouteCoverage)
|
@@ -1,12 +1,13 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
require 'contrast/utils/string_utils'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Api
|
8
8
|
module Decorators
|
9
|
-
# Used to decorate the ServerFeatures protobuf
|
9
|
+
# Used to decorate the {Contrast::Api::Settings::ServerFeatures} protobuf
|
10
|
+
# model to handle setting translation to boolean values.
|
10
11
|
module ServerFeatures
|
11
12
|
# 'defend' is legacy for 'protect' in the dtm.
|
12
13
|
def protect_enabled?
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/string_utils'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Api
|
8
|
+
module Decorators
|
9
|
+
# Used to decorate the {Contrast::Api::Dtm::TraceEvent} protobuf model to
|
10
|
+
# convert our {Contrast::Agent::AssessContrastEvent} to the dtm.
|
11
|
+
module TraceEvent
|
12
|
+
def self.included klass
|
13
|
+
klass.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Wrapper around build_event_object for the args array. Handles
|
17
|
+
# tainting the correct argument.
|
18
|
+
def build_event_args contrast_event, taint_target
|
19
|
+
contrast_event.args.each_index do |idx|
|
20
|
+
truncate_arg = taint_target != idx
|
21
|
+
event_arg = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.args[idx], truncate_arg)
|
22
|
+
args << event_arg
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# TeamServer only supports one object's taint ranges at a time.
|
27
|
+
# We'll find the taint ranges for the target and return those
|
28
|
+
def build_taint_ranges contrast_event, taint_target
|
29
|
+
# If there's no taint_target, this isn't a dataflow trace, but a
|
30
|
+
# trigger one
|
31
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless taint_target
|
32
|
+
|
33
|
+
properties = case taint_target
|
34
|
+
when Contrast::Utils::ObjectShare::OBJECT_KEY
|
35
|
+
contrast_event.object.cs__properties
|
36
|
+
when Contrast::Utils::ObjectShare::RETURN_KEY
|
37
|
+
contrast_event.ret.cs__properties
|
38
|
+
else
|
39
|
+
target = contrast_event.args[taint_target]
|
40
|
+
if target.is_a?(Hash)
|
41
|
+
if contrast_event.policy_node&.targets&.any?
|
42
|
+
target[contrast_event.policy_node.targets[0]].cs__properties
|
43
|
+
else
|
44
|
+
target[contrast_event.policy_node.sources[0]].cs__properties
|
45
|
+
end
|
46
|
+
else
|
47
|
+
target.cs__properties
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless properties.tracked?
|
52
|
+
|
53
|
+
properties.tags_to_dtm
|
54
|
+
end
|
55
|
+
|
56
|
+
# Class methods for TraceEvent
|
57
|
+
module ClassMethods
|
58
|
+
def build contrast_event
|
59
|
+
event_dtm = new
|
60
|
+
# Figure out what the target of this event was. It's a little
|
61
|
+
# annoying for us since P can be named (thanks, Ruby) where
|
62
|
+
# as for everyone else it is idx based.
|
63
|
+
taint_target = contrast_event.determine_taint_target(event_dtm) # This can't be pulled into the decorator because SourceEvent has a custom impl :/
|
64
|
+
|
65
|
+
event_dtm.type = contrast_event.policy_node.node_type
|
66
|
+
event_dtm.action = contrast_event.policy_node.build_action
|
67
|
+
event_dtm.timestamp_ms = contrast_event.time.to_i
|
68
|
+
event_dtm.thread = Contrast::Utils::StringUtils.force_utf8(contrast_event.thread)
|
69
|
+
truncate_obj = Contrast::Utils::ObjectShare::OBJECT_KEY != taint_target
|
70
|
+
event_dtm.object = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.object, truncate_obj)
|
71
|
+
truncate_ret = Contrast::Utils::ObjectShare::RETURN_KEY != taint_target
|
72
|
+
event_dtm.ret = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.ret, truncate_ret)
|
73
|
+
event_dtm.build_event_args(contrast_event, taint_target)
|
74
|
+
|
75
|
+
taint_ranges = event_dtm.build_taint_ranges(contrast_event, taint_target)
|
76
|
+
taint_ranges.each do |range|
|
77
|
+
event_dtm.taint_ranges << range
|
78
|
+
end
|
79
|
+
|
80
|
+
# We delayed doing this as long as possible b/c it's expensive
|
81
|
+
stack = Contrast::Utils::StackTraceUtils.build_assess_stack_array(contrast_event.stack_trace)
|
82
|
+
event_dtm.stack += stack
|
83
|
+
|
84
|
+
event_dtm.object_id = contrast_event.event_id.to_i
|
85
|
+
contrast_event.parent_ids&.each do |id|
|
86
|
+
parent = Contrast::Api::Dtm::ParentObjectId.new
|
87
|
+
parent.id = id.to_i
|
88
|
+
event_dtm.parent_object_ids << parent
|
89
|
+
end
|
90
|
+
|
91
|
+
event_dtm.signature = Contrast::Api::Dtm::TraceEventSignature.build(contrast_event.ret, contrast_event.policy_node, contrast_event.args)
|
92
|
+
event_dtm
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Contrast::Api::Dtm::TraceEvent.include(Contrast::Api::Decorators::TraceEvent)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/string_utils'
|
5
|
+
require 'contrast/utils/assess/tracking_util'
|
6
|
+
require 'base64'
|
7
|
+
require 'contrast/components/interface'
|
8
|
+
|
9
|
+
module Contrast
|
10
|
+
module Api
|
11
|
+
module Decorators
|
12
|
+
# Used to decorate the {Contrast::Api::Dtm::TraceEventObject} protobuf
|
13
|
+
# model.
|
14
|
+
module TraceEventObject
|
15
|
+
def self.included klass
|
16
|
+
klass.extend(ClassMethods)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Class methods for TraceEventObject
|
20
|
+
module ClassMethods
|
21
|
+
include Contrast::Components::Interface
|
22
|
+
access_component :scope
|
23
|
+
# Build the event object. We were originally going to include taint on
|
24
|
+
# each one, but TS doesn't accept / use that, so it is a waste of time.
|
25
|
+
#
|
26
|
+
# We'll truncate any object that isn't important to the taint ranges of
|
27
|
+
# this event, so that we don't murder TeamServer by, for instance,
|
28
|
+
# hypothetically sending the entire rendered HTML page >_> <_< >_>
|
29
|
+
ELLIPSIS = '...'
|
30
|
+
UNTRUNCATED_PORTION_LENGTH = 25
|
31
|
+
TRUNCATION_LENGTH = (UNTRUNCATED_PORTION_LENGTH * 2) + ELLIPSIS.length
|
32
|
+
def build object, truncate
|
33
|
+
event_object = new
|
34
|
+
with_contrast_scope do
|
35
|
+
obj_string = Contrast::Utils::StringUtils.force_utf8(object)
|
36
|
+
obj_string = truncate(obj_string) if truncate && obj_string.length > TRUNCATION_LENGTH
|
37
|
+
event_object.value = Base64.encode64(obj_string)
|
38
|
+
event_object.tracked = Contrast::Utils::Assess::TrackingUtil.tracked?(object)
|
39
|
+
end
|
40
|
+
event_object
|
41
|
+
end
|
42
|
+
|
43
|
+
def truncate obj_string
|
44
|
+
tmp = []
|
45
|
+
tmp << obj_string[0, UNTRUNCATED_PORTION_LENGTH]
|
46
|
+
tmp << ELLIPSIS
|
47
|
+
tmp << obj_string[
|
48
|
+
obj_string.length - UNTRUNCATED_PORTION_LENGTH,
|
49
|
+
UNTRUNCATED_PORTION_LENGTH]
|
50
|
+
tmp.join
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Contrast::Api::Dtm::TraceEventObject.include(Contrast::Api::Decorators::TraceEventObject)
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/string_utils'
|
5
|
+
require 'contrast/utils/assess/tracking_util'
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Api
|
10
|
+
module Decorators
|
11
|
+
# Used to decorate the {Contrast::Api::Dtm::TraceEventSignature} protobuf
|
12
|
+
# model.
|
13
|
+
module TraceEventSignature
|
14
|
+
def self.included klass
|
15
|
+
klass.extend(ClassMethods)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Class methods for TraceEventSignature
|
19
|
+
module ClassMethods
|
20
|
+
def build ret_obj, policy_node, args
|
21
|
+
signature = new
|
22
|
+
return_type = ret_obj ? ret_obj.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
|
23
|
+
signature.return_type = Contrast::Utils::StringUtils.force_utf8(return_type)
|
24
|
+
signature.class_name = Contrast::Utils::StringUtils.force_utf8(policy_node.class_name)
|
25
|
+
signature.method_name = Contrast::Utils::StringUtils.force_utf8(policy_node.method_name)
|
26
|
+
if args
|
27
|
+
args&.each do |arg|
|
28
|
+
arg_type = arg ? arg.cs__class.name : Contrast::Utils::ObjectShare::NIL_STRING
|
29
|
+
signature.arg_types << Contrast::Utils::StringUtils.force_utf8(arg_type)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
signature.constructor = policy_node.method_name == :new
|
33
|
+
# if there's a ret, then this method isn't nil. not 100% full proof since you can
|
34
|
+
# return nil, but this is the best we've got currently.
|
35
|
+
signature.void_method = ret_obj.nil?
|
36
|
+
# 8 is STATIC in Java... we have to placate them for now
|
37
|
+
# it has been requested that flags be removed since it isn't used
|
38
|
+
signature.flags = 8 unless policy_node.instance_method?
|
39
|
+
signature
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
Contrast::Api::Dtm::TraceEventSignature.include(Contrast::Api::Decorators::TraceEventSignature)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/object_share'
|
5
|
+
require 'contrast/utils/string_utils'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Api
|
9
|
+
module Decorators
|
10
|
+
# Used to decorate the {Contrast::Api::Dtm::TraceTaintRange} protobuf
|
11
|
+
# model.
|
12
|
+
module TraceTaintRange
|
13
|
+
def self.included klass
|
14
|
+
klass.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Class methods for TraceEventObject
|
18
|
+
module ClassMethods
|
19
|
+
# Convert the tags from Contrast::Agent::Assess::Property::Tagged to
|
20
|
+
# the form required for their Event's DTM.
|
21
|
+
#
|
22
|
+
# @param tags [Hash{String => Array<Contrast::Agent::Assess::Tag>}]
|
23
|
+
# @return [Array<Contrast::Api::Dtm::TraceTaintRange>]
|
24
|
+
def build_for_event tags
|
25
|
+
return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless tags&.any?
|
26
|
+
|
27
|
+
ranges = []
|
28
|
+
tags.each_value do |value|
|
29
|
+
next if value.empty?
|
30
|
+
|
31
|
+
value.each { |tag| ranges << build(tag) }
|
32
|
+
end
|
33
|
+
ranges
|
34
|
+
end
|
35
|
+
|
36
|
+
# Convert our Tags to their DTM equivalent
|
37
|
+
#
|
38
|
+
# @param tag [Contrast::Agent::Assess::Tag]
|
39
|
+
# @return [Contrast::Api::Dtm::TraceTaintRange]
|
40
|
+
def build tag
|
41
|
+
range = Contrast::Api::Dtm::TraceTaintRange.new
|
42
|
+
range.tag = Contrast::Utils::StringUtils.protobuf_safe_string(tag.label)
|
43
|
+
range.range = tag.start_idx.to_s + Contrast::Utils::ObjectShare::COLON + tag.end_idx.to_s
|
44
|
+
range
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
Contrast::Api::Dtm::TraceTaintRange.include(Contrast::Api::Decorators::TraceTaintRange)
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Copyright (c) 2020 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 Api
|
6
|
+
module Decorators
|
7
|
+
# A holder for the valid tags that can be sent to the Service, and
|
8
|
+
# ultimately TS, that we have to honor. Placed here so as not to clutter
|
9
|
+
# other code.
|
10
|
+
module TraceTaintRangeTags
|
11
|
+
# EventTagTypeDTM
|
12
|
+
VALID_TAGS = %w[
|
13
|
+
XML_ENCODED
|
14
|
+
XML_DECODED
|
15
|
+
HTML_ENCODED
|
16
|
+
HTML_DECODED
|
17
|
+
URL_ENCODED
|
18
|
+
URL_DECODED
|
19
|
+
CSS_ENCODED
|
20
|
+
CSS_DECODED
|
21
|
+
BASE64_ENCODED
|
22
|
+
BASE64_DECODED
|
23
|
+
JAVASCRIPT_ENCODED
|
24
|
+
JAVASCRIPT_DECODED
|
25
|
+
JAVA_ENCODED
|
26
|
+
JAVA_DECODED
|
27
|
+
CSV_ENCODED
|
28
|
+
CSV_DECODED
|
29
|
+
SQL_ENCODED
|
30
|
+
SQL_DECODED
|
31
|
+
LDAP_ENCODED
|
32
|
+
LDAP_DECODED
|
33
|
+
XPATH_ENCODED
|
34
|
+
XPATH_DECODED
|
35
|
+
OS_ENCODED
|
36
|
+
OS_DECODED
|
37
|
+
VBSCRIPT_ENCODED
|
38
|
+
VBSCRIPT_DECODED
|
39
|
+
POTENTIAL_SANITIZED
|
40
|
+
POTENTIAL_VALIDATED
|
41
|
+
NO_CONTROL_CHARS
|
42
|
+
CUSTOM
|
43
|
+
|
44
|
+
CUSTOM_ENCODED
|
45
|
+
CUSTOM_ENCODED_CMD_INJECTION
|
46
|
+
CUSTOM_ENCODED_EXPRESSION_LANGUAGE_INJECTION
|
47
|
+
CUSTOM_ENCODED_HEADER_INJECTION
|
48
|
+
CUSTOM_ENCODED_HQL_INJECTION
|
49
|
+
CUSTOM_ENCODED_LDAP_INJECTION
|
50
|
+
CUSTOM_ENCODED_LOG_INJECTION
|
51
|
+
CUSTOM_ENCODED_NOSQL_INJECTION
|
52
|
+
CUSTOM_ENCODED_PATH_TRAVERSAL
|
53
|
+
CUSTOM_ENCODED_REDOS
|
54
|
+
CUSTOM_ENCODED_REFLECTED_XSS
|
55
|
+
CUSTOM_ENCODED_REFLECTION_INJECTION
|
56
|
+
CUSTOM_ENCODED_SMTP_INJECTION
|
57
|
+
CUSTOM_ENCODED_SQL_INJECTION
|
58
|
+
CUSTOM_ENCODED_SSRF
|
59
|
+
CUSTOM_ENCODED_STORED_XSS
|
60
|
+
CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION
|
61
|
+
CUSTOM_ENCODED_UNSAFE_CODE_EXECUTION
|
62
|
+
CUSTOM_ENCODED_UNSAFE_READLINE
|
63
|
+
CUSTOM_ENCODED_UNSAFE_XML_DECODE
|
64
|
+
CUSTOM_ENCODED_UNTRUSTED_DESERIALIZATION
|
65
|
+
CUSTOM_ENCODED_UNVALIDATED_FORWARD
|
66
|
+
CUSTOM_ENCODED_UNVALIDATED_REDIRECT
|
67
|
+
CUSTOM_ENCODED_XPATH_INJECTION
|
68
|
+
CUSTOM_ENCODED_XXE
|
69
|
+
CUSTOM_SECURITY_CONTROL_APPLIED
|
70
|
+
|
71
|
+
CUSTOM_VALIDATED
|
72
|
+
CUSTOM_VALIDATED_CMD_INJECTION
|
73
|
+
CUSTOM_VALIDATED_EXPRESSION_LANGUAGE_INJECTION
|
74
|
+
CUSTOM_VALIDATED_HEADER_INJECTION
|
75
|
+
CUSTOM_VALIDATED_HQL_INJECTION
|
76
|
+
CUSTOM_VALIDATED_LDAP_INJECTION
|
77
|
+
CUSTOM_VALIDATED_LOG_INJECTION
|
78
|
+
CUSTOM_VALIDATED_NOSQL_INJECTION
|
79
|
+
CUSTOM_VALIDATED_PATH_TRAVERSAL
|
80
|
+
CUSTOM_VALIDATED_REDOS
|
81
|
+
CUSTOM_VALIDATED_REFLECTED_XSS
|
82
|
+
CUSTOM_VALIDATED_REFLECTION_INJECTION
|
83
|
+
CUSTOM_VALIDATED_SMTP_INJECTION
|
84
|
+
CUSTOM_VALIDATED_SQL_INJECTION
|
85
|
+
CUSTOM_VALIDATED_SSRF
|
86
|
+
CUSTOM_VALIDATED_STORED_XSS
|
87
|
+
CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION
|
88
|
+
CUSTOM_VALIDATED_UNSAFE_CODE_EXECUTION
|
89
|
+
CUSTOM_VALIDATED_UNSAFE_READLINE
|
90
|
+
CUSTOM_VALIDATED_UNSAFE_XML_DECODE
|
91
|
+
CUSTOM_VALIDATED_UNTRUSTED_DESERIALIZATION
|
92
|
+
CUSTOM_VALIDATED_UNVALIDATED_FORWARD
|
93
|
+
CUSTOM_VALIDATED_UNVALIDATED_REDIRECT
|
94
|
+
CUSTOM_VALIDATED_XPATH_INJECTION
|
95
|
+
CUSTOM_VALIDATED_XXE
|
96
|
+
|
97
|
+
DATABASE_WRITE
|
98
|
+
].cs__freeze
|
99
|
+
|
100
|
+
VALID_SOURCE_TAGS = %w[
|
101
|
+
NO_NEWLINES
|
102
|
+
UNTRUSTED
|
103
|
+
CROSS_SITE
|
104
|
+
LIMITED_CHARS
|
105
|
+
].cs__freeze
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/string_utils'
|
5
|
+
require 'contrast/utils/assess/tracking_util'
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Api
|
10
|
+
module Decorators
|
11
|
+
# Used to decorate the {Contrast::Api::Dtm::UserInput} protobuf model.
|
12
|
+
module UserInput
|
13
|
+
UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
|
14
|
+
user_input.input_type = :UNKNOWN
|
15
|
+
end.cs__freeze
|
16
|
+
|
17
|
+
def self.included klass
|
18
|
+
klass.extend(ClassMethods)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Used to add class methods to UserInput
|
22
|
+
module ClassMethods
|
23
|
+
def build_from_ia_result ia_result
|
24
|
+
return UNKNOWN_USER_INPUT.dup unless ia_result
|
25
|
+
|
26
|
+
user_input = new
|
27
|
+
user_input.input_type = ia_result.input_type.to_i
|
28
|
+
user_input.matcher_ids = ia_result.ids
|
29
|
+
user_input.path = ia_result.path.to_s
|
30
|
+
user_input.key = ia_result.key.to_s
|
31
|
+
user_input.value = ia_result.value.to_s
|
32
|
+
user_input
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Contrast::Api::Dtm::UserInput.include(Contrast::Api::Decorators::UserInput)
|