attackmap-analyzer-c
C ecosystem analyzer for AttackMap.
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.
- Web frameworks — civetweb (
mg_set_request_handlerextracts routes), libmicrohttpd (MHD_start_daemonentrypoint), mongoose (mg_http_listenentrypoint +mg_http_match_uripseudo-routes), libonion (onion_url_addroutes) - HTTP clients (external calls) — libcurl (
curl_easy_setopt(handle, CURLOPT_URL, "...")URL string literals) - 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) - 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) - Secrets —
getenv,secure_getenv,getenv_swith secret-shaped names (*SECRET*,*TOKEN*,*KEY*,*PASSWORD*,*PASS*,*PWD*) - Service hints — project name from
CMakeLists.txt(project(NAME ...)) - Dependencies (SBOM) — vcpkg, Conan and CMake manifests, so
--cvereaches native dependencies; unpinned CMake downloads are reported as supply-chain issues (see Dependencies) - Memory-safety and command-exec sinks — unbounded copies, non-constant printf formats,
system/popen/exec*, input-controlledmemcpylengths and allocation-size overflows, tied to request and input sources in the same function (see Native sinks)
All emissions populate AttackMap's Signal v2 fields (line numbers + evidence snippets + confidence) so downstream insights can cite path/to/file.c:NN.
Install
uv tool install attackmap --with attackmap-analyzer-c \
--index mlaify=https://pkg.mlaify.io/pypi/simple/ --index-strategy first-index
# or from source:
pip install git+https://github.com/mlaify/attackmap-analyzer-c.git
The analyzer is registered with AttackMap via the attackmap.analyzers entry-point group.
Usage with AttackMap
This analyzer is experimental and opt-in (enabled_by_default=False): installing it does not make it run on every scan. Select it explicitly:
attackmap analyze /path/to/c/repo -m c
Detection
detect() returns true when at least one .c file is present in the tree (a lone .h, such as an ObjC/Swift bridging header, doesn't count), in a single walk, ignoring _deps/, third_party/, external/, .cache/ and AttackMap's shared skip list (build/, out/, vendor/, node_modules/, .git/, ...). Skip directories are matched only inside the repo, so a checkout under e.g. /build/... is still scanned. Files are walked with attackmap.sdk.iter_repo_files, which does not follow symlinks out of the repo, and read with read_source, which falls back to cp1252/latin-1 for legacy-encoded sources. A CMakeLists.txt alongside .cpp files (and no .c files) is not claimed by this analyzer — that's the C++ analyzer's territory.
.h ownership
.h ownership is decided per repo, by the same rule in both the C and C++ analyzers, so exactly one of them analyzes each header whichever of -m c / -m cpp is selected:
.hbelongs to C++ if the repo has any C++ source or header (.cpp,.cc,.cxx,.hpp,.hxx,.ipp,.tpp) or aCMakeLists.txtthat enables CXX (project(... CXX ...),enable_language(CXX)orCMAKE_CXX_STANDARD). A bareproject(foo)doesn't count.- Otherwise
.hbelongs to C. - Files under directories either plugin prunes (
build/,third_party/,Debug/,Release/, ...) are never markers.
In a mixed repo, .c files go to C, and .cpp/.hpp/... plus .h go to C++. Running only one of the two analyzers on a mixed repo leaves the other's files unanalyzed. It never double-counts them.
Dependencies
native_deps.py emits DependencyHints (mlaify/AttackMap#191). The module is shared verbatim with attackmap-analyzer-cpp. Core dedupes identical records when both analyzers run.
| Source | Ecosystem | Version | dev |
|---|---|---|---|
vcpkg.json dependencies |
vcpkg |
overrides pin (resolved=True), else >= from version>=, else empty (the builtin-baseline decides; it's recorded in the evidence) |
"host": true |
conanfile.txt [requires] / [tool_requires] / [build_requires] / [test_requires] |
conan |
as written (1.2.13, [>=1.80 <2.0]) |
tool/build/test sections |
conanfile.py requires = ..., self.requires("x/1.0") and the tool/build/test forms (parsed with ast, never executed; comments and docstrings don't count) |
conan |
as written | tool/build/test |
conan.lock (Conan 2 lists and Conan 1.x graph_lock.nodes) |
conan |
exact (resolved=True) |
build_requires, build-context nodes |
CMake FetchContent_Declare / ExternalProject_Add / CPMAddPackage |
cmake |
GIT_TAG, a CPM version, or a version in the archive URL |
test/example manifests, test frameworks |
CMake find_package(Name [version] [EXACT]) |
cmake |
>=version / ==version, ranges 1.2...<2.0 → >=1.2,<2.0 |
test/example manifests, test frameworks |
cmake is inventory-only in core: it has no OSV database, so --cve reports those dependencies as not CVE-checked. conan and vcpkg map to OSV ConanCenter and vcpkg. Build tools and CMake modules (Threads, PkgConfig, Python3, Git...) aren't dependencies.
Unpinned downloads are SupplyChainIssue(kind="mutable_vcs_dependency") records:
| Download | Severity |
|---|---|
git download with no GIT_TAG, or a GIT_TAG that names a branch (main, master, develop...) |
medium |
| any other tag or a short SHA | low |
| a full 40-hex commit SHA | not flagged |
URL download without URL_HASH/URL_MD5 |
medium |
Values that are CMake variables (${X}) are never flagged. Comments, quoted strings and bracket arguments ([[ ]]) never contain commands. Malformed or deeply nested manifests are skipped.
Coverage notes
- 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).
- 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 ofif (strcmp(url, "/x") == 0)patterns inside the answer-callback. - 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. - OpenSSL EVP / RAND signals are confidence 0.8 — they're broad indicators of crypto usage but not strong defensive signals on their own.
- 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.
- Hardcoded
#define JWT_SECRET "abc..."macros are not extracted — too noisy.getenv("JWT_SECRET")is the canonical pattern we rely on.
Native sinks
The analyzer emits function-local C weaknesses as CodeWeakness records (mlaify/AttackMap#189). Core turns them into findings, one per severity tier, with CWE/OWASP/ASVS ids.
| Kind (rule id) | Fires on | Not reported |
|---|---|---|
unbounded_copy (CWE-120) |
gets; scanf/fscanf %s/%[ without a width; strcpy/strcat/sprintf %s whose source is traced to an input |
a literal or untraced source; a source with an upper-bound check first (strlen(s) < sizeof dst, directly or through a length alias; > 0 / < 0 checks don't count); a sized destination (malloc(strlen(s) + 1)); %.Ns; a bounded read (fgets, recv, %255s) copied into an array at least as large |
format_string (CWE-134) |
a printf-family format (printf, fprintf, sprintf, snprintf, syslog, civetweb/mongoose mg_printf, mg_http_reply) that is not a constant |
literals, #define and static const strings, literal ternaries, gettext _(), variadic and va_list wrappers forwarding their own fmt, untraced function results |
native_command_exec (CWE-78) |
system/popen with a non-constant command; exec* with an input-derived argument or a non-constant sh -c line |
constant commands, NULL, an untraced execv(path, args) without a shell |
tainted_copy_length (CWE-805) |
memcpy/memmove/strncpy/strncat length traced to an input |
lengths with an upper-bound check (n > sizeof dst, ck_assert_int_lt(n, cap)) or a clamp (MIN, n > cap ? cap : n, also inside the call) first, a destination allocated from the same length, a byte count returned by recv/read |
alloc_size_overflow (CWE-680) |
malloc/realloc/alloca of a product with an input-derived factor |
calloc, sums, untraced factors, a factor with an upper-bound check first or a SIZE_MAX/__builtin_mul_overflow guard |
Sources, traced per function through assignments, out-parameters and copy functions:
- Request input: civetweb
mg_get_request_info/mg_get_header/mg_get_var/mg_read, astruct mg_request_info *orstruct mg_http_message *, mongoosemg_http_get_var/mg_http_get_header, and theurl/upload_dataparameters of a libmicrohttpd handler. - Network input:
recv/recvfrom/SSL_read/BIO_read/mbedtls_ssl_read, andreadon a socket-named descriptor. - Local input: stdin (
fgets(..., stdin),scanf),argv/optargin a function that takesargv,getenv, and file reads.
Taint doesn't flow through calls to unknown functions (gethostbyname(argv[1])). A reassignment to a literal (u = "default") clears it. A copy between two declared arrays where the destination is at least as large isn't reported.
Severity and confidence:
| Input traced to the sink | Severity / confidence |
|---|---|
| request or network | high / high |
| stdin, argv, env or file | medium / medium |
| none (only non-constant formats and commands are reported) | low / low |
Code under examples/, demo/, samples/, contrib/ or docs/ is capped at low. Test, fuzz and benchmark code (test/, tests/, unittest/, fuzztest/, *_test.c, ...) is skipped. ATTACKMAP_INCLUDE_TESTS=1 scans it.
native_sinks.py is shared verbatim with attackmap-analyzer-cpp. It needs an attackmap core that exports CodeWeakness from attackmap.sdk. With an older core the analyzer still loads and emits no weaknesses.
License
MIT
Metadata
Release files for attackmap-analyzer-c 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| attackmap_analyzer_c-0.2.0.tar.gz | 60.9 kB | With provenance | Details for attackmap_analyzer_c-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| attackmap_analyzer_c-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for attackmap_analyzer_c-0.2.0-py3-none-any.whl |
Total release size: 103.1 kB
Release files / attackmap_analyzer_c-0.2.0.tar.gz
| Download URL | attackmap_analyzer_c-0.2.0.tar.gz |
|---|---|
| Size | 60.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a254b2e1d0076d4069028c45200d368827c67fb0cf9eab5d9f5ab03614f9b59a
|
|
BLAKE2b-256 checksum How to use checksums |
96e8a86dc0710e17f6d4f0ebacd0ec79e5a6fcebe3a94c62f643dd04bf0fb7cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logRelease files / attackmap_analyzer_c-0.2.0-py3-none-any.whl
| Download URL | attackmap_analyzer_c-0.2.0-py3-none-any.whl |
|---|---|
| Size | 42.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
54672247eebc01c776ed3d9672c46dd81dfb28f0253db8020b5052932b979f99
|
|
BLAKE2b-256 checksum How to use checksums |
11eb26c1c9afc0598132023eaf55a0edc3a8bafa2d3e5f7854e22e9b7f0eff19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logSecurity for attackmap-analyzer-c 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for attackmap_analyzer_c-0.2.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 14, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.