vigia-nids 0.2.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.
Files changed (119) hide show
  1. vigia_nids-0.2.0/.dockerignore +17 -0
  2. vigia_nids-0.2.0/.gitignore +31 -0
  3. vigia_nids-0.2.0/CHANGELOG.md +60 -0
  4. vigia_nids-0.2.0/Dockerfile +65 -0
  5. vigia_nids-0.2.0/LICENSE +202 -0
  6. vigia_nids-0.2.0/PKG-INFO +254 -0
  7. vigia_nids-0.2.0/README.md +206 -0
  8. vigia_nids-0.2.0/benchmarks/ESCALA.md +35 -0
  9. vigia_nids-0.2.0/benchmarks/RESULTADOS.md +448 -0
  10. vigia_nids-0.2.0/benchmarks/cic_antes_despues.py +173 -0
  11. vigia_nids-0.2.0/benchmarks/cic_deriva_real.py +198 -0
  12. vigia_nids-0.2.0/benchmarks/cic_envenenamiento_real.py +196 -0
  13. vigia_nids-0.2.0/benchmarks/cic_original_vs_corregido.py +161 -0
  14. vigia_nids-0.2.0/benchmarks/cic_ruido_engelen.py +181 -0
  15. vigia_nids-0.2.0/benchmarks/cic_split_experiment.py +128 -0
  16. vigia_nids-0.2.0/benchmarks/escala.py +153 -0
  17. vigia_nids-0.2.0/benchmarks/fetch_datasets.py +187 -0
  18. vigia_nids-0.2.0/benchmarks/make_demo_dataset.py +104 -0
  19. vigia_nids-0.2.0/docker-compose.yml +36 -0
  20. vigia_nids-0.2.0/docs/ARQUITECTURA.md +387 -0
  21. vigia_nids-0.2.0/docs/CHECKS.md +372 -0
  22. vigia_nids-0.2.0/docs/DERIVA.md +230 -0
  23. vigia_nids-0.2.0/docs/ENVENENAMIENTO.md +279 -0
  24. vigia_nids-0.2.0/docs/PLAN.md +439 -0
  25. vigia_nids-0.2.0/docs/USO.md +567 -0
  26. vigia_nids-0.2.0/pyproject.toml +104 -0
  27. vigia_nids-0.2.0/src/vigia/__init__.py +100 -0
  28. vigia_nids-0.2.0/src/vigia/api/__init__.py +6 -0
  29. vigia_nids-0.2.0/src/vigia/api/app.py +104 -0
  30. vigia_nids-0.2.0/src/vigia/api/jobs.py +143 -0
  31. vigia_nids-0.2.0/src/vigia/api/models.py +60 -0
  32. vigia_nids-0.2.0/src/vigia/api/routes.py +177 -0
  33. vigia_nids-0.2.0/src/vigia/api/security.py +120 -0
  34. vigia_nids-0.2.0/src/vigia/api/storage.py +128 -0
  35. vigia_nids-0.2.0/src/vigia/benchmark.py +257 -0
  36. vigia_nids-0.2.0/src/vigia/checks/__init__.py +12 -0
  37. vigia_nids-0.2.0/src/vigia/checks/duplicates.py +396 -0
  38. vigia_nids-0.2.0/src/vigia/checks/label_noise.py +216 -0
  39. vigia_nids-0.2.0/src/vigia/checks/labels.py +258 -0
  40. vigia_nids-0.2.0/src/vigia/checks/leakage.py +367 -0
  41. vigia_nids-0.2.0/src/vigia/checks/shortcuts.py +198 -0
  42. vigia_nids-0.2.0/src/vigia/checks/validity.py +310 -0
  43. vigia_nids-0.2.0/src/vigia/cli.py +559 -0
  44. vigia_nids-0.2.0/src/vigia/core/__init__.py +1 -0
  45. vigia_nids-0.2.0/src/vigia/core/context.py +117 -0
  46. vigia_nids-0.2.0/src/vigia/core/engine.py +51 -0
  47. vigia_nids-0.2.0/src/vigia/core/findings.py +155 -0
  48. vigia_nids-0.2.0/src/vigia/core/hashing.py +45 -0
  49. vigia_nids-0.2.0/src/vigia/core/registry.py +112 -0
  50. vigia_nids-0.2.0/src/vigia/core/streaming.py +290 -0
  51. vigia_nids-0.2.0/src/vigia/drift/__init__.py +31 -0
  52. vigia_nids-0.2.0/src/vigia/drift/checks.py +396 -0
  53. vigia_nids-0.2.0/src/vigia/drift/metrics.py +146 -0
  54. vigia_nids-0.2.0/src/vigia/fixes/__init__.py +42 -0
  55. vigia_nids-0.2.0/src/vigia/fixes/base.py +111 -0
  56. vigia_nids-0.2.0/src/vigia/fixes/dataset.py +179 -0
  57. vigia_nids-0.2.0/src/vigia/fixes/splits.py +161 -0
  58. vigia_nids-0.2.0/src/vigia/io/__init__.py +1 -0
  59. vigia_nids-0.2.0/src/vigia/io/pcap.py +84 -0
  60. vigia_nids-0.2.0/src/vigia/io/readers.py +203 -0
  61. vigia_nids-0.2.0/src/vigia/io/suricata.py +100 -0
  62. vigia_nids-0.2.0/src/vigia/io/zeek.py +151 -0
  63. vigia_nids-0.2.0/src/vigia/poison/__init__.py +42 -0
  64. vigia_nids-0.2.0/src/vigia/poison/combine.py +159 -0
  65. vigia_nids-0.2.0/src/vigia/poison/detectors.py +616 -0
  66. vigia_nids-0.2.0/src/vigia/poison/simulate.py +233 -0
  67. vigia_nids-0.2.0/src/vigia/profiles/__init__.py +40 -0
  68. vigia_nids-0.2.0/src/vigia/profiles/cic-ids-2017.yaml +129 -0
  69. vigia_nids-0.2.0/src/vigia/report/__init__.py +5 -0
  70. vigia_nids-0.2.0/src/vigia/report/render.py +202 -0
  71. vigia_nids-0.2.0/tests/conftest.py +73 -0
  72. vigia_nids-0.2.0/tests/unit/test_api.py +281 -0
  73. vigia_nids-0.2.0/tests/unit/test_benchmark.py +91 -0
  74. vigia_nids-0.2.0/tests/unit/test_context.py +114 -0
  75. vigia_nids-0.2.0/tests/unit/test_drift.py +188 -0
  76. vigia_nids-0.2.0/tests/unit/test_duplicates.py +155 -0
  77. vigia_nids-0.2.0/tests/unit/test_encoding.py +19 -0
  78. vigia_nids-0.2.0/tests/unit/test_engine_y_cli.py +330 -0
  79. vigia_nids-0.2.0/tests/unit/test_fixes.py +243 -0
  80. vigia_nids-0.2.0/tests/unit/test_label_noise.py +112 -0
  81. vigia_nids-0.2.0/tests/unit/test_labels.py +109 -0
  82. vigia_nids-0.2.0/tests/unit/test_leakage.py +252 -0
  83. vigia_nids-0.2.0/tests/unit/test_poison.py +290 -0
  84. vigia_nids-0.2.0/tests/unit/test_profiles.py +59 -0
  85. vigia_nids-0.2.0/tests/unit/test_readers.py +111 -0
  86. vigia_nids-0.2.0/tests/unit/test_readers_p1.py +260 -0
  87. vigia_nids-0.2.0/tests/unit/test_shortcuts.py +86 -0
  88. vigia_nids-0.2.0/tests/unit/test_streaming.py +140 -0
  89. vigia_nids-0.2.0/tests/unit/test_validity.py +145 -0
  90. vigia_nids-0.2.0/web/.gitignore +24 -0
  91. vigia_nids-0.2.0/web/.oxlintrc.json +8 -0
  92. vigia_nids-0.2.0/web/README.md +32 -0
  93. vigia_nids-0.2.0/web/index.html +13 -0
  94. vigia_nids-0.2.0/web/package-lock.json +1752 -0
  95. vigia_nids-0.2.0/web/package.json +27 -0
  96. vigia_nids-0.2.0/web/public/favicon.svg +1 -0
  97. vigia_nids-0.2.0/web/public/icons.svg +24 -0
  98. vigia_nids-0.2.0/web/src/App.tsx +51 -0
  99. vigia_nids-0.2.0/web/src/api.ts +126 -0
  100. vigia_nids-0.2.0/web/src/components/ApiKeyField.tsx +37 -0
  101. vigia_nids-0.2.0/web/src/components/Findings.css +71 -0
  102. vigia_nids-0.2.0/web/src/components/Findings.tsx +137 -0
  103. vigia_nids-0.2.0/web/src/components/SkippedChecks.tsx +47 -0
  104. vigia_nids-0.2.0/web/src/components/TrafficLight.css +80 -0
  105. vigia_nids-0.2.0/web/src/components/TrafficLight.tsx +124 -0
  106. vigia_nids-0.2.0/web/src/index.css +13 -0
  107. vigia_nids-0.2.0/web/src/main.tsx +17 -0
  108. vigia_nids-0.2.0/web/src/pages/Drift.tsx +248 -0
  109. vigia_nids-0.2.0/web/src/pages/Fix.tsx +124 -0
  110. vigia_nids-0.2.0/web/src/pages/Result.tsx +152 -0
  111. vigia_nids-0.2.0/web/src/pages/Upload.tsx +156 -0
  112. vigia_nids-0.2.0/web/src/styles/layout.css +116 -0
  113. vigia_nids-0.2.0/web/src/theme.css +313 -0
  114. vigia_nids-0.2.0/web/src/types.ts +75 -0
  115. vigia_nids-0.2.0/web/src/vite-env.d.ts +10 -0
  116. vigia_nids-0.2.0/web/tsconfig.app.json +30 -0
  117. vigia_nids-0.2.0/web/tsconfig.json +7 -0
  118. vigia_nids-0.2.0/web/tsconfig.node.json +23 -0
  119. vigia_nids-0.2.0/web/vite.config.ts +7 -0
