tcell_agent 0.2.29 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/Readme.txt +7 -0
  3. data/bin/tcell_agent +9 -0
  4. data/lib/tcell_agent/agent/policy_manager.rb +3 -0
  5. data/lib/tcell_agent/agent/policy_types.rb +4 -1
  6. data/lib/tcell_agent/appsensor/injections_matcher.rb +20 -0
  7. data/lib/tcell_agent/appsensor/injections_reporter.rb +15 -56
  8. data/lib/tcell_agent/appsensor/meta_data.rb +56 -2
  9. data/lib/tcell_agent/appsensor/rules/baserules.json +371 -138
  10. data/lib/tcell_agent/cmdi.rb +113 -0
  11. data/lib/tcell_agent/config/unknown_options.rb +2 -0
  12. data/lib/tcell_agent/configuration.rb +30 -16
  13. data/lib/tcell_agent/hooks/login_fraud.rb +79 -0
  14. data/lib/tcell_agent/instrumentation.rb +6 -11
  15. data/lib/tcell_agent/patches/meta_data.rb +14 -11
  16. data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +5 -9
  17. data/lib/tcell_agent/policies/appsensor_policy.rb +22 -206
  18. data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -2
  19. data/lib/tcell_agent/policies/command_injection_policy.rb +196 -0
  20. data/lib/tcell_agent/policies/content_security_policy.rb +3 -2
  21. data/lib/tcell_agent/policies/dataloss_policy.rb +3 -1
  22. data/lib/tcell_agent/policies/honeytokens_policy.rb +3 -1
  23. data/lib/tcell_agent/policies/http_redirect_policy.rb +51 -37
  24. data/lib/tcell_agent/policies/http_tx_policy.rb +5 -1
  25. data/lib/tcell_agent/policies/login_fraud_policy.rb +6 -1
  26. data/lib/tcell_agent/policies/patches_policy.rb +3 -1
  27. data/lib/tcell_agent/policies/policy.rb +10 -0
  28. data/lib/tcell_agent/policies/secure_headers_policy.rb +5 -2
  29. data/lib/tcell_agent/rails/auth/devise.rb +12 -23
  30. data/lib/tcell_agent/rails/csrf_exception.rb +1 -1
  31. data/lib/tcell_agent/rails/dlp.rb +50 -54
  32. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +0 -1
  33. data/lib/tcell_agent/rails/middleware/context_middleware.rb +0 -1
  34. data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
  35. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +7 -10
  36. data/lib/tcell_agent/rails/on_start.rb +0 -1
  37. data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -4
  38. data/lib/tcell_agent/rails.rb +0 -2
  39. data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
  40. data/lib/tcell_agent/rust/libtcellagent-0.6.1.so +0 -0
  41. data/lib/tcell_agent/rust/models.rb +61 -0
  42. data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
  43. data/lib/tcell_agent/rust/whisperer.rb +112 -0
  44. data/lib/tcell_agent/sensor_events/appsensor_event.rb +25 -21
  45. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +31 -24
  46. data/lib/tcell_agent/sensor_events/command_injection.rb +58 -0
  47. data/lib/tcell_agent/sensor_events/discovery.rb +1 -1
  48. data/lib/tcell_agent/sensor_events/login_fraud.rb +3 -13
  49. data/lib/tcell_agent/sensor_events/sensor.rb +81 -77
  50. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +8 -0
  51. data/lib/tcell_agent/start_background_thread.rb +12 -3
  52. data/lib/tcell_agent/utils/io.rb +4 -1
  53. data/lib/tcell_agent/utils/params.rb +1 -0
  54. data/lib/tcell_agent/version.rb +1 -1
  55. data/lib/tcell_agent.rb +0 -1
  56. data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +27 -9
  57. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +143 -193
  58. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +67 -0
  59. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -10
  60. data/spec/lib/tcell_agent/cmdi_spec.rb +748 -0
  61. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +8 -0
  62. data/spec/lib/tcell_agent/configuration_spec.rb +138 -6
  63. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +357 -0
  64. data/spec/lib/tcell_agent/patches/block_rule_spec.rb +70 -87
  65. data/spec/lib/tcell_agent/patches_spec.rb +9 -4
  66. data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +186 -9
  67. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +309 -484
  68. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +736 -0
  69. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +222 -41
  70. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +56 -32
  71. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +161 -85
  72. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +40 -72
  73. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +267 -0
  74. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +20 -15
  75. data/spec/spec_helper.rb +0 -9
  76. data/tcell_agent.gemspec +8 -3
  77. metadata +40 -39
  78. data/lib/tcell_agent/appsensor/sensor.rb +0 -52
  79. data/lib/tcell_agent/policies/appsensor/database_sensor.rb +0 -56
  80. data/lib/tcell_agent/policies/appsensor/misc_sensor.rb +0 -59
  81. data/lib/tcell_agent/policies/appsensor/payloads_policy.rb +0 -150
  82. data/lib/tcell_agent/policies/appsensor/request_size_sensor.rb +0 -25
  83. data/lib/tcell_agent/policies/appsensor/response_codes_sensor.rb +0 -73
  84. data/lib/tcell_agent/policies/appsensor/response_size_sensor.rb +0 -25
  85. data/lib/tcell_agent/policies/appsensor/size_sensor.rb +0 -71
  86. data/lib/tcell_agent/policies/appsensor/user_agent_sensor.rb +0 -47
  87. data/lib/tcell_agent/rails/auth/hooks.rb +0 -79
  88. data/lib/tcell_agent/sensor_events/util/redirect_utils.rb +0 -22
  89. data/spec/lib/tcell_agent/policies/appsensor/database_sensor_spec.rb +0 -165
  90. data/spec/lib/tcell_agent/policies/appsensor/misc_sensor_spec.rb +0 -429
  91. data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_apply_spec.rb +0 -466
  92. data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_from_json_spec.rb +0 -890
  93. data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_log_spec.rb +0 -417
  94. data/spec/lib/tcell_agent/policies/appsensor/request_size_sensor_spec.rb +0 -236
  95. data/spec/lib/tcell_agent/policies/appsensor/response_codes_sensor_spec.rb +0 -297
  96. data/spec/lib/tcell_agent/policies/appsensor/response_size_sensor_spec.rb +0 -241
  97. data/spec/lib/tcell_agent/policies/appsensor/user_agent_sensor_spec.rb +0 -172
  98. data/spec/lib/tcell_agent/rails/auth/hooks_spec.rb +0 -246
  99. data/spec/lib/tcell_agent/sensor_events/util/redirect_utils_spec.rb +0 -25
  100. data/spec/support/resources/baserules.json +0 -155
