attackmap-analyzer-omeka-s 0.1.0__py3-none-any.whl

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.

Potentially problematic release.


This version of attackmap-analyzer-omeka-s might be problematic. Click here for more details.

@@ -0,0 +1,3 @@
1
+ from .analyzer import OmekaSAnalyzer
2
+
3
+ __all__ = ["OmekaSAnalyzer"]
@@ -0,0 +1,249 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ import re
5
+ from pathlib import Path
6
+
7
+ from .contracts import AnalyzerMetadata, AuthHint, DatabaseHint, ExternalCall, Route, ScanResult, SecretHint
8
+
9
+ ROUTE_PATH_PATTERN = re.compile(r"['\"]route['\"]\s*=>\s*['\"]([^'\"]+)['\"]", re.IGNORECASE)
10
+ ROUTE_NAME_PATTERN = re.compile(r"['\"]([A-Za-z0-9_\\-]+)['\"]\s*=>\s*\[\s*['\"]type['\"]\s*=>", re.IGNORECASE)
11
+ CONTROLLER_PATTERN = re.compile(r"([A-Za-z_\\][A-Za-z0-9_\\]*Controller[A-Za-z0-9_\\]*)::class", re.IGNORECASE)
12
+ SERVICE_PATTERN = re.compile(
13
+ r"([A-Za-z_\\][A-Za-z0-9_\\]*(?:Service|Manager|Repository|Adapter|Connection)[A-Za-z0-9_\\]*)::class",
14
+ re.IGNORECASE,
15
+ )
16
+ OMEKA_SERVICE_PATTERN = re.compile(r"Omeka\\([A-Za-z_\\\\][A-Za-z0-9_\\\\]*)", re.IGNORECASE)
17
+ OUTBOUND_PATTERNS = [
18
+ re.compile(r"curl_init\s*\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
19
+ re.compile(r"file_get_contents\s*\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
20
+ re.compile(r"->(?:get|post|put|patch|delete|request)\s*\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
21
+ ]
22
+ SECRET_PATTERNS = [
23
+ re.compile(r"getenv\s*\(\s*['\"]([A-Z0-9_]*(SECRET|TOKEN|KEY|PASSWORD|API|DB)[A-Z0-9_]*)['\"]", re.IGNORECASE),
24
+ re.compile(r"\$_ENV\s*\[\s*['\"]([A-Z0-9_]*(SECRET|TOKEN|KEY|PASSWORD|API|DB)[A-Z0-9_]*)['\"]\s*\]", re.IGNORECASE),
25
+ ]
26
+
27
+
28
+ class OmekaSAnalyzer:
29
+ metadata = AnalyzerMetadata(
30
+ name="omeka-s",
31
+ display_name="Omeka S Analyzer",
32
+ version="0.1.0",
33
+ description="Application-aware Omeka S analyzer for Laminas module config, services, and extension surfaces.",
34
+ scope="Omeka S and Omeka-style Laminas MVC projects with module config-driven routes and services.",
35
+ targets=["omeka-s", "php-laminas", "php-web"],
36
+ languages=["php"],
37
+ priority=20,
38
+ experimental=True,
39
+ enabled_by_default=False,
40
+ )
41
+
42
+ @property
43
+ def name(self) -> str:
44
+ return self.metadata.name
45
+
46
+ def detect(self, repo_path: str | Path) -> bool:
47
+ root = Path(repo_path).resolve()
48
+ if not root.exists() or not root.is_dir():
49
+ return False
50
+
51
+ if self._has_omeka_composer_signals(root / "composer.json"):
52
+ return True
53
+
54
+ if (root / "config" / "application.config.php").exists() and any(root.rglob("module.config.php")):
55
+ if (root / "module").is_dir():
56
+ return True
57
+
58
+ for file_path in root.rglob("*.php"):
59
+ if any(part in {"vendor", ".git", "node_modules"} for part in file_path.parts):
60
+ continue
61
+ content = self._read_text(file_path)
62
+ if content and ("namespace Omeka" in content or "Omeka\\Connection" in content):
63
+ return True
64
+ return False
65
+
66
+ def analyze(self, repo_path: str | Path) -> ScanResult:
67
+ root = Path(repo_path).resolve()
68
+ result = ScanResult(root=str(root))
69
+ if not root.exists() or not root.is_dir():
70
+ return result
71
+
72
+ composer_path = root / "composer.json"
73
+ if composer_path.exists():
74
+ self._extract_composer_signals(composer_path, result)
75
+
76
+ for file_path in root.rglob("*.php"):
77
+ if not file_path.is_file():
78
+ continue
79
+ if any(part in {"vendor", ".git", "node_modules"} for part in file_path.parts):
80
+ continue
81
+
82
+ result.files_scanned += 1
83
+ if "php" not in result.languages:
84
+ result.languages.append("php")
85
+
86
+ content = self._read_text(file_path)
87
+ if content is None:
88
+ continue
89
+
90
+ relative = str(file_path.relative_to(root))
91
+ self._extract_routes_and_surfaces(content, relative, result)
92
+ self._extract_controllers_and_services(content, relative, result)
93
+ self._extract_extension_points(content, relative, result)
94
+ self._extract_external_calls(content, relative, result)
95
+ self._extract_datastores(content, relative, result)
96
+ self._extract_secret_hints(content, relative, result)
97
+
98
+ result.languages.sort()
99
+ return result
100
+
101
+ def _has_omeka_composer_signals(self, composer_path: Path) -> bool:
102
+ if not composer_path.exists():
103
+ return False
104
+ try:
105
+ data = json.loads(composer_path.read_text(encoding="utf-8"))
106
+ except (UnicodeDecodeError, json.JSONDecodeError):
107
+ return False
108
+
109
+ requirements = {
110
+ **(data.get("require", {}) if isinstance(data.get("require", {}), dict) else {}),
111
+ **(data.get("require-dev", {}) if isinstance(data.get("require-dev", {}), dict) else {}),
112
+ }
113
+ for package in requirements:
114
+ lowered = package.lower()
115
+ if lowered.startswith("omeka/") or lowered == "omeka-s":
116
+ return True
117
+ return False
118
+
119
+ def _extract_composer_signals(self, composer_path: Path, result: ScanResult) -> None:
120
+ try:
121
+ data = json.loads(composer_path.read_text(encoding="utf-8"))
122
+ except (UnicodeDecodeError, json.JSONDecodeError):
123
+ return
124
+
125
+ requirements = {
126
+ **(data.get("require", {}) if isinstance(data.get("require", {}), dict) else {}),
127
+ **(data.get("require-dev", {}) if isinstance(data.get("require-dev", {}), dict) else {}),
128
+ }
129
+ for package in requirements:
130
+ lowered = package.lower()
131
+ if lowered.startswith("omeka/") or lowered == "omeka-s":
132
+ self._append_unique_auth(result, "omeka_dependency", "composer.json")
133
+ if lowered.startswith("laminas/") or lowered.startswith("zendframework/"):
134
+ self._append_unique_auth(result, "laminas_dependency", "composer.json")
135
+ if "doctrine" in lowered:
136
+ self._append_unique_database(result, "sql", "composer.json")
137
+
138
+ def _extract_routes_and_surfaces(self, content: str, relative: str, result: ScanResult) -> None:
139
+ for match in ROUTE_PATH_PATTERN.finditer(content):
140
+ path = match.group(1)
141
+ self._append_unique_route(result, path, "ANY", relative)
142
+ self._append_surface_hint_for_path(result, path, relative)
143
+
144
+ for match in ROUTE_NAME_PATTERN.finditer(content):
145
+ route_name = match.group(1).lower()
146
+ if "admin" in route_name:
147
+ self._append_unique_auth(result, "omeka_surface:admin", relative)
148
+ elif "api" in route_name:
149
+ self._append_unique_auth(result, "omeka_surface:api", relative)
150
+ elif "site" in route_name:
151
+ self._append_unique_auth(result, "omeka_surface:site", relative)
152
+
153
+ def _extract_controllers_and_services(self, content: str, relative: str, result: ScanResult) -> None:
154
+ found_controller = False
155
+ for match in CONTROLLER_PATTERN.finditer(content):
156
+ found_controller = True
157
+ self._append_unique_auth(result, f"controller:{match.group(1)}", relative)
158
+ if found_controller:
159
+ self._append_unique_auth(result, "laminas_controller_mapping", relative)
160
+
161
+ for match in SERVICE_PATTERN.finditer(content):
162
+ service_name = match.group(1)
163
+ self._append_unique_auth(result, f"service:{service_name}", relative)
164
+ if "Connection" in service_name:
165
+ self._append_unique_database(result, "sql", relative)
166
+
167
+ for match in OMEKA_SERVICE_PATTERN.finditer(content):
168
+ service_name = match.group(1)
169
+ self._append_unique_auth(result, f"omeka_service:{service_name}", relative)
170
+ if service_name.lower().endswith("connection"):
171
+ self._append_unique_database(result, "sql", relative)
172
+
173
+ def _extract_extension_points(self, content: str, relative: str, result: ScanResult) -> None:
174
+ lowered = content.lower()
175
+ if "'service_manager'" in lowered or '"service_manager"' in lowered:
176
+ self._append_unique_auth(result, "omeka_extension:service_manager", relative)
177
+ if "'factories'" in lowered or '"factories"' in lowered:
178
+ self._append_unique_auth(result, "omeka_extension:factory", relative)
179
+ if "'navigation'" in lowered or '"navigation"' in lowered:
180
+ self._append_unique_auth(result, "omeka_extension:navigation", relative)
181
+ normalized = relative.replace("\\", "/")
182
+ if "/module/" in f"/{normalized}/":
183
+ self._append_unique_auth(result, "omeka_extension:module", relative)
184
+
185
+ def _extract_external_calls(self, content: str, relative: str, result: ScanResult) -> None:
186
+ for pattern in OUTBOUND_PATTERNS:
187
+ for match in pattern.finditer(content):
188
+ self._append_unique_external(result, match.group(1), relative)
189
+
190
+ def _extract_datastores(self, content: str, relative: str, result: ScanResult) -> None:
191
+ lowered = content.lower()
192
+ if "omeka\\connection" in lowered or "new pdo(" in lowered or "doctrine" in lowered:
193
+ self._append_unique_database(result, "sql", relative)
194
+
195
+ def _extract_secret_hints(self, content: str, relative: str, result: ScanResult) -> None:
196
+ for pattern in SECRET_PATTERNS:
197
+ for match in pattern.finditer(content):
198
+ self._append_unique_secret(result, match.group(1), relative)
199
+
200
+ def _append_surface_hint_for_path(self, result: ScanResult, path: str, relative: str) -> None:
201
+ lowered = path.lower()
202
+ if lowered.startswith("/admin") or "/admin/" in lowered:
203
+ self._append_unique_auth(result, "omeka_surface:admin", relative)
204
+ elif lowered.startswith("/api") or "/api/" in lowered:
205
+ self._append_unique_auth(result, "omeka_surface:api", relative)
206
+ elif lowered.startswith("/s/") or lowered.startswith("/site"):
207
+ self._append_unique_auth(result, "omeka_surface:site", relative)
208
+
209
+ @staticmethod
210
+ def _read_text(path: Path) -> str | None:
211
+ try:
212
+ return path.read_text(encoding="utf-8")
213
+ except UnicodeDecodeError:
214
+ return None
215
+
216
+ @staticmethod
217
+ def _append_unique_route(result: ScanResult, path: str, method: str, file: str) -> None:
218
+ key = (path, method, file)
219
+ if any((item.path, item.method, item.file) == key for item in result.routes):
220
+ return
221
+ result.routes.append(Route(path=path, method=method, file=file))
222
+
223
+ @staticmethod
224
+ def _append_unique_external(result: ScanResult, target: str, file: str) -> None:
225
+ key = (target, file)
226
+ if any((item.target, item.file) == key for item in result.external_calls):
227
+ return
228
+ result.external_calls.append(ExternalCall(target=target, file=file))
229
+
230
+ @staticmethod
231
+ def _append_unique_database(result: ScanResult, kind: str, file: str) -> None:
232
+ key = (kind, file)
233
+ if any((item.kind, item.file) == key for item in result.databases):
234
+ return
235
+ result.databases.append(DatabaseHint(kind=kind, file=file))
236
+
237
+ @staticmethod
238
+ def _append_unique_auth(result: ScanResult, hint: str, file: str) -> None:
239
+ key = (hint, file)
240
+ if any((item.hint, item.file) == key for item in result.auth_hints):
241
+ return
242
+ result.auth_hints.append(AuthHint(hint=hint, file=file))
243
+
244
+ @staticmethod
245
+ def _append_unique_secret(result: ScanResult, name: str, file: str) -> None:
246
+ key = (name, file)
247
+ if any((item.name, item.file) == key for item in result.secret_hints):
248
+ return
249
+ result.secret_hints.append(SecretHint(name=name, file=file))
@@ -0,0 +1,18 @@
1
+ from __future__ import annotations
2
+
3
+ from attackmap.sdk.contracts import AnalyzerMetadata, AnalyzerProtocol
4
+ from attackmap.sdk.models import AuthHint, DatabaseHint, ExternalCall, Route, ScanResult, SecretHint
5
+
6
+ # Compatibility alias used by existing analyzer implementations.
7
+ AttackMapAnalyzerProtocol = AnalyzerProtocol
8
+
9
+ __all__ = [
10
+ "AnalyzerMetadata",
11
+ "AttackMapAnalyzerProtocol",
12
+ "Route",
13
+ "ExternalCall",
14
+ "DatabaseHint",
15
+ "AuthHint",
16
+ "SecretHint",
17
+ "ScanResult",
18
+ ]
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: attackmap-analyzer-omeka-s
3
+ Version: 0.1.0
4
+ Summary: Application-aware Omeka S analyzer plugin for AttackMap
5
+ Author: AttackMap Contributors
6
+ Author-email: Matthew Davis <matthewd@matthewd.xyz>
7
+ Maintainer-email: Matthew Davis <matthewd@matthewd.xyz>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/mlaify/attack-map-analyzer-omeka-s
10
+ Project-URL: Repository, https://github.com/mlaify/attack-map-analyzer-omeka-s
11
+ Project-URL: Issues, https://github.com/mlaify/attack-map-analyzer-omeka-s/issues
12
+ Project-URL: Changelog, https://github.com/mlaify/attack-map-analyzer-omeka-s/blob/main/CHANGELOG.md
13
+ Project-URL: AttackMap core, https://github.com/mlaify/AttackMap
14
+ Keywords: security,static-analysis,appsec,defensive-security,attackmap,attackmap-plugin
15
+ Classifier: Development Status :: 4 - Beta
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Information Technology
18
+ Classifier: Intended Audience :: System Administrators
19
+ Classifier: License :: OSI Approved :: MIT License
20
+ Classifier: Operating System :: OS Independent
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: 3 :: Only
26
+ Classifier: Topic :: Security
27
+ Classifier: Topic :: Software Development :: Quality Assurance
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.11
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: pydantic>=2.7.0
33
+ Provides-Extra: core
34
+ Requires-Dist: attackmap>=0.1.0; extra == "core"
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
37
+ Requires-Dist: build>=1.2.0; extra == "dev"
38
+ Requires-Dist: attackmap>=0.1.0; extra == "dev"
39
+ Dynamic: license-file
40
+
41
+ # AttackMap Omeka S Analyzer
42
+
43
+ `attackmap-analyzer-omeka-s` is an application-aware analyzer module for AttackMap.
44
+
45
+ It focuses on Omeka S and emits structured scan signals for:
46
+ - likely admin, site, and API surfaces
47
+ - route and controller hints from Laminas-style module config
48
+ - Omeka service usage (for example `Omeka\\Connection`)
49
+ - module extension points such as navigation and service manager factories
50
+
51
+ This module is intentionally heuristic and incremental.
52
+
53
+ ## Install
54
+
55
+ ```bash
56
+ pip install git+https://github.com/mlaify/attackmap-analyzer-omeka-s.git
57
+ ```
58
+
59
+ ## Usage with AttackMap
60
+
61
+ ```bash
62
+ attackmap analyze /path/to/repo --module omeka-s
63
+ ```
@@ -0,0 +1,9 @@
1
+ attackmap_analyzer_omeka_s/__init__.py,sha256=f7tmiXptI52ZS3IqUAgfFJE37U8SvmSiCfVvIeg6iNQ,67
2
+ attackmap_analyzer_omeka_s/analyzer.py,sha256=n_cHB_mqBBpFvq6GuD0JuAMcEGB_VuF1sUuPVrq410c,11567
3
+ attackmap_analyzer_omeka_s/contracts.py,sha256=uwshWT7fHGD_lTg8LGS-4JxuHlRQJ7ejBS92Ls3p6Vc,496
4
+ attackmap_analyzer_omeka_s-0.1.0.dist-info/licenses/LICENSE,sha256=vtPQVGUyxq359j0JmD3_eJaXyHmaHyjzaMOtaLwJc88,1097
5
+ attackmap_analyzer_omeka_s-0.1.0.dist-info/METADATA,sha256=a5Fx7yuNVeaFfi4oFuGWIPFotoy7VdxwAvF4kMSXydQ,2470
6
+ attackmap_analyzer_omeka_s-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ attackmap_analyzer_omeka_s-0.1.0.dist-info/entry_points.txt,sha256=8nPbTJ6M_cG9JJbnX55LBWvirSBkIMcGc7QBhrFmy1o,74
8
+ attackmap_analyzer_omeka_s-0.1.0.dist-info/top_level.txt,sha256=D1Kpe1jvHYM75EpPrSiZEomxazbJH3fYM4trBT89AVk,27
9
+ attackmap_analyzer_omeka_s-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [attackmap.analyzers]
2
+ omeka_s = attackmap_analyzer_omeka_s:OmekaSAnalyzer
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Matthew Davis and AttackMap Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ attackmap_analyzer_omeka_s