@@ -0,0 +1,17 @@
1
+ .venv
2
+ .git
3
+ .mypy_cache
4
+ .pytest_cache
5
+ .ruff_cache
6
+ __pycache__
7
+ *.pyc
8
+ out
9
+ data
10
+ Datadeprueba
11
+ tests
12
+ benchmarks
13
+ docs
14
+
15
+ web/node_modules
16
+ web/dist
17
+ web/.gitignore
@@ -0,0 +1,31 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .venv/
8
+ venv/
9
+
10
+ # Herramientas
11
+ .pytest_cache/
12
+ .mypy_cache/
13
+ .ruff_cache/
14
+ .coverage
15
+ htmlcov/
16
+ graphify-out/
17
+
18
+ # Datos y salidas: los datasets de seguridad nunca se versionan
19
+ data/
20
+ out/
21
+ Datadeprueba/
22
+ *.pcap
23
+ *.pcapng
24
+ *.parquet
25
+ *.csv
26
+
27
+ # Editor / sistema operativo
28
+ .vscode/
29
+ .idea/
30
+ .DS_Store
31
+ Thumbs.db
@@ -0,0 +1,60 @@
1
+ # Changelog
2
+
3
+ Formato basado en [Keep a Changelog](https://keepachangelog.com/es-ES/1.1.0/),
4
+ y este proyecto sigue [Versionado Semántico](https://semver.org/lang/es/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.2.0] - 2026-09-29
9
+
10
+ ### Agregado
11
+
12
+ - El paquete se publica en PyPI como `vigia-nids` (el nombre `vigia` estaba
13
+ tomado); el comando y el paquete importable siguen siendo `vigia`.
14
+ - **Perfiles de datasets conocidos** (`vigia.profiles`, requisito R17):
15
+ `--profile cic-ids-2017` en `vigia audit` (y `vigia.load(profile=...)` en el
16
+ SDK) fija los roles de columna y expone IPs atacantes, ventanas de ataque y
17
+ errores conocidos documentados por el CIC, sin que un `--label-col` u otro
18
+ flag explícito pierda prioridad sobre el perfil.
19
+ - **`dup.near`** (requisito R2, casi-duplicados): MinHash LSH (extra opcional
20
+ `ml`, agrega `datasketch`) para encontrar filas casi idénticas que
21
+ `dup.exact` no detecta por no ser copias byte a byte. Umbral configurable
22
+ con `near_duplicate_threshold`.
23
+ - **API REST** (`vigia.api`, extra opcional `api`): FastAPI con endpoints para
24
+ subir datasets, lanzar auditorías, envenenamiento y deriva de forma
25
+ asíncrona (cola en proceso con `asyncio`, sin Celery ni Redis), consultar
26
+ estado y descargar el reporte HTML. Autenticación por `X-API-Key`, límite de
27
+ subida y de peticiones por minuto configurables por variable de entorno, y
28
+ borrado automático del dataset subido al terminar el trabajo.
29
+ - Comando `vigia serve` para levantar la API con uvicorn.
30
+ - **Panel web** (`web/`, React + Vite + TypeScript): subir un dataset, ver el
31
+ resultado (semáforo, hallazgos, checks no ejecutados), correcciones
32
+ sugeridas y comparación de deriva con PSI por columna. El semáforo gris
33
+ tiene la misma jerarquía visual que el rojo: nunca se confunde "no se pudo
34
+ revisar todo" con "está limpio". `docker compose up` sirve la API y el
35
+ panel juntos en un solo puerto.
36
+
37
+ ## [0.1.0] - 2026-09-22
38
+
39
+ Primera versión funcional. Los tres módulos implementados y validados contra
40
+ datos reales.
41
+
42
+ ### Agregado
43
+
44
+ - **Módulo 1 — Auditor** (`vigia audit`): 15 checks que cubren los diez
45
+ requisitos P0 (duplicados, validez, fugas entre entrenamiento y prueba,
46
+ ruido de etiqueta), validados contra CIC-IDS2017 y contra Engelen et al.
47
+ - **Módulo 2 — Envenenamiento** (`vigia poison`): 4 detectores, medidos sobre
48
+ tráfico real con ataques inyectados.
49
+ - **Módulo 3 — Deriva** (`vigia drift`): 4 checks, medidos sobre los cinco
50
+ días de CIC-IDS2017.
51
+ - 8 correcciones automáticas, con cuarentena de las filas afectadas.
52
+ - Lectores de CSV, Parquet, Zeek, Suricata EVE y PCAP (R13 y R14).
53
+ - CLI con 7 comandos y códigos de salida 0/1/2 para integrarse en CI.
54
+ - Reporte HTML y JSON, con semáforo rojo/amarillo/verde/gris.
55
+ - 188 tests, `ruff` y `mypy` limpios.
56
+ - Documentación: arquitectura, checks, uso, deriva y envenenamiento en
57
+ [`docs/`](docs/).
58
+
59
+ [0.2.0]: https://github.com/Joshua203-byte/Data/releases/tag/v0.2.0
60
+ [0.1.0]: https://github.com/Joshua203-byte/Data/releases/tag/v0.1.0
@@ -0,0 +1,65 @@
1
+ # Vigía — imagen única que sirve la API REST y el panel web
2
+ # (docs/PLAN.md, fase 3.5).
3
+ #
4
+ # Un solo contenedor: FastAPI sirve la API bajo /api/v1 y /health, y el
5
+ # build estático del panel (web/dist) montado en / vía StaticFiles
6
+ # (ver src/vigia/api/app.py, `VIGIA_WEB_DIST`). Esto evita un segundo
7
+ # contenedor con nginx solo para servir archivos estáticos -- para cuatro
8
+ # pantallas no vale la pena el proxy aparte.
9
+ #
10
+ # `docker compose up` deja todo navegable en http://localhost:8000.
11
+
12
+ # ---- Etapa 1: build del frontend --------------------------------------
13
+ FROM node:22-slim AS web-build
14
+ WORKDIR /web
15
+ COPY web/package.json web/package-lock.json ./
16
+ RUN npm ci
17
+ COPY web/ ./
18
+ # VITE_API_BASE_URL vacío: el panel y la API comparten origen en este
19
+ # contenedor (mismo proceso, mismo puerto), así que las rutas relativas
20
+ # alcanzan y no hace falta hardcodear un host.
21
+ ENV VITE_API_BASE_URL=""
22
+ RUN npm run build
23
+
24
+ # ---- Etapa 2: runtime Python -------------------------------------------
25
+ FROM python:3.12-slim AS runtime
26
+
27
+ # Metadatos minimos; no instalamos herramientas de compilacion que no hacen
28
+ # falta en runtime (pyarrow y demas traen wheels precompilados para slim).
29
+ RUN apt-get update \
30
+ && apt-get install -y --no-install-recommends curl \
31
+ && rm -rf /var/lib/apt/lists/*
32
+
33
+ # Usuario sin privilegios (docs/PLAN.md, 3.5): nunca corremos como root.
34
+ RUN groupadd --system vigia && useradd --system --gid vigia --home-dir /app --shell /usr/sbin/nologin vigia
35
+
36
+ WORKDIR /app
37
+
38
+ # Instalar el paquete con el extra `api`. `parquet` va también: es el
39
+ # formato recomendado para encadenar auditorías (docs/USO.md) y sin
40
+ # pyarrow la API no podría leer .parquet subidos.
41
+ COPY pyproject.toml README.md ./
42
+ COPY src ./src
43
+ RUN pip install --no-cache-dir ".[api,parquet]"
44
+
45
+ # Panel estático ya compilado, en la ruta que `VIGIA_WEB_DIST` espera por
46
+ # defecto (web/dist relativo al directorio de trabajo del proceso).
47
+ COPY --from=web-build /web/dist ./web/dist
48
+
49
+ # Directorio para datasets/uploads temporales (docs/PLAN.md, 3.5): un
50
+ # volumen se monta acá desde docker-compose.yml. El propio storage.py usa
51
+ # `tempfile.mkdtemp`, así que esto es principalmente para dejar un punto de
52
+ # montaje estable y, si se quiere, apuntar TMPDIR ahí.
53
+ RUN mkdir -p /data/uploads && chown -R vigia:vigia /app /data
54
+
55
+ ENV TMPDIR=/data/uploads \
56
+ PYTHONUNBUFFERED=1
57
+
58
+ USER vigia
59
+
60
+ EXPOSE 8000
61
+
62
+ HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
63
+ CMD curl -f http://localhost:8000/health || exit 1
64
+
65
+ CMD ["uvicorn", "vigia.api.app:app", "--host", "0.0.0.0", "--port", "8000"]
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,254 @@
1
+ Metadata-Version: 2.5
2
+ Name: vigia-nids
3
+ Version: 0.2.0
4
+ Summary: Control de calidad continuo para los datos de modelos de ciberseguridad
5
+ Project-URL: Homepage, https://github.com/Joshua203-byte/Data
6
+ Project-URL: Documentation, https://github.com/Joshua203-byte/Data/tree/main/vigia/docs
7
+ Project-URL: Issues, https://github.com/Joshua203-byte/Data/issues
8
+ Project-URL: Changelog, https://github.com/Joshua203-byte/Data/blob/main/vigia/CHANGELOG.md
9
+ Author: Joshua
10
+ License: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: data-quality,dataset,machine-learning,nids,security
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Security
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: polars>=1.0
22
+ Requires-Dist: pyyaml>=6.0
23
+ Requires-Dist: rich>=13.0
24
+ Requires-Dist: typer>=0.12
25
+ Provides-Extra: api
26
+ Requires-Dist: fastapi>=0.110; extra == 'api'
27
+ Requires-Dist: python-multipart>=0.0.9; extra == 'api'
28
+ Requires-Dist: uvicorn[standard]>=0.29; extra == 'api'
29
+ Provides-Extra: dev
30
+ Requires-Dist: httpx>=0.27; extra == 'dev'
31
+ Requires-Dist: mypy>=1.10; extra == 'dev'
32
+ Requires-Dist: psutil>=5.9; extra == 'dev'
33
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
34
+ Requires-Dist: pytest>=8.0; extra == 'dev'
35
+ Requires-Dist: ruff>=0.5; extra == 'dev'
36
+ Provides-Extra: ml
37
+ Requires-Dist: cleanlab>=2.6; extra == 'ml'
38
+ Requires-Dist: datasketch>=2.0; extra == 'ml'
39
+ Requires-Dist: lightgbm>=4.0; extra == 'ml'
40
+ Requires-Dist: numpy>=1.26; extra == 'ml'
41
+ Requires-Dist: scikit-learn>=1.4; extra == 'ml'
42
+ Provides-Extra: parquet
43
+ Requires-Dist: pyarrow>=15.0; extra == 'parquet'
44
+ Provides-Extra: pcap
45
+ Requires-Dist: nfstream>=6.5; extra == 'pcap'
46
+ Requires-Dist: pandas>=2.0; extra == 'pcap'
47
+ Description-Content-Type: text/markdown
48
+
49
+ # Vigía
50
+
51
+ **Control de calidad continuo para los datos de modelos de ciberseguridad.**
52
+
53
+ Vigía revisa los datasets con los que se entrenan los detectores de intrusiones y
54
+ responde una pregunta incómoda: *¿este 0.99 de F1 es real, o es un artefacto de
55
+ los datos?*
56
+
57
+ La investigación sobre los datasets más usados del área (CIC-IDS2017,
58
+ CSE-CIC-IDS2018, UGR'16) documenta duplicados masivos, etiquetas incorrectas,
59
+ fugas entre entrenamiento y prueba, y columnas que le delatan la respuesta al
60
+ modelo. El resultado es siempre el mismo: **el modelo parece excelente en el
61
+ laboratorio y falla en una red real.**
62
+
63
+ > Estado: **v0.2.0 — los tres módulos implementados y validados contra datos
64
+ > reales.** El auditor cubre los diez requisitos P0, más los lectores de Zeek,
65
+ > Suricata EVE y PCAP (R13 y R14). El monitor de deriva está medido sobre los
66
+ > cinco días de CIC-IDS2017, y los detectores de envenenamiento sobre ataques
67
+ > inyectados en ese mismo tráfico y sobre el ruido de etiqueta que documentaron
68
+ > Engelen et al. Los números están en
69
+ > [`benchmarks/RESULTADOS.md`](benchmarks/RESULTADOS.md), incluidos los casos
70
+ > donde el rendimiento es pobre.
71
+
72
+ ## Los tres módulos
73
+
74
+ | Módulo | Comando | Qué responde |
75
+ |---|---|---|
76
+ | **1. Auditor** | `vigia audit` | ¿Este dataset tiene defectos que inflen las métricas? |
77
+ | **2. Envenenamiento** | `vigia poison` | ¿Alguien insertó registros para manipular el modelo? |
78
+ | **3. Deriva** | `vigia drift` | ¿El tráfico de hoy sigue pareciéndose al de entrenamiento? |
79
+
80
+ 24 checks, 8 correcciones automáticas y la comparación de rendimiento
81
+ antes/después.
82
+
83
+ ## Instalación
84
+
85
+ ```bash
86
+ pip install -e ".[dev]" # desde el repositorio
87
+ vigia --help
88
+ ```
89
+
90
+ Requiere Python 3.11 o superior.
91
+
92
+ ## Uso
93
+
94
+ ```bash
95
+ # Auditar un dataset (las columnas se detectan solas por nombre)
96
+ vigia audit data/flows.csv --report out/
97
+
98
+ # Indicar las columnas explícitamente
99
+ vigia audit data/flows.parquet \
100
+ --label-col Label --split-col split --time-col Timestamp \
101
+ --report out/
102
+
103
+ # Correr solo una categoría de checks
104
+ vigia audit data/flows.csv --checks leak,dup
105
+
106
+ # En CI: salir con código 1 si hay hallazgos críticos
107
+ vigia audit data/train.csv --fail-on critical
108
+
109
+ # Listar los checks disponibles
110
+ vigia checks
111
+ ```
112
+
113
+ Desde Python:
114
+
115
+ ```python
116
+ import vigia
117
+
118
+ ctx = vigia.load("data/flows.parquet", label_col="Label", split_col="split")
119
+ report = vigia.audit(ctx)
120
+
121
+ print(report.traffic_light()) # 'rojo' | 'amarillo' | 'verde' | 'gris'
122
+ print(report.counts()) # {'critical': 2, 'high': 1, ...}
123
+
124
+ from vigia.report import write_report
125
+
126
+ write_report(report, "out/") # report.html + report.json
127
+ ```
128
+
129
+ ## Qué revisa hoy
130
+
131
+ | Check | Qué encuentra |
132
+ |---|---|
133
+ | `dup.exact` | Filas idénticas: el modelo se evalúa con ejemplos que ya vio |
134
+ | `dup.class_ratio` | Clases formadas mayoritariamente por duplicados |
135
+ | `dup.cross_split` | **Crítico.** La misma fila en entrenamiento y en prueba |
136
+ | `leak.temporal` | El conjunto de prueba se solapa con el de entrenamiento en el tiempo |
137
+ | `leak.host` | El mismo host atacante en ambos splits: el modelo memoriza la IP |
138
+ | `shortcut.single_feature` | Una sola columna predice la etiqueta demasiado bien |
139
+ | `shortcut.identifier` | IPs, IDs de flujo o timestamps usados como características |
140
+ | `validity.nan_inf` | NaN e infinitos (CIC-IDS2017 los tiene en las columnas de tasas) |
141
+ | `validity.constant` | Columnas con un solo valor |
142
+ | `validity.impossible` | Puertos > 65535, duraciones negativas, bytes negativos |
143
+ | `validity.column_names` | Nombres con espacios (`" Destination Port"`) o ambiguos |
144
+ | `leak.session` | Flujos de la misma conexión repartidos entre splits |
145
+ | `labels.conflict` | Filas idénticas con etiquetas distintas |
146
+ | `labels.noise` | Etiquetas que contradicen al resto del dataset (cleanlab) |
147
+ | `labels.taxonomy` | La misma clase escrita de varias formas |
148
+ | `labels.imbalance` | Clases con tan pocos ejemplos que su métrica no dice nada |
149
+
150
+ Cada hallazgo trae severidad, métrica, filas afectadas, ejemplos concretos y una
151
+ recomendación. Un check que no puede correr (falta la columna de split, por
152
+ ejemplo) no falla en silencio: aparece en la sección "checks no ejecutados" del
153
+ reporte.
154
+
155
+ ### El semáforo
156
+
157
+ | Color | Significa |
158
+ |---|---|
159
+ | **rojo** | Hay hallazgos críticos o altos |
160
+ | **amarillo** | Hay hallazgos medios o bajos |
161
+ | **verde** | Sin hallazgos y todos los checks se ejecutaron |
162
+ | **gris** | Sin hallazgos, pero algunos checks no se ejecutaron |
163
+
164
+ El gris existe porque "no encontré nada" y "está limpio" no son lo mismo. Si la
165
+ columna de etiqueta o la de split no se detectan, los checks que se saltan son
166
+ justamente los que buscan fuga y duplicados entre conjuntos: dar verde ahí sería
167
+ confirmar que el dataset está bien cuando en realidad casi no se lo revisó. Si el
168
+ semáforo da gris, especificá las columnas a mano con `--label-col` y `--split-col`.
169
+
170
+ ## Corregir
171
+
172
+ Los hallazgos nombran su corrección. `vigia fix` las aplica:
173
+
174
+ ```bash
175
+ # Ver las disponibles
176
+ vigia fixes
177
+
178
+ # Aplicarlas en cadena; el archivo original nunca se toca
179
+ vigia fix data/flows.csv \
180
+ --apply drop_duplicates,drop_constant,drop_identifiers \
181
+ --out data/flows_corregido.parquet
182
+ ```
183
+
184
+ Las filas con etiqueta dudosa **nunca se borran**: `quarantine_noise` las deja
185
+ en un archivo aparte para que una persona las revise.
186
+
187
+ ## Medir cuánto del rendimiento era real
188
+
189
+ ```python
190
+ from vigia.benchmark import compare
191
+
192
+ c = compare(ctx, ["drop_identifiers"])
193
+ print(c.summary())
194
+ print(c.after.per_class_recall)
195
+ ```
196
+
197
+ Entrena el mismo modelo antes y después de corregir. Una caída no significa
198
+ que las correcciones empeoraron el modelo: significa que el número original
199
+ estaba inflado. Sobre CIC-IDS2017, cambiar un split aleatorio por uno temporal
200
+ lleva el recall de DoS Hulk, PortScan y DDoS de ~0,95 a **0,00** — ver
201
+ [`benchmarks/RESULTADOS.md`](benchmarks/RESULTADOS.md).
202
+
203
+ ## Formatos de entrada
204
+
205
+ | Formato | Extensión | Notas |
206
+ |---|---|---|
207
+ | CSV | `.csv`, `.txt` | Reintenta en cp1252 si no es UTF-8 |
208
+ | Parquet | `.parquet`, `.pq` | Conserva los tipos |
209
+ | Zeek | `.log` | TSV con cabecera o JSON Lines |
210
+ | Suricata EVE | `.json`, `.eve` | `--event-type` elige flujos o alertas |
211
+ | PCAP | `.pcap`, `.pcapng`, `.cap` | Con `pip install 'vigia-nids[pcap]'` |
212
+
213
+ Archivo suelto o carpeta completa: los datasets CIC vienen partidos en un
214
+ archivo por día, Vigía los concatena y conserva la procedencia en
215
+ `__source_file`. Los PCAP se leen de a uno, porque extraer flujos tarda minutos.
216
+
217
+ Detalles de cada formato en [`docs/USO.md`](docs/USO.md#formatos-de-entrada).
218
+
219
+ ## Desarrollo
220
+
221
+ ```bash
222
+ pip install -e ".[dev,ml]"
223
+
224
+ pytest # pruebas
225
+ ruff check src tests # lint
226
+ ruff format src tests # formato
227
+ mypy src # tipos
228
+ ```
229
+
230
+ Agregar un check nuevo es una clase con cuatro atributos y un método. El
231
+ registro es automático al importarse el módulo desde `vigia/checks/__init__.py`.
232
+ Los detalles están en [`docs/ARQUITECTURA.md`](docs/ARQUITECTURA.md).
233
+
234
+ ## Documentación
235
+
236
+ | Documento | Para qué |
237
+ |---|---|
238
+ | [`docs/CHECKS.md`](docs/CHECKS.md) | Qué significa cada hallazgo del auditor y qué hacer |
239
+ | [`docs/ENVENENAMIENTO.md`](docs/ENVENENAMIENTO.md) | Módulo 2: los detectores, el simulador y qué tan bien funcionan |
240
+ | [`docs/DERIVA.md`](docs/DERIVA.md) | Módulo 3: los checks, las métricas y cómo leerlos |
241
+ | [`docs/USO.md`](docs/USO.md) | Referencia de la CLI, del SDK y del formato JSON |
242
+ | [`docs/ARQUITECTURA.md`](docs/ARQUITECTURA.md) | Cómo está armado por dentro; cómo agregar un check |
243
+ | [`benchmarks/RESULTADOS.md`](benchmarks/RESULTADOS.md) | Resultados verificados sobre NSL-KDD y CIC-IDS2017 |
244
+ | [`docs/PLAN.md`](docs/PLAN.md) | Qué falta hasta la 1.0, en qué orden y cómo |
245
+
246
+ ## Documento de diseño
247
+
248
+ El diseño completo — los tres módulos (auditor, envenenamiento, deriva), la
249
+ arquitectura, el plan por fases y las referencias académicas — está en
250
+ [`vigia.md`](../vigia.md).
251
+
252
+ ## Licencia
253
+
254
+ Apache 2.0.