tcell_agent 0.2.29 → 0.4.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 (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,172 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module Policies
5
-
6
- describe UserAgentSensor do
7
- context "#initialize" do
8
- context "default sensor" do
9
- it "should have properties set to defaults" do
10
- sensor = UserAgentSensor.new
11
- expect(sensor.enabled).to eq(false)
12
- expect(sensor.empty_enabled).to eq(false)
13
- expect(UserAgentSensor::DP_CODE).to eq("uaempty")
14
- end
15
- end
16
-
17
- context "setting enabled on sensor" do
18
- it "should have properties set to defaults" do
19
- sensor = UserAgentSensor.new({"enabled" => true, "empty_enabled" => false})
20
- expect(sensor.enabled).to eq(true)
21
- expect(sensor.empty_enabled).to eq(false)
22
- end
23
- end
24
-
25
- context "setting empty_enabled on sensor" do
26
- it "should have properties set to defaults" do
27
- sensor = UserAgentSensor.new({"enabled" => false, "empty_enabled" => true})
28
- expect(sensor.enabled).to eq(false)
29
- expect(sensor.empty_enabled).to eq(true)
30
- end
31
- end
32
-
33
- context "setting exclude_routes on sensor" do
34
- it "should exclude_routes set" do
35
- sensor = UserAgentSensor.new({
36
- "enabled" => false,
37
- "empty_enabled" => true,
38
- "exclude_routes" => ["route_id"]
39
- })
40
- expect(sensor.enabled).to eq(false)
41
- expect(sensor.empty_enabled).to eq(true)
42
- expect(sensor.excluded_route_ids).to eq({"route_id" => true})
43
- end
44
- end
45
- end
46
-
47
- context "#check" do
48
- before(:each) do
49
- @meta = TCellAgent::SensorEvents::AppSensorMetaEvent.new
50
- @meta.remote_address = "remote_address"
51
- @meta.method = "get"
52
- @meta.location = "location"
53
- @meta.route_id = "route_id"
54
- @meta.session_id = "session_id"
55
- @meta.user_id = "user_id"
56
- @meta.transaction_id = "transaction_id"
57
- end
58
-
59
- context "with disabled sensor" do
60
- context "with empty user agent" do
61
- it "should not send event" do
62
- sensor = UserAgentSensor.new({"enabled" => false, "empty_enabled" => false})
63
- @meta.user_agent = nil
64
-
65
- expect(TCellAgent).to_not receive(:send_event)
66
- sensor.check(@meta)
67
- end
68
- end
69
-
70
- context "with user agent present" do
71
- it "should not send event" do
72
- sensor = UserAgentSensor.new({"enabled" => false, "empty_enabled" => false})
73
- @meta.user_agent = "Mozilla"
74
-
75
- expect(TCellAgent).to_not receive(:send_event)
76
- sensor.check(@meta)
77
- end
78
- end
79
- end
80
-
81
- context "with enabled sensor" do
82
- before(:each) do
83
- @sensor = UserAgentSensor.new({"enabled" => true, "empty_enabled" => true})
84
- end
85
-
86
- context "with empty user agent" do
87
- it "should send event" do
88
- @meta.user_agent = ""
89
-
90
- expect(TCellAgent).to receive(:send_event).with({
91
- "event_type"=>"as",
92
- "dp"=>UserAgentSensor::DP_CODE,
93
- "remote_addr"=>"remote_address",
94
- "m"=>"get",
95
- "rid"=>"route_id"
96
- })
97
- @sensor.check(@meta)
98
- end
99
-
100
- context "no excluded routes" do
101
- it "should send an event" do
102
- @meta.user_agent = ""
103
- @sensor.excluded_route_ids = {}
104
-
105
- expect(TCellAgent).to receive(:send_event).with({
106
- "event_type"=>"as",
107
- "dp"=>UserAgentSensor::DP_CODE,
108
- "remote_addr"=>"remote_address",
109
- "m"=>"get",
110
- "rid"=>"route_id"
111
- })
112
- @sensor.check(@meta)
113
- end
114
- end
115
-
116
- context "has excluded routes" do
117
- context "route id matches" do
118
- it "should not send an event" do
119
- @meta.user_agent = ""
120
- @sensor.excluded_route_ids = {"route_id" => true}
121
-
122
- expect(TCellAgent).to_not receive(:send_event)
123
- @sensor.check(@meta)
124
- end
125
- end
126
- context "route id does not match" do
127
- it "should send an event" do
128
- @meta.user_agent = ""
129
- @sensor.excluded_route_ids = {"nonmatching" => true}
130
-
131
- expect(TCellAgent).to receive(:send_event).with({
132
- "event_type"=>"as",
133
- "dp"=>UserAgentSensor::DP_CODE,
134
- "remote_addr"=>"remote_address",
135
- "m"=>"get",
136
- "rid"=>"route_id"
137
- })
138
- @sensor.check(@meta)
139
- end
140
- end
141
- end
142
- end
143
-
144
- context "with blank space user agent" do
145
- it "should not send event" do
146
- @meta.user_agent = "\n \t \s"
147
-
148
- expect(TCellAgent).to receive(:send_event).with({
149
- "event_type"=>"as",
150
- "dp"=>UserAgentSensor::DP_CODE,
151
- "remote_addr"=>"remote_address",
152
- "m"=>"get",
153
- "rid"=>"route_id"
154
- })
155
- @sensor.check(@meta)
156
- end
157
- end
158
-
159
- context "with user agent present" do
160
- it "should not send event" do
161
- @meta.user_agent = "Mozilla"
162
-
163
- expect(TCellAgent).to_not receive(:send_event)
164
- @sensor.check(@meta)
165
- end
166
- end
167
- end
168
- end
169
- end
170
-
171
- end
172
- end
@@ -1,246 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
-
5
- module Hooks
6
- module V1
7
- module Frameworks
8
- module Rails
9
- module Login
10
- def self.register_login_event(status, rails_request, user_id, user_valid=nil)
11
- end
12
- end
13
- end
14
- end
15
- end
16
- end
17
-
18
- module Hooks
19
- module V1
20
- module Login
21
- LOGIN_SUCCESS = "success"
22
- LOGIN_FAILURE = "failure"
23
- def self.register_login_event(status, session_id, user_agent, referrer, remote_addr, header_keys, user_id, document_uri, user_valid=nil)
24
- end
25
- end
26
- end
27
- end
28
-
29
- describe "manually requiring auth hooks" do
30
- before(:all) do
31
- require 'tcell_agent/rails/auth/hooks'
32
- end
33
-
34
- describe "Using generic interface" do
35
- context "with a login failure" do
36
- it "should report the login failure" do
37
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
38
-
39
- expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
40
- login_fraud
41
- )
42
- expect(TCellAgent).to receive(:send_event).with(
43
- {
44
- "event_type" => "login",
45
- "header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
46
- "user_agent" => "user_agent",
47
- "referrer" => "referrer",
48
- "remote_addr" => "1.1.1.1",
49
- "user_id" => "user_id",
50
- "document_uri" => "http://tcell.tcell.io/login?param_name=",
51
- "session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
52
- "event_name" => "login-failure"
53
- }
54
- )
55
-
56
- status = Hooks::V1::Login::LOGIN_FAILURE
57
- header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
58
- document_uri = "http://tcell.tcell.io/login?param_name=param_value"
59
-
60
- Hooks::V1::Login.register_login_event(
61
- status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
62
- )
63
- end
64
- end
65
-
66
- context "with a login success" do
67
- it "should report the login success" do
68
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
69
-
70
- expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
71
- login_fraud
72
- )
73
- expect(TCellAgent).to receive(:send_event).with(
74
- {
75
- "event_type" => "login",
76
- "header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
77
- "user_agent" => "user_agent",
78
- "referrer" => "referrer",
79
- "remote_addr" => "1.1.1.1",
80
- "user_id" => "user_id",
81
- "document_uri" => "http://tcell.tcell.io/login?param_name=",
82
- "session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
83
- "event_name" => "login-success"
84
- }
85
- )
86
-
87
- status = Hooks::V1::Login::LOGIN_SUCCESS
88
- header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
89
- document_uri = "http://tcell.tcell.io/login?param_name=param_value"
90
-
91
- Hooks::V1::Login.register_login_event(
92
- status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
93
- )
94
- end
95
- end
96
-
97
- context "with an unknown status" do
98
- it "should log the error" do
99
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
100
- logger = double("logger")
101
-
102
- expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
103
- login_fraud
104
- )
105
- expect(TCellAgent).to_not receive(:send_event)
106
- expect(TCellAgent).to receive(:logger).and_return(logger)
107
- expect(logger).to receive(:error).with("Unkown login status: mumbo-jumbo")
108
-
109
- status = "mumbo-jumbo"
110
- header_keys = ["HTTP_USER_AGENT", "HTTP_X_FORWARDED_FOR"]
111
- document_uri = "http://tcell.tcell.io/login?param_name=param_value"
112
-
113
- Hooks::V1::Login.register_login_event(
114
- status, "session_id", "user_agent", "referrer", "1.1.1.1", header_keys, "user_id", document_uri
115
- )
116
- end
117
- end
118
- end
119
-
120
- describe "Using rails interface" do
121
- context "with a login failure" do
122
- it "should report the login failure" do
123
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
124
- rails_request = double("rails_request")
125
- tcell_data = TCellAgent::Instrumentation::TCellData.new
126
- tcell_data.user_agent = "user_agent"
127
- tcell_data.referrer = "referrer"
128
- tcell_data.ip_address = "1.1.1.1"
129
- tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
130
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
131
- request_env = {
132
- TCellAgent::Instrumentation::TCELL_ID => tcell_data,
133
- "HTTP_USER_AGENT" => true,
134
- "HTTP_X_FORWARDED_FOR" => true
135
- }
136
-
137
-
138
- expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
139
- login_fraud
140
- )
141
- expect(rails_request).to receive(:env).and_return(request_env)
142
- expect(rails_request).to receive(:env).and_return(request_env)
143
- expect(TCellAgent).to receive(:send_event).with(
144
- {
145
- "event_type" => "login",
146
- "header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
147
- "user_agent" => "user_agent",
148
- "referrer" => "referrer",
149
- "remote_addr" => "1.1.1.1",
150
- "user_id" => "user_id",
151
- "document_uri" => "http://tcell.tcell.io/login?param_name=",
152
- "session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
153
- "event_name" => "login-failure"
154
- }
155
- )
156
-
157
- status = Hooks::V1::Login::LOGIN_FAILURE
158
-
159
- Hooks::V1::Frameworks::Rails::Login.register_login_event(
160
- status, rails_request, "user_id"
161
- )
162
- end
163
- end
164
-
165
- context "with a login success" do
166
- it "should report the login success" do
167
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
168
- rails_request = double("rails_request")
169
- tcell_data = TCellAgent::Instrumentation::TCellData.new
170
- tcell_data.user_agent = "user_agent"
171
- tcell_data.referrer = "referrer"
172
- tcell_data.ip_address = "1.1.1.1"
173
- tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
174
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
175
- request_env = {
176
- TCellAgent::Instrumentation::TCELL_ID => tcell_data,
177
- "HTTP_USER_AGENT" => true,
178
- "HTTP_X_FORWARDED_FOR" => true
179
- }
180
-
181
-
182
- expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
183
- login_fraud
184
- )
185
- expect(rails_request).to receive(:env).and_return(request_env)
186
- expect(rails_request).to receive(:env).and_return(request_env)
187
- expect(TCellAgent).to receive(:send_event).with(
188
- {
189
- "event_type" => "login",
190
- "header_keys" => ["USER_AGENT", "X_FORWARDED_FOR"],
191
- "user_agent" => "user_agent",
192
- "referrer" => "referrer",
193
- "remote_addr" => "1.1.1.1",
194
- "user_id" => "user_id",
195
- "document_uri" => "http://tcell.tcell.io/login?param_name=",
196
- "session" => "48c0ce7961d8d5d4bd57bd77976b3d38",
197
- "event_name" => "login-success"
198
- }
199
- )
200
-
201
- status = Hooks::V1::Login::LOGIN_SUCCESS
202
-
203
- Hooks::V1::Frameworks::Rails::Login.register_login_event(
204
- status, rails_request, "user_id"
205
- )
206
- end
207
- end
208
-
209
- context "with an unknown status" do
210
- it "should log the error" do
211
- login_fraud = double("login_fraud", enabled: true, login_failed_enabled: true)
212
- logger = double("logger")
213
- rails_request = double("rails_request")
214
- tcell_data = TCellAgent::Instrumentation::TCellData.new
215
- tcell_data.user_agent = "user_agent"
216
- tcell_data.referrer = "referrer"
217
- tcell_data.ip_address = "1.1.1.1"
218
- tcell_data.path = "http://tcell.tcell.io/login?param_name=param_value"
219
- tcell_data.hmac_session_id = TCellAgent::SensorEvents::Util.hmac("session_id")
220
- request_env = {
221
- TCellAgent::Instrumentation::TCELL_ID => tcell_data,
222
- "HTTP_USER_AGENT" => true,
223
- "HTTP_X_FORWARDED_FOR" => true
224
- }
225
-
226
-
227
- expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::LoginFraud).and_return(
228
- login_fraud
229
- )
230
- expect(rails_request).to receive(:env).and_return(request_env)
231
- expect(TCellAgent).to_not receive(:send_event)
232
- expect(TCellAgent).to receive(:logger).and_return(logger)
233
- expect(logger).to receive(:error).with("Unkown login status: mumbo-jumbo")
234
-
235
- status = "mumbo-jumbo"
236
-
237
- Hooks::V1::Frameworks::Rails::Login.register_login_event(
238
- status, rails_request, "user_id"
239
- )
240
- end
241
- end
242
- end
243
-
244
- end
245
-
246
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module SensorEvents
5
- module Util
6
- describe Util do
7
- context "Domain from Url" do
8
- it "Test Simple Domain" do
9
- expect(Util.domainFromUrl("https://www.google.com")).to eq("www.google.com")
10
- end
11
- it "Test More Complex Domain" do
12
- expect(Util.domainFromUrl("https://www.test.com:8000/abc/def")).to eq("www.test.com")
13
- end
14
- end
15
- context "abc" do
16
- it "abc" do
17
- expect(Util.wildcardMatch("test","test")).to eq(true)
18
- expect(Util.wildcardMatch("www.google.com","*.google.com")).to eq(true)
19
- expect(Util.wildcardMatch("google.com","*.google.com")).to eq(false)
20
- end
21
- end
22
- end
23
- end
24
- end
25
- end
@@ -1,155 +0,0 @@
1
- {
2
- "version":"20160322",
3
- "sensors":{
4
- "xss":{
5
- "patterns":[
6
- {
7
- "title":"Basic Injection",
8
- "sophistication":1,
9
- "common": "(?:<(script|iframe|embed|frame|frameset|object|img|applet|body|html|style|layer|link|ilayer|meta|bgsound))",
10
- "id": "1"
11
- },
12
- {
13
- "title":"Alert or Event XSS",
14
- "sophistication":2,
15
- "common": "(?:(alert|on\\w+|function\\s+\\w+)\\s*\\(\\s*(['+\\d\\w](,?\\s*['+\\d\\w]*)*)*\\s*\\))",
16
- "id": "2"
17
- },
18
- {
19
- "title":"Tag Breaks",
20
- "sophistication":2,
21
- "common": "(?:\\\"[^\\\"]*[^-]?>)|(?:[^\\w\\s]\\s*\\/>)|(?:>\\\")",
22
- "id": "3"
23
- },
24
- {
25
- "title":"Attribute Breaks",
26
- "sophistication":3,
27
- "common": "(?:\\\"+.*[<=]\\s*\\\"[^\\\"]+\\\")|(?:\\\"\\s*\\w+\\s*=)|(?:>\\w=\\/)|(?:#.+\\)[\\\"\\s]*>)|(?:\\\"\\s*(?:src|style|on\\w+)\\s*=\\s*\\\")|(?:[^\\\"]?\\\"[,;\\s]+\\w*[\\[\\(])(?:^>[\\w\\s]*<\\/?\\w{2,}>)",
28
- "id": "4"
29
- },
30
- {
31
- "title":"Basic Obfuscation",
32
- "sophistication":3,
33
- "common": "(?:[\\\".]script\\s*\\()|(?:\\$\\$?\\s*\\(\\s*[\\w\\\"])|(?:\\/[\\w\\s]+\\/\\.)|(?:=\\s*\\/\\w+\\/\\s*\\.)|(?:(?:this|window|top|parent|frames|self|content)\\[\\s*[(,\\\"]*\\s*[\\w\\$])|(?:,\\s*new\\s+\\w+\\s*[,;)])",
34
- "id": "5"
35
- },
36
- {
37
- "title":"Common Concatenation",
38
- "sophistication":3,
39
- "common": "(?:=\\s*\\w+\\s*\\+\\s*\\\")|(?:\\+=\\s*\\(\\s\\\")|(?:!+\\s*[\\d.,]+\\w?\\d*\\s*\\?)|(?:=\\s*\\[s*\\])|(?:\\\"\\s*\\+\\s*\\\")|(?:[^\\s]\\[\\s*\\d+\\s*\\]\\s*[;+])|(?:\\\"\\s*[&|]+\\s*\\\")|(?:\\/\\s*\\?\\s*\\\")|(?:\\/\\s*\\)\\s*\\[)|(?:\\d\\?.+:\\d)|(?:\\]\\s*\\[\\W*\\w)|(?:[^\\s]\\s*=\\s*\\/)",
40
- "id": "6"
41
- },
42
- {
43
- "title":"IFrame Tag Injection",
44
- "sophistication":1,
45
- "common": "<iframe.*",
46
- "id": "7"
47
- }
48
- ]
49
- },
50
- "cmdi":{
51
- "safe_pattern":"^[a-zA-Z0-9_\\s\\r\\n\\t]*$",
52
- "patterns":[
53
- {
54
- "title":"Common Remote Attempts",
55
- "sophistication":2,
56
- "id":"1",
57
- "common":"(?:[\\;\\|\\`]\\W*?\\bcc|\\b(wget|curl))\\b|\\/cc(?:[\\'\\\"\\|\\;\\`\\-\\s]|$)",
58
- "ruby":"(?i:(?:[\\;\\|\\`]\\W*?\\bcc|\\b(wget|curl))\\b|\\/cc(?:[\\'\\\"\\|\\;\\`\\-\\s]|$))"
59
- },
60
- {
61
- "title":"Common Command Attempts",
62
- "sophistication":1,
63
- "id":"2",
64
- "common":"(?:\\b(?:(?:n(?:et(?:\\b\\W+?\\blocalgroup|\\.exe)|(?:map|c)\\.exe)|t(?:racer(?:oute|t)|elnet\\.exe|clsh8?|ftp)|(?:w(?:guest|sh)|rcmd|ftp)\\.exe|echo\\b\\W*?\\by+)\\b|c(?:md(?:(?:\\.exe|32)\\b|\\b\\W*?\\\\\\/c)|d(?:\\b\\W*?[\\\\\\/]|\\W*?\\.\\.)|hmod.{0,40}?\\+.{0,3}x))|[\\;\\|\\`]\\W*?\\b(?:(?:c(?:h(?:grp|mod|own|sh)|md|pp)|p(?:asswd|ython|erl|ing|s)|n(?:asm|map|c)|f(?:inger|tp)|(?:kil|mai)l|(?:xte)?rm|ls(?:of)?|telnet|uname|echo|id)\\b|g(?:\\+\\+|cc\\b)))"
65
- }
66
- ]
67
- },
68
- "sqli":{
69
- "safe_pattern":"^[a-zA-Z0-9_\\s\\r\\n\\t]*$",
70
- "patterns":[
71
- {
72
- "title":"Common Encoding Obfuscations",
73
- "sophistication":3,
74
- "common": "(?:(?:\\d[\\\"'`\u00b4\u2019\u2018]\\s+[\\\"'`\u00b4\u2019\u2018]\\s+\\d)|(?:^admin\\s*?[\\\"'`\u00b4\u2019\u2018]|(\\/\\*)+[\\\"'`\u00b4\u2019\u2018]+\\s?(?:--|#|\\/\\*|{)?)|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?\\b(x?or|div|like|between|and)\\b\\s*?[+<>=(),-]\\s*?[\\d\\\"'`\u00b4\u2019\u2018])|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?[^\\w\\s]?=\\s*?[\\\"'`\u00b4\u2019\u2018])|(?:[\\\"'`\u00b4\u2019\u2018]\\W*?[+=]+\\W*?[\\\"'`\u00b4\u2019\u2018])|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?[!=|][\\d\\s!=+-]+.*?[\\\"'`\u00b4\u2019\u2018(].*?$)|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?[!=|][\\d\\s!=]+.*?\\d+$)|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?like\\W+[\\w\\\"'`\u00b4\u2019\u2018(])|(?:\\sis\\s*?0\\W)|(?:where\\s[\\s\\w\\.,-]+\\s=)|(?:[\\\"'`\u00b4\u2019\u2018][<>~]+[\\\"'`\u00b4\u2019\u2018]))",
75
- "id": "1"
76
- },
77
- {
78
- "title":"Common Probes/Executions",
79
- "sophistication":1,
80
- "common": "\\b(?:having)\\b\\s+(\\d{1,10}|'[^=]{1,10}')\\s*?[=<>]|(?:\\bexecute(\\s{1,5}[\\w\\.$]{1,5}\\s{0,3})?\\()|\\bhaving\\b ?(?:\\d{1,10}|[\\'\\\"][^=]{1,10}[\\'\\\"]) ?[=<>]+|(?:\\bcreate\\s+?table.{0,20}?\\()|(?:\\blike\\W*?char\\W*?\\()|(?:(?:(select(.*?)case|from(.*?)limit|order\\sby)))|exists\\s(\\sselect|select\\Sif(null)?\\s\\(|select\\Stop|select\\Sconcat|system\\s\\(|\\b(?:having)\\b\\s+(\\d{1,10})|'[^=]{1,10}')",
81
- "id": "2"
82
- },
83
- {
84
- "title":"Comment Injection",
85
- "sophistication":1,
86
- "common": "([';]--|--[\\s\\r\\n\\v\\f]|(?:--[^-]*?-)|([^\\-&])#.*?[\\s\\r\\n\\v\\f]|;?\\\\x00)",
87
- "id": "3"
88
- },
89
- {
90
- "title":"Extraction Attempts 1",
91
- "sophistication":1,
92
- "common": "(?:(?:@.+=\\s*?\\(\\s*?select)|(?:\\d+\\s*?(x?or|div|like|between|and)\\s*?\\d+\\s*?[\\-+])|(?:\\/\\w+;?\\s+(?:having|and|x?or|div|like|between|and|select)\\W)|(?:\\d\\s+group\\s+by.+\\()|(?:(?:;|#|--)\\s*?(?:drop|alter))|(?:(?:;|#|--)\\s*?(?:update|insert)\\s*?\\w{2,})|(?:[^\\w]SET\\s*?@\\w+)|(?:(?:n?and|x?x?or|div|like|between|and|not |\\|\\||\\&\\&)[\\s(]+\\w+[\\s)]*?[!=+]+[\\s\\d]*?[\\\"'`\u00b4\u2019\u2018=()]))",
93
- "id": "4"
94
- },
95
- {
96
- "title":"Extraction Attempts 2",
97
- "sophistication":2,
98
- "pattern": "(?:(?:in\\s*?\\(+\\s*?select)|(?:(?:n?and|x?x?or|div|like|between|and|not |\\|\\||\\&\\&)\\s+[\\s\\w+]+(?:regexp\\s*?\\(|sounds\\s+like\\s*?[\\\"'`\u00b4\u2019\u2018]|[=\\d]+x))|([\\\"'`\u00b4\u2019\u2018]\\s*?\\d\\s*?(?:--|#))|(?:[\\\"'`\u00b4\u2019\u2018][\\%&<>^=]+\\d\\s*?(=|x?or|div|like|between|and))|(?:[\\\"'`\u00b4\u2019\u2018]\\W+[\\w+-]+\\s*?=\\s*?\\d\\W+[\\\"'`\u00b4\u2019\u2018])|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?is\\s*?\\d.+[\\\"'`\u00b4\u2019\u2018]?\\w)|(?:[\\\"'`\u00b4\u2019\u2018]\\|?[\\w-]{3,}[^\\w\\s.,]+[\\\"'`\u00b4\u2019\u2018])|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?is\\s*?[\\d.]+\\s*?\\W.*?[\\\"'`\u00b4\u2019\u2018]))",
99
- "id": "5"
100
- },
101
- {
102
- "title":"Extraction Attempts 3",
103
- "sophistication":3,
104
- "pattern": "(?:(?:\\d[\\\"'`\u00b4\u2019\u2018]\\s+[\\\"'`\u00b4\u2019\u2018]\\s+\\d)|(?:^admin\\s*?[\\\"'`\u00b4\u2019\u2018]|(\\/\\*)+[\\\"'`\u00b4\u2019\u2018]+\\s?(?:--|#|\\/\\*|{)?)|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?\\b(x?or|div|like|between|and)\\b\\s*?[+<>=(),-]\\s*?[\\d\\\"'`\u00b4\u2019\u2018])|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?[^\\w\\s]?=\\s*?[\\\"'`\u00b4\u2019\u2018])|(?:[\\\"'`\u00b4\u2019\u2018]\\W*?[+=]+\\W*?[\\\"'`\u00b4\u2019\u2018])|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?[!=|][\\d\\s!=+-]+.*?[\\\"'`\u00b4\u2019\u2018(].*?$)|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?[!=|][\\d\\s!=]+.*?\\d+$)|(?:[\\\"'`\u00b4\u2019\u2018]\\s*?like\\W+[\\w\\\"'`\u00b4\u2019\u2018(])|(?:\\sis\\s*?0\\W)|(?:where\\s[\\s\\w\\.,-]+\\s=)|(?:[\\\"'`\u00b4\u2019\u2018][<>~]+[\\\"'`\u00b4\u2019\u2018]))",
105
- "id": "6"
106
- }
107
- ]
108
- },
109
- "fpt":{
110
- "patterns":[
111
- {
112
- "title":"Windows Probing",
113
- "sophistication":1,
114
- "common": "(?:(?:\\/|\\\\)?\\.+(\\/|\\\\)(?:\\.+)?)|(?:\\w+\\.exe\\??\\s)|(?:;\\s*\\w+\\s*\\/[\\w*-]+\\/)|(?:\\d\\.\\dx\\|)|(?:%(?:c0\\.|af\\.|5c\\.))|(?:\\/(?:%2e){2})",
115
- "ruby": "(?:(?:\\/|\\\\)?\\.+(\\/|\\\\)(?:\\.*))|(?:\\w+\\.exe\\??\\s)|(?:;\\s*\\w+\\s*\\/[\\w*-]+\\/)|(?:\\d\\.\\dx\\|)|(?:%(?:c0\\.|af\\.|5c\\.))|(?:\\/(?:%2e){2})",
116
- "id": "1"
117
- },
118
- {
119
- "title":"Unix Probing",
120
- "sophistication":1,
121
- "common": "(?:%c0%ae\\/)|(?:(?:\\/|\\\\)(home|conf|usr|etc|proc|opt|s?bin|local|dev|tmp|kern|[br]oot|sys|system|windows|winnt|program|%[a-z_-]{3,}%)(?:\\/|\\\\))|(?:(?:\\/|\\\\)inetpub|localstart\\.asp|boot\\.ini)",
122
- "id": "2"
123
- },
124
- {
125
- "title":"Attempt for /etc/passwd",
126
- "sophistication":1,
127
- "common": "(?:etc\\/\\W*passwd)",
128
- "id": "3"
129
- }
130
- ]
131
- },
132
- "nullbyte":{
133
- "safe_pattern":"^[a-zA-Z0-9_\\s\\r\\n\\t]*$",
134
- "patterns":[
135
- {
136
- "title":"Any Null Byte",
137
- "sophistication":1,
138
- "id":"1",
139
- "common":"\\0"
140
- }
141
- ]
142
- },
143
- "retr":{
144
- "safe_pattern":"^[a-zA-Z0-9_\\s\\r\\n\\t]*$",
145
- "patterns":[
146
- {
147
- "title":"Any Line-Break Character",
148
- "sophistication":1,
149
- "id":"1",
150
- "common":"(\\n|\\r)"
151
- }
152
- ]
153
- }
154
- }
155
- }