lents_adutils 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.4
2
+ Name: lents_adutils
3
+ Version: 0.1.0
4
+ Summary:
5
+ Author: Antonio Lentini
6
+ Author-email: 111151429+lentscode@users.noreply.github.com
7
+ Requires-Python: >=3.14
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.14
10
+ Requires-Dist: requests (>=2.34.2,<3.0.0)
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Utils for Attack&Defense CTFs
14
+
@@ -0,0 +1 @@
1
+ # Utils for Attack&Defense CTFs
@@ -0,0 +1,24 @@
1
+ [project]
2
+ name = "lents_adutils"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = [
6
+ {name = "Antonio Lentini",email = "111151429+lentscode@users.noreply.github.com"}
7
+ ]
8
+ readme = "README.md"
9
+ requires-python = ">=3.14"
10
+ dependencies = [
11
+ "requests (>=2.34.2,<3.0.0)"
12
+ ]
13
+
14
+ [tool.poetry]
15
+ packages = [{include = "adutils", from = "src"}]
16
+
17
+ [build-system]
18
+ requires = ["poetry-core>=2.0.0,<3.0.0"]
19
+ build-backend = "poetry.core.masonry.api"
20
+
21
+ [dependency-groups]
22
+ dev = [
23
+ "black (>=26.5.1,<27.0.0)"
24
+ ]
@@ -0,0 +1 @@
1
+ from adutils.exploit import Exploit
@@ -0,0 +1,81 @@
1
+ from abc import ABC, abstractmethod
2
+ from concurrent.futures import ThreadPoolExecutor
3
+ from requests import put, get
4
+ from requests.exceptions import ConnectTimeout
5
+ from time import sleep
6
+ from json import loads
7
+
8
+
9
+ class Exploit(ABC):
10
+ def __init__(
11
+ self,
12
+ port: int,
13
+ team_token: str,
14
+ n_teams: int = 80,
15
+ sleep_interval: int = 60,
16
+ ignore: list[int] = [],
17
+ verbose: bool = True,
18
+ submit_url: str = "http://10.10.0.1/flags",
19
+ submit_timeout: int = 5,
20
+ flag_ids_url: str = "http://10.10.0.1:8081/flagIds",
21
+ ):
22
+ self.port = port
23
+ self.team_token = team_token
24
+ self.n_teams = n_teams
25
+ self.sleep_interval = sleep_interval
26
+ self.ignore = ignore
27
+ self.flags: list[str] = []
28
+ self.verbose = verbose
29
+ self.submit_url = submit_url
30
+ self.submit_timeout = submit_timeout
31
+ self.flag_ids_url = flag_ids_url
32
+ self.flag_ids: dict = {}
33
+
34
+ def generate_ip(self, team_id: int) -> str:
35
+ return f"10.80.{team_id}.1"
36
+
37
+ def get_flag_ids(self):
38
+ response = get(self.flag_ids_url)
39
+ self.flag_ids = loads(response.content)
40
+
41
+ def flagout(self, flag: str):
42
+ if self.verbose:
43
+ print(f"Found flag = {flag}")
44
+ self.flags.append(flag)
45
+
46
+ @abstractmethod
47
+ def run(self, ip: str):
48
+ pass
49
+
50
+ def submit_flags(self):
51
+ try:
52
+ put(
53
+ self.submit_url,
54
+ headers={"X-Team-Token": self.team_token},
55
+ json=self.flags,
56
+ timeout=self.submit_timeout,
57
+ )
58
+ except ConnectTimeout as e:
59
+ print(f"[submit_flags] TIMEOUT: {e}")
60
+
61
+ def start(self):
62
+ while True:
63
+ self.get_flag_ids()
64
+ with ThreadPoolExecutor() as executor:
65
+ ips: list[str] = []
66
+ for i in range(self.n_teams):
67
+ if i in self.ignore:
68
+ continue
69
+
70
+ ip = self.generate_ip(i)
71
+ ips.append(ip)
72
+ list(executor.map(self.run, ips))
73
+
74
+ if self.verbose:
75
+ print(
76
+ f"Submitting {len(self.flags)} flags to {self.submit_url} with token {self.team_token}"
77
+ )
78
+ self.submit_flags()
79
+ if self.verbose:
80
+ print(f"Sleeping for {self.sleep_interval} before next cycle")
81
+ sleep(self.sleep_interval)