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.
Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -2
  3. data/.simplecov +0 -1
  4. data/Rakefile +0 -1
  5. data/ext/cs__assess_array/cs__assess_array.c +41 -10
  6. data/ext/cs__assess_array/cs__assess_array.h +4 -1
  7. data/lib/contrast/agent/assess/policy/trigger_method.rb +3 -3
  8. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  9. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
  10. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -1
  11. data/lib/contrast/agent/assess/property/evented.rb +11 -11
  12. data/lib/contrast/agent/assess.rb +0 -1
  13. data/lib/contrast/agent/excluder.rb +53 -35
  14. data/lib/contrast/agent/exclusion_matcher.rb +21 -9
  15. data/lib/contrast/agent/middleware.rb +12 -6
  16. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -0
  17. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +146 -127
  18. data/lib/contrast/agent/protect/input_analyzer/worth_watching_analyzer.rb +116 -0
  19. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +20 -0
  20. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  21. data/lib/contrast/agent/protect/rule/base.rb +47 -55
  22. data/lib/contrast/agent/protect/rule/base_service.rb +48 -24
  23. data/lib/contrast/agent/protect/rule/bot_blocker/bot_blocker_input_classification.rb +98 -0
  24. data/lib/contrast/agent/protect/rule/bot_blocker.rb +81 -0
  25. data/lib/contrast/agent/protect/rule/cmd_injection.rb +20 -2
  26. data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +8 -5
  27. data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +22 -22
  28. data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +64 -0
  29. data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +63 -0
  30. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +2 -58
  31. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
  32. data/lib/contrast/agent/protect/rule/deserialization.rb +3 -14
  33. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +2 -2
  34. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +0 -11
  35. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +29 -34
  36. data/lib/contrast/agent/protect/rule/no_sqli.rb +25 -18
  37. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_input_classification.rb +61 -0
  38. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass.rb +114 -0
  39. data/lib/contrast/agent/protect/rule/path_traversal.rb +40 -13
  40. data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +33 -15
  41. data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +0 -14
  42. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -62
  43. data/lib/contrast/agent/protect/rule/sqli.rb +74 -3
  44. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +39 -63
  45. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +6 -33
  46. data/lib/contrast/agent/protect/rule/xss/reflected_xss_input_classification.rb +58 -0
  47. data/lib/contrast/agent/protect/rule/xss.rb +15 -20
  48. data/lib/contrast/agent/protect/rule/xxe.rb +4 -24
  49. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +19 -40
  50. data/lib/contrast/agent/reporting/attack_result/response_type.rb +9 -9
  51. data/lib/contrast/agent/reporting/details/ip_denylist_details.rb +10 -2
  52. data/lib/contrast/agent/reporting/details/virtual_patch_details.rb +8 -2
  53. data/lib/contrast/agent/reporting/input_analysis/details/bot_blocker_details.rb +27 -0
  54. data/lib/contrast/agent/reporting/input_analysis/details/protect_rule_details.rb +15 -0
  55. data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +1 -2
  56. data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +16 -2
  57. data/lib/contrast/agent/reporting/masker/masker.rb +2 -0
  58. data/lib/contrast/agent/reporting/report.rb +1 -0
  59. data/lib/contrast/agent/reporting/reporter.rb +35 -14
  60. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +3 -9
  61. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +16 -13
  62. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +12 -7
  63. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +3 -3
  64. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +1 -2
  65. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +6 -1
  66. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +0 -2
  67. data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +0 -1
  68. data/lib/contrast/agent/reporting/reporting_events/finding.rb +6 -6
  69. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +239 -93
  70. data/lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb +10 -23
  71. data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +10 -9
  72. data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +0 -5
  73. data/lib/contrast/agent/reporting/reporting_events/library_discovery.rb +0 -1
  74. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +12 -0
  75. data/lib/contrast/agent/reporting/reporting_events/poll.rb +1 -11
  76. data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +0 -1
  77. data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +0 -1
  78. data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +8 -0
  79. data/lib/contrast/agent/reporting/reporting_events/server_settings.rb +40 -0
  80. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +2 -2
  81. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
  82. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +43 -1
  83. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +8 -4
  84. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +1 -1
  85. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +58 -4
  86. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +4 -6
  87. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +77 -16
  88. data/lib/contrast/agent/reporting/server_settings_worker.rb +44 -0
  89. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +14 -2
  90. data/lib/contrast/agent/reporting/settings/code_exclusion.rb +6 -1
  91. data/lib/contrast/agent/reporting/settings/exclusion_base.rb +18 -0
  92. data/lib/contrast/agent/reporting/settings/exclusions.rb +2 -1
  93. data/lib/contrast/agent/reporting/settings/helpers.rb +7 -0
  94. data/lib/contrast/agent/reporting/settings/input_exclusion.rb +9 -3
  95. data/lib/contrast/agent/reporting/settings/protect.rb +15 -15
  96. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +39 -2
  97. data/lib/contrast/agent/reporting/settings/rule_definition.rb +3 -0
  98. data/lib/contrast/agent/reporting/settings/security_logger.rb +77 -0
  99. data/lib/contrast/agent/reporting/settings/server_features.rb +9 -0
  100. data/lib/contrast/agent/reporting/settings/syslog.rb +34 -5
  101. data/lib/contrast/agent/request.rb +3 -14
  102. data/lib/contrast/agent/request_context.rb +6 -9
  103. data/lib/contrast/agent/request_context_extend.rb +9 -148
  104. data/lib/contrast/agent/request_handler.rb +5 -10
  105. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +1 -1
  106. data/lib/contrast/agent/thread_watcher.rb +37 -18
  107. data/lib/contrast/agent/version.rb +1 -1
  108. data/lib/contrast/agent.rb +6 -11
  109. data/lib/contrast/agent_lib/api/command_injection.rb +46 -0
  110. data/lib/contrast/agent_lib/api/init.rb +101 -0
  111. data/lib/contrast/agent_lib/api/input_tracing.rb +267 -0
  112. data/lib/contrast/agent_lib/api/method_tempering.rb +29 -0
  113. data/lib/contrast/agent_lib/api/panic.rb +87 -0
  114. data/lib/contrast/agent_lib/api/path_semantic_file_security_bypass.rb +40 -0
  115. data/lib/contrast/agent_lib/interface.rb +260 -0
  116. data/lib/contrast/agent_lib/interface_base.rb +118 -0
  117. data/lib/contrast/agent_lib/return_types/eval_result.rb +44 -0
  118. data/lib/contrast/agent_lib/test.rb +29 -0
  119. data/lib/contrast/api/communication/connection_status.rb +20 -5
  120. data/lib/contrast/components/agent.rb +34 -14
  121. data/lib/contrast/components/api.rb +23 -0
  122. data/lib/contrast/components/app_context.rb +23 -5
  123. data/lib/contrast/components/app_context_extend.rb +0 -25
  124. data/lib/contrast/components/assess.rb +34 -4
  125. data/lib/contrast/components/assess_rules.rb +18 -0
  126. data/lib/contrast/components/base.rb +40 -0
  127. data/lib/contrast/components/config/sources.rb +95 -0
  128. data/lib/contrast/components/config.rb +19 -19
  129. data/lib/contrast/components/heap_dump.rb +10 -0
  130. data/lib/contrast/components/inventory.rb +15 -2
  131. data/lib/contrast/components/logger.rb +18 -0
  132. data/lib/contrast/components/polling.rb +36 -0
  133. data/lib/contrast/components/protect.rb +52 -2
  134. data/lib/contrast/components/ruby_component.rb +16 -1
  135. data/lib/contrast/components/sampling.rb +70 -13
  136. data/lib/contrast/components/security_logger.rb +13 -0
  137. data/lib/contrast/components/settings.rb +105 -90
  138. data/lib/contrast/config/certification_configuration.rb +14 -0
  139. data/lib/contrast/config/config.rb +46 -0
  140. data/lib/contrast/config/diagnostics.rb +114 -0
  141. data/lib/contrast/config/diagnostics_tools.rb +98 -0
  142. data/lib/contrast/config/effective_config.rb +65 -0
  143. data/lib/contrast/config/effective_config_value.rb +32 -0
  144. data/lib/contrast/config/exception_configuration.rb +12 -0
  145. data/lib/contrast/config/protect_rule_configuration.rb +8 -8
  146. data/lib/contrast/config/protect_rules_configuration.rb +23 -60
  147. data/lib/contrast/config/request_audit_configuration.rb +13 -0
  148. data/lib/contrast/config/server_configuration.rb +41 -2
  149. data/lib/contrast/configuration.rb +29 -12
  150. data/lib/contrast/extension/assess/array.rb +9 -0
  151. data/lib/contrast/extension/assess/erb.rb +1 -1
  152. data/lib/contrast/extension/delegator.rb +2 -0
  153. data/lib/contrast/framework/manager.rb +3 -1
  154. data/lib/contrast/framework/rails/railtie.rb +0 -1
  155. data/lib/contrast/framework/rails/support.rb +0 -1
  156. data/lib/contrast/tasks/config.rb +1 -8
  157. data/lib/contrast/utils/assess/event_limit_utils.rb +31 -9
  158. data/lib/contrast/utils/assess/trigger_method_utils.rb +5 -4
  159. data/lib/contrast/utils/duck_utils.rb +1 -0
  160. data/lib/contrast/utils/hash_digest.rb +2 -2
  161. data/lib/contrast/utils/input_classification_base.rb +155 -0
  162. data/lib/contrast/utils/os.rb +0 -20
  163. data/lib/contrast/utils/reporting/application_activity_batch_utils.rb +81 -0
  164. data/lib/contrast/utils/response_utils.rb +0 -16
  165. data/lib/contrast/utils/routes_sent.rb +60 -0
  166. data/lib/contrast/utils/stack_trace_utils.rb +3 -15
  167. data/lib/contrast/utils/string_utils.rb +10 -7
  168. data/lib/contrast/utils/telemetry_client.rb +1 -2
  169. data/lib/contrast/utils/timer.rb +16 -0
  170. data/lib/contrast.rb +5 -4
  171. data/resources/protect/policy.json +1 -2
  172. data/ruby-agent.gemspec +7 -6
  173. metadata +69 -130
  174. data/exe/contrast_service +0 -23
  175. data/lib/contrast/agent/assess/contrast_event.rb +0 -157
  176. data/lib/contrast/agent/assess/events/event_factory.rb +0 -34
  177. data/lib/contrast/agent/assess/events/source_event.rb +0 -46
  178. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +0 -64
  179. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +0 -118
  180. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +0 -45
  181. data/lib/contrast/agent/reaction_processor.rb +0 -47
  182. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +0 -36
  183. data/lib/contrast/agent/service_heartbeat.rb +0 -35
  184. data/lib/contrast/api/communication/messaging_queue.rb +0 -128
  185. data/lib/contrast/api/communication/response_processor.rb +0 -90
  186. data/lib/contrast/api/communication/service_lifecycle.rb +0 -77
  187. data/lib/contrast/api/communication/socket.rb +0 -44
  188. data/lib/contrast/api/communication/socket_client.rb +0 -130
  189. data/lib/contrast/api/communication/speedracer.rb +0 -138
  190. data/lib/contrast/api/communication/tcp_socket.rb +0 -32
  191. data/lib/contrast/api/communication/unix_socket.rb +0 -28
  192. data/lib/contrast/api/communication.rb +0 -20
  193. data/lib/contrast/api/decorators/address.rb +0 -59
  194. data/lib/contrast/api/decorators/agent_startup.rb +0 -56
  195. data/lib/contrast/api/decorators/application_settings.rb +0 -43
  196. data/lib/contrast/api/decorators/application_startup.rb +0 -56
  197. data/lib/contrast/api/decorators/bot_blocker.rb +0 -37
  198. data/lib/contrast/api/decorators/http_request.rb +0 -137
  199. data/lib/contrast/api/decorators/input_analysis.rb +0 -18
  200. data/lib/contrast/api/decorators/instrumentation_mode.rb +0 -35
  201. data/lib/contrast/api/decorators/ip_denylist.rb +0 -37
  202. data/lib/contrast/api/decorators/message.rb +0 -67
  203. data/lib/contrast/api/decorators/rasp_rule_sample.rb +0 -52
  204. data/lib/contrast/api/decorators/response_type.rb +0 -17
  205. data/lib/contrast/api/decorators/server_features.rb +0 -25
  206. data/lib/contrast/api/decorators/user_input.rb +0 -51
  207. data/lib/contrast/api/decorators/virtual_patch.rb +0 -34
  208. data/lib/contrast/api/decorators.rb +0 -22
  209. data/lib/contrast/api/dtm.pb.rb +0 -363
  210. data/lib/contrast/api/settings.pb.rb +0 -500
  211. data/lib/contrast/api.rb +0 -16
  212. data/lib/contrast/components/contrast_service.rb +0 -88
  213. data/lib/contrast/components/service.rb +0 -55
  214. data/lib/contrast/tasks/service.rb +0 -84
  215. data/lib/contrast/utils/input_classification.rb +0 -73
  216. data/lib/protobuf/code_generator.rb +0 -129
  217. data/lib/protobuf/decoder.rb +0 -28
  218. data/lib/protobuf/deprecation.rb +0 -117
  219. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +0 -79
  220. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +0 -360
  221. data/lib/protobuf/descriptors.rb +0 -3
  222. data/lib/protobuf/encoder.rb +0 -11
  223. data/lib/protobuf/enum.rb +0 -365
  224. data/lib/protobuf/exceptions.rb +0 -9
  225. data/lib/protobuf/field/base_field.rb +0 -380
  226. data/lib/protobuf/field/base_field_object_definitions.rb +0 -504
  227. data/lib/protobuf/field/bool_field.rb +0 -64
  228. data/lib/protobuf/field/bytes_field.rb +0 -67
  229. data/lib/protobuf/field/double_field.rb +0 -25
  230. data/lib/protobuf/field/enum_field.rb +0 -56
  231. data/lib/protobuf/field/field_array.rb +0 -102
  232. data/lib/protobuf/field/field_hash.rb +0 -122
  233. data/lib/protobuf/field/fixed32_field.rb +0 -25
  234. data/lib/protobuf/field/fixed64_field.rb +0 -28
  235. data/lib/protobuf/field/float_field.rb +0 -43
  236. data/lib/protobuf/field/int32_field.rb +0 -21
  237. data/lib/protobuf/field/int64_field.rb +0 -34
  238. data/lib/protobuf/field/integer_field.rb +0 -23
  239. data/lib/protobuf/field/message_field.rb +0 -51
  240. data/lib/protobuf/field/sfixed32_field.rb +0 -27
  241. data/lib/protobuf/field/sfixed64_field.rb +0 -28
  242. data/lib/protobuf/field/signed_integer_field.rb +0 -29
  243. data/lib/protobuf/field/sint32_field.rb +0 -21
  244. data/lib/protobuf/field/sint64_field.rb +0 -21
  245. data/lib/protobuf/field/string_field.rb +0 -51
  246. data/lib/protobuf/field/uint32_field.rb +0 -21
  247. data/lib/protobuf/field/uint64_field.rb +0 -21
  248. data/lib/protobuf/field/varint_field.rb +0 -77
  249. data/lib/protobuf/field.rb +0 -74
  250. data/lib/protobuf/generators/base.rb +0 -85
  251. data/lib/protobuf/generators/enum_generator.rb +0 -39
  252. data/lib/protobuf/generators/extension_generator.rb +0 -27
  253. data/lib/protobuf/generators/field_generator.rb +0 -193
  254. data/lib/protobuf/generators/file_generator.rb +0 -262
  255. data/lib/protobuf/generators/group_generator.rb +0 -122
  256. data/lib/protobuf/generators/message_generator.rb +0 -104
  257. data/lib/protobuf/generators/option_generator.rb +0 -17
  258. data/lib/protobuf/generators/printable.rb +0 -160
  259. data/lib/protobuf/generators/service_generator.rb +0 -50
  260. data/lib/protobuf/lifecycle.rb +0 -33
  261. data/lib/protobuf/logging.rb +0 -39
  262. data/lib/protobuf/message/fields.rb +0 -233
  263. data/lib/protobuf/message/serialization.rb +0 -85
  264. data/lib/protobuf/message.rb +0 -241
  265. data/lib/protobuf/optionable.rb +0 -72
  266. data/lib/protobuf/tasks/compile.rake +0 -80
  267. data/lib/protobuf/tasks.rb +0 -1
  268. data/lib/protobuf/varint.rb +0 -20
  269. data/lib/protobuf/varint_pure.rb +0 -31
  270. data/lib/protobuf/version.rb +0 -3
  271. data/lib/protobuf/wire_type.rb +0 -10
  272. data/lib/protobuf.rb +0 -91
  273. data/proto/dynamic_discovery.proto +0 -46
  274. data/proto/google/protobuf/compiler/plugin.proto +0 -183
  275. data/proto/google/protobuf/descriptor.proto +0 -911
  276. data/proto/rpc.proto +0 -71
  277. data/service_executables/.gitkeep +0 -0
  278. data/service_executables/VERSION +0 -1
  279. data/service_executables/linux/contrast-service +0 -0
  280. 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/api/decorators/response_type'
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
- UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
22
- user_input.input_type = :UNKNOWN
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::Api::Dtm::AttackResult::ResponseType::BLOCKED,
36
- Contrast::Api::Dtm::AttackResult::ResponseType::MONITORED
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 != Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
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 the
131
- # Service.
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::Api::Settings::InputAnalysisResult] the
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::Api::Dtm::AttackResult, nil] previous
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 Service to tell the
135
+ # need to build out details to send to the TeamServer to tell the
144
136
  # story of the attack
