class PopulateTargetsCommand(object): def __init__(self): self.target_service = TargetService() self.location_service = LocationService() def execute(self): for h in settings.HONEYPOTS: if not self.target_service.get_model(ip=h['ip']): location = self.location_service.create_model(**h['location']) self.target_service.create_model( ip=h['ip'], location=location )
class ConvertToCyberAttacksCommand(object): def __init__(self, raw_cyber_attacks): self.raw_cyber_attacks = raw_cyber_attacks self.cyber_attack_service = CyberAttackService() self.attacker_service = AttackerService() self.target_service = TargetService() self.timestamp_service = TimestampService() self.location_service = LocationService() def execute(self): PopulateTargetsCommand().execute() for raw_cyber_attack in self.raw_cyber_attacks: raw_timestamp = datetime.fromtimestamp(raw_cyber_attack.time) raw_attacker_location = IPLookUpCommand(raw_cyber_attack.source_ip).execute() self.cyber_attack_service.create_model( timestamp=self.timestamp_service.create_model( hour=raw_timestamp.hour, minute=raw_timestamp.minute, second=raw_timestamp.second ), attacker=self.attacker_service.create_model( ip=raw_cyber_attack.source_ip, location=self.location_service.create_model( city=raw_attacker_location['city'], state=raw_attacker_location['state'], country=raw_attacker_location['country'], latitude=raw_attacker_location['latitude'], longitude=raw_attacker_location['longitude'] ) ), target=self.target_service.get_model(ip=raw_cyber_attack.dest_ip), source_port=raw_cyber_attack.source_port, destination_port=raw_cyber_attack.dest_port, service=raw_cyber_attack.service )