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

@@ -0,0 +1,3 @@
1
+ from .analyzer import CAnalyzer
2
+
3
+ __all__ = ["CAnalyzer"]
@@ -0,0 +1,386 @@
1
+ """C ecosystem analyzer for AttackMap.
2
+
3
+ Coverage (v0.1):
4
+ - Web frameworks: civetweb (mg_set_request_handler routes), libmicrohttpd
5
+ (MHD_start_daemon entrypoint), mongoose (mg_http_listen entrypoint +
6
+ mg_http_match_uri pseudo-routes), libonion (onion_url_add routes)
7
+ - HTTP clients (external calls): libcurl (CURLOPT_URL string literals)
8
+ - Databases: sqlite3 (sqlite3_open*), libpq (PQconnectdb*), MySQL/MariaDB C
9
+ client (mysql_real_connect), hiredis (redisConnect*), MongoDB C driver
10
+ (mongoc_client_new)
11
+ - Auth/crypto: OpenSSL (broad framework hint via EVP_/SSL_/RSA_), mbedTLS,
12
+ libsodium (crypto_pwhash, crypto_secretbox), Argon2 reference impl,
13
+ bcrypt-c, scrypt
14
+ - Secrets: getenv / secure_getenv / getenv_s with secret-shaped names
15
+ - Service hints: project name from CMakeLists.txt
16
+
17
+ C is more fragmented than other ecosystems — there's no single dominant
18
+ HTTP framework, and routing patterns vary widely. We capture what regex
19
+ can reach reliably and conservatively confidence-tag pattern hits.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import re
25
+ from pathlib import Path
26
+
27
+ from .contracts import (
28
+ AnalyzerMetadata,
29
+ AuthHint,
30
+ DatabaseHint,
31
+ EntrypointHint,
32
+ ExternalCall,
33
+ FrameworkHint,
34
+ Route,
35
+ ScanResult,
36
+ SecretHint,
37
+ ServiceHint,
38
+ )
39
+
40
+ CODE_SUFFIXES = {".c", ".h"}
41
+ SKIP_DIRS = {
42
+ "build",
43
+ ".git",
44
+ "_deps",
45
+ "third_party",
46
+ "vendor",
47
+ "external",
48
+ ".cache",
49
+ "out",
50
+ "node_modules",
51
+ }
52
+ _SNIPPET_MAX_CHARS = 160
53
+
54
+
55
+ # ---------- Patterns ----------
56
+
57
+ # civetweb: mg_set_request_handler(ctx, "/path", handler, NULL)
58
+ CIVETWEB_ROUTE_PATTERN = re.compile(
59
+ r'\bmg_set_request_handler\s*\(\s*\w+\s*,\s*"([^"]+)"',
60
+ )
61
+
62
+ # mongoose: mg_http_match_uri(hm, "/path") inside an event handler — pseudo-routes
63
+ MONGOOSE_MATCH_URI_PATTERN = re.compile(
64
+ r'\bmg_http_match_uri\s*\(\s*\w+\s*,\s*"([^"]+)"',
65
+ )
66
+
67
+ # libonion: onion_url_add(url, "^/path/?$", handler, ...)
68
+ ONION_ROUTE_PATTERN = re.compile(
69
+ r'\bonion_url_add(?:_static|_with_data)?\s*\(\s*\w+\s*,\s*"([^"]+)"',
70
+ )
71
+
72
+ # libcurl: curl_easy_setopt(handle, CURLOPT_URL, "https://...")
73
+ LIBCURL_URL_PATTERN = re.compile(
74
+ r'\bcurl_easy_setopt\s*\(\s*\w+\s*,\s*CURLOPT_URL\s*,\s*"(https?://[^"]+)"',
75
+ )
76
+
77
+ # DBs
78
+ DB_PATTERNS: list[tuple[re.Pattern[str], str]] = [
79
+ (re.compile(r'\bsqlite3_open(?:_v2)?\s*\('), "sqlite"),
80
+ (re.compile(r'\bPQconnectdb(?:Params)?\s*\(|\bPQsetdbLogin\s*\('), "postgresql"),
81
+ (re.compile(r'\bmysql_real_connect\s*\(|\bmariadb_real_connect\s*\('), "mysql"),
82
+ (re.compile(r'\bredisConnect(?:WithTimeout)?\s*\('), "redis"),
83
+ (re.compile(r'\bmongoc_client_new\s*\(|\bmongoc_uri_new\s*\('), "mongodb"),
84
+ ]
85
+
86
+ # Auth / crypto
87
+ AUTH_PATTERNS: list[tuple[re.Pattern[str], str, float]] = [
88
+ (re.compile(r'\bcrypto_pwhash(?:_argon2(?:i|id))?\s*\(|\bcrypto_pwhash_str\s*\('), "argon2", 0.9),
89
+ (re.compile(r'\bargon2(?:i|d|id)?_hash\w*\s*\('), "argon2", 0.9),
90
+ (re.compile(r'\bbcrypt(?:_hashpw|_checkpw|_gensalt)?\s*\('), "bcrypt", 0.9),
91
+ (re.compile(r'\bscrypt(?:_kdf)?\s*\('), "scrypt", 0.9),
92
+ (re.compile(r'\bcrypto_secretbox\w*\s*\(|\bcrypto_aead_(?:chacha20poly1305|aes256gcm)\w*\s*\('), "libsodium_aead", 0.85),
93
+ (re.compile(r'\bSSL_CTX_new\s*\(|\bSSL_new\s*\(|\bTLS_method\s*\(|\bTLS_(?:client|server)_method\s*\('), "openssl_tls", 0.85),
94
+ (re.compile(r'\bEVP_PKEY_new\s*\(|\bEVP_(?:Encrypt|Decrypt)Init\w*\s*\('), "openssl_evp", 0.8),
95
+ (re.compile(r'\bRAND_bytes\s*\(|\bRAND_priv_bytes\s*\('), "openssl_rand", 0.8),
96
+ (re.compile(r'\bmbedtls_(?:ssl|x509)_\w+\s*\('), "mbedtls", 0.85),
97
+ (re.compile(r'\bjwt_(?:encode|decode|new|verify)\s*\('), "jwt", 0.85),
98
+ (re.compile(r'\bAuthorization\b'), "authorization_header", 0.6),
99
+ (re.compile(r'\bBearer\b'), "bearer_token", 0.6),
100
+ (re.compile(r'\bapi[_-]?key\b', re.IGNORECASE), "api_key", 0.6),
101
+ ]
102
+
103
+ FRAMEWORK_PATTERNS: list[tuple[re.Pattern[str], str]] = [
104
+ (re.compile(r'\bMHD_start_daemon\s*\(|\bMHD_create_response\w*\s*\(|#\s*include\s+["<]microhttpd\.h'), "libmicrohttpd"),
105
+ (re.compile(r'\bmg_start\s*\(|\bmg_set_request_handler\s*\(|#\s*include\s+["<]civetweb\.h'), "civetweb"),
106
+ (re.compile(r'\bmg_mgr_init\s*\(|\bmg_http_listen\s*\(|#\s*include\s+["<]mongoose\.h'), "mongoose"),
107
+ (re.compile(r'\bonion_new\s*\(|\bonion_listen\s*\(|#\s*include\s+["<]onion/onion\.h'), "libonion"),
108
+ (re.compile(r'#\s*include\s+["<]openssl/'), "openssl"),
109
+ (re.compile(r'#\s*include\s+["<]mbedtls/'), "mbedtls"),
110
+ (re.compile(r'#\s*include\s+["<]sodium\.h'), "libsodium"),
111
+ (re.compile(r'#\s*include\s+["<]curl/curl\.h'), "libcurl"),
112
+ (re.compile(r'#\s*include\s+["<]sqlite3\.h'), "sqlite3"),
113
+ (re.compile(r'#\s*include\s+["<]libpq-fe\.h'), "libpq"),
114
+ (re.compile(r'#\s*include\s+["<]hiredis/hiredis\.h'), "hiredis"),
115
+ (re.compile(r'#\s*include\s+["<]mongoc/mongoc\.h|#\s*include\s+["<]mongoc\.h'), "mongoc"),
116
+ ]
117
+
118
+ ENTRYPOINT_PATTERNS: list[tuple[re.Pattern[str], str]] = [
119
+ (re.compile(r'\bMHD_start_daemon\s*\('), "mhd_start_daemon"),
120
+ (re.compile(r'\bmg_start\s*\('), "civetweb_start"),
121
+ (re.compile(r'\bmg_http_listen\s*\('), "mongoose_http_listen"),
122
+ (re.compile(r'\bonion_listen\s*\('), "onion_listen"),
123
+ (re.compile(r'\baccept\s*\(\s*\w+\s*,\s*\(struct\s+sockaddr\s*\*\)'), "raw_socket_accept"),
124
+ ]
125
+
126
+ # Secrets via getenv / secure_getenv / getenv_s
127
+ SECRET_PATTERNS: list[re.Pattern[str]] = [
128
+ re.compile(
129
+ r'\b(?:secure_)?getenv\s*\(\s*"([A-Z0-9_]*(?:SECRET|TOKEN|KEY|PASSWORD|PASS|PWD)[A-Z0-9_]*)"',
130
+ ),
131
+ re.compile(
132
+ r'\bgetenv_s\s*\([^,]*,\s*[^,]*,\s*"([A-Z0-9_]*(?:SECRET|TOKEN|KEY|PASSWORD|PASS|PWD)[A-Z0-9_]*)"',
133
+ ),
134
+ ]
135
+
136
+
137
+ def _line_of(content: str, offset: int) -> int:
138
+ if offset <= 0:
139
+ return 1
140
+ return content.count("\n", 0, offset) + 1
141
+
142
+
143
+ def _line_snippet(content: str, offset: int, *, max_chars: int = _SNIPPET_MAX_CHARS) -> str:
144
+ line_start = content.rfind("\n", 0, offset) + 1
145
+ line_end = content.find("\n", offset)
146
+ if line_end == -1:
147
+ line_end = len(content)
148
+ line = content[line_start:line_end].strip()
149
+ if len(line) > max_chars:
150
+ line = line[: max_chars - 1] + "…"
151
+ return line
152
+
153
+
154
+ def _project_name_from_cmake(cmake_path: Path) -> str | None:
155
+ if not cmake_path.exists():
156
+ return None
157
+ try:
158
+ text = cmake_path.read_text(encoding="utf-8")
159
+ except UnicodeDecodeError:
160
+ return None
161
+ match = re.search(r"\bproject\s*\(\s*([A-Za-z0-9_\-]+)", text)
162
+ if match:
163
+ return match.group(1)
164
+ return None
165
+
166
+
167
+ class CAnalyzer:
168
+ metadata = AnalyzerMetadata(
169
+ name="c",
170
+ display_name="C Analyzer",
171
+ version="0.1.0",
172
+ description="C ecosystem analyzer covering libmicrohttpd, civetweb, mongoose, libonion, libcurl, OpenSSL, libsodium, sqlite3, libpq, mysql, hiredis, mongoc.",
173
+ scope="C source trees and CMake/Make projects. Detects HTTP server entrypoints, libcurl outbound calls, common DB and crypto libraries.",
174
+ targets=["c", "civetweb", "libmicrohttpd", "mongoose"],
175
+ languages=["c"],
176
+ priority=20,
177
+ experimental=True, # C ecosystem coverage is heuristic and partial; mark experimental.
178
+ enabled_by_default=True,
179
+ )
180
+
181
+ @property
182
+ def name(self) -> str:
183
+ return self.metadata.name
184
+
185
+ # ---------- Public entry points ----------
186
+
187
+ def detect(self, repo_path: str | Path) -> bool:
188
+ root = Path(repo_path).resolve()
189
+ if not root.exists() or not root.is_dir():
190
+ return False
191
+ for path in root.rglob("*"):
192
+ if any(part in SKIP_DIRS for part in path.parts):
193
+ continue
194
+ if not path.is_file():
195
+ continue
196
+ if path.suffix in CODE_SUFFIXES:
197
+ return True
198
+ if path.name in {"CMakeLists.txt", "Makefile"}:
199
+ # Disambiguate: a CMake project may be C++ rather than C. Only return True
200
+ # when there's at least one .c file alongside it; otherwise let the C++
201
+ # analyzer claim the repo.
202
+ for sibling in path.parent.rglob("*.c"):
203
+ if any(part in SKIP_DIRS for part in sibling.parts):
204
+ continue
205
+ return True
206
+ return False
207
+
208
+ def analyze(self, repo_path: str | Path) -> ScanResult:
209
+ root = Path(repo_path).resolve()
210
+ result = ScanResult(root=str(root))
211
+ if not root.exists() or not root.is_dir():
212
+ return result
213
+
214
+ for cmake in root.rglob("CMakeLists.txt"):
215
+ if any(part in SKIP_DIRS for part in cmake.parts):
216
+ continue
217
+ project = _project_name_from_cmake(cmake)
218
+ if project:
219
+ self._append_unique_service(result, f"project:{project}", str(cmake.relative_to(root)))
220
+
221
+ for file_path in root.rglob("*"):
222
+ if not file_path.is_file():
223
+ continue
224
+ if any(part in SKIP_DIRS for part in file_path.parts):
225
+ continue
226
+ if file_path.suffix not in CODE_SUFFIXES:
227
+ continue
228
+
229
+ result.files_scanned += 1
230
+ if "c" not in result.languages:
231
+ result.languages.append("c")
232
+
233
+ try:
234
+ content = file_path.read_text(encoding="utf-8")
235
+ except UnicodeDecodeError:
236
+ continue
237
+
238
+ relative = str(file_path.relative_to(root))
239
+ self._extract_routes(content, relative, result)
240
+ self._extract_databases(content, relative, result)
241
+ self._extract_auth(content, relative, result)
242
+ self._extract_secrets(content, relative, result)
243
+ self._extract_external_calls(content, relative, result)
244
+ self._extract_frameworks(content, relative, result)
245
+ self._extract_entrypoints(content, relative, result)
246
+
247
+ result.languages.sort()
248
+ return result
249
+
250
+ # ---------- Extractors ----------
251
+
252
+ def _extract_routes(self, content: str, relative: str, result: ScanResult) -> None:
253
+ for match in CIVETWEB_ROUTE_PATTERN.finditer(content):
254
+ path = match.group(1)
255
+ self._append_unique_route(result, path, "ANY", relative, _line_of(content, match.start()))
256
+ for match in MONGOOSE_MATCH_URI_PATTERN.finditer(content):
257
+ path = match.group(1)
258
+ self._append_unique_route(result, path, "ANY", relative, _line_of(content, match.start()))
259
+ for match in ONION_ROUTE_PATTERN.finditer(content):
260
+ path = match.group(1)
261
+ self._append_unique_route(result, path, "ANY", relative, _line_of(content, match.start()))
262
+
263
+ def _extract_databases(self, content: str, relative: str, result: ScanResult) -> None:
264
+ for pattern, kind in DB_PATTERNS:
265
+ match = pattern.search(content)
266
+ if match is None:
267
+ continue
268
+ self._append_unique_database(
269
+ result, kind, relative,
270
+ _line_of(content, match.start()),
271
+ _line_snippet(content, match.start()),
272
+ )
273
+
274
+ def _extract_auth(self, content: str, relative: str, result: ScanResult) -> None:
275
+ for pattern, hint, confidence in AUTH_PATTERNS:
276
+ match = pattern.search(content)
277
+ if match is None:
278
+ continue
279
+ self._append_unique_auth(
280
+ result, hint, relative,
281
+ _line_of(content, match.start()),
282
+ _line_snippet(content, match.start()),
283
+ confidence,
284
+ )
285
+
286
+ def _extract_secrets(self, content: str, relative: str, result: ScanResult) -> None:
287
+ for pattern in SECRET_PATTERNS:
288
+ for match in pattern.finditer(content):
289
+ name = match.group(1)
290
+ self._append_unique_secret(
291
+ result, name, relative,
292
+ _line_of(content, match.start()),
293
+ _line_snippet(content, match.start()),
294
+ )
295
+
296
+ def _extract_external_calls(self, content: str, relative: str, result: ScanResult) -> None:
297
+ for match in LIBCURL_URL_PATTERN.finditer(content):
298
+ target = match.group(1)
299
+ self._append_unique_external(
300
+ result, target, relative,
301
+ _line_of(content, match.start()),
302
+ _line_snippet(content, match.start()),
303
+ )
304
+
305
+ def _extract_frameworks(self, content: str, relative: str, result: ScanResult) -> None:
306
+ for pattern, name in FRAMEWORK_PATTERNS:
307
+ match = pattern.search(content)
308
+ if match is None:
309
+ continue
310
+ self._append_unique_framework(
311
+ result, name, relative,
312
+ _line_of(content, match.start()),
313
+ _line_snippet(content, match.start()),
314
+ )
315
+
316
+ def _extract_entrypoints(self, content: str, relative: str, result: ScanResult) -> None:
317
+ for pattern, hint in ENTRYPOINT_PATTERNS:
318
+ match = pattern.search(content)
319
+ if match is None:
320
+ continue
321
+ self._append_unique_entrypoint(
322
+ result, hint, relative,
323
+ _line_of(content, match.start()),
324
+ _line_snippet(content, match.start()),
325
+ )
326
+
327
+ # ---------- Append helpers ----------
328
+
329
+ @staticmethod
330
+ def _append_unique_route(result: ScanResult, path: str, method: str, file: str, line: int | None) -> None:
331
+ key = (path, method, file)
332
+ if any((item.path, item.method, item.file) == key for item in result.routes):
333
+ return
334
+ result.routes.append(Route(path=path, method=method, file=file, line=line))
335
+
336
+ @staticmethod
337
+ def _append_unique_database(result: ScanResult, kind: str, file: str, line: int | None, evidence: str | None) -> None:
338
+ key = (kind, file)
339
+ if any((item.kind, item.file) == key for item in result.databases):
340
+ return
341
+ result.databases.append(DatabaseHint(kind=kind, file=file, line=line, evidence_text=evidence))
342
+
343
+ @staticmethod
344
+ def _append_unique_auth(result: ScanResult, hint: str, file: str, line: int | None, evidence: str | None, confidence: float) -> None:
345
+ key = (hint, file)
346
+ if any((item.hint, item.file) == key for item in result.auth_hints):
347
+ return
348
+ result.auth_hints.append(AuthHint(hint=hint, file=file, line=line, evidence_text=evidence, confidence=confidence))
349
+
350
+ @staticmethod
351
+ def _append_unique_secret(result: ScanResult, name: str, file: str, line: int | None, evidence: str | None) -> None:
352
+ key = (name, file)
353
+ if any((item.name, item.file) == key for item in result.secret_hints):
354
+ return
355
+ result.secret_hints.append(SecretHint(name=name, file=file, line=line, evidence_text=evidence, confidence=0.85))
356
+
357
+ @staticmethod
358
+ def _append_unique_external(result: ScanResult, target: str, file: str, line: int | None, evidence: str | None) -> None:
359
+ key = (target, file)
360
+ if any((item.target, item.file) == key for item in result.external_calls):
361
+ return
362
+ result.external_calls.append(ExternalCall(target=target, file=file, line=line, evidence_text=evidence))
363
+
364
+ @staticmethod
365
+ def _append_unique_framework(result: ScanResult, hint: str, file: str, line: int | None, evidence: str | None) -> None:
366
+ key = (hint, file)
367
+ if any((item.hint, item.file) == key for item in result.framework_hints):
368
+ return
369
+ result.framework_hints.append(FrameworkHint(hint=hint, file=file, line=line, evidence_text=evidence))
370
+
371
+ @staticmethod
372
+ def _append_unique_entrypoint(result: ScanResult, hint: str, file: str, line: int | None, evidence: str | None) -> None:
373
+ key = (hint, file)
374
+ if any((item.hint, item.file) == key for item in result.entrypoint_hints):
375
+ return
376
+ result.entrypoint_hints.append(EntrypointHint(hint=hint, file=file, line=line, evidence_text=evidence))
377
+
378
+ @staticmethod
379
+ def _append_unique_service(result: ScanResult, hint: str, file: str) -> None:
380
+ key = (hint, file)
381
+ if any((item.hint, item.file) == key for item in result.service_hints):
382
+ return
383
+ result.service_hints.append(ServiceHint(hint=hint, file=file))
384
+
385
+
386
+ __all__ = ["CAnalyzer"]
@@ -0,0 +1,30 @@
1
+ from __future__ import annotations
2
+
3
+ from attackmap.sdk.contracts import AnalyzerMetadata, AnalyzerProtocol
4
+ from attackmap.sdk.models import (
5
+ AuthHint,
6
+ DatabaseHint,
7
+ EntrypointHint,
8
+ ExternalCall,
9
+ FrameworkHint,
10
+ Route,
11
+ ScanResult,
12
+ SecretHint,
13
+ ServiceHint,
14
+ )
15
+
16
+ AttackMapAnalyzerProtocol = AnalyzerProtocol
17
+
18
+ __all__ = [
19
+ "AnalyzerMetadata",
20
+ "AttackMapAnalyzerProtocol",
21
+ "Route",
22
+ "ExternalCall",
23
+ "DatabaseHint",
24
+ "AuthHint",
25
+ "EntrypointHint",
26
+ "FrameworkHint",
27
+ "ServiceHint",
28
+ "SecretHint",
29
+ "ScanResult",
30
+ ]
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: attackmap-analyzer-c
3
+ Version: 0.1.0
4
+ Summary: C ecosystem analyzer plugin for AttackMap (libmicrohttpd, civetweb, mongoose; libcurl; OpenSSL/mbedTLS/libsodium; sqlite3/libpq/mysql/hiredis/mongoc).
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-c
10
+ Project-URL: Repository, https://github.com/mlaify/attackmap-analyzer-c
11
+ Project-URL: Issues, https://github.com/mlaify/attackmap-analyzer-c/issues
12
+ Project-URL: Changelog, https://github.com/mlaify/attackmap-analyzer-c/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-c
42
+
43
+ C ecosystem analyzer for [AttackMap](https://github.com/mlaify/AttackMap).
44
+
45
+ C is more fragmented than language-specific ecosystems — there's no dominant web framework, and routing patterns vary widely. This analyzer captures what regex can reach reliably from common third-party libraries.
46
+
47
+ - **Web frameworks** — civetweb (`mg_set_request_handler` extracts routes), libmicrohttpd (`MHD_start_daemon` entrypoint), mongoose (`mg_http_listen` entrypoint + `mg_http_match_uri` pseudo-routes), libonion (`onion_url_add` routes)
48
+ - **HTTP clients (external calls)** — libcurl (`curl_easy_setopt(handle, CURLOPT_URL, "...")` URL string literals)
49
+ - **Databases** — sqlite3 (`sqlite3_open*`), libpq (`PQconnectdb*`, `PQsetdbLogin`), MySQL/MariaDB C client (`mysql_real_connect`, `mariadb_real_connect`), hiredis (`redisConnect*`), MongoDB C driver (`mongoc_client_new`)
50
+ - **Auth/crypto** — OpenSSL (TLS context, EVP cipher, RAND), mbedTLS (SSL/X.509), libsodium (`crypto_pwhash`, `crypto_secretbox`, `crypto_aead_*`), Argon2 reference impl (`argon2id_hash_*`), bcrypt-c, scrypt, JWT C libraries (`jwt_encode`, `jwt_decode`)
51
+ - **Secrets** — `getenv`, `secure_getenv`, `getenv_s` with secret-shaped names (`*SECRET*`, `*TOKEN*`, `*KEY*`, `*PASSWORD*`, `*PASS*`, `*PWD*`)
52
+ - **Service hints** — project name from `CMakeLists.txt` (`project(NAME ...)`)
53
+
54
+ All emissions populate AttackMap's Signal v2 fields (line numbers + evidence snippets + confidence) so downstream insights can cite `path/to/file.c:NN`.
55
+
56
+ ## Install
57
+
58
+ ```bash
59
+ pip install git+https://github.com/mlaify/attackmap-analyzer-c.git
60
+ ```
61
+
62
+ The analyzer is auto-discovered by AttackMap via the `attackmap.analyzers` entry-point group.
63
+
64
+ ## Usage with AttackMap
65
+
66
+ ```bash
67
+ # Auto-discovered when installed:
68
+ attackmap analyze /path/to/c/repo
69
+
70
+ # Or invoke explicitly:
71
+ attackmap analyze /path/to/c/repo --module c
72
+ ```
73
+
74
+ ## Detection
75
+
76
+ `detect()` returns true when any `.c` or `.h` file is present in the tree, ignoring `build/`, `.git/`, `_deps/`, `third_party/`, `vendor/`, `external/`, `.cache/`, `out/`, and `node_modules/`. A `CMakeLists.txt` alongside `.cpp` files (and no `.c` files) is **not** claimed by this analyzer — that's the C++ analyzer's territory.
77
+
78
+ ## Coverage notes
79
+
80
+ - **Marked experimental**: regex-based extraction in C has more false positives than language-with-strict-imports analyzers. Keep the confidence-tier model in mind when consuming output (0.6 keyword sweeps vs. 0.85+ canonical function-name hits).
81
+ - **Routes**: civetweb / mongoose / libonion all expose path strings explicitly in their routing API; libmicrohttpd does not (single-callback dispatch on `url`). For libmicrohttpd, only the entrypoint is captured — per-route URLs would need to be regexed out of `if (strcmp(url, "/x") == 0)` patterns inside the answer-callback.
82
+ - **HTTP method on routes**: the C web frameworks covered here don't statically declare HTTP methods at registration time (handlers branch on method internally), so all routes are emitted with method `ANY`.
83
+ - **OpenSSL EVP / RAND** signals are confidence 0.8 — they're broad indicators of crypto usage but not strong defensive signals on their own.
84
+ - **Authorization / Bearer / api_key keyword matches** are tier-0.6 (low confidence). They're useful as supporting evidence for an auth posture, not as load-bearing.
85
+ - **Hardcoded `#define JWT_SECRET "abc..."` macros** are not extracted — too noisy. `getenv("JWT_SECRET")` is the canonical pattern we rely on.
86
+
87
+ ## License
88
+
89
+ MIT
@@ -0,0 +1,9 @@
1
+ attackmap_analyzer_c/__init__.py,sha256=G3ZOjgZiuQK_CDy8L7fcz7dbBgJffguB6_1Dkha8R0s,57
2
+ attackmap_analyzer_c/analyzer.py,sha256=nqv4kndXPJM4aBIfqVeeK7FDvpbcCVH3sPLawltbzpc,16276
3
+ attackmap_analyzer_c/contracts.py,sha256=dsveFe7szz7xceev0PIfyc5jQlNiES0whsdxwu9D7YI,578
4
+ attackmap_analyzer_c-0.1.0.dist-info/licenses/LICENSE,sha256=vtPQVGUyxq359j0JmD3_eJaXyHmaHyjzaMOtaLwJc88,1097
5
+ attackmap_analyzer_c-0.1.0.dist-info/METADATA,sha256=vpUOgI8Zj_SmLTcnelR8IDX8YnpF2kWasubYQ7JJDKk,5400
6
+ attackmap_analyzer_c-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ attackmap_analyzer_c-0.1.0.dist-info/entry_points.txt,sha256=bbLuVViJv9O1QXdWbxvIkynOApW6BWyzb4gfjBR7K3E,57
8
+ attackmap_analyzer_c-0.1.0.dist-info/top_level.txt,sha256=nAhdEvU6t_VL0uOhBmYqTlFfTtz8JeCq8sAeMmBPmNY,21
9
+ attackmap_analyzer_c-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
+ c = attackmap_analyzer_c:CAnalyzer
@@ -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_c