attackmap-analyzer-python 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.

Potentially problematic release.


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

@@ -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,121 @@
1
+ Metadata-Version: 2.4
2
+ Name: attackmap-analyzer-python
3
+ Version: 0.1.0
4
+ Summary: Comprehensive Python ecosystem analyzer plugin for AttackMap (Django, Starlette, AIOHTTP, Sanic, Litestar, DRF; SQLAlchemy/asyncpg/motor; passlib/PyJWT/authlib; httpx/aiohttp).
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-python
10
+ Project-URL: Repository, https://github.com/mlaify/attackmap-analyzer-python
11
+ Project-URL: Issues, https://github.com/mlaify/attackmap-analyzer-python/issues
12
+ Project-URL: Changelog, https://github.com/mlaify/attackmap-analyzer-python/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-python
42
+
43
+ Comprehensive Python ecosystem analyzer for [AttackMap](https://github.com/mlaify/AttackMap).
44
+
45
+ This plugin is **additive** over AttackMap's built-in `python-web` analyzer. The built-in handles FastAPI / Flask routes via the core scanner; this plugin adds everything else.
46
+
47
+ - **Web frameworks** —
48
+ - **Django** routing (`path("users/", ...)`, `re_path(r"^api/...$", ...)`, legacy `url(...)`) gated by `urlpatterns =` in the file
49
+ - **Django REST Framework** routers (`router.register(r'users', UserViewSet)`) and `@api_view(['GET', 'POST'])` decorators
50
+ - **Starlette** `Route("/x", endpoint=h, methods=["GET", "POST"])` and `WebSocketRoute("/ws/...")`
51
+ - **AIOHTTP** `app.router.add_get/post/...` and `web.get/post/...` helpers (gated by aiohttp import)
52
+ - **Sanic** `@app.get("/x")`, `@app.post("/x")` (gated by sanic import)
53
+ - **Litestar** (and legacy Starlite) top-level `@get("/x")` / `@post(...)` decorators (gated by litestar/starlite import)
54
+ - **Flask** `app.add_url_rule("/x", view_func=...)` (additive — built-in covers `@app.route`)
55
+ - **Databases** —
56
+ - **SQLAlchemy** `create_engine("postgresql://...")` with dialect-aware kind inference (postgresql / mysql / mariadb / sqlite / oracle / sqlserver)
57
+ - **asyncpg** / **psycopg2-3** / **pymysql** / **motor.motor_asyncio** / **pymongo** / **redis.asyncio** / **aioredis** / **sqlmodel** / **tortoise**
58
+ - **boto3 resources/clients** for `dynamodb` and `s3`
59
+ - **Django** `DATABASES` dict in `settings.py` — `ENGINE` value parsed for the kind
60
+ - **Auth packages** —
61
+ - **passlib** `CryptContext`, `passlib.hash.argon2/bcrypt/scrypt`
62
+ - **bcrypt** standalone (`bcrypt.hashpw`, `bcrypt.checkpw`)
63
+ - **argon2-cffi** (`from argon2 import PasswordHasher`)
64
+ - **PyJWT** / **python-jose** (`jwt.encode`, `jwt.decode`, `jose.jwt`)
65
+ - **authlib** (`OAuth(...)`, `OAuth2Session(...)`)
66
+ - **fastapi-users** (`BearerTransport`, `JWTStrategy`)
67
+ - **flask-jwt-extended** (`@jwt_required`, `create_access_token`)
68
+ - **django.contrib.auth** (`authenticate`, `make_password`)
69
+ - **casbin** (`Enforcer`)
70
+ - **HTTP clients (external calls)** — **httpx** sync + async, **aiohttp.ClientSession**, **urllib.request.urlopen**
71
+ - **Secrets** —
72
+ - `os.environ.get("X")` and `os.environ["X"]` with secret-shaped names (built-in only covers `os.getenv`)
73
+ - **pydantic-settings** `BaseSettings` field-name extraction (`jwt_secret: str = ...`)
74
+ - `dotenv_values(...)` accessors with secret-shaped keys
75
+ - **Service hints** — `[project] name` from `pyproject.toml`, `[tool.poetry] name`, `name="..."` from `setup.py`, `[metadata] name` from `setup.cfg`, presence of `manage.py` → `framework:django`, Django `INSTALLED_APPS` third-party / local apps
76
+
77
+ All emissions populate AttackMap's Signal v2 fields (line numbers, evidence snippets, confidence) so downstream insights can cite `path/to/module.py:NN`.
78
+
79
+ ## Install
80
+
81
+ ```bash
82
+ pip install git+https://github.com/mlaify/attackmap-analyzer-python.git
83
+ ```
84
+
85
+ The analyzer is auto-discovered by AttackMap via the `attackmap.analyzers` entry-point group.
86
+
87
+ ## Usage with AttackMap
88
+
89
+ ```bash
90
+ # Auto-discovered when installed:
91
+ attackmap analyze /path/to/python/repo
92
+
93
+ # Or invoke explicitly:
94
+ attackmap analyze /path/to/python/repo --module python
95
+ ```
96
+
97
+ ## Detection
98
+
99
+ `detect()` returns true when any of the following are present, ignoring `.venv/`, `venv/`, `env/`, `.tox/`, `__pycache__/`, `.pytest_cache/`, `dist/`, `build/`, `node_modules/`, `.git/`, `.mypy_cache/`, `.ruff_cache/`, and `site-packages/`:
100
+
101
+ - A `pyproject.toml`, `setup.py`, `setup.cfg`, `manage.py`, or `Pipfile` at the root
102
+ - Any `.py` file in the tree
103
+
104
+ ## Coverage notes
105
+
106
+ - **Framework-gated extraction**: route extractors for AIOHTTP, Sanic, Litestar, and Starlette only fire when the file imports the corresponding framework. This prevents mis-attributing generic `@get(...)` / `web.get(...)` / `app.get(...)` calls to a framework when they're really custom decorators or method calls.
107
+ - **Django routing requires `urlpatterns =`** to be in the file. A bare `path("/x", ...)` in any other context (e.g., `pathlib.Path("/x")` is well-behaved, but a project that also has `from django.urls import path; path("/x", view)` outside a urls.py won't fire — by design).
108
+ - **Django settings extraction**: gated by presence of one of `INSTALLED_APPS`, `DATABASES`, `MIDDLEWARE`, or `ROOT_URLCONF`. Built-in Django apps (`django.*`) are filtered out of the INSTALLED_APPS service hints to keep signal high.
109
+ - **DRF `@api_view(['GET', 'POST'])`**: emits framework hints (`drf_api_view:GET`, `drf_api_view:POST`) rather than routes — the actual path is in `urls.py`, which is extracted separately.
110
+ - **Tornado** is not yet covered — its class-based `RequestHandler` routing requires per-class method extraction (`def get(self): ...`, `def post(self): ...`).
111
+ - **pydantic-settings** field extraction matches any class field whose name contains `secret`, `token`, `key`, `password`, `pass`, or `pwd`. False positives are possible (e.g., a non-secret `signing_key` config). Confidence is the standard 0.85.
112
+
113
+ ## Coexistence with the built-in `python-web` analyzer
114
+
115
+ AttackMap ships with a `python-web` built-in that handles FastAPI / Flask via the core scanner. When this plugin is installed, both analyzers run on every Python repo. AttackMap's overlay deduplication merges their output so users see a single unified set of findings — no double-counting.
116
+
117
+ This plugin runs at `priority=15` (slightly higher than the built-in's 20), so its richer output lands first.
118
+
119
+ ## License
120
+
121
+ MIT
@@ -0,0 +1,81 @@
1
+ # attackmap-analyzer-python
2
+
3
+ Comprehensive Python ecosystem analyzer for [AttackMap](https://github.com/mlaify/AttackMap).
4
+
5
+ This plugin is **additive** over AttackMap's built-in `python-web` analyzer. The built-in handles FastAPI / Flask routes via the core scanner; this plugin adds everything else.
6
+
7
+ - **Web frameworks** —
8
+ - **Django** routing (`path("users/", ...)`, `re_path(r"^api/...$", ...)`, legacy `url(...)`) gated by `urlpatterns =` in the file
9
+ - **Django REST Framework** routers (`router.register(r'users', UserViewSet)`) and `@api_view(['GET', 'POST'])` decorators
10
+ - **Starlette** `Route("/x", endpoint=h, methods=["GET", "POST"])` and `WebSocketRoute("/ws/...")`
11
+ - **AIOHTTP** `app.router.add_get/post/...` and `web.get/post/...` helpers (gated by aiohttp import)
12
+ - **Sanic** `@app.get("/x")`, `@app.post("/x")` (gated by sanic import)
13
+ - **Litestar** (and legacy Starlite) top-level `@get("/x")` / `@post(...)` decorators (gated by litestar/starlite import)
14
+ - **Flask** `app.add_url_rule("/x", view_func=...)` (additive — built-in covers `@app.route`)
15
+ - **Databases** —
16
+ - **SQLAlchemy** `create_engine("postgresql://...")` with dialect-aware kind inference (postgresql / mysql / mariadb / sqlite / oracle / sqlserver)
17
+ - **asyncpg** / **psycopg2-3** / **pymysql** / **motor.motor_asyncio** / **pymongo** / **redis.asyncio** / **aioredis** / **sqlmodel** / **tortoise**
18
+ - **boto3 resources/clients** for `dynamodb` and `s3`
19
+ - **Django** `DATABASES` dict in `settings.py` — `ENGINE` value parsed for the kind
20
+ - **Auth packages** —
21
+ - **passlib** `CryptContext`, `passlib.hash.argon2/bcrypt/scrypt`
22
+ - **bcrypt** standalone (`bcrypt.hashpw`, `bcrypt.checkpw`)
23
+ - **argon2-cffi** (`from argon2 import PasswordHasher`)
24
+ - **PyJWT** / **python-jose** (`jwt.encode`, `jwt.decode`, `jose.jwt`)
25
+ - **authlib** (`OAuth(...)`, `OAuth2Session(...)`)
26
+ - **fastapi-users** (`BearerTransport`, `JWTStrategy`)
27
+ - **flask-jwt-extended** (`@jwt_required`, `create_access_token`)
28
+ - **django.contrib.auth** (`authenticate`, `make_password`)
29
+ - **casbin** (`Enforcer`)
30
+ - **HTTP clients (external calls)** — **httpx** sync + async, **aiohttp.ClientSession**, **urllib.request.urlopen**
31
+ - **Secrets** —
32
+ - `os.environ.get("X")` and `os.environ["X"]` with secret-shaped names (built-in only covers `os.getenv`)
33
+ - **pydantic-settings** `BaseSettings` field-name extraction (`jwt_secret: str = ...`)
34
+ - `dotenv_values(...)` accessors with secret-shaped keys
35
+ - **Service hints** — `[project] name` from `pyproject.toml`, `[tool.poetry] name`, `name="..."` from `setup.py`, `[metadata] name` from `setup.cfg`, presence of `manage.py` → `framework:django`, Django `INSTALLED_APPS` third-party / local apps
36
+
37
+ All emissions populate AttackMap's Signal v2 fields (line numbers, evidence snippets, confidence) so downstream insights can cite `path/to/module.py:NN`.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ pip install git+https://github.com/mlaify/attackmap-analyzer-python.git
43
+ ```
44
+
45
+ The analyzer is auto-discovered by AttackMap via the `attackmap.analyzers` entry-point group.
46
+
47
+ ## Usage with AttackMap
48
+
49
+ ```bash
50
+ # Auto-discovered when installed:
51
+ attackmap analyze /path/to/python/repo
52
+
53
+ # Or invoke explicitly:
54
+ attackmap analyze /path/to/python/repo --module python
55
+ ```
56
+
57
+ ## Detection
58
+
59
+ `detect()` returns true when any of the following are present, ignoring `.venv/`, `venv/`, `env/`, `.tox/`, `__pycache__/`, `.pytest_cache/`, `dist/`, `build/`, `node_modules/`, `.git/`, `.mypy_cache/`, `.ruff_cache/`, and `site-packages/`:
60
+
61
+ - A `pyproject.toml`, `setup.py`, `setup.cfg`, `manage.py`, or `Pipfile` at the root
62
+ - Any `.py` file in the tree
63
+
64
+ ## Coverage notes
65
+
66
+ - **Framework-gated extraction**: route extractors for AIOHTTP, Sanic, Litestar, and Starlette only fire when the file imports the corresponding framework. This prevents mis-attributing generic `@get(...)` / `web.get(...)` / `app.get(...)` calls to a framework when they're really custom decorators or method calls.
67
+ - **Django routing requires `urlpatterns =`** to be in the file. A bare `path("/x", ...)` in any other context (e.g., `pathlib.Path("/x")` is well-behaved, but a project that also has `from django.urls import path; path("/x", view)` outside a urls.py won't fire — by design).
68
+ - **Django settings extraction**: gated by presence of one of `INSTALLED_APPS`, `DATABASES`, `MIDDLEWARE`, or `ROOT_URLCONF`. Built-in Django apps (`django.*`) are filtered out of the INSTALLED_APPS service hints to keep signal high.
69
+ - **DRF `@api_view(['GET', 'POST'])`**: emits framework hints (`drf_api_view:GET`, `drf_api_view:POST`) rather than routes — the actual path is in `urls.py`, which is extracted separately.
70
+ - **Tornado** is not yet covered — its class-based `RequestHandler` routing requires per-class method extraction (`def get(self): ...`, `def post(self): ...`).
71
+ - **pydantic-settings** field extraction matches any class field whose name contains `secret`, `token`, `key`, `password`, `pass`, or `pwd`. False positives are possible (e.g., a non-secret `signing_key` config). Confidence is the standard 0.85.
72
+
73
+ ## Coexistence with the built-in `python-web` analyzer
74
+
75
+ AttackMap ships with a `python-web` built-in that handles FastAPI / Flask via the core scanner. When this plugin is installed, both analyzers run on every Python repo. AttackMap's overlay deduplication merges their output so users see a single unified set of findings — no double-counting.
76
+
77
+ This plugin runs at `priority=15` (slightly higher than the built-in's 20), so its richer output lands first.
78
+
79
+ ## License
80
+
81
+ MIT
@@ -0,0 +1,74 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "attackmap-analyzer-python"
7
+ version = "0.1.0"
8
+ description = "Comprehensive Python ecosystem analyzer plugin for AttackMap (Django, Starlette, AIOHTTP, Sanic, Litestar, DRF; SQLAlchemy/asyncpg/motor; passlib/PyJWT/authlib; httpx/aiohttp)."
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = {text = "MIT"}
12
+ authors = [
13
+ {name = "Matthew Davis", email = "matthewd@matthewd.xyz"},
14
+ {name = "AttackMap Contributors"},
15
+ ]
16
+ maintainers = [
17
+ {name = "Matthew Davis", email = "matthewd@matthewd.xyz"},
18
+ ]
19
+ keywords = [
20
+ "security",
21
+ "static-analysis",
22
+ "appsec",
23
+ "defensive-security",
24
+ "attackmap",
25
+ "attackmap-plugin",
26
+ ]
27
+ classifiers = [
28
+ "Development Status :: 4 - Beta",
29
+ "Intended Audience :: Developers",
30
+ "Intended Audience :: Information Technology",
31
+ "Intended Audience :: System Administrators",
32
+ "License :: OSI Approved :: MIT License",
33
+ "Operating System :: OS Independent",
34
+ "Programming Language :: Python :: 3",
35
+ "Programming Language :: Python :: 3.11",
36
+ "Programming Language :: Python :: 3.12",
37
+ "Programming Language :: Python :: 3.13",
38
+ "Programming Language :: Python :: 3 :: Only",
39
+ "Topic :: Security",
40
+ "Topic :: Software Development :: Quality Assurance",
41
+ "Typing :: Typed",
42
+ ]
43
+ dependencies = [
44
+ "pydantic>=2.7.0",
45
+ ]
46
+
47
+ [project.optional-dependencies]
48
+ core = [
49
+ "attackmap>=0.1.0",
50
+ ]
51
+ dev = [
52
+ "pytest>=8.0.0",
53
+ "build>=1.2.0",
54
+ "attackmap>=0.1.0",
55
+ ]
56
+
57
+ [project.urls]
58
+ Homepage = "https://github.com/mlaify/attackmap-analyzer-python"
59
+ Repository = "https://github.com/mlaify/attackmap-analyzer-python"
60
+ Issues = "https://github.com/mlaify/attackmap-analyzer-python/issues"
61
+ Changelog = "https://github.com/mlaify/attackmap-analyzer-python/blob/main/CHANGELOG.md"
62
+ "AttackMap core" = "https://github.com/mlaify/AttackMap"
63
+
64
+ [project.entry-points."attackmap.analyzers"]
65
+ python = "attackmap_analyzer_python:PythonAnalyzer"
66
+
67
+ [tool.setuptools]
68
+ package-dir = {"" = "src"}
69
+
70
+ [tool.setuptools.packages.find]
71
+ where = ["src"]
72
+
73
+ [tool.pytest.ini_options]
74
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .analyzer import PythonAnalyzer
2
+
3
+ __all__ = ["PythonAnalyzer"]