145
- # @return [Contrast::Api::Dtm::AttackResult] the attack result from
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 the Service.
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::Api::Settings::InputAnalysisResult] the
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::Api::Dtm::AttackResult, nil] previous
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 the Service to tell the
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::Api::Dtm::AttackResult] the attack result from
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 the Service
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::Api::Dtm::AttackResult]
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 Contrast::Api::Settings::ProtectionRule::Mode::MONITOR
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 Contrast::Api::Settings::ProtectionRule::Mode::BLOCK
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::Api::Settings::InputAnalysisResult] the
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::Api::Dtm::AttackResult] previous
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 == Contrast::Api::Settings::ProtectionRule::Mode::BLOCK_AT_PERIMETER
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::Api::Dtm::AttackResult, nil] previous attack result for this rule, if one exists,
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.build_protect_stack_array
304
+ stack = Contrast::Utils::StackTraceUtils.build_protect_report_stack_array
313
305
  return unless stack
314
306
 
315
- sample.stack_trace_elements += stack
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::Api::Settings::InputAnalysisResult] the analysis of the input that was
321
- # determined to be an attack
322
- # @param result [Contrast::Api::Dtm::AttackResult, nil] previous attack result for this rule, if one exists,
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 the Service to tell the
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::Api::Settings::InputAnalysisResult] the analysis of the input that was
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::Api::Settings::InputAnalysisResult] the analysis of the input that was
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::Api::Settings::InputAnalysisResult] the analysis of the input that was
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) && Contrast::CONTRAST_SERVICE.use_agent_communication?
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&.speedracer_input_analysis&.results&.any? do |result|
28
- result.rule_id == rule_name
29
- end
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 == Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION ||
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::Api::Settings::InputAnalysis>]
89
+ # @return [Array<Contrast::Agent::Reporting::InputAnalysis>]
64
90
  def gather_ia_results context
