tcell_agent 0.4.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -22
  3. data/bin/tcell_agent +127 -132
  4. data/lib/tcell_agent/agent/event_processor.rb +23 -22
  5. data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
  6. data/lib/tcell_agent/agent/policy_manager.rb +20 -15
  7. data/lib/tcell_agent/agent/policy_types.rb +5 -11
  8. data/lib/tcell_agent/agent/static_agent.rb +5 -1
  9. data/lib/tcell_agent/agent.rb +6 -4
  10. data/lib/tcell_agent/api.rb +7 -9
  11. data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
  12. data/lib/tcell_agent/authlogic.rb +3 -3
  13. data/lib/tcell_agent/cmdi.rb +6 -4
  14. data/lib/tcell_agent/config/unknown_options.rb +3 -1
  15. data/lib/tcell_agent/configuration.rb +47 -49
  16. data/lib/tcell_agent/devise.rb +2 -2
  17. data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
  18. data/lib/tcell_agent/instrumentation.rb +11 -10
  19. data/lib/tcell_agent/logger.rb +2 -2
  20. data/lib/tcell_agent/patches/meta_data.rb +9 -13
  21. data/lib/tcell_agent/patches.rb +7 -10
  22. data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
  23. data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
  24. data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
  25. data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
  26. data/lib/tcell_agent/policies/policy.rb +0 -2
  27. data/lib/tcell_agent/policies/rust_policies.rb +90 -0
  28. data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
  29. data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
  30. data/lib/tcell_agent/rails/auth/devise.rb +44 -23
  31. data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
  32. data/lib/tcell_agent/rails/better_ip.rb +1 -1
  33. data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
  34. data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
  35. data/lib/tcell_agent/rails/dlp.rb +6 -6
  36. data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
  37. data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
  38. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
  39. data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
  40. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
  41. data/lib/tcell_agent/rails/routes/grape.rb +6 -6
  42. data/lib/tcell_agent/rails/routes.rb +8 -11
  43. data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
  44. data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
  45. data/lib/tcell_agent/rust/models.rb +16 -0
  46. data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
  47. data/lib/tcell_agent/rust/whisperer.rb +119 -48
  48. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
  49. data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
  50. data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
  51. data/lib/tcell_agent/sensor_events/patches.rb +21 -0
  52. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
  53. data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
  54. data/lib/tcell_agent/servers/puma.rb +2 -2
  55. data/lib/tcell_agent/servers/unicorn.rb +1 -1
  56. data/lib/tcell_agent/utils/passwords.rb +28 -0
  57. data/lib/tcell_agent/version.rb +1 -1
  58. data/lib/tcell_agent.rb +1 -5
  59. data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
  60. data/spec/apps/rails-3.2/log/development.log +0 -0
  61. data/spec/apps/rails-3.2/log/test.log +12 -0
  62. data/spec/apps/rails-4.1/log/test.log +0 -0
  63. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
  64. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
  65. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
  66. data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
  67. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
  68. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
  69. data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
  70. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
  71. data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
  72. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
  73. data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
  74. data/spec/lib/tcell_agent/patches_spec.rb +70 -111
  75. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
  76. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
  77. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
  78. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
  79. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
  80. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
  81. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
  82. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
  83. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
  84. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
  85. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
  86. data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
  87. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
  88. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
  89. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
  90. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
  91. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
  92. data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
  93. data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
  94. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
  95. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
  96. data/spec/lib/tcell_agent/rails_spec.rb +1 -6
  97. data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
  98. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
  99. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
  100. data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
  101. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
  102. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
  103. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
  104. data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
  105. data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
  106. data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
  107. data/spec/lib/tcell_agent_spec.rb +8 -8
  108. data/spec/spec_helper.rb +4 -4
  109. data/spec/support/middleware_helper.rb +10 -10
  110. data/spec/support/static_agent_overrides.rb +16 -12
  111. data/tcell_agent.gemspec +17 -33
  112. metadata +43 -198
  113. data/LICENSE_libinjection +0 -32
  114. data/Readme.txt +0 -7
  115. data/ext/libinjection/extconf.rb +0 -3
  116. data/ext/libinjection/libinjection.h +0 -65
  117. data/ext/libinjection/libinjection_html5.c +0 -847
  118. data/ext/libinjection/libinjection_html5.h +0 -54
  119. data/ext/libinjection/libinjection_sqli.c +0 -2317
  120. data/ext/libinjection/libinjection_sqli.h +0 -295
  121. data/ext/libinjection/libinjection_sqli_data.h +0 -9004
  122. data/ext/libinjection/libinjection_wrap.c +0 -3525
  123. data/ext/libinjection/libinjection_xss.c +0 -531
  124. data/ext/libinjection/libinjection_xss.h +0 -21
  125. data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
  126. data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
  127. data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
  128. data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
  129. data/lib/tcell_agent/patches/block_rule.rb +0 -93
  130. data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
  131. data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
  132. data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
  133. data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
  134. data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
  135. data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
  136. data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
  137. data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
  138. data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
  139. data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
  140. data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
  141. data/lib/tcell_agent/policies/patches_policy.rb +0 -84
  142. data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
  143. data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
  144. data/spec/apps/rails-3.2/Gemfile +0 -25
  145. data/spec/apps/rails-3.2/Gemfile.lock +0 -126
  146. data/spec/apps/rails-3.2/Rakefile +0 -7
  147. data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
  148. data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
  149. data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
  150. data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
  151. data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
  152. data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
  153. data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
  154. data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
  155. data/spec/apps/rails-3.2/config/application.rb +0 -63
  156. data/spec/apps/rails-3.2/config/boot.rb +0 -6
  157. data/spec/apps/rails-3.2/config/environment.rb +0 -5
  158. data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
  159. data/spec/apps/rails-3.2/config/routes.rb +0 -11
  160. data/spec/apps/rails-3.2/config.ru +0 -4
  161. data/spec/apps/rails-4.1/Gemfile +0 -7
  162. data/spec/apps/rails-4.1/Gemfile.lock +0 -114
  163. data/spec/apps/rails-4.1/Rakefile +0 -6
  164. data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
  165. data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
  166. data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
  167. data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
  168. data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
  169. data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
  170. data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
  171. data/spec/apps/rails-4.1/config/application.rb +0 -24
  172. data/spec/apps/rails-4.1/config/boot.rb +0 -4
  173. data/spec/apps/rails-4.1/config/environment.rb +0 -5
  174. data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
  175. data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
  176. data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
  177. data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
  178. data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
  179. data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
  180. data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
  181. data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
  182. data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
  183. data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
  184. data/spec/apps/rails-4.1/config/routes.rb +0 -12
  185. data/spec/apps/rails-4.1/config/secrets.yml +0 -22
  186. data/spec/apps/rails-4.1/config.ru +0 -4
  187. data/spec/controllers/application_controller.rb +0 -12
  188. data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
  189. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
  190. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
  191. data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
  192. data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
  193. data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
  194. data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
  195. data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
  196. data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
  197. data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
  198. data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
  199. data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +0 -22
