@@ -220,11 +220,12 @@ def get_deep_security_info(self):
220
220
"""
221
221
self ._log ("Requesting information from Deep Security about your deployment" , priority = True )
222
222
if self .dsm :
223
- self .dsm .get_all ()
223
+ self .dsm .policies .get ()
224
+ self .dsm .computer_groups .get ()
224
225
self ._log ("Requesting rules from the Deep Security manager. This will take a few seconds..." )
225
- self .dsm .get_all_rules ()
226
+ self .dsm .rules . get ()
226
227
self ._log ("Requesting computers from the Deep Security manager. This will take a few seconds..." )
227
- self .dsm .get_computers_with_details ()
228
+ self .dsm .computers . get ()
228
229
self ._log ("Requested information from the Deep Security manager cached locally" )
229
230
230
231
def compare_ec2_to_deep_security (self ):
@@ -236,7 +237,7 @@ def compare_ec2_to_deep_security(self):
236
237
recommendations = {}
237
238
if self .dsm and self .dsm .computers and self .instances :
238
239
for computer_id , computer_details in self .dsm .computers .items ():
239
- ds_instance_map [computer_details .cloud_object_instance_id ] = computer_id
240
+ ds_instance_map [computer_details .cloud_instance_id ] = computer_id
240
241
241
242
for instance_id , instance_details in self .instances .items ():
242
243
if ds_instance_map .has_key (instance_id ):
@@ -258,8 +259,8 @@ def does_rule_match_sqli(self, rule):
258
259
sqli_recommended = True
259
260
260
261
if 'application_type_id' in dir (rule ):
261
- if self .dsm .application_types .has_key (rule .application_type_id ):
262
- if self .dsm .application_types [rule .application_type_id ].tbuid in self .tbuids :
262
+ if self .dsm .rules [ ' application_types' ] .has_key (rule .application_type_id ):
263
+ if self .dsm .rules [ ' application_types' ] [rule .application_type_id ].tbuid in self .tbuids :
263
264
sqli_recommended = True
264
265
265
266
for pattern in self .patterns :
@@ -278,43 +279,46 @@ def analyze_computer(self, ds_computer_id):
278
279
Analyze the specified computer to determine if it should be
279
280
protected by SQLi rules
280
281
"""
281
- self ._log ("Analyzing computer {}:{}" .format (ds_computer_id , self .dsm .computers [ds_computer_id ].hostname ))
282
+ self ._log ("Analyzing computer {}:{}" .format (ds_computer_id , self .dsm .computers [ds_computer_id ].name ))
282
283
recommendation = False
283
- self .dsm .get_recommended_rules_for_computer (ds_computer_id )
284
+ self .dsm .get_rule_recommendations_for_computer (ds_computer_id )
284
285
computer = self .dsm .computers [ds_computer_id ]
285
286
sqli_recommendations = []
286
-
287
- # check at the policy level
288
- if computer .policy_id :
289
- self ._log ("Computer is protected by Deep Security. Checking rules" )
290
- for rule_type in [
291
- 'integrity_monitoring_rules' ,
292
- 'log_inspection_rules' ,
293
- 'intrusion_prevention_rules'
294
- ]:
295
- if self .dsm .policies .has_key (computer .policy_id ):
296
- rule_set = getattr (self .dsm .policies [computer .policy_id ], rule_type )
297
- if rule_set : # policy has these type of rules applied
298
- for rule_id in getattr (self .dsm .policies [computer .policy_id ], rule_type )[- 1 ]:
299
- rule = self .dsm .rules [rule_type .replace ('_rules' , '' )][rule_id ]
300
- if self .does_rule_match_sqli (rule ): sqli_recommendations .append (rule )
287
+
288
+ if 'cloud_instance_id' in dir (computer ) and computer .cloud_instance_id and computer .cloud_instance_id .startswith ('i-' ):
289
+ # this is an AWS instance
290
+
291
+ # check at the policy level
292
+ if computer .policy_id :
293
+ self ._log ("Computer is protected by Deep Security. Checking rules" )
294
+ for rule_type in [
295
+ 'integrity_monitoring_rule_ids' ,
296
+ 'intrusion_prevention_rule_ids' ,
297
+ 'log_inspection_rule_ids'
298
+ # application_types
299
+ ]:
300
+ if self .dsm .policies .has_key (computer .policy_id ):
301
+ rule_set = getattr (self .dsm .policies [computer .policy_id ], rule_type )
302
+ if rule_set and rule_set .has_key ('item' ): # policy has these type of rules applied
303
+ for rule_id in rule_set ['item' ]:
304
+ rule = self .dsm .rules [rule_type .replace ('_rule_ids' , '' )][rule_id ]
305
+ if self .does_rule_match_sqli (rule ): sqli_recommendations .append (rule )
306
+ else :
307
+ self ._log ("Instance {} has no rules of type {} applied" .format (computer .cloud_instance_id , rule_type ))
301
308
else :
302
- self ._log ("Instance {} has no rules of type {} applied" .format (computer .cloud_object_instance_id , rule_type ))
303
- else :
304
- self ._log ("Policy {} is not available for analysis" .format (computer .policy_id ))
305
- else :
306
- self ._log ("Deep Security is aware of the instance but is not protecting it with a policy" )
307
- recommendation = None
308
-
309
- # now check for any recommendations to the computer
310
- for rule_type , rules in computer .recommended_rules .items ():
311
- self ._log ("Checking for recommended {} rules" .format (rule_type ))
312
- for rule_id , rule in rules .items ():
313
- if self .does_rule_match_sqli (rule ): sqli_recommendations .append (rule )
314
-
315
- for application_type_id , application_type in computer .application_types .items ():
316
- if application_type .tbuid in self .tbuids :
317
- sqli_recommendations .append (application_type )
309
+ self ._log ("Policy {} is not available for analysis" .format (computer .policy_id ))
310
+ else :
311
+ self ._log ("Deep Security is aware of the instance but is not protecting it with a policy" )
312
+ recommendation = None
313
+
314
+ # now check for any recommendations to the computer
315
+ if computer .recommended_rules :
316
+ for rule_type , rules in computer .recommended_rules .items ():
317
+ self ._log ("Checking for recommended {} rules" .format (rule_type ))
318
+ for rule_id , rule in rules .items ():
319
+ if self .does_rule_match_sqli (rule ): sqli_recommendations .append (rule )
320
+ else :
321
+ self ._log ("There are no rule recommendations for instance {}" .format (computer .cloud_instance_id ))
318
322
319
323
if len (sqli_recommendations ) > 1 :
320
324
recommendation = True if len (sqli_recommendations ) > 0 else False
0 commit comments