async def test_several_stable_cohorts_increase_concurrency(self): policy = SlowStartPolicy(initial=3, cohort_size=1) await policy.record(duration=10.5) await policy.record(duration=10.5) await policy.record(duration=10.5) assert policy.concurrency > 3
async def configure_hammertime(proxy=None, retry_count=3, cookies=None, concurrency=0, **kwargs): loop = custom_event_loop() engine = AioHttpEngine(loop=loop, verify_ssl=False, proxy=proxy) await engine.session.close() connector = TCPConnector(loop=loop, verify_ssl=False, use_dns_cache=True, ttl_dns_cache=None) if cookies is not None: engine.session = ClientSession(loop=loop, connector=connector, cookie_jar=DummyCookieJar(loop=loop)) else: engine.session = ClientSession(loop=loop, connector=connector) scale_policy = SlowStartPolicy(initial=3) if concurrency > 0: scale_policy = StaticPolicy(concurrency) kb = KnowledgeBase() hammertime = HammerTime(loop=loop, request_engine=engine, retry_count=retry_count, proxy=proxy, kb=kb, scale_policy=scale_policy) setup_hammertime_heuristics(hammertime, **kwargs) hammertime.collect_successful_requests() hammertime.kb = kb return hammertime
def initialize_hammertime(self, proxy=None, verify_ssl=True, ca_certificate_file=None, concurrency=0): loop = custom_event_loop() if proxy is not None and verify_ssl and ca_certificate_file is None: self.output_manager.log_message( "Verifying SSL authentication of the target over a proxy without providing " "a CA certificate. Scan may fail if target is a https website." ) scale_policy = SlowStartPolicy(initial=3) if concurrency > 0: scale_policy = StaticPolicy(concurrency) request_engine = AioHttpEngine(loop=loop, verify_ssl=verify_ssl, ca_certificate_file=ca_certificate_file) self.hammertime = HammerTime(loop=loop, retry_count=3, proxy=proxy, request_engine=request_engine, scale_policy=scale_policy) self.config_hammertime()
async def test_large_increase_reverts(self): policy = SlowStartPolicy(initial=3, cohort_size=1) await policy.record(duration=15) # Discard b = await policy.record(duration=10.5) # Stay c = await policy.record(duration=10.5) # Scale up d = await policy.record(duration=11.5) # Discard e = await policy.record(duration=12.7) # Backtrack / cooldown assert c == d and b > e
async def test_slight_decrease_is_accepted(self): policy = SlowStartPolicy(initial=3, cohort_size=1) await policy.record(duration=15) # Discard await policy.record(duration=10.5) # Stay await policy.record(duration=10.5) # Scale up d = await policy.record(duration=11.5) # Discard e = await policy.record(duration=10.498) # Scale up assert e > d
async def test_intermim_cohorts_get_discarded(self): policy = SlowStartPolicy(initial=3, cohort_size=1) await policy.record(duration=15) # Discard await policy.record(duration=10.5) # Stay c = await policy.record(duration=10.5) # Scale up d = await policy.record(duration=11.5) # Discard e = await policy.record(duration=10.5) # Scale up assert c == d and e > d
async def test_not_scaling_back_up_after_ceiling_reached(self): policy = SlowStartPolicy(initial=3, cohort_size=1) await policy.record(duration=15) # Discard b = await policy.record(duration=10.5) # Stay await policy.record(duration=10.5) # Scale up await policy.record(duration=11.5) # Discard e = await policy.record(duration=12.7) # Backtrack / cooldown await policy.record(duration=10.7) # Discard g = await policy.record(duration=10.5) # Scale back up h = await policy.record(duration=10.5) # Stay assert b > e and b > g and g == h
async def test_initial_cohort_cannot_cause_change(self): policy = SlowStartPolicy(initial=3, cohort_size=1) await policy.record(duration=10.5) assert policy.concurrency == 3
async def test_initial_scale_target(self): policy = SlowStartPolicy(initial=3) assert policy.concurrency == 3