@@ -6,279 +6,262 @@ module TCellAgent
6
6
  module Instrumentation
7
7
  module Rails
8
8
  module Middleware
9
+ regex_policy = {
10
+ 'data' => {
11
+ 'patterns' => [
12
+ {
13
+ 'id' => 'tc-xss-1',
14
+ 'pattern' => '(?:<(script|iframe|embed|frame|frameset|' \
15
+ 'object|img|applet|body|html|style|layer|link|ilayer|meta|bgsound))',
16
+ 'sensor' => 'xss',
17
+ 'title' => 'Basic Injection'
18
+ },
9
19
 
20
+ {
21
+ 'id' => 'tc-sqli-1',
22
+ 'pattern' => "(?:(?:\\d[\"'`\u00b4\u2019\u2018]\\s+" \
23
+ "[\"'`\u00b4\u2019\u2018]\\s+\\d)|(?:^admin" \
24
+ "\\s*?[\"'`\u00b4\u2019\u2018]|(/\\*)+[\"'`" \
25
+ "\u00b4\u2019\u2018]+\\s?(?:--|#|/\\*|\\{)?)|" \
26
+ "(?:[\"'`\u00b4\u2019\u2018]\\s*?\\b(x?or|div|" \
27
+ 'like|between|and)\\b\\s*?[+<>=(),-]\\s*?[\\d"' \
28
+ "'`\u00b4\u2019\u2018])|(?:[\"'`\u00b4\u2019\u2018]" \
29
+ "\\s*?[^\\w\\s]?=\\s*?[\"'`\u00b4\u2019\u2018])|(?:[\"'`" \
30
+ "\u00b4\u2019\u2018]\\W*?[+=]+\\W*?[\"'`\u00b4\u2019\u2018])" \
31
+ "|(?:[\"'`\u00b4\u2019\u2018]\\s*?[!=|][\\d\\s!=+-]+.*?[\"'`" \
32
+ "\u00b4\u2019\u2018(].*?$)|(?:[\"'`\u00b4\u2019\u2018]\\s*?[!=|]" \
33
+ "[\\d\\s!=]+.*?\\d+$)|(?:[\"'`\u00b4\u2019\u2018]\\s*?" \
34
+ "like\\W+[\\w\"'`\u00b4\u2019\u2018(])|(?:\\sis\\s*?0\\W)" \
35
+ "|(?:where\\s[\\s\\w\\.,-]+\\s=)|(?:[\"'`\u00b4\u2019\u2018" \
36
+ "][<>~]+[\"'`\u00b4\u2019\u2018]))",
37
+ 'sensor' => 'sqli',
38
+ 'title' => 'Basic Injection'
39
+ },
10
40
 
11
- class MockAppsensorRackApp
41
+ {
42
+ 'id' => 'tc-fpt-2',
43
+ 'pattern' => '(?:%c0%ae/)|(?:(?:/|\\\\)(conf|usr|etc|proc|opt|s?bin' \
44
+ '|local|dev|tmp|kern|[br]oot|sys|system|windows|winnt|program|' \
45
+ '%[a-z_-]{3,}%)(?:/|\\\\))|(?:(?:/|\\\\)inetpub|localstart\\.asp|' \
46
+ 'boot\\.ini)',
47
+ 'sensor' => 'fpt',
48
+ 'title' => 'Common System Probing'
49
+ }
50
+ ],
51
+ 'version' => 1_518_546_622_571
52
+ },
53
+ 'policy_id' => 'f3a313b0-10eb-11e8-8080-808080808080',
54
+ 'version' => 1
55
+ }
12
56
 
