attackmap-analyzer-php-laminas 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-php-laminas might be problematic. Click here for more details.

@@ -0,0 +1,4 @@
1
+ from .analyzer import PhpLaminasAnalyzer
2
+ from .contracts import AnalyzerMetadata
3
+
4
+ __all__ = ["AnalyzerMetadata", "PhpLaminasAnalyzer"]
@@ -0,0 +1,236 @@
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
+ LAMINAS_ROUTE_PATTERN = re.compile(r"['\"]route['\"]\s*=>\s*['\"]([^'\"]+)['\"]", re.IGNORECASE)
10
+ LAMINAS_CONTROLLER_PATTERN = re.compile(
11
+ r"([A-Za-z_\\][A-Za-z0-9_\\]*Controller[A-Za-z0-9_\\]*)::class",
12
+ re.IGNORECASE,
13
+ )
14
+ LAMINAS_SERVICE_PATTERN = re.compile(
15
+ r"([A-Za-z_\\][A-Za-z0-9_\\]*(?:Service|Manager|Repository|TableGateway|Adapter)[A-Za-z0-9_\\]*)::class",
16
+ re.IGNORECASE,
17
+ )
18
+
19
+ OUTBOUND_PATTERNS = [
20
+ re.compile(r"curl_init\s*\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
21
+ re.compile(r"file_get_contents\s*\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
22
+ re.compile(r"->request\s*\(\s*['\"](?:GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD)['\"]\s*,\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
23
+ re.compile(r"->(?:get|post|put|patch|delete)\s*\(\s*['\"](https?://[^'\"]+)['\"]", re.IGNORECASE),
24
+ ]
25
+
26
+ DATABASE_PATTERNS = [
27
+ (re.compile(r"\bnew\s+PDO\s*\(", re.IGNORECASE), "sql"),
28
+ (re.compile(r"Doctrine\\DBAL|Doctrine\\ORM|EntityManager", re.IGNORECASE), "sql"),
29
+ (re.compile(r"\bmysqli_connect\s*\(", re.IGNORECASE), "mysql"),
30
+ (re.compile(r"\bnew\s+mysqli\s*\(", re.IGNORECASE), "mysql"),
31
+ (re.compile(r"\bpg_connect\s*\(", re.IGNORECASE), "postgresql"),
32
+ (re.compile(r"\bRedis\s*::|\bnew\s+Redis\s*\(", re.IGNORECASE), "redis"),
33
+ ]
34
+
35
+ AUTH_PATTERNS = [
36
+ (re.compile(r"\bsession_start\s*\(", re.IGNORECASE), "session"),
37
+ (re.compile(r"\$_SESSION\b", re.IGNORECASE), "session"),
38
+ (re.compile(r"JWT|firebase\\jwt", re.IGNORECASE), "jwt"),
39
+ (re.compile(r"\bAuth::|\bauth\s*\(", re.IGNORECASE), "auth"),
40
+ ]
41
+
42
+ SECRET_PATTERNS = [
43
+ re.compile(r"getenv\s*\(\s*['\"]([A-Z0-9_]*(SECRET|TOKEN|KEY|PASSWORD|API|DB)[A-Z0-9_]*)['\"]", re.IGNORECASE),
44
+ re.compile(r"\$_ENV\s*\[\s*['\"]([A-Z0-9_]*(SECRET|TOKEN|KEY|PASSWORD|API|DB)[A-Z0-9_]*)['\"]\s*\]", re.IGNORECASE),
45
+ re.compile(r"\$_SERVER\s*\[\s*['\"]([A-Z0-9_]*(SECRET|TOKEN|KEY|PASSWORD|API|DB)[A-Z0-9_]*)['\"]\s*\]", re.IGNORECASE),
46
+ ]
47
+
48
+
49
+ class PhpLaminasAnalyzer:
50
+ metadata = AnalyzerMetadata(
51
+ name="php-laminas",
52
+ display_name="PHP Laminas Analyzer",
53
+ version="0.1.0",
54
+ description="Framework-aware Laminas analyzer for route, controller, and service mapping hints.",
55
+ scope="Laminas and Zend Framework MVC projects using module and application config arrays.",
56
+ targets=["php-laminas", "laminas", "zendframework"],
57
+ languages=["php"],
58
+ priority=30,
59
+ experimental=True,
60
+ enabled_by_default=False,
61
+ )
62
+
63
+ @property
64
+ def name(self) -> str:
65
+ return self.metadata.name
66
+
67
+ def detect(self, repo_path: str | Path) -> bool:
68
+ root = Path(repo_path).resolve()
69
+ if not root.exists() or not root.is_dir():
70
+ return False
71
+
72
+ if self._has_laminas_composer_dependencies(root / "composer.json"):
73
+ return True
74
+
75
+ if (root / "module").is_dir() and (root / "config" / "application.config.php").exists():
76
+ return True
77
+
78
+ if any(root.rglob("module.config.php")):
79
+ return True
80
+
81
+ return False
82
+
83
+ def analyze(self, repo_path: str | Path) -> ScanResult:
84
+ root = Path(repo_path).resolve()
85
+ result = ScanResult(root=str(root))
86
+
87
+ if not root.exists() or not root.is_dir():
88
+ return result
89
+
90
+ composer_path = root / "composer.json"
91
+ if composer_path.exists():
92
+ self._extract_composer_signals(composer_path, result)
93
+
94
+ for file_path in root.rglob("*.php"):
95
+ if not file_path.is_file():
96
+ continue
97
+ if any(part in {"vendor", ".git", "node_modules"} for part in file_path.parts):
98
+ continue
99
+
100
+ result.files_scanned += 1
101
+ if "php" not in result.languages:
102
+ result.languages.append("php")
103
+
104
+ content = self._read_text(file_path)
105
+ if content is None:
106
+ continue
107
+
108
+ relative = str(file_path.relative_to(root))
109
+ self._extract_routes(content, relative, result)
110
+ self._extract_laminas_controllers(content, relative, result)
111
+ self._extract_laminas_services(content, relative, result)
112
+ self._extract_external_calls(content, relative, result)
113
+ self._extract_datastores(content, relative, result)
114
+ self._extract_auth_hints(content, relative, result)
115
+ self._extract_secret_hints(content, relative, result)
116
+
117
+ result.languages.sort()
118
+ return result
119
+
120
+ def _has_laminas_composer_dependencies(self, composer_path: Path) -> bool:
121
+ if not composer_path.exists():
122
+ return False
123
+ try:
124
+ data = json.loads(composer_path.read_text(encoding="utf-8"))
125
+ except (UnicodeDecodeError, json.JSONDecodeError):
126
+ return False
127
+
128
+ requirements = {
129
+ **(data.get("require", {}) if isinstance(data.get("require", {}), dict) else {}),
130
+ **(data.get("require-dev", {}) if isinstance(data.get("require-dev", {}), dict) else {}),
131
+ }
132
+ for package in requirements:
133
+ lowered = package.lower()
134
+ if lowered.startswith("laminas/") or lowered.startswith("zendframework/"):
135
+ return True
136
+ return False
137
+
138
+ def _extract_composer_signals(self, composer_path: Path, result: ScanResult) -> None:
139
+ try:
140
+ data = json.loads(composer_path.read_text(encoding="utf-8"))
141
+ except (UnicodeDecodeError, json.JSONDecodeError):
142
+ return
143
+
144
+ requirements = {
145
+ **(data.get("require", {}) if isinstance(data.get("require", {}), dict) else {}),
146
+ **(data.get("require-dev", {}) if isinstance(data.get("require-dev", {}), dict) else {}),
147
+ }
148
+
149
+ for package in requirements:
150
+ lowered = package.lower()
151
+ if lowered.startswith("laminas/") or lowered.startswith("zendframework/"):
152
+ self._append_unique_auth(result, "laminas_dependency", "composer.json")
153
+ if "doctrine" in lowered:
154
+ self._append_unique_database(result, "sql", "composer.json")
155
+
156
+ def _extract_routes(self, content: str, relative: str, result: ScanResult) -> None:
157
+ for match in LAMINAS_ROUTE_PATTERN.finditer(content):
158
+ self._append_unique_route(result, match.group(1), "ANY", relative)
159
+
160
+ def _extract_laminas_controllers(self, content: str, relative: str, result: ScanResult) -> None:
161
+ found = False
162
+ for match in LAMINAS_CONTROLLER_PATTERN.finditer(content):
163
+ found = True
164
+ self._append_unique_auth(result, f"controller:{match.group(1)}", relative)
165
+ if found:
166
+ self._append_unique_auth(result, "laminas_controller_mapping", relative)
167
+
168
+ def _extract_laminas_services(self, content: str, relative: str, result: ScanResult) -> None:
169
+ found = False
170
+ for match in LAMINAS_SERVICE_PATTERN.finditer(content):
171
+ found = True
172
+ self._append_unique_auth(result, f"service:{match.group(1)}", relative)
173
+ if found or "'service_manager'" in content or '"service_manager"' in content:
174
+ self._append_unique_auth(result, "laminas_service_manager", relative)
175
+
176
+ def _extract_external_calls(self, content: str, relative: str, result: ScanResult) -> None:
177
+ for pattern in OUTBOUND_PATTERNS:
178
+ for match in pattern.finditer(content):
179
+ self._append_unique_external(result, match.group(1), relative)
180
+
181
+ def _extract_datastores(self, content: str, relative: str, result: ScanResult) -> None:
182
+ for pattern, kind in DATABASE_PATTERNS:
183
+ if pattern.search(content):
184
+ self._append_unique_database(result, kind, relative)
185
+
186
+ def _extract_auth_hints(self, content: str, relative: str, result: ScanResult) -> None:
187
+ for pattern, hint in AUTH_PATTERNS:
188
+ if pattern.search(content):
189
+ self._append_unique_auth(result, hint, relative)
190
+
191
+ def _extract_secret_hints(self, content: str, relative: str, result: ScanResult) -> None:
192
+ for pattern in SECRET_PATTERNS:
193
+ for match in pattern.finditer(content):
194
+ self._append_unique_secret(result, match.group(1), relative)
195
+
196
+ @staticmethod
197
+ def _read_text(path: Path) -> str | None:
198
+ try:
199
+ return path.read_text(encoding="utf-8")
200
+ except UnicodeDecodeError:
201
+ return None
202
+
203
+ @staticmethod
204
+ def _append_unique_route(result: ScanResult, path: str, method: str, file: str) -> None:
205
+ key = (path, method, file)
206
+ if any((item.path, item.method, item.file) == key for item in result.routes):
207
+ return
208
+ result.routes.append(Route(path=path, method=method, file=file))
209
+
210
+ @staticmethod
211
+ def _append_unique_external(result: ScanResult, target: str, file: str) -> None:
212
+ key = (target, file)
213
+ if any((item.target, item.file) == key for item in result.external_calls):
214
+ return
215
+ result.external_calls.append(ExternalCall(target=target, file=file))
216
+
217
+ @staticmethod
218
+ def _append_unique_database(result: ScanResult, kind: str, file: str) -> None:
219
+ key = (kind, file)
220
+ if any((item.kind, item.file) == key for item in result.databases):
221
+ return
222
+ result.databases.append(DatabaseHint(kind=kind, file=file))
223
+
224
+ @staticmethod
225
+ def _append_unique_auth(result: ScanResult, hint: str, file: str) -> None:
226
+ key = (hint, file)
227
+ if any((item.hint, item.file) == key for item in result.auth_hints):
228
+ return
229
+ result.auth_hints.append(AuthHint(hint=hint, file=file))
230
+
231
+ @staticmethod
232
+ def _append_unique_secret(result: ScanResult, name: str, file: str) -> None:
233
+ key = (name, file)
234
+ if any((item.name, item.file) == key for item in result.secret_hints):
235
+ return
236
+ 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,71 @@
1
+ Metadata-Version: 2.4
2
+ Name: attackmap-analyzer-php-laminas
3
+ Version: 0.1.0
4
+ Summary: Framework-aware Laminas 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/attackmap-analyzer-php-laminas
10
+ Project-URL: Repository, https://github.com/mlaify/attackmap-analyzer-php-laminas
11
+ Project-URL: Issues, https://github.com/mlaify/attackmap-analyzer-php-laminas/issues
12
+ Project-URL: Changelog, https://github.com/mlaify/attackmap-analyzer-php-laminas/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-analyzer-php-laminas
42
+
43
+ Framework-aware Laminas analyzer for [AttackMap](https://github.com/mlaify/AttackMap).
44
+
45
+ This module focuses on structured signal extraction for Laminas/Zend MVC projects:
46
+
47
+ - route paths from config arrays
48
+ - controller mapping hints
49
+ - service-manager mapping hints
50
+ - broad PHP security signals (outbound calls, datastore, auth, secret hints)
51
+
52
+ ## Analyzer identity
53
+
54
+ - `name`: `php-laminas`
55
+ - `display_name`: `PHP Laminas Analyzer`
56
+ - `version`: `0.1.0`
57
+ - `experimental`: `true`
58
+ - `enabled_by_default`: `false`
59
+
60
+ ## Detection
61
+
62
+ `detect(repo_path)` returns true when one or more Laminas indicators exist:
63
+
64
+ - composer dependencies beginning with `laminas/` or `zendframework/`
65
+ - `config/application.config.php`
66
+ - any `module.config.php`
67
+ - `module/` directory
68
+
69
+ ## Notes
70
+
71
+ This analyzer is heuristic and intentionally avoids AST parsing in this first iteration.
@@ -0,0 +1,9 @@
1
+ attackmap_analyzer_php_laminas/__init__.py,sha256=4wp4tJNHoemXe4AUKvk3ErxIsYXv3p1IFcPCn7Gf0sU,135
2
+ attackmap_analyzer_php_laminas/analyzer.py,sha256=iwFA0MVgZdn9VMZLEwu3pgjnlwzVf4uv4NId3r8tUJU,10104
3
+ attackmap_analyzer_php_laminas/contracts.py,sha256=uwshWT7fHGD_lTg8LGS-4JxuHlRQJ7ejBS92Ls3p6Vc,496
4
+ attackmap_analyzer_php_laminas-0.1.0.dist-info/licenses/LICENSE,sha256=vtPQVGUyxq359j0JmD3_eJaXyHmaHyjzaMOtaLwJc88,1097
5
+ attackmap_analyzer_php_laminas-0.1.0.dist-info/METADATA,sha256=jJdMRK3tSSDHvO3kYN8Na64zqrPfxrG7aGDr80Co3uk,2719
6
+ attackmap_analyzer_php_laminas-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ attackmap_analyzer_php_laminas-0.1.0.dist-info/entry_points.txt,sha256=CIQ2tQZ9jtJ_6VaH97xijB3ZdhSUxw2Iul3Mf-3nxrQ,86
8
+ attackmap_analyzer_php_laminas-0.1.0.dist-info/top_level.txt,sha256=QWrIbf38wt3JHLIdPJ1KP6CsLr2vIH2B0KqJ2hQ3PQk,31
9
+ attackmap_analyzer_php_laminas-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
+ php_laminas = attackmap_analyzer_php_laminas:PhpLaminasAnalyzer
@@ -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_php_laminas