test.py 936 B

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. """LOIC against a local http.server: verify N requests reach the target."""
  3. import sys, os, time
  4. sys.path.insert(0, os.path.abspath("test"))
  5. from _lib.local_target import http_target
  6. from core.mods.loic import ionize, LOIC
  7. err = []
  8. class Holder:
  9. def __init__(self, agents):
  10. self.agents = agents
  11. self.user_agent = agents[0]
  12. self.payload = ""
  13. self.attack_mode = "loic"
  14. h = Holder(["Mozilla/5.0 (UFONet-test)"])
  15. rounds = 7
  16. with http_target() as (port, counter):
  17. target = f"http://127.0.0.1:{port}/test"
  18. ionize(h, target, rounds, None)
  19. _deadline = time.time() + 3
  20. while counter["get"] < rounds and time.time() < _deadline:
  21. time.sleep(0.1)
  22. hits = counter["get"]
  23. if hits != rounds:
  24. err.append(f"expected {rounds} GET hits, got {hits}")
  25. print(f"loic_rounds={rounds} hits={hits}")
  26. for e in err:
  27. print("FAIL:", e)
  28. sys.exit(0 if not err else 1)