57
+ class MockAppsensorRackApp
13
58
  attr_reader :request_body
14
59
 
15
- def initialize(route_id=nil)
60
+ def initialize(route_id = nil)
16
61
  @route_id = route_id
17
62
  @request_headers = {}
18
63
  end
19
64
 
20
65
  def call(env)
21
66
  @env = env
22
- rack_request = Rack::Request.new(env)
23
- response_headers = {'Content-Type' => 'text/html'}
24
- env["tcell.request_data"].transaction_id = "a-b-c-d-e-f"
25
- env["tcell.request_data"].route_id = @route_id
26
- #env["tcell.request_data"].route_id = "x-b-c-d-e-f"
67
+ Rack::Request.new(env)
68
+ response_headers = { 'Content-Type' => 'text/html' }
69
+ env['tcell.request_data'].transaction_id = 'a-b-c-d-e-f'
70
+ env['tcell.request_data'].route_id = @route_id
27
71
  [200, response_headers, ['OK']]
28
72
  end
29
73
 
30
74
  def [](key)
31
75
  @env[key]
32
76
  end
33
-
34
77
  end
35
78
 
36
79
  describe HeadersMiddleware do
37
-
38
80
  let(:app) { MockAppsensorRackApp.new }
39
- let(:app2) { MockAppsensorRackApp.new(route_id="myrouteid") }
81
+ let(:app2) { MockAppsensorRackApp.new('myrouteid') }
40
82
 
41
- subject { withTCellMiddleware( app ) }
42
-
43
- context "Appsensor Middleware" do
44
- before(:all) do
45
- # need to ensure default rules file is loaded
46
- AppSensorRuleManager.instance.load_default_rules_file
47
- end
83
+ subject { with_tcell_middleware(app) }
48
84
 
85
+ context 'Appsensor Middleware' do
49
86
  before(:each) do
50
87
  TCellAgent.configuration = TCellAgent::Configuration.new
51
- TCellAgent.configuration.read_config_from_file(get_test_resource_path("normal_config.json"))
88
+ TCellAgent.configuration.read_config_from_file(get_test_resource_path('normal_config.json'))
52
89
  end
53
90
  let(:request) { Rack::MockRequest.new(subject) }
54
- let(:request2) { Rack::MockRequest.new( withTCellMiddleware( app2 )) }
91
+ let(:request2) { Rack::MockRequest.new(with_tcell_middleware(app2)) }
55
92
  let(:agent) { ::TCellAgent::Agent.new }
56
- context "XSS" do
57
- context "with allow_payloads = false" do
93
+
94
+ context 'XSS' do
95
+ context 'with allow_payloads = false' do
58
96
  before(:each) do
59
97
  old_uap = TCellAgent.configuration.allow_payloads
