tcell_agent 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -22
- data/bin/tcell_agent +127 -132
- data/lib/tcell_agent/agent/event_processor.rb +23 -22
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
- data/lib/tcell_agent/agent/policy_manager.rb +20 -15
- data/lib/tcell_agent/agent/policy_types.rb +5 -11
- data/lib/tcell_agent/agent/static_agent.rb +5 -1
- data/lib/tcell_agent/agent.rb +6 -4
- data/lib/tcell_agent/api.rb +7 -9
- data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
- data/lib/tcell_agent/authlogic.rb +3 -3
- data/lib/tcell_agent/cmdi.rb +6 -4
- data/lib/tcell_agent/config/unknown_options.rb +3 -1
- data/lib/tcell_agent/configuration.rb +47 -49
- data/lib/tcell_agent/devise.rb +2 -2
- data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
- data/lib/tcell_agent/instrumentation.rb +11 -10
- data/lib/tcell_agent/logger.rb +2 -2
- data/lib/tcell_agent/patches/meta_data.rb +9 -13
- data/lib/tcell_agent/patches.rb +7 -10
- data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
- data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
- data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
- data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +90 -0
- data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
- data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
- data/lib/tcell_agent/rails/auth/devise.rb +44 -23
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
- data/lib/tcell_agent/rails/better_ip.rb +1 -1
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
- data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
- data/lib/tcell_agent/rails/dlp.rb +6 -6
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
- data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
- data/lib/tcell_agent/rails/routes/grape.rb +6 -6
- data/lib/tcell_agent/rails/routes.rb +8 -11
- data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +16 -0
- data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +119 -48
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
- data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
- data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
- data/lib/tcell_agent/sensor_events/patches.rb +21 -0
- data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
- data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
- data/lib/tcell_agent/servers/puma.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +1 -1
- data/lib/tcell_agent/utils/passwords.rb +28 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/lib/tcell_agent.rb +1 -5
- data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
- data/spec/apps/rails-3.2/log/development.log +0 -0
- data/spec/apps/rails-3.2/log/test.log +12 -0
- data/spec/apps/rails-4.1/log/test.log +0 -0
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
- data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
- data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
- data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
- data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
- data/spec/lib/tcell_agent/patches_spec.rb +70 -111
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
- data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
- data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
- data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
- data/spec/lib/tcell_agent/rails_spec.rb +1 -6
- data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
- data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
- data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
- data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
- data/spec/lib/tcell_agent_spec.rb +8 -8
- data/spec/spec_helper.rb +4 -4
- data/spec/support/middleware_helper.rb +10 -10
- data/spec/support/static_agent_overrides.rb +16 -12
- data/tcell_agent.gemspec +17 -33
- metadata +43 -198
- data/LICENSE_libinjection +0 -32
- data/Readme.txt +0 -7
- data/ext/libinjection/extconf.rb +0 -3
- data/ext/libinjection/libinjection.h +0 -65
- data/ext/libinjection/libinjection_html5.c +0 -847
- data/ext/libinjection/libinjection_html5.h +0 -54
- data/ext/libinjection/libinjection_sqli.c +0 -2317
- data/ext/libinjection/libinjection_sqli.h +0 -295
- data/ext/libinjection/libinjection_sqli_data.h +0 -9004
- data/ext/libinjection/libinjection_wrap.c +0 -3525
- data/ext/libinjection/libinjection_xss.c +0 -531
- data/ext/libinjection/libinjection_xss.h +0 -21
- data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
- data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
- data/lib/tcell_agent/patches/block_rule.rb +0 -93
- data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
- data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
- data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
- data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
- data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
- data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
- data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
- data/lib/tcell_agent/policies/patches_policy.rb +0 -84
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
- data/spec/apps/rails-3.2/Gemfile +0 -25
- data/spec/apps/rails-3.2/Gemfile.lock +0 -126
- data/spec/apps/rails-3.2/Rakefile +0 -7
- data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
- data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
- data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
- data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
- data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-3.2/config/application.rb +0 -63
- data/spec/apps/rails-3.2/config/boot.rb +0 -6
- data/spec/apps/rails-3.2/config/environment.rb +0 -5
- data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
- data/spec/apps/rails-3.2/config/routes.rb +0 -11
- data/spec/apps/rails-3.2/config.ru +0 -4
- data/spec/apps/rails-4.1/Gemfile +0 -7
- data/spec/apps/rails-4.1/Gemfile.lock +0 -114
- data/spec/apps/rails-4.1/Rakefile +0 -6
- data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
- data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
- data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-4.1/config/application.rb +0 -24
- data/spec/apps/rails-4.1/config/boot.rb +0 -4
- data/spec/apps/rails-4.1/config/environment.rb +0 -5
- data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
- data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
- data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
- data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
- data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
- data/spec/apps/rails-4.1/config/routes.rb +0 -12
- data/spec/apps/rails-4.1/config/secrets.yml +0 -22
- data/spec/apps/rails-4.1/config.ru +0 -4
- data/spec/controllers/application_controller.rb +0 -12
- data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
- data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
- data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
- data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
- data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
- data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
- data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +0 -22
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'tcell_agent/appsensor/injections_matcher'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module Patches
|
5
|
-
|
6
|
-
class SensorsMatcher
|
7
|
-
attr_accessor :injections_matcher
|
8
|
-
|
9
|
-
def initialize(injections_matcher)
|
10
|
-
@injections_matcher = injections_matcher
|
11
|
-
end
|
12
|
-
|
13
|
-
def any_matches?(meta_data)
|
14
|
-
return true unless @injections_matcher.enabled
|
15
|
-
|
16
|
-
@injections_matcher.each_injection(meta_data) do |injection_attempt|
|
17
|
-
return true
|
18
|
-
end
|
19
|
-
|
20
|
-
return false
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.from_json(sensor_matcher_json)
|
24
|
-
injections_matcher =
|
25
|
-
TCellAgent::AppSensor::InjectionsMatcher.from_json(2, sensor_matcher_json)
|
26
|
-
SensorsMatcher.new(injections_matcher)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'tcell_agent/policies/appsensor/injection_sensor'
|
2
|
-
|
3
|
-
|
4
|
-
module TCellAgent
|
5
|
-
module Policies
|
6
|
-
|
7
|
-
class CmdiSensor < InjectionSensor
|
8
|
-
|
9
|
-
def initialize(policy_json=nil)
|
10
|
-
super(
|
11
|
-
"cmdi",
|
12
|
-
policy_json
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
def applicable_for_param_type?(param_type)
|
17
|
-
InjectionSensor::COOKIE_PARAM != param_type
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'tcell_agent/policies/appsensor/injection_sensor'
|
2
|
-
|
3
|
-
|
4
|
-
module TCellAgent
|
5
|
-
module Policies
|
6
|
-
|
7
|
-
class FptSensor < InjectionSensor
|
8
|
-
|
9
|
-
def initialize(policy_json=nil)
|
10
|
-
super(
|
11
|
-
"fpt",
|
12
|
-
policy_json
|
13
|
-
)
|
14
|
-
end
|
15
|
-
|
16
|
-
def applicable_for_param_type?(param_type)
|
17
|
-
InjectionSensor::COOKIE_PARAM != param_type
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
@@ -1,117 +0,0 @@
|
|
1
|
-
require 'tcell_agent/utils/params'
|
2
|
-
|
3
|
-
|
4
|
-
module TCellAgent
|
5
|
-
module Policies
|
6
|
-
|
7
|
-
class InjectionAttempt
|
8
|
-
|
9
|
-
attr_accessor :type_of_param, :detection_point, :param_name, :param_value, :pattern
|
10
|
-
|
11
|
-
def initialize(type_of_param, detection_point, vuln_results)
|
12
|
-
@type_of_param = type_of_param
|
13
|
-
@param_name = vuln_results["param"]
|
14
|
-
@param_value = vuln_results["value"]
|
15
|
-
@pattern = vuln_results["pattern"]
|
16
|
-
@detection_point = detection_point
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
class InjectionSensor
|
22
|
-
GET_PARAM = TCellAgent::Utils::Params::GET_PARAM
|
23
|
-
POST_PARAM = TCellAgent::Utils::Params::POST_PARAM
|
24
|
-
JSON_PARAM = TCellAgent::Utils::Params::JSON_PARAM
|
25
|
-
COOKIE_PARAM = TCellAgent::Utils::Params::COOKIE_PARAM
|
26
|
-
URI_PARAM = TCellAgent::Utils::Params::URI_PARAM
|
27
|
-
HEADER_PARAM = TCellAgent::Utils::Params::HEADER_PARAM
|
28
|
-
|
29
|
-
attr_accessor :enabled, :detection_point, :exclude_headers, :exclude_forms,
|
30
|
-
:exclude_cookies, :exclusions, :active_pattern_ids, :v1_compatability_enabled,
|
31
|
-
:excluded_route_ids
|
32
|
-
|
33
|
-
|
34
|
-
def initialize(detection_point, policy_json=nil)
|
35
|
-
@enabled = false
|
36
|
-
@detection_point = detection_point
|
37
|
-
@exclude_headers = false
|
38
|
-
@exclude_forms = false
|
39
|
-
@exclude_cookies = false
|
40
|
-
@exclusions = {}
|
41
|
-
@active_pattern_ids = Set.new
|
42
|
-
@v1_compatability_enabled = false
|
43
|
-
@rule_manager = AppSensorRuleManager.instance
|
44
|
-
@excluded_route_ids = {}
|
45
|
-
|
46
|
-
if policy_json
|
47
|
-
@enabled = policy_json.fetch("enabled", false)
|
48
|
-
@exclude_headers = policy_json.fetch("exclude_headers", false)
|
49
|
-
@exclude_forms = policy_json.fetch("exclude_forms", false)
|
50
|
-
@exclude_cookies = policy_json.fetch("exclude_cookies", false)
|
51
|
-
@v1_compatability_enabled = policy_json.fetch("v1_compatability_enabled", false)
|
52
|
-
|
53
|
-
@excluded_route_ids = Set.new(policy_json.fetch("exclude_routes", []))
|
54
|
-
@active_pattern_ids = Set.new(policy_json.fetch("patterns", []))
|
55
|
-
|
56
|
-
policy_json.fetch("exclusions", {}).each do |common_word, locations|
|
57
|
-
@exclusions[common_word] = Set.new(locations)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def applicable_for_param_type?(param_type)
|
63
|
-
true
|
64
|
-
end
|
65
|
-
|
66
|
-
def get_ruleset
|
67
|
-
@rule_manager.get_ruleset_for(@detection_point)
|
68
|
-
end
|
69
|
-
|
70
|
-
def find_vulnerability(param_name, param_value)
|
71
|
-
rules = get_ruleset
|
72
|
-
return nil unless rules
|
73
|
-
|
74
|
-
rules.check_violation(param_name, param_value, @active_pattern_ids, @v1_compatability_enabled)
|
75
|
-
end
|
76
|
-
|
77
|
-
def get_injection_attempt(type_of_param, appsensor_meta, param_name, param_value)
|
78
|
-
return false unless @enabled
|
79
|
-
|
80
|
-
return false if @excluded_route_ids.include?(appsensor_meta.route_id)
|
81
|
-
|
82
|
-
if @exclude_forms &&
|
83
|
-
(GET_PARAM == type_of_param ||
|
84
|
-
POST_PARAM == type_of_param ||
|
85
|
-
JSON_PARAM == type_of_param ||
|
86
|
-
URI_PARAM == type_of_param)
|
87
|
-
return false
|
88
|
-
end
|
89
|
-
|
90
|
-
if @exclude_cookies && COOKIE_PARAM == type_of_param
|
91
|
-
return false
|
92
|
-
end
|
93
|
-
|
94
|
-
if @exclude_headers && HEADER_PARAM == type_of_param
|
95
|
-
return false
|
96
|
-
end
|
97
|
-
|
98
|
-
vuln_results = find_vulnerability(param_name, param_value)
|
99
|
-
|
100
|
-
if vuln_results
|
101
|
-
InjectionAttempt.new(type_of_param, @detection_point, vuln_results)
|
102
|
-
else
|
103
|
-
false
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def to_s
|
108
|
-
"<#{self.class.name} enabled: #{@enabled} dp: #{@detection_point} " +
|
109
|
-
"exclude_headers: #{@exclude_headers} exclude_forms: #{exclude_forms} " +
|
110
|
-
"exclude_cookies: #{exclude_cookies} v1_compatability_enabled: #{@v1_compatability_enabled} " +
|
111
|
-
"active_pattern_ids: #{@active_pattern_ids} exclusions: #{exclusions} " +
|
112
|
-
"excluded_route_ids: #{@excluded_route_ids}>"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'tcell_agent/policies/appsensor/injection_sensor'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module Policies
|
5
|
-
|
6
|
-
class NullbyteSensor < InjectionSensor
|
7
|
-
|
8
|
-
def initialize(policy_json=nil)
|
9
|
-
super(
|
10
|
-
"null",
|
11
|
-
policy_json
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def get_ruleset
|
16
|
-
@rule_manager.get_ruleset_for("nullbyte")
|
17
|
-
end
|
18
|
-
|
19
|
-
def applicable_for_param_type?(param_type)
|
20
|
-
InjectionSensor::COOKIE_PARAM != param_type
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'tcell_agent/policies/appsensor/injection_sensor'
|
2
|
-
|
3
|
-
module TCellAgent
|
4
|
-
module Policies
|
5
|
-
|
6
|
-
class RetrSensor < InjectionSensor
|
7
|
-
|
8
|
-
def initialize(policy_json=nil)
|
9
|
-
super(
|
10
|
-
"retr",
|
11
|
-
policy_json
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def applicable_for_param_type?(param_type)
|
16
|
-
InjectionSensor::POST_PARAM != param_type && InjectionSensor::JSON_PARAM != param_type
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'libinjection/libinjection'
|
2
|
-
require 'tcell_agent/policies/appsensor/injection_sensor'
|
3
|
-
|
4
|
-
module TCellAgent
|
5
|
-
module Policies
|
6
|
-
|
7
|
-
class SqliSensor < InjectionSensor
|
8
|
-
|
9
|
-
attr_accessor :libinjection
|
10
|
-
|
11
|
-
def initialize(policy_json=nil)
|
12
|
-
super(
|
13
|
-
"sqli",
|
14
|
-
policy_json
|
15
|
-
)
|
16
|
-
|
17
|
-
@libinjection = false
|
18
|
-
|
19
|
-
if policy_json
|
20
|
-
@libinjection = policy_json.fetch("libinjection", false)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def find_vulnerability(param_name, param_value)
|
25
|
-
if @libinjection && Libinjection.is_sqli(param_value) == 1
|
26
|
-
return {"param" => param_name, "value" => param_value, "pattern" => "li"}
|
27
|
-
end
|
28
|
-
|
29
|
-
super(param_name, param_value)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'libinjection/libinjection'
|
2
|
-
require 'tcell_agent/policies/appsensor/injection_sensor'
|
3
|
-
|
4
|
-
module TCellAgent
|
5
|
-
module Policies
|
6
|
-
|
7
|
-
class XssSensor < InjectionSensor
|
8
|
-
|
9
|
-
attr_accessor :libinjection
|
10
|
-
|
11
|
-
def initialize(policy_json=nil)
|
12
|
-
super(
|
13
|
-
"xss",
|
14
|
-
policy_json
|
15
|
-
)
|
16
|
-
|
17
|
-
@libinjection = false
|
18
|
-
|
19
|
-
if policy_json
|
20
|
-
@libinjection = policy_json.fetch("libinjection", false)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def find_vulnerability(param_name, param_value)
|
25
|
-
if @libinjection && Libinjection.is_xss(param_value) == 1
|
26
|
-
return {"param" => param_name, "value" => param_value, "pattern" => "li"}
|
27
|
-
end
|
28
|
-
|
29
|
-
super(param_name, param_value)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'tcell_agent/instrumentation'
|
2
|
-
require 'tcell_agent/appsensor/injections_reporter'
|
3
|
-
require 'tcell_agent/rust/models'
|
4
|
-
require 'tcell_agent/rust/whisperer'
|
5
|
-
require 'tcell_agent/policies/policy'
|
6
|
-
|
7
|
-
|
8
|
-
module TCellAgent
|
9
|
-
module Policies
|
10
|
-
|
11
|
-
class AppSensorPolicy < Policy
|
12
|
-
attr_reader :appfirewall_enabled, :appfirewall_ptr
|
13
|
-
|
14
|
-
def initialize(appfirewall_enabled=false, appfirewall_ptr=nil)
|
15
|
-
@appfirewall_ptr = appfirewall_ptr
|
16
|
-
@appfirewall_enabled = appfirewall_enabled
|
17
|
-
end
|
18
|
-
|
19
|
-
def process_meta_event(appsensor_meta)
|
20
|
-
return unless @appfirewall_enabled && @appfirewall_ptr
|
21
|
-
|
22
|
-
TCellAgent::Instrumentation.safe_block("AppSensor inspection") do
|
23
|
-
request_response = TCellAgent::Rust::Models.create_request_response(appsensor_meta)
|
24
|
-
whisper = TCellAgent::Rust::Whisperer.apply_appfirewall(@appfirewall_ptr, request_response)
|
25
|
-
TCellAgent::AppSensor::InjectionsReporter.report_and_log(whisper["apply_response"])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def free_native_memory
|
30
|
-
TCellAgent::Rust::Whisperer.free_appfirewall(@appfirewall_ptr) if @appfirewall_ptr
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.from_json(policy_json)
|
34
|
-
return nil unless policy_json
|
35
|
-
|
36
|
-
whisper = TCellAgent::Rust::Whisperer.init_appfirewall(
|
37
|
-
policy_json, TCellAgent.configuration.allow_payloads
|
38
|
-
)
|
39
|
-
if whisper["error"]
|
40
|
-
TCellAgent.logger.debug("Error initializing AppFirewall Policy: #{whisper['error']}")
|
41
|
-
return AppSensorPolicy.new
|
42
|
-
else
|
43
|
-
return AppSensorPolicy.new(whisper["enabled"], whisper["policy_ptr"])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|
49
|
-
end
|
@@ -1,196 +0,0 @@
|
|
1
|
-
require 'tcell_agent/rust/whisperer'
|
2
|
-
require 'tcell_agent/sensor_events/command_injection'
|
3
|
-
require 'tcell_agent/policies/policy'
|
4
|
-
|
5
|
-
|
6
|
-
module TCellAgent
|
7
|
-
module Policies
|
8
|
-
|
9
|
-
class CommandRule
|
10
|
-
IGNORE = "ignore"
|
11
|
-
REPORT = "report"
|
12
|
-
BLOCK = "block"
|
13
|
-
|
14
|
-
attr_reader :rule_id, :action, :command
|
15
|
-
|
16
|
-
def initialize(policy_json)
|
17
|
-
@rule_id = nil
|
18
|
-
@action = nil
|
19
|
-
@command = nil
|
20
|
-
|
21
|
-
if policy_json
|
22
|
-
@rule_id = policy_json["rule_id"]
|
23
|
-
@action = policy_json["action"]
|
24
|
-
@command = policy_json["command"]
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def ignore?
|
29
|
-
@action == IGNORE
|
30
|
-
end
|
31
|
-
|
32
|
-
def report?
|
33
|
-
@action == REPORT
|
34
|
-
end
|
35
|
-
|
36
|
-
def block?
|
37
|
-
@action == BLOCK
|
38
|
-
end
|
39
|
-
|
40
|
-
def valid?
|
41
|
-
!!@rule_id && [IGNORE, REPORT, BLOCK].include?(@action)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class CommandInjectionPolicy < Policy
|
46
|
-
attr_accessor :policy_id, :version, :enabled, :overall_action, :command_rules, :compound_statement_rule,
|
47
|
-
:collect_full_commandline
|
48
|
-
|
49
|
-
def initialize
|
50
|
-
@enabled = false
|
51
|
-
@version = nil
|
52
|
-
@policy_id = nil
|
53
|
-
@overall_action = nil
|
54
|
-
@command_rules = {}
|
55
|
-
@compound_statement_rule = nil
|
56
|
-
@collect_full_commandline = false
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.from_json(policy_json)
|
60
|
-
return nil unless policy_json
|
61
|
-
policy_json = policy_json.deep_dup
|
62
|
-
|
63
|
-
policy_id = policy_json["policy_id"]
|
64
|
-
|
65
|
-
raise "Policy ID missing" unless policy_id
|
66
|
-
|
67
|
-
command_injection_policy = CommandInjectionPolicy.new
|
68
|
-
command_injection_policy.policy_id = policy_id
|
69
|
-
command_injection_policy.version = policy_json["version"]
|
70
|
-
|
71
|
-
if 1 != command_injection_policy.version
|
72
|
-
TCellAgent.logger.error("Command Injection not supported: #{command_injection_policy.version}")
|
73
|
-
return command_injection_policy
|
74
|
-
end
|
75
|
-
|
76
|
-
policy_data = policy_json["data"]
|
77
|
-
command_rules = {}
|
78
|
-
overall_action = nil
|
79
|
-
compound_statement_rule = nil
|
80
|
-
if policy_data
|
81
|
-
command_injection_policy.collect_full_commandline = !!policy_data["collect_full_commandline"]
|
82
|
-
|
83
|
-
(policy_data["command_rules"] or []).each do |command_rule_policy|
|
84
|
-
command_rule = CommandRule.new(command_rule_policy)
|
85
|
-
if command_rule.valid?
|
86
|
-
command = command_rule.command
|
87
|
-
if command
|
88
|
-
if command_rules.has_key?(command)
|
89
|
-
TCellAgent.logger.warn(
|
90
|
-
"CommandInjectionPolicy multiple rules for one " +
|
91
|
-
"command (dropping rule): #{command} #{command_rule.action}"
|
92
|
-
)
|
93
|
-
else
|
94
|
-
command_rules[command] = command_rule
|
95
|
-
end
|
96
|
-
elsif !command_rule.ignore?
|
97
|
-
overall_action = command_rule
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
compound_statement_rules = policy_data["compound_statement_rules"]
|
103
|
-
if compound_statement_rules && compound_statement_rules.size > 0
|
104
|
-
compound_statement_rule = CommandRule.new(compound_statement_rules[0])
|
105
|
-
if !compound_statement_rule.valid? || compound_statement_rule.ignore?
|
106
|
-
compound_statement_rule = nil
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
command_injection_policy.command_rules = command_rules
|
111
|
-
command_injection_policy.overall_action = overall_action
|
112
|
-
command_injection_policy.compound_statement_rule = compound_statement_rule
|
113
|
-
command_injection_policy.enabled = !overall_action.nil? || !compound_statement_rule.nil? || command_rules.size > 0
|
114
|
-
end
|
115
|
-
|
116
|
-
command_injection_policy
|
117
|
-
end
|
118
|
-
|
119
|
-
def block?(cmd, tcell_context)
|
120
|
-
return false unless @enabled
|
121
|
-
|
122
|
-
commands = parse_cmd(cmd).fetch('commands', [])
|
123
|
-
|
124
|
-
command_injection_match_events = []
|
125
|
-
block_command = false
|
126
|
-
|
127
|
-
if commands.size > 1 && !!@compound_statement_rule
|
128
|
-
if !@compound_statement_rule.ignore?
|
129
|
-
command_injection_match_events.push(
|
130
|
-
TCellAgent::SensorEvents::CommandInjectionMatchEvent.new(
|
131
|
-
@compound_statement_rule.rule_id, @compound_statement_rule.command
|
132
|
-
)
|
133
|
-
)
|
134
|
-
block_command = block_command || @compound_statement_rule.block?
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
commands.each do |command_info|
|
139
|
-
command = command_info["command"]
|
140
|
-
command_rule = command_rules[command] || @overall_action
|
141
|
-
if command_rule && !command_rule.ignore?
|
142
|
-
command_injection_match_events.push(
|
143
|
-
TCellAgent::SensorEvents::CommandInjectionMatchEvent.new(
|
144
|
-
command_rule.rule_id,
|
145
|
-
command
|
146
|
-
)
|
147
|
-
)
|
148
|
-
block_command = block_command || command_rule.block?
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
if command_injection_match_events.size > 0
|
153
|
-
method, remote_address, route_id, session_id, user_id, full_commandline = nil
|
154
|
-
if tcell_context
|
155
|
-
method = tcell_context.request_method
|
156
|
-
remote_address = tcell_context.ip_address
|
157
|
-
route_id = tcell_context.route_id
|
158
|
-
session_id = tcell_context.hmac_session_id
|
159
|
-
user_id = tcell_context.user_id
|
160
|
-
end
|
161
|
-
|
162
|
-
if @collect_full_commandline
|
163
|
-
full_commandline = cmd
|
164
|
-
end
|
165
|
-
|
166
|
-
TCellAgent.send_event(
|
167
|
-
TCellAgent::SensorEvents::CommandInjectionEvent.new(
|
168
|
-
commands,
|
169
|
-
block_command,
|
170
|
-
command_injection_match_events,
|
171
|
-
method=method,
|
172
|
-
remote_address=remote_address,
|
173
|
-
route_id=route_id,
|
174
|
-
session_id=session_id,
|
175
|
-
user_id=user_id,
|
176
|
-
full_commandline=full_commandline
|
177
|
-
)
|
178
|
-
)
|
179
|
-
end
|
180
|
-
|
181
|
-
block_command
|
182
|
-
end
|
183
|
-
|
184
|
-
private
|
185
|
-
def parse_cmd(cmd)
|
186
|
-
TCellAgent::Instrumentation.safe_block("Call Rust Parse Command") do
|
187
|
-
require "tcell_agent/rust/whisperer"
|
188
|
-
|
189
|
-
return TCellAgent::Rust::Whisperer.parse_cmd(cmd)
|
190
|
-
end
|
191
|
-
|
192
|
-
return {}
|
193
|
-
end
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# See the file "LICENSE" for the full license governing this code.
|
2
|
-
|
3
|
-
#String sh_policy_string = ""
|
4
|
-
#+"{"
|
5
|
-
#+"\"policy_id\":\"00a1\","
|
6
|
-
#+"\"token_salt\":\"salt123\","
|
7
|
-
#+"\"tokens\": ["
|
8
|
-
#+" {\"type\":\"cred\", \"id\":\"deny\", \"token\":\"abcdefgh\"}"
|
9
|
-
#+" ]"
|
10
|
-
#+"}";
|
11
|
-
require 'pbkdf2'
|
12
|
-
require 'openssl'
|
13
|
-
require 'tcell_agent/policies/policy'
|
14
|
-
|
15
|
-
|
16
|
-
module TCellAgent
|
17
|
-
module Policies
|
18
|
-
class HoneytokensPolicy < Policy
|
19
|
-
attr_accessor :policy_id
|
20
|
-
attr_accessor :token_salt
|
21
|
-
attr_accessor :cred_tokens
|
22
|
-
|
23
|
-
def id_for_credentialstring(credential_string)
|
24
|
-
if cred_tokens
|
25
|
-
credential_hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha512'), token_salt, credential_string)
|
26
|
-
if cred_tokens.has_key?(credential_hmac)
|
27
|
-
return cred_tokens[credential_hmac]
|
28
|
-
end
|
29
|
-
end
|
30
|
-
return nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.from_json(policy_json)
|
34
|
-
if (!policy_json)
|
35
|
-
return nil
|
36
|
-
end
|
37
|
-
|
38
|
-
honeytokens_policy = HoneytokensPolicy.new
|
39
|
-
if policy_json.has_key?("policy_id")
|
40
|
-
honeytokens_policy.policy_id = policy_json["policy_id"]
|
41
|
-
else
|
42
|
-
raise "Policy ID missing"
|
43
|
-
end
|
44
|
-
|
45
|
-
if policy_json.has_key?("token_salt")
|
46
|
-
honeytokens_policy.token_salt = policy_json["token_salt"]
|
47
|
-
else
|
48
|
-
raise "Token Salt missing"
|
49
|
-
end
|
50
|
-
|
51
|
-
if policy_json.has_key?("tokens")
|
52
|
-
tokens = policy_json["tokens"]
|
53
|
-
tokens.each do |token|
|
54
|
-
if (token.has_key?("type") && token.has_key?("id") && token.has_key?("token"))
|
55
|
-
if (token["type"] == "cred")
|
56
|
-
if honeytokens_policy.cred_tokens == nil
|
57
|
-
honeytokens_policy.cred_tokens = {}
|
58
|
-
end
|
59
|
-
honeytokens_policy.cred_tokens[token["token"]] = token["id"]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
return honeytokens_policy
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|