@@ -1,466 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module Policies
5
-
6
- describe AppSensorPolicy do
7
-
8
- describe "#apply" do
9
-
10
- context "with send_payloads disabled" do
11
- it "should return nil payload" do
12
- policy = PayloadsPolicy.from_json({
13
- "payloads" => {
14
- "send_payloads" => false
15
- }
16
- })
17
-
18
- expect(TCellAgent).to_not receive(:configuration)
19
- expect(policy).to receive(:log).with(
20
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
21
- )
22
-
23
- payload = policy.apply(
24
- "xss",
25
- nil,
26
- TCellAgent::Utils::Params::GET_PARAM,
27
- "password",
28
- "alert()",
29
- {"l" => "query"},
30
- "pattern"
31
- )
32
-
33
- expect(payload).to eq(
34
- nil
35
- )
36
- end
37
- end
38
-
39
- context "with send_payloads enabled" do
40
- context "with allow_unencrypted_appfirewall_payloads disabled" do
41
- it "should return nil payload" do
42
- policy = PayloadsPolicy.from_json({
43
- "payloads" => {
44
- "send_payloads" => true
45
- }
46
- })
47
-
48
- configuration = double("configuration")
49
-
50
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
51
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
52
- false
53
- )
54
- expect(policy).to receive(:log).with(
55
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
56
- )
57
-
58
- payload = policy.apply(
59
- "xss",
60
- nil,
61
- TCellAgent::Utils::Params::GET_PARAM,
62
- "password",
63
- "alert()",
64
- {"l" => "query"},
65
- "pattern"
66
- )
67
-
68
- expect(payload).to eq(
69
- nil
70
- )
71
- end
72
- end
73
-
74
- context "with allow_unencrypted_appfirewall_payloads enabled" do
75
- context "with no blacklist" do
76
- context "with no whitelist" do
77
- it "return the vulnerable value" do
78
- policy = PayloadsPolicy.from_json({
79
- "payloads" => {
80
- "send_payloads" => true
81
- }
82
- })
83
- configuration = double("configuration")
84
-
85
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
86
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
87
- true
88
- )
89
- expect(policy).to receive(:log).with(
90
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
91
- )
92
-
93
- payload = policy.apply(
94
- "xss",
95
- nil,
96
- TCellAgent::Utils::Params::GET_PARAM,
97
- "password",
98
- "alert()",
99
- {"l" => "query"},
100
- "pattern"
101
- )
102
-
103
- expect(payload).to eq(
104
- "alert()"
105
- )
106
- end
107
- end
108
-
109
- context "with a whitelist" do
110
- context "that does not specify locations for the param" do
111
- it "return return NOT_WHITELISTED" do
112
- policy = PayloadsPolicy.from_json({
113
- "payloads" => {
114
- "send_payloads" => true,
115
- "send_whitelist" => {
116
- "username" => ["*"]
117
- }
118
- }
119
- })
120
- configuration = double("configuration")
121
-
122
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
123
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
124
- true
125
- )
126
- expect(policy).to receive(:log).with(
127
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
128
- )
129
-
130
- payload = policy.apply(
131
- "xss",
132
- nil,
133
- TCellAgent::Utils::Params::GET_PARAM,
134
- "password",
135
- "alert()",
136
- {"l" => "query"},
137
- "pattern"
138
- )
139
-
140
- expect(payload).to eq(
141
- "NOT_WHITELISTED"
142
- )
143
- end
144
- end
145
-
146
- context "that specifies locations for the param" do
147
- context "param location does not match specified location do" do
148
- it "return should return NOT_WHITELISTED" do
149
- policy = PayloadsPolicy.from_json({
150
- "payloads" => {
151
- "send_payloads" => true,
152
- "send_whitelist" => {
153
- "username" => ["*"],
154
- "password" => ["cookie"]
155
- }
156
- }
157
- })
158
- configuration = double("configuration")
159
-
160
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
161
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
162
- true
163
- )
164
- expect(policy).to receive(:log).with(
165
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
166
- )
167
-
168
- payload = policy.apply(
169
- "xss",
170
- nil,
171
- TCellAgent::Utils::Params::GET_PARAM,
172
- "password",
173
- "alert()",
174
- {"l" => "query"},
175
- "pattern"
176
- )
177
-
178
- expect(payload).to eq(
179
- "NOT_WHITELISTED"
180
- )
181
- end
182
- end
183
-
184
- context "param location matches the specified location in the whitelist" do
185
- it "return the vulnerable value" do
186
- policy = PayloadsPolicy.from_json({
187
- "payloads" => {
188
- "send_payloads" => true,
189
- "send_whitelist" => {
190
- "username" => ["*"],
191
- "PASSWORD" => ["form"]
192
- }
193
- }
194
- })
195
- configuration = double("configuration")
196
-
197
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
198
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
199
- true
200
- )
201
- expect(policy).to receive(:log).with(
202
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
203
- )
204
-
205
- payload = policy.apply(
206
- "xss",
207
- nil,
208
- TCellAgent::Utils::Params::GET_PARAM,
209
- "password",
210
- "alert()",
211
- {"l" => "query"},
212
- "pattern"
213
- )
214
-
215
- expect(payload).to eq(
216
- "alert()"
217
- )
218
- end
219
- end
220
- end
221
- end
222
- end
223
-
224
- context "with a blacklist" do
225
- context "that does not specify locations for the param" do
226
- context "with no whitelist" do
227
- it "should return the vulnerable value" do
228
- policy = PayloadsPolicy.from_json({
229
- "payloads" => {
230
- "send_payloads" => true,
231
- "send_blacklist" => {
232
- "username" => ["*"]
233
- }
234
- }
235
- })
236
- configuration = double("configuration")
237
-
238
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
239
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
240
- true
241
- )
242
- expect(policy).to receive(:log).with(
243
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
244
- )
245
-
246
- payload = policy.apply(
247
- "xss",
248
- nil,
249
- TCellAgent::Utils::Params::GET_PARAM,
250
- "password",
251
- "alert()",
252
- {"l" => "query"},
253
- "pattern"
254
- )
255
-
256
- expect(payload).to eq(
257
- "alert()"
258
- )
259
- end
260
- end
261
-
262
- context "with a whitelist" do
263
- context "that does not specify locations for the param" do
264
- it "should return NOT_WHITELISTED" do
265
- policy = PayloadsPolicy.from_json({
266
- "payloads" => {
267
- "send_payloads" => true,
268
- "send_blacklist" => {
269
- "username" => ["*"]
270
- },
271
- "send_whitelist" => {
272
- "username" => ["*"]
273
- }
274
- }
275
- })
276
- configuration = double("configuration")
277
-
278
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
279
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
280
- true
281
- )
282
- expect(policy).to receive(:log).with(
283
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
284
- )
285
-
286
- payload = policy.apply(
287
- "xss",
288
- nil,
289
- TCellAgent::Utils::Params::GET_PARAM,
290
- "password",
291
- "alert()",
292
- {"l" => "query"},
293
- "pattern"
294
- )
295
-
296
- expect(payload).to eq(
297
- "NOT_WHITELISTED"
298
- )
299
- end
300
- end
301
-
302
- context "that specifies locations for the param" do
303
- context "param location does not match specified location" do
304
- it "should return NOT_WHITELISTED" do
305
- policy = PayloadsPolicy.from_json({
306
- "payloads" => {
307
- "send_payloads" => true,
308
- "send_blacklist" => {
309
- "username" => ["*"],
310
- },
311
- "send_whitelist" => {
312
- "password" => ["cookie"]
313
- }
314
- }
315
- })
316
- configuration = double("configuration")
317
-
318
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
319
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
320
- true
321
- )
322
- expect(policy).to receive(:log).with(
323
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
324
- )
325
-
326
- payload = policy.apply(
327
- "xss",
328
- nil,
329
- TCellAgent::Utils::Params::GET_PARAM,
330
- "password",
331
- "alert()",
332
- {"l" => "query"},
333
- "pattern"
334
- )
335
-
336
- expect(payload).to eq(
337
- "NOT_WHITELISTED"
338
- )
339
- end
340
- end
341
-
342
- context "param location matches the specified location" do
343
- it "should return the vulnerable value" do
344
- policy = PayloadsPolicy.from_json({
345
- "payloads" => {
346
- "send_payloads" => true,
347
- "send_blacklist" => {
348
- "username" => ["*"],
349
- },
350
- "send_whitelist" => {
351
- "PASSWORD" => ["form"]
352
- }
353
- }
354
- })
355
- configuration = double("configuration")
356
-
357
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
358
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
359
- true
360
- )
361
- expect(policy).to receive(:log).with(
362
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
363
- )
364
-
365
- payload = policy.apply(
366
- "xss",
367
- nil,
368
- TCellAgent::Utils::Params::GET_PARAM,
369
- "password",
370
- "alert()",
371
- {"l" => "query"},
372
- "pattern"
373
- )
374
-
375
- expect(payload).to eq(
376
- "alert()"
377
- )
378
- end
379
- end
380
- end
381
- end
382
- end
383
-
384
- context "that specifies locations for the param" do
385
- context "param location does not match specified location" do
386
- it "should return the vulnerable value" do
387
- policy = PayloadsPolicy.from_json({
388
- "payloads" => {
389
- "send_payloads" => true,
390
- "send_blacklist" => {
391
- "password" => ["cookie"],
392
- }
393
- }
394
- })
395
- configuration = double("configuration")
396
-
397
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
398
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
399
- true
400
- )
401
- expect(policy).to receive(:log).with(
402
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
403
- )
404
-
405
- payload = policy.apply(
406
- "xss",
407
- nil,
408
- TCellAgent::Utils::Params::GET_PARAM,
409
- "password",
410
- "alert()",
411
- {"l" => "query"},
412
- "pattern"
413
- )
414
-
415
- expect(payload).to eq(
416
- "alert()"
417
- )
418
- end
419
- end
420
-
421
- context "param location matches the specified location" do
422
- it "should return BLACKLISTED" do
423
- policy = PayloadsPolicy.from_json({
424
- "payloads" => {
425
- "send_payloads" => true,
426
- "send_blacklist" => {
427
- "password" => ["form"],
428
- }
429
- }
430
- })
431
- configuration = double("configuration")
432
-
433
- expect(TCellAgent).to receive(:configuration).and_return(configuration)
434
- expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads).and_return(
435
- true
436
- )
437
- expect(policy).to receive(:log).with(
438
- "xss", nil, TCellAgent::Utils::Params::GET_PARAM, "password", "alert()", {"l" => "query"}, "pattern"
439
- )
440
-
441
- payload = policy.apply(
442
- "xss",
443
- nil,
444
- TCellAgent::Utils::Params::GET_PARAM,
445
- "password",
446
- "alert()",
447
- {"l" => "query"},
448
- "pattern"
449
- )
450
-
451
- expect(payload).to eq(
452
- "BLACKLISTED"
453
- )
454
- end
455
- end
456
- end
457
- end
458
- end
459
- end
460
-
461
- end
462
-
463
- end
464
-
465
- end
466
- end