60
- TCellAgent.configuration.allow_payloads = false
61
- TCellAgent.thread_agent.processPolicyJson({"appsensor"=>{
62
- "policy_id" => "153ed270",
63
- "version" => 2,
64
- "data" => {
65
- "options" => {
66
- "payloads" => {
67
- "send_payloads" => true,
68
- "log_payloads" => false
69
- }
70
- },
71
- "sensors" => {
72
- "xss" => {
73
- "patterns" => ["1", "2", "8"]
98
+ TCellAgent.configuration.allow_payloads = true
99
+ TCellAgent.thread_agent.processPolicyJson(
100
+ {
101
+ 'regex' => regex_policy,
102
+ 'appsensor' => {
103
+ 'policy_id' => '153ed270',
104
+ 'version' => 2,
105
+ 'data' => {
106
+ 'options' => {
107
+ 'payloads' => {
108
+ 'send_payloads' => true,
109
+ 'log_payloads' => false
110
+ }
111
+ },
112
+ 'sensors' => {
113
+ 'xss' => {
114
+ 'dynamic_patterns' => ['tc-xss-1'],
115
+ 'patterns' => ['1']
116
+ }
117
+ }
74
118
  }
75
119
  }
76
- }
77
- }}, cache=false)
120
+ },
121
+ false
122
+ )
123
+
78
124
  TCellAgent.empty_event_queue
79
125
  TCellAgent.configuration.allow_payloads = old_uap
80
126
  end
81
- it "alerts on get xss payload" do
82
- response = request.get("/foo?xyz=%3CSCRIPT%3Ealert(1)%3C%2Fscript%3E", 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
83
- expected_as = {
84
- "event_type"=>"as",
85
- "dp"=>"xss",
86
- "param"=>"xyz",
87
- "remote_addr"=>"1.3.3.4",
88
- "m"=>"GET",
89
- "pattern"=>"1",
90
- "uri"=>"http://example.org/foo?xyz=",
91
- "meta"=>{"l" => "query"}}
92
- expect(TCellAgent.event_queue).to include(expected_as)
93
- end
94
127
 
95
- it "alerts on post xss payload" do
96
- response = request.post("/foo", :input => "x=<SCRIPT>alert(1)</SCRIPT>", 'REMOTE_ADDR' => '1.2.3.4,3.4.5.6')
128
+ it 'alerts on get xss payload' do
129
+ request.get('/foo?xyz=%3CSCRIPT%3Ealert(1)%3C%2Fscript%3E', 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
97
130
  expected_as = {
98
- "event_type"=>"as",
99
- "dp"=>"xss",
100
- "param"=>"x",
101
- "remote_addr"=>"1.2.3.4",
102
- "m"=>"POST",
103
- "pattern"=>"1",
104
- "uri"=>"http://example.org/foo",
105
- "meta"=>{"l" => "body"}}
131
+ 'event_type' => 'as',
132
+ 'dp' => 'xss',
133
+ 'param' => 'xyz',
134
+ 'remote_addr' => '1.3.3.4',
135
+ 'm' => 'GET',
136
+ 'pattern' => 'tc-xss-1',
137
+ 'uri' => 'http://example.org/foo?xyz=',
138
+ 'meta' => { 'l' => 'query' },
139
+ 'payload' => '<SCRIPT>alert(1)</script>'
140
+ }
106
141
  expect(TCellAgent.event_queue).to include(expected_as)
107
- end #/it
142
+ end
108
143
 
109
- it "alerts on get xss payload with route_id" do
110
- response = request2.get("/foo?xyz=%3Cscript%3Ealert(1)%3C%2Fscript%3E")
144
+ it 'alerts on post xss payload' do
145
+ request.post('/foo', :input => 'x=<SCRIPT>alert(1)</SCRIPT>', 'REMOTE_ADDR' => '1.2.3.4,3.4.5.6')
111
146
  expected_as = {
112
- "event_type"=>"as",
113
- "dp"=>"xss",
114
- "param"=>"xyz",
115
- "rid"=>"myrouteid",
116
- "m"=>"GET",
117
- "pattern"=>"1",
118
- "uri"=>"http://example.org/foo?xyz=",
119
- "meta"=>{"l" => "query"}}
147
+ 'event_type' => 'as',
148
+ 'dp' => 'xss',
149
+ 'param' => 'x',
150
+ 'remote_addr' => '1.2.3.4',
151
+ 'm' => 'POST',
152
+ 'pattern' => 'tc-xss-1',
153
+ 'uri' => 'http://example.org/foo',
154
+ 'meta' => { 'l' => 'body' },
155
+ 'payload' => '<SCRIPT>alert(1)</SCRIPT>'
156
+ }
120
157
  expect(TCellAgent.event_queue).to include(expected_as)
121
158
  end
122
- end
123
159
 
124
- context "with allow_payloads = true" do
125
- before(:each) do
126
- old_uap = TCellAgent.configuration.allow_payloads
127
- TCellAgent.configuration.allow_payloads = true
128
- TCellAgent.thread_agent.processPolicyJson({"appsensor"=>{
129
- "policy_id" => "153ed270",
130
- "version" => 2,
131
- "data" => {
132
- "options" => {
133
- "payloads" => {
134
- "send_payloads" => true,
135
- "log_payloads" => false
136
- }
137
- },
138
- "sensors" => {
139
- "xss" => {
140
- "patterns" => ["1", "2", "8"]
141
- }
142
- }
143
- }
144
- }}, cache=false)
145
- TCellAgent.empty_event_queue
146
- TCellAgent.configuration.allow_payloads = old_uap
147
- end
148
-
149
- it "checks that payload is sent in xss with route_id" do
150
- response = request2.get("/foo?xyz=%3Cscript%3Ealert(1)%3C%2Fscript%3E")
160
+ it 'alerts on get xss payload with route_id' do
161
+ request2.get('/foo?xyz=%3Cscript%3Ealert(1)%3C%2Fscript%3E')
151
162
  expected_as = {
152
- "event_type"=>"as",
153
- "dp"=>"xss",
154
- "param"=>"xyz",
155
- "rid"=>"myrouteid",
156
- "m"=>"GET",
157
- "pattern"=>"1",
158
- "uri"=>"http://example.org/foo?xyz=",
159
- "payload"=>"<script>alert(1)</script>",
160
- "meta"=>{"l" => "query"}}
161
-
163
+ 'event_type' => 'as',
164
+ 'dp' => 'xss',
165
+ 'param' => 'xyz',
166
+ 'rid' => 'myrouteid',
167
+ 'm' => 'GET',
168
+ 'pattern' => 'tc-xss-1',
169
+ 'uri' => 'http://example.org/foo?xyz=',
170
+ 'meta' => { 'l' => 'query' },
171
+ 'payload' => '<script>alert(1)</script>'
172
+ }
162
173
  expect(TCellAgent.event_queue).to include(expected_as)
163
174
  end
164
175
  end
165
-
166
176
  end
167
177
 
168
- context "SQL Injection" do
178
+ context 'SQL Injection' do
169
179
  before(:each) do
170
- TCellAgent.thread_agent.processPolicyJson({"appsensor"=>{
171
- "policy_id"=>"153ed270",
172
- "version" => 2,
173
- "data"=>{
174
- "sensors" => {
175
- "xss" => {
176
- "patterns" => ["1"]
177
- },
178
- "sqli" => {
179
- "patterns" => ["1"]
180
- },
181
- "cmdi" => {
182
- "patterns" => ["1"]
180
+ TCellAgent.thread_agent.processPolicyJson(
181
+ {
182
+ 'regex' => regex_policy,
183
+ 'appsensor' => {
184
+ 'policy_id' => '153ed270',
185
+ 'version' => 2,
186
+ 'data' => {
187
+ 'sensors' => {
188
+ 'sqli' => {
189
+ 'dynamic_patterns' => ['tc-sqli-1'],
190
+ 'patterns' => ['1']
191
+ }
192
+ }
183
193
  }
184
194
  }
185
- }
186
- }}, cache=false)
195
+ },
196
+ false
197
+ )
187
198
  TCellAgent.empty_event_queue
188
199
  end
189
200
 
190
- it "alerts on get sqli payload" do
201
+ it 'alerts on get sqli payload' do
191
202
  old_uap = TCellAgent.configuration.allow_payloads
192
203
  TCellAgent.configuration.allow_payloads = false
193
204
  # ' OR '3'='3
194
- response = request.get("/foo?xyz=abds&def=%27%20OR%20%273%27%3D%273", 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
205
+ request.get('/foo?xyz=abds&def=%27%20OR%20%273%27%3D%273', 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
195
206
  TCellAgent.configuration.allow_payloads = old_uap
196
207
  expected_as = {
197
- "event_type"=>"as",
198
- "dp"=>"sqli",
199
- "param"=>"def",
200
- "remote_addr"=>"1.3.3.4",
201
- "m"=>"GET",
202
- "pattern"=>"1",
203
- "uri"=>"http://example.org/foo?xyz=&def=",
204
- "meta"=>{"l" => "query"}}
208
+ 'event_type' => 'as',
209
+ 'dp' => 'sqli',
210
+ 'param' => 'def',
211
+ 'remote_addr' => '1.3.3.4',
212
+ 'm' => 'GET',
213
+ 'pattern' => 'tc-sqli-1',
214
+ 'uri' => 'http://example.org/foo?xyz=&def=',
215
+ 'meta' => { 'l' => 'query' }
216
+ }
205
217
  expect(TCellAgent.event_queue).to include(expected_as)
206
218
  end
207
219
  end
208
220
 
209
- context "File Path Traversal" do
210
- it "alerts on most obvious payload" do
211
- TCellAgent.thread_agent.processPolicyJson({"appsensor"=>{
212
- "policy_id"=>"153ed270",
213
- "version" => 2,
214
- "data"=>{
215
- "options" => {
216
- "payloads" => {
217
- "send_payloads" => false,
218
- "log_payloads" => false
219
- }
220
- },
221
- "sensors" => {
222
- "fpt" => {
223
- "patterns" => ["1", "2", "3"]
224
- }
225
- }
226
- }
227
- }}, cache=false)
228
- TCellAgent.empty_event_queue
229
-
230
- response = request.get("/foo?xyz=/ETC/PASSWD", 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
231
- expected_as = {
232
- "event_type"=>"as",
233
- "dp"=>"fpt",
234
- "param"=>"xyz",
235
- "remote_addr"=>"1.3.3.4",
236
- "m"=>"GET",
237
- "pattern"=>"2",
238
- "uri"=>"http://example.org/foo?xyz=",
239
- "meta"=>{"l" => "query"}}
240
- expect(TCellAgent.event_queue).to include(expected_as)
241
- end
242
-
243
- it "checks that payload is sent" do
244
- TCellAgent.thread_agent.processPolicyJson({"appsensor"=>{
245
- "policy_id"=>"153ed270",
246
- "version" => 2,
247
- "data"=>{
248
- "options" => {
249
- "payloads" => {
250
- "send_payloads" => true,
251
- "log_payloads" => false
252
- }
253
- },
254
- "sensors" => {
255
- "fpt" => {
256
- "patterns" => ["1", "2", "3"]
221
+ context 'File Path Traversal' do
222
+ it 'alerts on most obvious payload' do
223
+ TCellAgent.thread_agent.processPolicyJson(
224
+ {
225
+ 'regex' => regex_policy,
226
+ 'appsensor' => {
227
+ 'policy_id' => '153ed270',
228
+ 'version' => 2,
229
+ 'data' => {
230
+ 'options' => {
231
+ 'payloads' => {
232
+ 'send_payloads' => false,
233
+ 'log_payloads' => false
234
+ }
235
+ },
236
+ 'sensors' => {
237
+ 'fpt' => {
238
+ 'dynamic_patterns' => ['tc-fpt-2'],
239
+ 'patterns' => ['2']
240
+ }
241
+ }
257
242
  }
258
243
  }
259
- }
260
- }}, cache=false)
244
+ },
245
+ false
246
+ )
261
247
  TCellAgent.empty_event_queue
262
248
 
263
- response = request.get("/foo?xyz=/etc/passwd", 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
249
+ request.get('/foo?xyz=/ETC/PASSWD', 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
264
250
  expected_as = {
265
- "event_type"=>"as",
266
- "dp"=>"fpt",
267
- "param"=>"xyz",
268
- "remote_addr"=>"1.3.3.4",
269
- "m"=>"GET",
270
- "pattern"=>"2",
271
- "uri"=>"http://example.org/foo?xyz=",
272
- "payload"=>"/etc/passwd",
273
- "meta"=>{"l" => "query"}}
251
+ 'event_type' => 'as',
252
+ 'dp' => 'fpt',
253
+ 'param' => 'xyz',
254
+ 'remote_addr' => '1.3.3.4',
255
+ 'm' => 'GET',
256
+ 'pattern' => 'tc-fpt-2',
257
+ 'uri' => 'http://example.org/foo?xyz=',
258
+ 'meta' => { 'l' => 'query' }
259
+ }
274
260
  expect(TCellAgent.event_queue).to include(expected_as)
275
261
  end
276
262
  end
277
263
  end
278
-
279
264
  end
280
-
281
-
282
265
  end
283
266
  end
284
267
  end