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 CyberAttackServiceIntegrationTestCase(TestCase): def setUp(self): self.timestamp_service = TimestampService() self.location_service = LocationService() self.attacker_service = AttackerService() self.target_service = TargetService() self.cyber_attack_service = CyberAttackService() self.cyber_attack = self.cyber_attack_service.create_model( timestamp=self.timestamp_service.create_model(hour=1, minute=2, second=3), attacker=self.attacker_service.create_model( ip='123.123.123.123', location=self.location_service.create_model( city='fooCity', state='fooState', country='fooCountry', latitude=44, longitude=-70 ) ), target=self.target_service.create_model( ip='999.999.999.999', location=self.location_service.create_model( city='barCity', state='barState', country='barCountry', latitude=50, longitude=-75 ) ), source_port=44, destination_port=22, service='ssh' ) def test_init(self): """ Test the init method. :raise AssertionError: """ self.assertEqual(CyberAttack, self.cyber_attack_service.model) def test_get(self): self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(timestamp=self.cyber_attack.timestamp)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(attacker=self.cyber_attack.attacker)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(target=self.cyber_attack.target)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(timestamp__hour=self.cyber_attack.timestamp.hour)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(timestamp__minute=self.cyber_attack.timestamp.minute)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(timestamp__second=self.cyber_attack.timestamp.second)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(attacker__ip=self.cyber_attack.attacker.ip)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(attacker__location__city=self.cyber_attack.attacker.location.city)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(attacker__location__state=self.cyber_attack.attacker.location.state)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(attacker__location__country=self.cyber_attack.attacker.location.country)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(target__ip=self.cyber_attack.target.ip)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(target__location__latitude=self.cyber_attack.target.location.latitude)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(target__location__longitude=self.cyber_attack.target.location.longitude)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(target__location__city=self.cyber_attack.target.location.city)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(target__location__state=self.cyber_attack.target.location.state)) self.assertEqual(self.cyber_attack, self.cyber_attack_service.get_model(target__location__country=self.cyber_attack.target.location.country))
class DemoAttacksCommand(object): def __init__(self): self.cyber_attack_service = CyberAttackService() self.attacker_service = AttackerService() self.target_service = TargetService() self.timestamp_service = TimestampService() self.location_service = LocationService() def execute(self): cyber_attack_generator = self.__generate_cyber_attacks(40) return [cyber_attack for cyber_attack in cyber_attack_generator] def __generate_cyber_attacks(self, amount): attacker_locations = [ { 'city': 'Moscow', 'state': '', 'country': 'Russia', 'latitude': 1, 'longitude': 1 }, { 'city': 'Berlin', 'state': '', 'country': 'Germany', 'latitude': 1, 'longitude': 1 }, { 'city': 'Pyongyang', 'state': '', 'country': 'North Korea', 'latitude': 1, 'longitude': 1 } ] target_locations = [ { 'city': 'Portland', 'state': 'ME', 'country': 'US', 'latitude': 43.6615, 'longitude': -70.2553 }, { 'city': 'Bangor', 'state': 'ME', 'country': 'US', 'latitude': 44.8012, 'longitude': -68.7778 }, { 'city': 'Augusta', 'state': 'ME', 'country': 'US', 'latitude': 44.3106, 'longitude': -69.7795 } ] services = [ { 'port': 22, 'type': 'ssh' }, { 'port': 80, 'type': 'http' }, { 'port': 115, 'type': 'sftp' } ] start_time = datetime.now() for i in range(amount): dummy_time = start_time - timedelta(seconds=60-((i+1)*1.5)) dummy_attacker_location = random.choice(attacker_locations) dummy_target_location = random.choice(target_locations) dummy_service = random.choice(services) cyberattack = self.cyber_attack_service.create_model( timestamp=self.timestamp_service.create_model( hour=dummy_time.hour, minute=dummy_time.minute, second=dummy_time.second ), attacker=self.attacker_service.create_model( ip='111.111.111.111', location=self.location_service.create_model( city=dummy_attacker_location['city'], state=dummy_attacker_location['state'], country=dummy_attacker_location['country'], latitude=dummy_attacker_location['latitude'], longitude=dummy_attacker_location['longitude'] ) ), target=self.target_service.create_model( ip='222.222.222.{0}'.format(i), location=self.location_service.create_model( city=dummy_target_location['city'], state=dummy_target_location['state'], country=dummy_target_location['country'], latitude=dummy_target_location['latitude'], longitude=dummy_target_location['longitude'] ) ), source_port=0, destination_port=dummy_service['port'], service=dummy_service['type'] ) yield cyberattack