tcell_agent 0.2.19 → 0.2.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE_libinjection +32 -0
- data/Rakefile +14 -1
- data/ext/libinjection/extconf.rb +3 -0
- data/ext/libinjection/libinjection.h +65 -0
- data/ext/libinjection/libinjection_html5.c +847 -0
- data/ext/libinjection/libinjection_html5.h +54 -0
- data/ext/libinjection/libinjection_sqli.c +2317 -0
- data/ext/libinjection/libinjection_sqli.h +295 -0
- data/ext/libinjection/libinjection_sqli_data.h +9004 -0
- data/ext/libinjection/libinjection_wrap.c +3525 -0
- data/ext/libinjection/libinjection_xss.c +531 -0
- data/ext/libinjection/libinjection_xss.h +21 -0
- data/lib/tcell_agent/configuration.rb +0 -48
- data/lib/tcell_agent/logger.rb +1 -0
- data/lib/tcell_agent/policies/appsensor/database_sensor.rb +8 -20
- data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +30 -46
- data/lib/tcell_agent/policies/appsensor/login_sensor.rb +1 -4
- data/lib/tcell_agent/policies/appsensor/misc_sensor.rb +8 -22
- data/lib/tcell_agent/policies/appsensor/payloads_policy.rb +143 -0
- data/lib/tcell_agent/policies/appsensor/response_codes_sensor.rb +3 -1
- data/lib/tcell_agent/policies/appsensor/sensor.rb +21 -2
- data/lib/tcell_agent/policies/appsensor/size_sensor.rb +3 -1
- data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +9 -0
- data/lib/tcell_agent/policies/appsensor/user_agent_sensor.rb +1 -5
- data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +9 -1
- data/lib/tcell_agent/policies/appsensor_policy.rb +40 -19
- data/lib/tcell_agent/policies/http_redirect_policy.rb +12 -2
- data/lib/tcell_agent/rails/csrf_exception.rb +1 -1
- data/lib/tcell_agent/rails/dlp.rb +98 -76
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +1 -2
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +2 -2
- data/lib/tcell_agent/rails/on_start.rb +53 -20
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +12 -19
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +7 -2
- data/lib/tcell_agent/sensor_events/sensor.rb +10 -11
- data/lib/tcell_agent/sensor_events/server_agent.rb +17 -12
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +148 -139
- data/lib/tcell_agent/utils/params.rb +24 -21
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/configuration_spec.rb +0 -179
- data/spec/lib/tcell_agent/policies/appsensor/database_sensor_spec.rb +6 -4
- data/spec/lib/tcell_agent/policies/appsensor/misc_sensor_spec.rb +31 -22
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_apply_spec.rb +466 -0
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_from_json_spec.rb +890 -0
- data/spec/lib/tcell_agent/policies/appsensor/payloads_policy_log_spec.rb +484 -0
- data/spec/lib/tcell_agent/policies/appsensor/request_size_sensor_spec.rb +4 -3
- data/spec/lib/tcell_agent/policies/appsensor/response_codes_sensor_spec.rb +4 -4
- data/spec/lib/tcell_agent/policies/appsensor/response_size_sensor_spec.rb +1 -1
- data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +85 -0
- data/spec/lib/tcell_agent/policies/appsensor/user_agent_sensor_spec.rb +36 -16
- data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +188 -312
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +61 -0
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +18 -11
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +14 -15
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +1 -1
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +6 -5
- data/spec/lib/tcell_agent/utils/params_spec.rb +28 -108
- data/tcell_agent.gemspec +21 -1
- metadata +37 -4
@@ -0,0 +1,484 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module TCellAgent
|
4
|
+
module Policies
|
5
|
+
|
6
|
+
describe AppSensorPolicy do
|
7
|
+
|
8
|
+
describe "#log" do
|
9
|
+
before(:each) do
|
10
|
+
@meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
|
11
|
+
@meta.remote_address = "remote_address"
|
12
|
+
@meta.method = "get"
|
13
|
+
@meta.location = "location"
|
14
|
+
@meta.route_id = "route_id"
|
15
|
+
@meta.session_id = "session_id"
|
16
|
+
@meta.user_id = "user_id"
|
17
|
+
@meta.transaction_id = "transaction_id"
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with log_payloads disabled" do
|
21
|
+
it "should not log" do
|
22
|
+
policy = PayloadsPolicy.from_json({
|
23
|
+
"payloads" => {
|
24
|
+
"log_payloads" => false
|
25
|
+
}
|
26
|
+
})
|
27
|
+
|
28
|
+
expect(TCellAgent).to_not receive(:configuration)
|
29
|
+
expect(TCellAgent).to_not receive(:appfirewall_payloads_logger)
|
30
|
+
|
31
|
+
policy.log(
|
32
|
+
"xss",
|
33
|
+
@meta,
|
34
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
35
|
+
"password",
|
36
|
+
"alert()",
|
37
|
+
{"l" => "query"},
|
38
|
+
"pattern"
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with log_payloads enabled" do
|
44
|
+
context "with allow_unencrypted_appfirewall_payloads_logging disabled" do
|
45
|
+
it "should not log" do
|
46
|
+
policy = PayloadsPolicy.from_json({
|
47
|
+
"payloads" => {
|
48
|
+
"log_payloads" => true
|
49
|
+
}
|
50
|
+
})
|
51
|
+
|
52
|
+
configuration = double("configuration")
|
53
|
+
|
54
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
55
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
56
|
+
false
|
57
|
+
)
|
58
|
+
expect(TCellAgent).to_not receive(:appfirewall_payloads_logger)
|
59
|
+
|
60
|
+
policy.log(
|
61
|
+
"xss",
|
62
|
+
@meta,
|
63
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
64
|
+
"password",
|
65
|
+
"alert()",
|
66
|
+
{"l" => "query"},
|
67
|
+
"pattern"
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "with allow_unencrypted_appfirewall_payloads_logging enabled" do
|
73
|
+
context "with no blacklist" do
|
74
|
+
context "with no whitelist" do
|
75
|
+
it "should log the value" do
|
76
|
+
policy = PayloadsPolicy.from_json({
|
77
|
+
"payloads" => {
|
78
|
+
"log_payloads" => true
|
79
|
+
}
|
80
|
+
})
|
81
|
+
configuration = double("configuration")
|
82
|
+
appfirewall_payloads_logger = double("appfirewall_payloads_logger")
|
83
|
+
|
84
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
85
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
86
|
+
true
|
87
|
+
)
|
88
|
+
expect(TCellAgent).to receive(:appfirewall_payloads_logger).and_return(
|
89
|
+
appfirewall_payloads_logger
|
90
|
+
)
|
91
|
+
expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
|
92
|
+
:post_process
|
93
|
+
)
|
94
|
+
expect(appfirewall_payloads_logger).to receive(:info).with({
|
95
|
+
"event_type" => "as",
|
96
|
+
"dp" => "xss",
|
97
|
+
"param" => "password",
|
98
|
+
"remote_addr" => "remote_address",
|
99
|
+
"m" => "get",
|
100
|
+
"pattern" => "pattern",
|
101
|
+
"meta" => {"l" => "query"},
|
102
|
+
"rid" => "route_id"
|
103
|
+
}.to_json)
|
104
|
+
|
105
|
+
policy.log(
|
106
|
+
"xss",
|
107
|
+
@meta,
|
108
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
109
|
+
"password",
|
110
|
+
"alert()",
|
111
|
+
{"l" => "query"},
|
112
|
+
"pattern"
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "with a whitelist" do
|
118
|
+
context "that does not specify locations for the param" do
|
119
|
+
it "should not log" do
|
120
|
+
policy = PayloadsPolicy.from_json({
|
121
|
+
"payloads" => {
|
122
|
+
"log_payloads" => true,
|
123
|
+
"log_whitelist" => {
|
124
|
+
"username" => ["*"]
|
125
|
+
}
|
126
|
+
}
|
127
|
+
})
|
128
|
+
configuration = double("configuration")
|
129
|
+
|
130
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
131
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
132
|
+
true
|
133
|
+
)
|
134
|
+
expect(TCellAgent).to_not receive(:appfirewall_payloads_logger)
|
135
|
+
|
136
|
+
policy.log(
|
137
|
+
"xss",
|
138
|
+
@meta,
|
139
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
140
|
+
"password",
|
141
|
+
"alert()",
|
142
|
+
{"l" => "query"},
|
143
|
+
"pattern"
|
144
|
+
)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "that specifies locations for the param" do
|
149
|
+
context "param location does not match specified location do" do
|
150
|
+
it "should not log" do
|
151
|
+
policy = PayloadsPolicy.from_json({
|
152
|
+
"payloads" => {
|
153
|
+
"log_payloads" => true,
|
154
|
+
"log_whitelist" => {
|
155
|
+
"username" => ["*"],
|
156
|
+
"password" => ["cookie"]
|
157
|
+
}
|
158
|
+
}
|
159
|
+
})
|
160
|
+
configuration = double("configuration")
|
161
|
+
|
162
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
163
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
164
|
+
true
|
165
|
+
)
|
166
|
+
expect(TCellAgent).to_not receive(:appfirewall_payloads_logger)
|
167
|
+
|
168
|
+
policy.log(
|
169
|
+
"xss",
|
170
|
+
@meta,
|
171
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
172
|
+
"password",
|
173
|
+
"alert()",
|
174
|
+
{"l" => "query"},
|
175
|
+
"pattern"
|
176
|
+
)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "param location matches the specified location in the whitelist" do
|
181
|
+
it "should log the value" do
|
182
|
+
policy = PayloadsPolicy.from_json({
|
183
|
+
"payloads" => {
|
184
|
+
"log_payloads" => true,
|
185
|
+
"log_whitelist" => {
|
186
|
+
"username" => ["*"],
|
187
|
+
"PASSWORD" => ["form"]
|
188
|
+
}
|
189
|
+
}
|
190
|
+
})
|
191
|
+
configuration = double("configuration")
|
192
|
+
appfirewall_payloads_logger = double("appfirewall_payloads_logger")
|
193
|
+
|
194
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
195
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
196
|
+
true
|
197
|
+
)
|
198
|
+
expect(TCellAgent).to receive(:appfirewall_payloads_logger).and_return(
|
199
|
+
appfirewall_payloads_logger
|
200
|
+
)
|
201
|
+
expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
|
202
|
+
:post_process
|
203
|
+
)
|
204
|
+
expect(appfirewall_payloads_logger).to receive(:info).with({
|
205
|
+
"event_type" => "as",
|
206
|
+
"dp" => "xss",
|
207
|
+
"param" => "password",
|
208
|
+
"remote_addr" => "remote_address",
|
209
|
+
"m" => "get",
|
210
|
+
"pattern" => "pattern",
|
211
|
+
"meta" => {"l" => "query"},
|
212
|
+
"rid" => "route_id",
|
213
|
+
}.to_json)
|
214
|
+
|
215
|
+
policy.log(
|
216
|
+
"xss",
|
217
|
+
@meta,
|
218
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
219
|
+
"password",
|
220
|
+
"alert()",
|
221
|
+
{"l" => "query"},
|
222
|
+
"pattern"
|
223
|
+
)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context "with a blacklist" do
|
231
|
+
context "that does not specify locations for the param" do
|
232
|
+
context "with no whitelist" do
|
233
|
+
it "should log the value" do
|
234
|
+
policy = PayloadsPolicy.from_json({
|
235
|
+
"payloads" => {
|
236
|
+
"log_payloads" => true,
|
237
|
+
"log_blacklist" => {
|
238
|
+
"username" => ["*"]
|
239
|
+
}
|
240
|
+
}
|
241
|
+
})
|
242
|
+
configuration = double("configuration")
|
243
|
+
appfirewall_payloads_logger = double("appfirewall_payloads_logger")
|
244
|
+
|
245
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
246
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
247
|
+
true
|
248
|
+
)
|
249
|
+
expect(TCellAgent).to receive(:appfirewall_payloads_logger).and_return(
|
250
|
+
appfirewall_payloads_logger
|
251
|
+
)
|
252
|
+
expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
|
253
|
+
:post_process
|
254
|
+
)
|
255
|
+
expect(appfirewall_payloads_logger).to receive(:info).with({
|
256
|
+
"event_type" => "as",
|
257
|
+
"dp" => "xss",
|
258
|
+
"param" => "password",
|
259
|
+
"remote_addr" => "remote_address",
|
260
|
+
"m" => "get",
|
261
|
+
"pattern" => "pattern",
|
262
|
+
"meta" => {"l" => "query"},
|
263
|
+
"rid" => "route_id"
|
264
|
+
}.to_json)
|
265
|
+
|
266
|
+
policy.log(
|
267
|
+
"xss",
|
268
|
+
@meta,
|
269
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
270
|
+
"password",
|
271
|
+
"alert()",
|
272
|
+
{"l" => "query"},
|
273
|
+
"pattern"
|
274
|
+
)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
context "with a whitelist" do
|
279
|
+
context "that does not specify locations for the param" do
|
280
|
+
it "should not log" do
|
281
|
+
policy = PayloadsPolicy.from_json({
|
282
|
+
"payloads" => {
|
283
|
+
"log_payloads" => true,
|
284
|
+
"log_blacklist" => {
|
285
|
+
"username" => ["*"]
|
286
|
+
},
|
287
|
+
"log_whitelist" => {
|
288
|
+
"username" => ["*"]
|
289
|
+
}
|
290
|
+
}
|
291
|
+
})
|
292
|
+
configuration = double("configuration")
|
293
|
+
|
294
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
295
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
296
|
+
true
|
297
|
+
)
|
298
|
+
expect(TCellAgent).to_not receive(:appfirewall_payloads_logger)
|
299
|
+
|
300
|
+
policy.log(
|
301
|
+
"xss",
|
302
|
+
@meta,
|
303
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
304
|
+
"password",
|
305
|
+
"alert()",
|
306
|
+
{"l" => "query"},
|
307
|
+
"pattern"
|
308
|
+
)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
context "that specifies locations for the param" do
|
313
|
+
context "param location does not match specified location" do
|
314
|
+
it "should not log" do
|
315
|
+
policy = PayloadsPolicy.from_json({
|
316
|
+
"payloads" => {
|
317
|
+
"log_payloads" => true,
|
318
|
+
"log_blacklist" => {
|
319
|
+
"username" => ["*"],
|
320
|
+
},
|
321
|
+
"log_whitelist" => {
|
322
|
+
"password" => ["cookie"]
|
323
|
+
}
|
324
|
+
}
|
325
|
+
})
|
326
|
+
configuration = double("configuration")
|
327
|
+
|
328
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
329
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
330
|
+
true
|
331
|
+
)
|
332
|
+
expect(TCellAgent).to_not receive(:appfirewall_payloads_logger)
|
333
|
+
|
334
|
+
policy.log(
|
335
|
+
"xss",
|
336
|
+
@meta,
|
337
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
338
|
+
"password",
|
339
|
+
"alert()",
|
340
|
+
{"l" => "query"},
|
341
|
+
"pattern"
|
342
|
+
)
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context "param location matches the specified location" do
|
347
|
+
it "should log the value" do
|
348
|
+
policy = PayloadsPolicy.from_json({
|
349
|
+
"payloads" => {
|
350
|
+
"log_payloads" => true,
|
351
|
+
"log_blacklist" => {
|
352
|
+
"username" => ["*"],
|
353
|
+
},
|
354
|
+
"log_whitelist" => {
|
355
|
+
"PASSWORD" => ["form"]
|
356
|
+
}
|
357
|
+
}
|
358
|
+
})
|
359
|
+
configuration = double("configuration")
|
360
|
+
appfirewall_payloads_logger = double("appfirewall_payloads_logger")
|
361
|
+
|
362
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
363
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
364
|
+
true
|
365
|
+
)
|
366
|
+
expect(TCellAgent).to receive(:appfirewall_payloads_logger).and_return(
|
367
|
+
appfirewall_payloads_logger
|
368
|
+
)
|
369
|
+
expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
|
370
|
+
:post_process
|
371
|
+
)
|
372
|
+
expect(appfirewall_payloads_logger).to receive(:info).with({
|
373
|
+
"event_type" => "as",
|
374
|
+
"dp" => "xss",
|
375
|
+
"param" => "password",
|
376
|
+
"remote_addr" => "remote_address",
|
377
|
+
"m" => "get",
|
378
|
+
"pattern" => "pattern",
|
379
|
+
"meta" => {"l" => "query"},
|
380
|
+
"rid" => "route_id"
|
381
|
+
}.to_json)
|
382
|
+
|
383
|
+
policy.log(
|
384
|
+
"xss",
|
385
|
+
@meta,
|
386
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
387
|
+
"password",
|
388
|
+
"alert()",
|
389
|
+
{"l" => "query"},
|
390
|
+
"pattern"
|
391
|
+
)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
context "that specifies locations for the param" do
|
399
|
+
context "param location does not match specified location" do
|
400
|
+
it "should log the value" do
|
401
|
+
policy = PayloadsPolicy.from_json({
|
402
|
+
"payloads" => {
|
403
|
+
"log_payloads" => true,
|
404
|
+
"log_blacklist" => {
|
405
|
+
"password" => ["cookie"],
|
406
|
+
}
|
407
|
+
}
|
408
|
+
})
|
409
|
+
configuration = double("configuration")
|
410
|
+
appfirewall_payloads_logger = double("appfirewall_payloads_logger")
|
411
|
+
|
412
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
413
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
414
|
+
true
|
415
|
+
)
|
416
|
+
expect(TCellAgent).to receive(:appfirewall_payloads_logger).and_return(
|
417
|
+
appfirewall_payloads_logger
|
418
|
+
)
|
419
|
+
expect_any_instance_of(TCellAgent::SensorEvents::TCellAppSensorEvent).to receive(
|
420
|
+
:post_process
|
421
|
+
)
|
422
|
+
expect(appfirewall_payloads_logger).to receive(:info).with({
|
423
|
+
"event_type" => "as",
|
424
|
+
"dp" => "xss",
|
425
|
+
"param" => "password",
|
426
|
+
"remote_addr" => "remote_address",
|
427
|
+
"m" => "get",
|
428
|
+
"pattern" => "pattern",
|
429
|
+
"meta" => {"l" => "query"},
|
430
|
+
"rid" => "route_id"
|
431
|
+
}.to_json)
|
432
|
+
|
433
|
+
policy.log(
|
434
|
+
"xss",
|
435
|
+
@meta,
|
436
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
437
|
+
"password",
|
438
|
+
"alert()",
|
439
|
+
{"l" => "query"},
|
440
|
+
"pattern"
|
441
|
+
)
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
context "param location matches the specified location" do
|
446
|
+
it "should not log" do
|
447
|
+
policy = PayloadsPolicy.from_json({
|
448
|
+
"payloads" => {
|
449
|
+
"log_payloads" => true,
|
450
|
+
"log_blacklist" => {
|
451
|
+
"password" => ["form"],
|
452
|
+
}
|
453
|
+
}
|
454
|
+
})
|
455
|
+
configuration = double("configuration")
|
456
|
+
|
457
|
+
expect(TCellAgent).to receive(:configuration).and_return(configuration)
|
458
|
+
expect(configuration).to receive(:allow_unencrypted_appfirewall_payloads_logging).and_return(
|
459
|
+
true
|
460
|
+
)
|
461
|
+
expect(TCellAgent).to_not receive(:appfirewall_payloads_logger)
|
462
|
+
|
463
|
+
policy.log(
|
464
|
+
"xss",
|
465
|
+
@meta,
|
466
|
+
TCellAgent::Utils::Params::GET_PARAM,
|
467
|
+
"password",
|
468
|
+
"alert()",
|
469
|
+
{"l" => "query"},
|
470
|
+
"pattern"
|
471
|
+
)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|
475
|
+
end
|
476
|
+
end
|
477
|
+
end
|
478
|
+
|
479
|
+
end
|
480
|
+
|
481
|
+
end
|
482
|
+
|
483
|
+
end
|
484
|
+
end
|
@@ -145,10 +145,11 @@ module TCellAgent
|
|
145
145
|
{
|
146
146
|
"event_type" => "as",
|
147
147
|
"dp" => RequestSizeSensor::DP_UNUSUAL_REQUEST_SIZE,
|
148
|
-
"param" =>
|
148
|
+
"param" => nil,
|
149
149
|
"remote_addr" => "remote_address",
|
150
|
-
"
|
151
|
-
"
|
150
|
+
"m" => "get",
|
151
|
+
"meta" => {"sz" => 2048},
|
152
|
+
"rid" => "excluded_route_id"
|
152
153
|
}
|
153
154
|
)
|
154
155
|
sensor.check(meta, 2048)
|
@@ -177,7 +177,7 @@ module TCellAgent
|
|
177
177
|
|
178
178
|
it "should send an event" do
|
179
179
|
expect(@sensor).to receive(:send_event).with(
|
180
|
-
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4],
|
180
|
+
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4], nil, {code: 400} , nil, nil
|
181
181
|
)
|
182
182
|
@sensor.check(@meta, 400)
|
183
183
|
end
|
@@ -187,7 +187,7 @@ module TCellAgent
|
|
187
187
|
@sensor.excluded_route_ids = {}
|
188
188
|
|
189
189
|
expect(@sensor).to receive(:send_event).with(
|
190
|
-
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4],
|
190
|
+
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4], nil, {code: 400} , nil, nil
|
191
191
|
)
|
192
192
|
@sensor.check(@meta, 400)
|
193
193
|
end
|
@@ -207,7 +207,7 @@ module TCellAgent
|
|
207
207
|
@sensor.excluded_route_ids = {"unmatching_route_id" => true}
|
208
208
|
|
209
209
|
expect(@sensor).to receive(:send_event).with(
|
210
|
-
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4],
|
210
|
+
@meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[4], nil, {code: 400} , nil, nil
|
211
211
|
)
|
212
212
|
@sensor.check(@meta, 400)
|
213
213
|
end
|
@@ -255,7 +255,7 @@ module TCellAgent
|
|
255
255
|
meta.transaction_id = "transaction_id"
|
256
256
|
|
257
257
|
expect(sensor).to receive(:send_event).with(
|
258
|
-
meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[500],
|
258
|
+
meta, ResponseCodesSensor::RESPONSE_CODE_DP_DICT[500], nil, {code: 500} , nil, nil
|
259
259
|
)
|
260
260
|
sensor.check(meta, 500)
|
261
261
|
end
|
@@ -142,7 +142,7 @@ module TCellAgent
|
|
142
142
|
meta.transaction_id = "transaction_id"
|
143
143
|
|
144
144
|
expect(sensor).to receive(:send_event).with(
|
145
|
-
meta, ResponseSizeSensor::DP_UNUSUAL_RESPONSE_SIZE, "2048
|
145
|
+
meta, ResponseSizeSensor::DP_UNUSUAL_RESPONSE_SIZE, nil, {"sz" => 2048}, nil, nil
|
146
146
|
)
|
147
147
|
sensor.check(meta, 2048)
|
148
148
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module TCellAgent
|
@@ -145,6 +147,89 @@ module TCellAgent
|
|
145
147
|
end
|
146
148
|
|
147
149
|
end
|
150
|
+
|
151
|
+
describe "#find_vulnerability" do
|
152
|
+
before(:each) do
|
153
|
+
@sensor = SqliSensor.new({"enabled" => true})
|
154
|
+
end
|
155
|
+
|
156
|
+
context "with libinjection enabled" do
|
157
|
+
context "with param value that doesn't match any vulnerabilities" do
|
158
|
+
it "should return nil" do
|
159
|
+
@sensor.libinjection = true
|
160
|
+
|
161
|
+
ruleset = double("ruleset")
|
162
|
+
expect(@sensor).to receive(:get_ruleset).and_return(ruleset)
|
163
|
+
expect(ruleset).to receive(:check_violation).with(
|
164
|
+
"param", "value", {}, false
|
165
|
+
).and_return(nil)
|
166
|
+
|
167
|
+
expect(@sensor.find_vulnerability("param", "value")).to eq(nil)
|
168
|
+
end
|
169
|
+
|
170
|
+
context "and it has utf-8 chars" do
|
171
|
+
it "should return nil but not fail miserably" do
|
172
|
+
@sensor.libinjection = true
|
173
|
+
|
174
|
+
ruleset = double("ruleset")
|
175
|
+
expect(@sensor).to receive(:get_ruleset).and_return(ruleset)
|
176
|
+
expect(ruleset).to receive(:check_violation).with(
|
177
|
+
"param", "Müller", {}, false
|
178
|
+
).and_return(nil)
|
179
|
+
|
180
|
+
expect(@sensor.find_vulnerability("param", "Müller")).to eq(nil)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "with param value that matches a vulnerability" do
|
186
|
+
it "should return the param and it's value" do
|
187
|
+
@sensor.libinjection = true
|
188
|
+
|
189
|
+
expect(@sensor).to_not receive(:get_ruleset)
|
190
|
+
|
191
|
+
expect(@sensor.find_vulnerability("param_name", "' OR 1=1")).to eq(
|
192
|
+
{"param"=>"param_name", "value"=>"' OR 1=1", "pattern"=>"li"}
|
193
|
+
)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "with no ruleset" do
|
199
|
+
it "should return nil" do
|
200
|
+
expect(@sensor).to receive(:get_ruleset).and_return(nil)
|
201
|
+
|
202
|
+
expect(@sensor.find_vulnerability("param", "value")).to eq(nil)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context "with ruletset" do
|
207
|
+
context "with param value that doesn't match any vulnerabilities" do
|
208
|
+
it "should return nil" do
|
209
|
+
ruleset = double("ruleset")
|
210
|
+
expect(@sensor).to receive(:get_ruleset).and_return(ruleset)
|
211
|
+
expect(ruleset).to receive(:check_violation).with(
|
212
|
+
"param", "value", {}, false
|
213
|
+
).and_return(nil)
|
214
|
+
|
215
|
+
expect(@sensor.find_vulnerability("param", "value")).to eq(nil)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context "with param value that matches a vulnerability" do
|
220
|
+
it "should return the param and it's value" do
|
221
|
+
ruleset = double("ruleset")
|
222
|
+
expect(@sensor).to receive(:get_ruleset).and_return(ruleset)
|
223
|
+
expect(ruleset).to receive(:check_violation).with(
|
224
|
+
"param", "value", {}, false
|
225
|
+
).and_return(true)
|
226
|
+
|
227
|
+
expect(@sensor.find_vulnerability("param", "value")).to eq(true)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
148
233
|
end
|
149
234
|
|
150
235
|
end
|