65
- context.speedracer_input_analysis.results.select do |ia_result|
66
- ia_result.rule_id == rule_name
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::Api::Dtm::AttackResult]
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 service to be extracted early
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::Api::Settings::InputAnalysis>]
111
+ # @param ia_results [Array<Contrast::Agent::Reporting::InputAnalysis>]
83
112
  # @param **kwargs
84
- # @return [Contrast::Api::Dtm::AttackResult, nil]
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::Api::Dtm::AttackResult, nil]
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
- required_level = if ia_result.cs__is_a?(Contrast::Api::Settings::InputAnalysisResult)
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
- SUB_RULES = [Contrast::Agent::Protect::Rule::CmdiBackdoors.new].cs__freeze
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
- SUB_RULES
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&.speedracer_input_analysis&.results&.any? do |result|
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::Api::Settings::InputAnalysisResult] gathered results
106
+ # @param ia_results [Contrast::Agent::Reporting::Settings::InputAnalysisResult] gathered results
107
107
  # @param cmd [String] potential attack vector
108
- # @return [Contrast::Api::Settings::InputAnalysisResult, nil] matched input_type
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.speedracer_input_analysis.results.select do |ia_result|
122
- ia_result.rule_id == Contrast::Agent::Protect::Rule::CmdInjection::NAME
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