tcell_agent 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/tcell_agent +10 -2
- data/lib/tcell_agent.rb +3 -3
- data/lib/tcell_agent/agent.rb +42 -52
- data/lib/tcell_agent/agent/event_processor.rb +129 -162
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +57 -62
- data/lib/tcell_agent/agent/policy_manager.rb +83 -104
- data/lib/tcell_agent/agent/policy_types.rb +24 -29
- data/lib/tcell_agent/agent/route_manager.rb +36 -46
- data/lib/tcell_agent/agent/static_agent.rb +19 -21
- data/lib/tcell_agent/api.rb +23 -28
- data/lib/tcell_agent/appsensor/injections_reporter.rb +7 -11
- data/lib/tcell_agent/authlogic.rb +7 -7
- data/lib/tcell_agent/cmdi.rb +22 -23
- data/lib/tcell_agent/config/unknown_options.rb +71 -69
- data/lib/tcell_agent/configuration.rb +187 -191
- data/lib/tcell_agent/devise.rb +13 -15
- data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
- data/lib/tcell_agent/instrumentation.rb +120 -124
- data/lib/tcell_agent/logger.rb +29 -45
- data/lib/tcell_agent/patches.rb +5 -5
- data/lib/tcell_agent/policies/dataloss_policy.rb +263 -288
- data/lib/tcell_agent/policies/http_redirect_policy.rb +25 -37
- data/lib/tcell_agent/policies/http_tx_policy.rb +48 -52
- data/lib/tcell_agent/policies/login_fraud_policy.rb +15 -20
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +24 -29
- data/lib/tcell_agent/rails.rb +2 -3
- data/lib/tcell_agent/rails/auth/authlogic.rb +2 -2
- data/lib/tcell_agent/rails/auth/devise.rb +2 -2
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +2 -2
- data/lib/tcell_agent/rails/better_ip.rb +12 -16
- data/lib/tcell_agent/rails/csrf_exception.rb +4 -7
- data/lib/tcell_agent/rails/dlp.rb +208 -107
- data/lib/tcell_agent/rails/dlp/process_request.rb +37 -47
- data/lib/tcell_agent/rails/dlp_handler.rb +9 -11
- data/lib/tcell_agent/rails/js_agent_insert.rb +11 -14
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +8 -7
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +4 -5
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +5 -8
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +24 -27
- data/lib/tcell_agent/rails/on_start.rb +5 -5
- data/lib/tcell_agent/rails/responses.rb +7 -9
- data/lib/tcell_agent/rails/routes.rb +62 -81
- data/lib/tcell_agent/rails/routes/grape.rb +25 -30
- data/lib/tcell_agent/rails/routes/route_id.rb +9 -14
- data/lib/tcell_agent/rails/settings_reporter.rb +44 -33
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +15 -18
- data/lib/tcell_agent/routes/table.rb +31 -33
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.dylib → libtcellagent-1.3.1.dylib} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.so → libtcellagent-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.0.so → libtcellagent-alpine-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +32 -37
- data/lib/tcell_agent/rust/tcellagent-1.3.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +101 -104
- data/lib/tcell_agent/sensor_events/app_config.rb +7 -7
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +26 -27
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +20 -88
- data/lib/tcell_agent/sensor_events/command_injection.rb +52 -80
- data/lib/tcell_agent/sensor_events/discovery.rb +27 -27
- data/lib/tcell_agent/sensor_events/dlp.rb +50 -56
- data/lib/tcell_agent/sensor_events/honeytokens.rb +9 -9
- data/lib/tcell_agent/sensor_events/metrics.rb +20 -21
- data/lib/tcell_agent/sensor_events/patches.rb +10 -12
- data/lib/tcell_agent/sensor_events/sensor.rb +32 -36
- data/lib/tcell_agent/sensor_events/server_agent.rb +130 -127
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +60 -80
- data/lib/tcell_agent/sensor_events/util/utils.rb +3 -5
- data/lib/tcell_agent/servers/passenger.rb +5 -9
- data/lib/tcell_agent/servers/puma.rb +18 -27
- data/lib/tcell_agent/servers/rails_server.rb +5 -9
- data/lib/tcell_agent/servers/thin.rb +2 -4
- data/lib/tcell_agent/servers/unicorn.rb +18 -27
- data/lib/tcell_agent/servers/webrick.rb +2 -4
- data/lib/tcell_agent/settings_reporter.rb +126 -0
- data/lib/tcell_agent/sinatra.rb +24 -26
- data/lib/tcell_agent/start_background_thread.rb +21 -142
- data/lib/tcell_agent/system_info.rb +4 -3
- data/lib/tcell_agent/tcell_context.rb +150 -0
- data/lib/tcell_agent/userinfo.rb +3 -3
- data/lib/tcell_agent/utils/io.rb +19 -24
- data/lib/tcell_agent/utils/params.rb +9 -15
- data/lib/tcell_agent/utils/queue_with_timeout.rb +26 -32
- data/lib/tcell_agent/utils/strings.rb +4 -6
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +5 -5
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +7 -7
- data/spec/lib/tcell_agent/cmdi_spec.rb +21 -21
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +29 -24
- data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
- data/spec/lib/tcell_agent/patches_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +23 -23
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +69 -0
- data/spec/lib/tcell_agent/rails/dlp_spec.rb +1039 -0
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +271 -0
- data/spec/lib/tcell_agent/rails/logger_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +3 -3
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +4 -4
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +11 -8
- data/spec/lib/tcell_agent/rails/responses_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +4 -4
- data/spec/lib/tcell_agent/rust/models_spec.rb +83 -75
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +14 -14
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +19 -70
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +1 -1
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +162 -0
- data/spec/lib/tcell_agent/tcell_context_spec.rb +154 -0
- data/spec/spec_helper.rb +5 -0
- metadata +18 -10
- data/lib/tcell_agent/appsensor/meta_data.rb +0 -132
- data/lib/tcell_agent/patches/meta_data.rb +0 -59
- data/lib/tcell_agent/rust/tcellagent-1.3.0.dll +0 -0
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +0 -71
@@ -1,35 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require
|
6
|
-
require "tcell_agent/policies/http_redirect_policy"
|
7
|
-
require "tcell_agent/policies/login_fraud_policy"
|
8
|
-
require "tcell_agent/policies/dataloss_policy"
|
9
|
-
require "tcell_agent/policies/rust_policies"
|
1
|
+
require 'tcell_agent/policies/http_tx_policy'
|
2
|
+
require 'tcell_agent/policies/http_redirect_policy'
|
3
|
+
require 'tcell_agent/policies/login_fraud_policy'
|
4
|
+
require 'tcell_agent/policies/dataloss_policy'
|
5
|
+
require 'tcell_agent/policies/rust_policies'
|
10
6
|
|
11
7
|
module TCellAgent
|
12
8
|
class PolicyTypes
|
13
|
-
CSP =
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
ClassMap = {
|
28
|
-
HttpTx=>TCellAgent::Policies::HttpTxPolicy,
|
29
|
-
HttpRedirect=>TCellAgent::Policies::HttpRedirectPolicy,
|
30
|
-
LoginFraud=>TCellAgent::Policies::LoginFraudPolicy,
|
31
|
-
DataLoss=>TCellAgent::Policies::DataLossPolicy
|
32
|
-
}
|
9
|
+
CSP = 'csp-headers'.freeze
|
10
|
+
CLICKJACKING = 'clickjacking'.freeze
|
11
|
+
SECUREHEADERS = 'secure-headers'.freeze
|
12
|
+
HTTPTX = 'http-tx'.freeze
|
13
|
+
HTTPREDIRECT = 'http-redirect'.freeze
|
14
|
+
LOGINFRAUD = 'login'.freeze
|
15
|
+
DATALOSS = 'dlp'.freeze
|
16
|
+
APPSENSOR = 'appsensor'.freeze
|
17
|
+
PATCHES = 'patches'.freeze
|
18
|
+
COMMANDINJECTION = 'cmdi'.freeze
|
19
|
+
REGEX = 'regex'.freeze
|
20
|
+
RUST = 'rust'.freeze
|
21
|
+
JSAGENTINJECTION = 'jsagentinjection'.freeze
|
33
22
|
|
23
|
+
CLASS_MAP = {
|
24
|
+
HTTPTX => TCellAgent::Policies::HttpTxPolicy,
|
25
|
+
HTTPREDIRECT => TCellAgent::Policies::HttpRedirectPolicy,
|
26
|
+
LOGINFRAUD => TCellAgent::Policies::LoginFraudPolicy,
|
27
|
+
DATALOSS => TCellAgent::Policies::DataLossPolicy
|
28
|
+
}.freeze
|
34
29
|
end
|
35
30
|
end
|
@@ -1,15 +1,13 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
# See the file "LICENSE" for the full license governing this code.
|
4
2
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require 'tcell_agent/logger'
|
4
|
+
require 'tcell_agent/version'
|
5
|
+
require 'tcell_agent/api'
|
6
|
+
require 'tcell_agent/configuration'
|
9
7
|
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
8
|
+
require 'tcell_agent/routes/table'
|
9
|
+
require 'tcell_agent/sensor_events/discovery'
|
10
|
+
require 'tcell_agent'
|
13
11
|
|
14
12
|
module TCellAgent
|
15
13
|
class Agent
|
@@ -18,48 +16,40 @@ module TCellAgent
|
|
18
16
|
database,
|
19
17
|
schema,
|
20
18
|
table,
|
21
|
-
fields.join(
|
22
|
-
].join(
|
19
|
+
fields.join(',')
|
20
|
+
].join(',').hash
|
23
21
|
end
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
end
|
23
|
+
def discover_database_fields(route_id, database, schema, table, fields)
|
24
|
+
return if route_id.nil? || database.nil? || schema.nil? || table.nil? || fields.nil?
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
if TCellAgent::Agent.is_parent_process? == false
|
38
|
-
TCellAgent.queue_metric({"_type"=>"discover_database_fields",
|
39
|
-
"route_id"=>route_id,
|
40
|
-
"database"=>database,
|
41
|
-
"schema"=>schema,
|
42
|
-
"table"=>table,
|
43
|
-
"fields"=>fields})
|
26
|
+
if TCellAgent::Agent.parent_process? == false
|
27
|
+
TCellAgent.queue_metric('_type' => 'discover_database_fields',
|
28
|
+
'route_id' => route_id,
|
29
|
+
'database' => database,
|
30
|
+
'schema' => schema,
|
31
|
+
'table' => table,
|
32
|
+
'fields' => fields)
|
44
33
|
return
|
45
34
|
end
|
35
|
+
|
46
36
|
query_hash = TCellAgent::Agent.get_database_discovery_identifier(database, schema, table, fields)
|
47
|
-
if (@route_table.routes[route_id].database_queries_discovered.fetch(query_hash, false) == false)
|
48
|
-
@route_table.routes[route_id].database_queries_discovered[query_hash] = true
|
49
|
-
event = (TCellAgent::SensorEvents::DiscoveryEvent.new(route_id)).for_database_fields(database, schema, table, fields)
|
50
|
-
TCellAgent.send_event(event)
|
51
|
-
end
|
52
|
-
#discovered_fields = fields.select { |field|
|
53
|
-
# @route_table.routes[route_id].database_queries_discoverd[database][schema][table][field].discovered != true
|
54
|
-
#}
|
55
|
-
#if (discovered_fields.length > 0)
|
56
|
-
# discovered_fields.each { |field|
|
57
|
-
# @route_table.routes[route_id].database[database][schema][table][field].discovered = true
|
58
|
-
# }
|
59
|
-
# event = (TCellAgent::SensorEvents::DiscoveryEvent.new(route_id)).for_database_fields(database, schema, table, fields)
|
60
|
-
# TCellAgent.send_event(event)
|
61
|
-
#end
|
62
|
-
end
|
63
37
|
|
38
|
+
return if @route_table.routes[route_id].database_queries_discovered.fetch(query_hash, false)
|
39
|
+
|
40
|
+
@route_table.routes[route_id].database_queries_discovered[query_hash] = true
|
41
|
+
event = TCellAgent::SensorEvents::DiscoveryEvent.new(route_id).for_database_fields(database, schema, table, fields)
|
42
|
+
TCellAgent.send_event(event)
|
43
|
+
# discovered_fields = fields.select { |field|
|
44
|
+
# @route_table.routes[route_id].database_queries_discoverd[database][schema][table][field].discovered != true
|
45
|
+
# }
|
46
|
+
# if (discovered_fields.length > 0)
|
47
|
+
# discovered_fields.each { |field|
|
48
|
+
# @route_table.routes[route_id].database[database][schema][table][field].discovered = true
|
49
|
+
# }
|
50
|
+
# event = (TCellAgent::SensorEvents::DiscoveryEvent.new(route_id)).for_database_fields(database, schema, table, fields)
|
51
|
+
# TCellAgent.send_event(event)
|
52
|
+
# end
|
53
|
+
end
|
64
54
|
end
|
65
|
-
end
|
55
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
# See the file "LICENSE" for the full license governing this code.
|
4
2
|
require 'tcell_agent/sensor_events/metrics'
|
5
3
|
require 'monitor'
|
@@ -9,10 +7,10 @@ module TCellAgent
|
|
9
7
|
@@my_thread_agent = nil
|
10
8
|
|
11
9
|
def self.thread_agent
|
12
|
-
if
|
10
|
+
if thread_agent_defined? == false
|
13
11
|
@@instance_lock.synchronize do
|
14
|
-
if
|
15
|
-
@@my_thread_agent= TCellAgent::Agent.new(Process.pid)
|
12
|
+
if thread_agent_defined? == false
|
13
|
+
@@my_thread_agent = TCellAgent::Agent.new(Process.pid)
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
@@ -23,45 +21,45 @@ module TCellAgent
|
|
23
21
|
@@my_thread_agent != nil
|
24
22
|
end
|
25
23
|
|
26
|
-
# setter
|
27
24
|
def self.thread_agent=(some_agent)
|
28
25
|
@@instance_lock.synchronize do
|
29
26
|
@@my_thread_agent = some_agent
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
33
|
-
#class << self
|
34
|
-
# attr_accessor :thread_agent
|
35
|
-
#end
|
36
30
|
def self.send_event(event)
|
37
|
-
|
31
|
+
thread_agent.queue_sensor_event(event)
|
38
32
|
end
|
33
|
+
|
39
34
|
def self.queue_metric(event)
|
40
|
-
|
35
|
+
thread_agent._queue_metric(event)
|
41
36
|
end
|
37
|
+
|
42
38
|
def self.policy(policy_type)
|
43
|
-
|
39
|
+
thread_agent.policies.fetch(policy_type, nil)
|
44
40
|
end
|
41
|
+
|
45
42
|
def self.increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
|
46
|
-
|
43
|
+
thread_agent.increment_session_info(hmac_session_id, user_id, ip_address, user_agent)
|
47
44
|
end
|
45
|
+
|
48
46
|
def self.increment_route(route_id, response_time)
|
49
|
-
|
50
|
-
end
|
51
|
-
def self.discover_database_field(route_id, database, schema, table, field)
|
52
|
-
self.thread_agent.discover_database_field(route_id, database, schema, table, field)
|
47
|
+
thread_agent.increment_route(route_id, response_time)
|
53
48
|
end
|
49
|
+
|
54
50
|
def self.discover_database_fields(route_id, database, schema, table, fields)
|
55
|
-
|
51
|
+
thread_agent.discover_database_fields(route_id, database, schema, table, fields)
|
56
52
|
end
|
53
|
+
|
57
54
|
def self.stop_agent
|
58
|
-
|
55
|
+
thread_agent.stop_agent = true
|
59
56
|
end
|
57
|
+
|
60
58
|
def self.ensure_event_processor_running
|
61
|
-
|
59
|
+
thread_agent.ensure_event_processor_running
|
62
60
|
end
|
63
61
|
|
64
62
|
def self.safe_to_send_cmdi_events?
|
65
|
-
|
63
|
+
thread_agent.safe_to_send_cmdi_events?
|
66
64
|
end
|
67
65
|
end
|
data/lib/tcell_agent/api.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
# See the file "LICENSE" for the full license governing this code.
|
3
2
|
require 'json'
|
4
3
|
require 'tcell_agent/logger'
|
@@ -10,63 +9,59 @@ require 'net/http'
|
|
10
9
|
|
11
10
|
module TCellAgent
|
12
11
|
class TCellApi
|
12
|
+
def initialize; end
|
13
13
|
|
14
|
-
def
|
15
|
-
end
|
16
|
-
|
17
|
-
def poll_api(last_id=nil)
|
14
|
+
def poll_api(last_id = nil)
|
18
15
|
if !TCellAgent.configuration || !TCellAgent.configuration.tcell_api_url || !TCellAgent.configuration.app_id
|
19
|
-
raise TCellAgent::ConfigurationException
|
16
|
+
raise TCellAgent::ConfigurationException, "Config Information Not Found, can't poll for policy updates"
|
20
17
|
end
|
21
18
|
|
22
19
|
full_url = TCellAgent.configuration.tcell_api_url.sub(
|
23
20
|
'{app_id}',
|
24
21
|
TCellAgent.configuration.app_id
|
25
22
|
)
|
26
|
-
full_url += "&last_id=#{last_id
|
23
|
+
full_url += "&last_id=#{last_id}" if last_id
|
27
24
|
|
28
|
-
TCellAgent.logger.debug
|
25
|
+
TCellAgent.logger.debug("tCell.io API Request: #{full_url}")
|
29
26
|
|
30
27
|
uri = URI(full_url)
|
31
28
|
req = Net::HTTP::Get.new(uri.request_uri)
|
32
29
|
req['Authorization'] = 'Bearer ' + TCellAgent.configuration.api_key
|
33
30
|
begin
|
34
|
-
req['TCellAgent'] =
|
31
|
+
req['TCellAgent'] = 'RubyAgent ' + TCellAgent::VERSION
|
35
32
|
rescue StandardError => e
|
36
|
-
TCellAgent.logger.debug("tCell.io Could not add agent string:
|
33
|
+
TCellAgent.logger.debug("tCell.io Could not add agent string: #{e.message}")
|
37
34
|
end
|
38
35
|
|
39
36
|
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => (uri.scheme == 'https')) { |http| http.request(req) }
|
40
37
|
|
41
38
|
if res.is_a?(Net::HTTPSuccess)
|
42
|
-
TCellAgent.logger.debug("tCell.io API Response: #{res.body}".force_encoding(
|
39
|
+
TCellAgent.logger.debug("tCell.io API Response: #{res.body}".force_encoding('UTF-8'))
|
43
40
|
return JSON.parse(res.body)
|
44
41
|
else
|
45
42
|
TCellAgent.logger.error("Received error response while contacting api: #{res.inspect}")
|
46
43
|
end
|
47
44
|
|
48
|
-
|
45
|
+
nil
|
49
46
|
end
|
50
47
|
|
51
48
|
def send_event_set(events)
|
52
49
|
if !TCellAgent.configuration || !TCellAgent.configuration.tcell_input_url || !TCellAgent.configuration.app_id
|
53
|
-
raise TCellAgent::ConfigurationException
|
50
|
+
raise TCellAgent::ConfigurationException, "Config Information Not Found, can't send events"
|
54
51
|
end
|
55
52
|
|
56
|
-
if
|
57
|
-
return false
|
58
|
-
end
|
53
|
+
return false if events.nil?
|
59
54
|
|
60
|
-
eventset = {
|
61
|
-
|
62
|
-
|
55
|
+
eventset = { 'uuid' => TCellAgent.configuration.uuid,
|
56
|
+
'hostname' => TCellAgent.configuration.host_identifier,
|
57
|
+
'events' => events }
|
63
58
|
TCellAgent.logger.debug("Sending #{JSON.dump(eventset)}")
|
64
59
|
full_url = TCellAgent.configuration.tcell_input_url +
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
'/app/' +
|
61
|
+
TCellAgent.configuration.app_id +
|
62
|
+
'/server_agent'
|
68
63
|
|
69
|
-
TCellAgent.logger.debug("tCell.io SendEvents API Request: "
|
64
|
+
TCellAgent.logger.debug("tCell.io SendEvents API Request: #{full_url}")
|
70
65
|
|
71
66
|
uri = URI(full_url)
|
72
67
|
req = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
|
@@ -76,21 +71,21 @@ module TCellAgent
|
|
76
71
|
req['Accept'] = 'application/json'
|
77
72
|
|
78
73
|
begin
|
79
|
-
req['TCellAgent'] =
|
74
|
+
req['TCellAgent'] = 'RubyAgent ' + TCellAgent::VERSION
|
80
75
|
rescue StandardError => e
|
81
|
-
TCellAgent.logger.debug(
|
76
|
+
TCellAgent.logger.debug('tCell.io Could not add agent string: ' + e.message)
|
82
77
|
end
|
83
78
|
|
84
79
|
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => (uri.scheme == 'https')) { |http| http.request(req) }
|
85
80
|
|
86
81
|
TCellAgent.logger.debug("tCell.io SendEvents API Response: #{res.code}")
|
87
82
|
|
88
|
-
|
83
|
+
res.is_a?(Net::HTTPSuccess)
|
89
84
|
end
|
90
85
|
|
91
86
|
def valid_header?(str)
|
92
|
-
|
93
|
-
|
87
|
+
# TODO: test the unescaped backslash
|
88
|
+
str =~ %r{^[\p{L}\w\d\-_ :/,;.'\"%?@#=$]*$}
|
94
89
|
end
|
95
90
|
end
|
96
91
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require 'tcell_agent/sensor_events/appsensor_event'
|
2
2
|
|
3
|
-
|
4
3
|
module TCellAgent
|
5
4
|
module AppSensor
|
6
|
-
|
7
5
|
module InjectionsReporter
|
8
6
|
def self.report_and_log(events)
|
9
7
|
(events || []).each do |event|
|
@@ -11,18 +9,16 @@ module TCellAgent
|
|
11
9
|
TCellAgent::SensorEvents::TCellAppSensorEvent.build_from_native_lib_event(event)
|
12
10
|
)
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
next unless event.key?('full_payload')
|
13
|
+
event_to_log = {}.merge(event)
|
14
|
+
event_to_log['payload'] = event_to_log.delete('full_payload')
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
16
|
+
cleaned_event = TCellAgent::SensorEvents::TCellAppSensorEvent.build_from_native_lib_event(
|
17
|
+
event_to_log
|
18
|
+
)
|
19
|
+
TCellAgent.logger.info(JSON.dump(cleaned_event))
|
23
20
|
end
|
24
21
|
end
|
25
22
|
end
|
26
|
-
|
27
23
|
end
|
28
24
|
end
|
@@ -8,17 +8,17 @@ module TCellAgent
|
|
8
8
|
if defined?(Authlogic)
|
9
9
|
TCellAgent::UserInformation.class_eval do
|
10
10
|
class << self
|
11
|
-
alias_method :
|
12
|
-
def
|
13
|
-
orig_user_id =
|
11
|
+
alias_method :original_get_user_from_request, :get_user_from_request
|
12
|
+
def get_user_from_request(request)
|
13
|
+
orig_user_id = original_get_user_from_request(request)
|
14
14
|
begin
|
15
|
-
if request.session && request.session.
|
16
|
-
return request.session[
|
15
|
+
if request.session && request.session.key?('user_credentials_id')
|
16
|
+
return request.session['user_credentials_id'].to_s
|
17
17
|
end
|
18
|
-
rescue StandardError
|
18
|
+
rescue StandardError
|
19
19
|
return orig_user_id
|
20
20
|
end
|
21
|
-
|
21
|
+
orig_user_id
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
data/lib/tcell_agent/cmdi.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'tcell_agent/agent/policy_types'
|
2
2
|
require 'tcell_agent/utils/strings'
|
3
3
|
|
4
|
-
|
5
4
|
module TCellAgent
|
6
5
|
module Cmdi
|
7
6
|
def self.block_command?(cmd)
|
8
|
-
TCellAgent::Instrumentation.safe_block(
|
7
|
+
TCellAgent::Instrumentation.safe_block('Checking Command Injection Policy') do
|
9
8
|
if TCellAgent::Utils::Strings.present?(cmd)
|
10
|
-
rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::
|
9
|
+
rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
|
11
10
|
if rust_policies && rust_policies.cmdi_enabled
|
12
11
|
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(
|
13
12
|
Thread.current.object_id, {}
|
@@ -18,14 +17,14 @@ module TCellAgent
|
|
18
17
|
end
|
19
18
|
end
|
20
19
|
|
21
|
-
|
20
|
+
false
|
22
21
|
end
|
23
22
|
|
24
23
|
def self.parse_command(*args)
|
25
|
-
cmd =
|
24
|
+
cmd = ''
|
26
25
|
|
27
|
-
TCellAgent::Instrumentation.safe_block(
|
28
|
-
|
26
|
+
TCellAgent::Instrumentation.safe_block('CMDI Parsing *args') do
|
27
|
+
unless args.empty?
|
29
28
|
args_copy = Array.new(args)
|
30
29
|
args_copy.shift if args_copy.first.is_a?(Hash)
|
31
30
|
args_copy.pop if args_copy.last.is_a?(Hash)
|
@@ -35,7 +34,7 @@ module TCellAgent
|
|
35
34
|
args_copy.unshift(cmd_n_argv0.first)
|
36
35
|
end
|
37
36
|
|
38
|
-
cmd = args_copy.join(
|
37
|
+
cmd = args_copy.join(' ')
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
@@ -48,7 +47,7 @@ module Kernel
|
|
48
47
|
alias_method :tcell_original_backtick, :`
|
49
48
|
def `(cmd)
|
50
49
|
if TCellAgent::Cmdi.block_command?(cmd)
|
51
|
-
raise Errno::ENOENT
|
50
|
+
raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
52
51
|
end
|
53
52
|
|
54
53
|
tcell_original_backtick(cmd)
|
@@ -58,7 +57,7 @@ module Kernel
|
|
58
57
|
def exec(*args)
|
59
58
|
cmd = TCellAgent::Cmdi.parse_command(*args)
|
60
59
|
if TCellAgent::Cmdi.block_command?(cmd)
|
61
|
-
raise Errno::ENOENT
|
60
|
+
raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
62
61
|
end
|
63
62
|
|
64
63
|
tcell_original_exec(*args)
|
@@ -68,7 +67,7 @@ module Kernel
|
|
68
67
|
def system(*args)
|
69
68
|
cmd = TCellAgent::Cmdi.parse_command(*args)
|
70
69
|
if TCellAgent::Cmdi.block_command?(cmd)
|
71
|
-
raise Errno::ENOENT
|
70
|
+
raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
72
71
|
end
|
73
72
|
|
74
73
|
tcell_original_system(*args)
|
@@ -78,10 +77,10 @@ module Kernel
|
|
78
77
|
def spawn(*args)
|
79
78
|
cmd = TCellAgent::Cmdi.parse_command(*args)
|
80
79
|
if TCellAgent::Cmdi.block_command?(cmd)
|
81
|
-
raise Errno::ENOENT
|
80
|
+
raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
82
81
|
end
|
83
82
|
|
84
|
-
|
83
|
+
tcell_original_spawn(*args)
|
85
84
|
end
|
86
85
|
end
|
87
86
|
|
@@ -89,27 +88,27 @@ class IO
|
|
89
88
|
class << self
|
90
89
|
alias_method :tcell_original_popen, :popen
|
91
90
|
def popen(*args)
|
92
|
-
|
93
|
-
cmd =
|
91
|
+
unless args.empty?
|
92
|
+
cmd = ''
|
94
93
|
|
95
|
-
TCellAgent::Instrumentation.safe_block(
|
94
|
+
TCellAgent::Instrumentation.safe_block('CMDI Parsing popen *args') do
|
96
95
|
args_copy = Array.new(args)
|
97
96
|
args_copy.shift if args_copy.first.is_a?(Hash)
|
98
97
|
args_copy.pop if args_copy.last.is_a?(Hash)
|
99
98
|
|
100
|
-
if args_copy.first.is_a?(String)
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
99
|
+
cmd = if args_copy.first.is_a?(String)
|
100
|
+
args_copy.shift
|
101
|
+
else
|
102
|
+
TCellAgent::Cmdi.parse_command(*args_copy.shift)
|
103
|
+
end
|
105
104
|
end
|
106
105
|
|
107
106
|
if TCellAgent::Cmdi.block_command?(cmd)
|
108
|
-
raise Errno::ENOENT
|
107
|
+
raise Errno::ENOENT, "tCell.io Agent: Command not allowed by policy: #{cmd}"
|
109
108
|
end
|
110
109
|
end
|
111
110
|
|
112
|
-
|
111
|
+
tcell_original_popen(*args)
|
113
112
|
end
|
114
113
|
end
|
115
114
|
end
|