def test_same_round_different_batch(self, Sniffer): # Mock captured parameteres for Sniffer capture0 = {'data': 'exlength', 'records': 1} capture1 = {'data': 'length', 'records': 1} instance = Sniffer.return_value instance.read.return_value = capture0 # Mock initial round mock_target = Target.objects.create( endpoint='https://di.uoa.gr/?breach=%s', prefix='test', alphabet='0123456789', name='webuoagr', confidence_threshold=1.0 ) dif_batch_victim = Victim.objects.create( target=mock_target, sourceip='192.168.10.141', snifferendpoint='http://localhost/' ) dif_batch_round = Round.objects.create( victim=dif_batch_victim, amount=1, knownsecret='testsecret', knownalphabet='01', ) self.dif_batch_samplesets = [ SampleSet.objects.create( round=dif_batch_round, candidatealphabet='0', data=hexlify('length2') ), SampleSet.objects.create( round=dif_batch_round, candidatealphabet='1', data=hexlify('length') ) ] strategy0 = Strategy(dif_batch_victim) work0 = strategy0.get_work() strategy0.work_completed() instance.read.return_value = capture1 strategy1 = Strategy(dif_batch_victim) work1 = strategy1.get_work() strategy1.work_completed() dif_batch_strategy0 = Strategy(dif_batch_victim) dif_batch_work0 = dif_batch_strategy0.get_work() dif_batch_strategy1 = Strategy(dif_batch_victim) dif_batch_work1 = dif_batch_strategy1.get_work() # Check if new Samplesets are equal to the original ones. self.assertEqual(dif_batch_work0, work0) self.assertEqual(dif_batch_work1, work1)
def test_advance_round(self, Sniffer): # Mock captured parameteres for Sniffer capture0 = {'data': 'bigbignextround', 'records': 1} capture1 = {'data': 'smallround', 'records': 1} instance = Sniffer.return_value instance.read.return_value = capture0 # Mock initial round mock_target = Target.objects.create( endpoint='https://di.uoa.gr/?breach=%s', prefix='test', alphabet='0123456789', name='ruptureit' ) next_round_victim = Victim.objects.create( target=mock_target, sourceip='192.168.10.141', snifferendpoint='http://localhost/' ) next_round = Round.objects.create( victim=next_round_victim, amount=1, knownsecret='testsecret', knownalphabet='01', ) next_round_samplesets = [ SampleSet.objects.create( round=next_round, candidatealphabet='0', data='bigbignextround' ), SampleSet.objects.create( round=next_round, candidatealphabet='1', data='smallround' ) ] strategy0 = Strategy(next_round_victim) work0 = strategy0.get_work() self.assertTrue(work0) self.assertFalse(strategy0.work_completed()) instance.read.return_value = capture1 strategy1 = Strategy(next_round_victim) work1 = strategy1.get_work() self.assertTrue(work1) self.assertFalse(strategy1.work_completed()) new_round_strategy = Strategy(next_round_victim) new_round_work = new_round_strategy.get_work() self.assertEqual( new_round_work['url'], 'https://di.uoa.gr/?breach=^1^3^2^5^4^7^6^9^8^testsecret10^' )
def test_same_round_different_batch(self, Sniffer): # Mock captured parameteres for Sniffer capture0 = {'data': 'exlength', 'records': 1} capture1 = {'data': 'length', 'records': 1} instance = Sniffer.return_value instance.read.return_value = capture0 # Mock initial round mock_target = Target.objects.create( endpoint='https://di.uoa.gr/?breach=%s', prefix='test', alphabet='0123456789', name='webuoagr', confidence_threshold=1.0) dif_batch_victim = Victim.objects.create( target=mock_target, sourceip='192.168.10.141', snifferendpoint='http://localhost/') dif_batch_round = Round.objects.create( victim=dif_batch_victim, amount=1, knownsecret='testsecret', knownalphabet='01', ) self.dif_batch_samplesets = [ SampleSet.objects.create(round=dif_batch_round, candidatealphabet='0', data=hexlify('length2')), SampleSet.objects.create(round=dif_batch_round, candidatealphabet='1', data=hexlify('length')) ] strategy0 = Strategy(dif_batch_victim) work0 = strategy0.get_work() strategy0.work_completed() instance.read.return_value = capture1 strategy1 = Strategy(dif_batch_victim) work1 = strategy1.get_work() strategy1.work_completed() dif_batch_strategy0 = Strategy(dif_batch_victim) dif_batch_work0 = dif_batch_strategy0.get_work() dif_batch_strategy1 = Strategy(dif_batch_victim) dif_batch_work1 = dif_batch_strategy1.get_work() # Check if new Samplesets are equal to the original ones. self.assertEqual(dif_batch_work0, work0) self.assertEqual(dif_batch_work1, work1)
def test_advance_round(self, Sniffer): # Mock captured parameteres for Sniffer capture0 = {'data': 'bigbignextround', 'records': 1} capture1 = {'data': 'smallround', 'records': 1} instance = Sniffer.return_value instance.read.return_value = capture0 # Mock initial round mock_target = Target.objects.create( endpoint='https://di.uoa.gr/?breach=%s', prefix='test', alphabet='0123456789', name='ruptureit') next_round_victim = Victim.objects.create( target=mock_target, sourceip='192.168.10.141', snifferendpoint='http://localhost/') next_round = Round.objects.create( victim=next_round_victim, amount=1, knownsecret='testsecret', knownalphabet='01', ) next_round_samplesets = [ SampleSet.objects.create(round=next_round, candidatealphabet='0', data='bigbignextround'), SampleSet.objects.create(round=next_round, candidatealphabet='1', data='smallround') ] strategy0 = Strategy(next_round_victim) work0 = strategy0.get_work() self.assertTrue(work0) self.assertFalse(strategy0.work_completed()) instance.read.return_value = capture1 strategy1 = Strategy(next_round_victim) work1 = strategy1.get_work() self.assertTrue(work1) self.assertFalse(strategy1.work_completed()) new_round_strategy = Strategy(next_round_victim) new_round_work = new_round_strategy.get_work() self.assertEqual( new_round_work['url'], 'https://di.uoa.gr/?breach=^1^3^2^5^4^7^6^9^8^testsecret10^')
def work_completed(request, victim_id=0): assert (victim_id) realtime_parameters = json.loads(request.body.decode('utf-8')) assert ('success' in realtime_parameters) success = realtime_parameters['success'] try: victim = Victim.objects.get(pk=victim_id) except: raise Http404('Victim not found') strategy = Strategy(victim) victory = strategy.work_completed(success) return JsonResponse({'victory': victory})
def work_completed(request, victim_id=0): assert(victim_id) realtime_parameters = json.loads(request.body.decode('utf-8')) assert('success' in realtime_parameters) success = realtime_parameters['success'] try: victim = Victim.objects.get(pk=victim_id) except: raise Http404('Victim not found') strategy = Strategy(victim) victory = strategy.work_completed(success) return JsonResponse({ 'victory': victory })