Implementa xexeu feeds import/sync e sincronização periódica de CVE/KEV embutida no xexeu serve
This commit is contained in:
1 parent
b4d2c29d24
commit
4ce5d7f595
7 files changed
+1817
-48
No files matched your search
Generated
+665
-9
@@ -61,7 +61,7 @@ version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -72,7 +72,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -228,6 +228,12 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.22.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
|
||||
|
||||
[[package]]
|
||||
name = "base64"
|
||||
version = "0.23.1"
|
||||
@@ -277,6 +283,12 @@ version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "cfg_aliases"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
|
||||
|
||||
[[package]]
|
||||
name = "chacha20"
|
||||
version = "0.10.2"
|
||||
@@ -495,6 +507,17 @@ dependencies = [
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "displaydoc"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.3"
|
||||
@@ -508,7 +531,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -566,6 +589,15 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.34"
|
||||
@@ -607,8 +639,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"wasi",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -630,9 +664,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"r-efi 6.0.0",
|
||||
"rand_core",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -733,6 +769,23 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
"smallvec",
|
||||
"tokio",
|
||||
"want",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-rustls"
|
||||
version = "0.27.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfa8e654703247911e29c23fbeaa261834bd9bb74efba2f9acddc37bfb127f53"
|
||||
dependencies = [
|
||||
"http",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"rustls",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tower-service",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -741,13 +794,22 @@ version = "0.1.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"httparse",
|
||||
"hyper",
|
||||
"ipnet",
|
||||
"libc",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -774,12 +836,116 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icu_collections"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd"
|
||||
dependencies = [
|
||||
"displaydoc",
|
||||
"potential_utf",
|
||||
"utf8_iter",
|
||||
"yoke",
|
||||
"zerofrom",
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icu_locale_core"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0"
|
||||
dependencies = [
|
||||
"displaydoc",
|
||||
"litemap",
|
||||
"tinystr",
|
||||
"writeable",
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icu_normalizer"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599"
|
||||
dependencies = [
|
||||
"icu_collections",
|
||||
"icu_normalizer_data",
|
||||
"icu_properties",
|
||||
"icu_provider",
|
||||
"smallvec",
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icu_normalizer_data"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc"
|
||||
|
||||
[[package]]
|
||||
name = "icu_properties"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f"
|
||||
dependencies = [
|
||||
"displaydoc",
|
||||
"icu_collections",
|
||||
"icu_locale_core",
|
||||
"icu_properties_data",
|
||||
"icu_provider",
|
||||
"zerotrie",
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icu_properties_data"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf"
|
||||
|
||||
[[package]]
|
||||
name = "icu_provider"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514"
|
||||
dependencies = [
|
||||
"displaydoc",
|
||||
"icu_locale_core",
|
||||
"writeable",
|
||||
"yoke",
|
||||
"zerofrom",
|
||||
"zerotrie",
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
|
||||
dependencies = [
|
||||
"idna_adapter",
|
||||
"smallvec",
|
||||
"utf8_iter",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna_adapter"
|
||||
version = "1.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"
|
||||
dependencies = [
|
||||
"icu_normalizer",
|
||||
"icu_properties",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.14.2"
|
||||
@@ -848,12 +1014,24 @@ version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||
|
||||
[[package]]
|
||||
name = "litemap"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
||||
|
||||
[[package]]
|
||||
name = "lru-slab"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154"
|
||||
|
||||
[[package]]
|
||||
name = "matchit"
|
||||
version = "0.8.4"
|
||||
@@ -880,7 +1058,7 @@ checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"wasi",
|
||||
"windows-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -946,7 +1124,7 @@ dependencies = [
|
||||
"arrow-ipc",
|
||||
"arrow-schema",
|
||||
"arrow-select",
|
||||
"base64",
|
||||
"base64 0.23.1",
|
||||
"bytes",
|
||||
"chrono",
|
||||
"half",
|
||||
@@ -977,6 +1155,15 @@ version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
|
||||
|
||||
[[package]]
|
||||
name = "potential_utf"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661"
|
||||
dependencies = [
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
@@ -986,6 +1173,62 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn"
|
||||
version = "0.11.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"cfg_aliases",
|
||||
"pin-project-lite",
|
||||
"quinn-proto",
|
||||
"quinn-udp",
|
||||
"rustc-hash",
|
||||
"rustls",
|
||||
"socket2",
|
||||
"thiserror 2.0.21",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn-proto"
|
||||
version = "0.11.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04759210543be93709136e28212294a659ef5001836ff4eab4d663e4529bba83"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"getrandom 0.4.3",
|
||||
"lru-slab",
|
||||
"rand",
|
||||
"rand_pcg",
|
||||
"ring",
|
||||
"rustc-hash",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"slab",
|
||||
"thiserror 2.0.21",
|
||||
"tinyvec",
|
||||
"tracing",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quinn-udp"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694"
|
||||
dependencies = [
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"socket2",
|
||||
"tracing",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
@@ -1024,6 +1267,67 @@ version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
|
||||
|
||||
[[package]]
|
||||
name = "rand_pcg"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a"
|
||||
dependencies = [
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-rustls",
|
||||
"hyper-util",
|
||||
"js-sys",
|
||||
"log",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"quinn",
|
||||
"rustls",
|
||||
"rustls-pki-types",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tower",
|
||||
"tower-http",
|
||||
"tower-service",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"webpki-roots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ring"
|
||||
version = "0.17.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"cfg-if",
|
||||
"getrandom 0.2.17",
|
||||
"libc",
|
||||
"untrusted",
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rsqlite-vfs"
|
||||
version = "0.2.0"
|
||||
@@ -1048,6 +1352,12 @@ dependencies = [
|
||||
"sqlite-wasm-rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "2.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
|
||||
|
||||
[[package]]
|
||||
name = "rustc_version"
|
||||
version = "0.4.1"
|
||||
@@ -1067,7 +1377,42 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls"
|
||||
version = "0.23.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
"ring",
|
||||
"rustls-pki-types",
|
||||
"rustls-webpki",
|
||||
"subtle",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-pki-types"
|
||||
version = "1.15.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
|
||||
dependencies = [
|
||||
"web-time",
|
||||
"zeroize",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustls-webpki"
|
||||
version = "0.103.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281"
|
||||
dependencies = [
|
||||
"ring",
|
||||
"rustls-pki-types",
|
||||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1221,7 +1566,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1234,6 +1579,12 @@ dependencies = [
|
||||
"rsqlite-vfs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "stable_deref_trait"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
@@ -1261,6 +1612,12 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
@@ -1288,6 +1645,20 @@ name = "sync_wrapper"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synstructure"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
@@ -1299,7 +1670,7 @@ dependencies = [
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1351,6 +1722,22 @@ dependencies = [
|
||||
"crunchy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinystr"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a"
|
||||
dependencies = [
|
||||
"displaydoc",
|
||||
"zerovec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tinyvec"
|
||||
version = "1.13.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee"
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.54.1"
|
||||
@@ -1364,7 +1751,7 @@ dependencies = [
|
||||
"signal-hook-registry",
|
||||
"socket2",
|
||||
"tokio-macros",
|
||||
"windows-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1378,6 +1765,16 @@ dependencies = [
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio-rustls"
|
||||
version = "0.26.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db"
|
||||
dependencies = [
|
||||
"rustls",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "1.1.8+spec-1.1.0"
|
||||
@@ -1433,6 +1830,24 @@ dependencies = [
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-http"
|
||||
version = "0.6.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bytes",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"pin-project-lite",
|
||||
"tower",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.3"
|
||||
@@ -1465,6 +1880,12 @@ dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "twox-hash"
|
||||
version = "2.1.5"
|
||||
@@ -1494,12 +1915,45 @@ version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "untrusted"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8_iter"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0"
|
||||
dependencies = [
|
||||
"utf_types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "utf_types"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
@@ -1512,6 +1966,15 @@ version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b"
|
||||
dependencies = [
|
||||
"try-lock",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.1+wasi-snapshot-preview1"
|
||||
@@ -1539,6 +2002,17 @@ dependencies = [
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.80"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e14e0327cb5368ad60ccb22d04a9827a693c95a926d8d125e9fa39e0baec501"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"tokio",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.130"
|
||||
@@ -1571,6 +2045,16 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-sys"
|
||||
version = "0.3.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d7d179596ff5ec0f6de4db64d54011bde6289cc49603d3a6e4ce3f329207ab88"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "web-time"
|
||||
version = "1.1.0"
|
||||
@@ -1581,6 +2065,15 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webpki-roots"
|
||||
version = "1.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f5f280bbb2b287bc8e7de7e3852945a0ff50d1bbcb5ed42b6c7a568c546df171"
|
||||
dependencies = [
|
||||
"rustls-pki-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.62.2"
|
||||
@@ -1640,6 +2133,15 @@ dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
@@ -1649,6 +2151,70 @@ dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "1.0.4"
|
||||
@@ -1661,6 +2227,12 @@ version = "0.57.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
|
||||
|
||||
[[package]]
|
||||
name = "writeable"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc"
|
||||
|
||||
[[package]]
|
||||
name = "xexeu-cli"
|
||||
version = "0.1.0"
|
||||
@@ -1686,6 +2258,7 @@ dependencies = [
|
||||
"croner",
|
||||
"ipnet",
|
||||
"parquet",
|
||||
"reqwest",
|
||||
"rusqlite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -1697,6 +2270,29 @@ dependencies = [
|
||||
"ulid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yoke"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3"
|
||||
dependencies = [
|
||||
"stable_deref_trait",
|
||||
"yoke-derive",
|
||||
"zerofrom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yoke-derive"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerocopy"
|
||||
version = "0.8.63"
|
||||
@@ -1717,6 +2313,66 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerofrom"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272"
|
||||
dependencies = [
|
||||
"zerofrom-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerofrom-derive"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879"
|
||||
|
||||
[[package]]
|
||||
name = "zerotrie"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f"
|
||||
dependencies = [
|
||||
"displaydoc",
|
||||
"yoke",
|
||||
"zerofrom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerovec"
|
||||
version = "0.11.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40"
|
||||
dependencies = [
|
||||
"yoke",
|
||||
"zerofrom",
|
||||
"zerovec-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zerovec-derive"
|
||||
version = "0.11.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.23"
|
||||
|
||||
@@ -14,7 +14,7 @@ use axum::{Json, Router};
|
||||
use chrono::{DateTime, Utc};
|
||||
use clap::{Parser, Subcommand};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
use xexeu_core::batch::{EngineMode, SweepBatch, SweepManifest, SweepStatus};
|
||||
use xexeu_core::config::{ValidationReport, XexeuConfig};
|
||||
use xexeu_core::diff::{diff_batch, DiffOptions};
|
||||
@@ -27,6 +27,7 @@ use xexeu_core::storage::{SqliteStorage, Storage};
|
||||
use xexeu_core::targets::{
|
||||
effective_cadence, expand_group, filter_in_scope, resolve_name, scope_ranges, IpRange,
|
||||
};
|
||||
use xexeu_core::vuln::{import_kev, import_nvd, sync_feeds, KevCatalog, SyncOptions, VulnDatabase};
|
||||
|
||||
const DEFAULT_CONFIG: &str = "config/xexeu.toml";
|
||||
|
||||
@@ -118,12 +119,20 @@ enum FeedsAction {
|
||||
Sync {
|
||||
#[arg(long, default_value = "config/xexeu.toml")]
|
||||
config: PathBuf,
|
||||
#[arg(long, default_value = "data/xexeu")]
|
||||
data_dir: PathBuf,
|
||||
},
|
||||
/// Import feed files copied manually for isolated networks.
|
||||
Import {
|
||||
directory: PathBuf,
|
||||
directory: Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
nvd: Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
kev: Option<PathBuf>,
|
||||
#[arg(long, default_value = "config/xexeu.toml")]
|
||||
config: PathBuf,
|
||||
#[arg(long, default_value = "data/xexeu")]
|
||||
data_dir: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -154,11 +163,23 @@ async fn main() -> ExitCode {
|
||||
Err(message) => fail(&message),
|
||||
},
|
||||
Command::Changes { since, data_dir } => run_changes(&since, &data_dir),
|
||||
Command::Feeds { action } => match action {
|
||||
FeedsAction::Import {
|
||||
directory,
|
||||
nvd,
|
||||
kev,
|
||||
config: _,
|
||||
data_dir,
|
||||
} => run_feeds_import(directory, nvd, kev, &data_dir),
|
||||
FeedsAction::Sync {
|
||||
config: _,
|
||||
data_dir,
|
||||
} => run_feeds_sync(&data_dir).await,
|
||||
},
|
||||
Command::Config { action } => match action {
|
||||
ConfigAction::Check { config } => run_config_check(&config),
|
||||
},
|
||||
Command::Doctor { json } => run_doctor(json),
|
||||
Command::Feeds { .. } => not_implemented("feeds"),
|
||||
Command::Export { .. } => not_implemented("export"),
|
||||
}
|
||||
}
|
||||
@@ -605,6 +626,8 @@ struct ServerState {
|
||||
config_path: PathBuf,
|
||||
storage: Arc<Mutex<SqliteStorage>>,
|
||||
sweeps_ingested: Arc<AtomicUsize>,
|
||||
vuln_db: Arc<RwLock<VulnDatabase>>,
|
||||
feeds_last_sync: Arc<RwLock<Option<DateTime<Utc>>>>,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
@@ -626,6 +649,9 @@ struct StatusResponse {
|
||||
version: &'static str,
|
||||
config_path: String,
|
||||
sweeps_ingested: usize,
|
||||
feeds_cve_count: usize,
|
||||
feeds_kev_count: usize,
|
||||
feeds_last_sync: Option<String>,
|
||||
groups: Vec<GroupScheduleDto>,
|
||||
}
|
||||
|
||||
@@ -659,11 +685,23 @@ async fn status_handler(State(state): State<ServerState>) -> Json<StatusResponse
|
||||
})
|
||||
.collect();
|
||||
|
||||
let (cve_count, kev_count) = {
|
||||
let db = state.vuln_db.read().await;
|
||||
(db.cve_count(), db.kev_count())
|
||||
};
|
||||
let last_sync = {
|
||||
let sync = state.feeds_last_sync.read().await;
|
||||
sync.map(|dt| dt.to_rfc3339())
|
||||
};
|
||||
|
||||
Json(StatusResponse {
|
||||
status: "ok",
|
||||
version: env!("CARGO_PKG_VERSION"),
|
||||
config_path: state.config_path.display().to_string(),
|
||||
sweeps_ingested: state.sweeps_ingested.load(Ordering::SeqCst),
|
||||
feeds_cve_count: cve_count,
|
||||
feeds_kev_count: kev_count,
|
||||
feeds_last_sync: last_sync,
|
||||
groups,
|
||||
})
|
||||
}
|
||||
@@ -814,8 +852,8 @@ async fn dashboard_handler() -> Html<&'static str> {
|
||||
const sRes = await fetch('/api/status');
|
||||
const status = await sRes.json();
|
||||
document.getElementById('status-card').innerHTML = `
|
||||
<div><strong>Versão:</strong> ${status.version} | <strong>Lotes Ingeridos:</strong> ${status.sweeps_ingested}</div>
|
||||
<div style="margin-top: 6px; font-size: 0.85rem; color: #94a3b8;">Configuração: <code>${status.config_path}</code></div>
|
||||
<div><strong>Versão:</strong> ${status.version} | <strong>Lotes Ingeridos:</strong> ${status.sweeps_ingested} | <strong>CVEs:</strong> ${status.feeds_cve_count} (${status.feeds_kev_count} no KEV)</div>
|
||||
<div style="margin-top: 6px; font-size: 0.85rem; color: #94a3b8;">Configuração: <code>${status.config_path}</code> | <strong>Último Sync:</strong> ${status.feeds_last_sync || 'não executado'}</div>
|
||||
`;
|
||||
const hRes = await fetch('/api/hosts');
|
||||
const hosts = await hRes.json();
|
||||
@@ -842,6 +880,23 @@ async fn dashboard_handler() -> Html<&'static str> {
|
||||
Html(HTML)
|
||||
}
|
||||
|
||||
fn parse_duration_str(raw: &str) -> Option<Duration> {
|
||||
let raw = raw.trim();
|
||||
if raw.len() > 1 {
|
||||
let (num_str, unit) = raw.split_at(raw.len() - 1);
|
||||
if let Ok(n) = num_str.parse::<u64>() {
|
||||
match unit {
|
||||
"s" => return Some(Duration::from_secs(n)),
|
||||
"m" => return Some(Duration::from_secs(n * 60)),
|
||||
"h" => return Some(Duration::from_secs(n * 3600)),
|
||||
"d" => return Some(Duration::from_secs(n * 86400)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
async fn run_serve(
|
||||
bind: &str,
|
||||
config_path: &Path,
|
||||
@@ -865,6 +920,33 @@ async fn run_serve(
|
||||
let shared_storage = Arc::new(Mutex::new(storage));
|
||||
let sweeps_ingested = Arc::new(AtomicUsize::new(0));
|
||||
|
||||
// Load initial vulnerability database if present on disk
|
||||
let vuln_db_path = data_dir.join("vuln_db.json");
|
||||
let (initial_db, last_sync) = if vuln_db_path.exists() {
|
||||
match VulnDatabase::load_from_file(&vuln_db_path) {
|
||||
Ok(db) => {
|
||||
println!(
|
||||
"Base de vulnerabilidades carregada: {} CVEs ({} no KEV)",
|
||||
db.cve_count(),
|
||||
db.kev_count()
|
||||
);
|
||||
(db, None)
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!(
|
||||
"aviso: falha ao carregar {}: {err}; iniciando base vazia",
|
||||
vuln_db_path.display()
|
||||
);
|
||||
(VulnDatabase::default(), None)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
(VulnDatabase::default(), None)
|
||||
};
|
||||
|
||||
let shared_vuln_db = Arc::new(RwLock::new(initial_db));
|
||||
let shared_last_sync = Arc::new(RwLock::new(last_sync));
|
||||
|
||||
// Spawn background poller for incoming sweeps.
|
||||
let poller_storage = Arc::clone(&shared_storage);
|
||||
let poller_ingested = Arc::clone(&sweeps_ingested);
|
||||
@@ -873,11 +955,50 @@ async fn run_serve(
|
||||
poll_sweeps(poller_sweeps, poller_storage, poller_ingested).await;
|
||||
});
|
||||
|
||||
// Spawn periodic background sync if auto_sync is enabled in config
|
||||
if config.defaults.feeds.auto_sync {
|
||||
let timer_db = Arc::clone(&shared_vuln_db);
|
||||
let timer_last_sync = Arc::clone(&shared_last_sync);
|
||||
let timer_db_path = vuln_db_path.clone();
|
||||
let interval_str = config.defaults.feeds.sync_interval.clone();
|
||||
tokio::spawn(async move {
|
||||
let interval = parse_duration_str(&interval_str).unwrap_or(Duration::from_secs(86400));
|
||||
println!("Sincronizador automático de feeds ativo (intervalo: {interval_str})");
|
||||
loop {
|
||||
tokio::time::sleep(interval).await;
|
||||
println!("Iniciando sincronização periódica de feeds de vulnerabilidade...");
|
||||
let sync_opts = SyncOptions::default();
|
||||
match sync_feeds(&sync_opts).await {
|
||||
Ok(downloaded) => {
|
||||
let mut db_guard = timer_db.write().await;
|
||||
db_guard.merge(downloaded);
|
||||
if let Err(e) = db_guard.save_to_file(&timer_db_path) {
|
||||
eprintln!(
|
||||
"aviso: falha ao salvar base de vulnerabilidades atualizada: {e}"
|
||||
);
|
||||
}
|
||||
let mut sync_guard = timer_last_sync.write().await;
|
||||
*sync_guard = Some(Utc::now());
|
||||
println!(
|
||||
"Feeds sincronizados periodicamente com sucesso ({} CVEs)",
|
||||
db_guard.cve_count()
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("aviso: falha na sincronização periódica de feeds: {e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let state = ServerState {
|
||||
config: Arc::new(config),
|
||||
config_path: config_path.to_path_buf(),
|
||||
storage: shared_storage,
|
||||
sweeps_ingested,
|
||||
vuln_db: shared_vuln_db,
|
||||
feeds_last_sync: shared_last_sync,
|
||||
};
|
||||
|
||||
let app = Router::new()
|
||||
@@ -932,6 +1053,145 @@ fn run_changes(since: &str, data_dir: &Path) -> ExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_matching_file(dir: &Path, keyword: &str, ext: &str) -> Option<PathBuf> {
|
||||
let entries = fs::read_dir(dir).ok()?;
|
||||
for entry in entries.flatten() {
|
||||
let path = entry.path();
|
||||
if path.is_file() {
|
||||
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
|
||||
let lower = name.to_lowercase();
|
||||
if lower.contains(keyword) && lower.ends_with(ext) {
|
||||
return Some(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn run_feeds_import(
|
||||
directory: Option<PathBuf>,
|
||||
nvd_path: Option<PathBuf>,
|
||||
kev_path: Option<PathBuf>,
|
||||
data_dir: &Path,
|
||||
) -> ExitCode {
|
||||
let nvd_file = nvd_path.or_else(|| {
|
||||
directory.as_ref().map(|d| {
|
||||
let direct = d.join("nvd.json");
|
||||
if direct.exists() {
|
||||
direct
|
||||
} else {
|
||||
find_matching_file(d, "nvd", "json").unwrap_or(direct)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
let kev_file = kev_path.or_else(|| {
|
||||
directory.as_ref().map(|d| {
|
||||
let direct_json = d.join("kev.json");
|
||||
if direct_json.exists() {
|
||||
direct_json
|
||||
} else {
|
||||
let direct_csv = d.join("kev.csv");
|
||||
if direct_csv.exists() {
|
||||
direct_csv
|
||||
} else {
|
||||
find_matching_file(d, "kev", "json")
|
||||
.or_else(|| find_matching_file(d, "kev", "csv"))
|
||||
.unwrap_or(direct_json)
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
let nvd_file = match nvd_file {
|
||||
Some(f) if f.exists() => f,
|
||||
Some(f) => return fail(&format!("arquivo NVD não encontrado em: {}", f.display())),
|
||||
None => return fail("informe o diretório com os feeds ou use --nvd <arquivo>"),
|
||||
};
|
||||
|
||||
let nvd = match import_nvd(&nvd_file) {
|
||||
Ok(c) => c,
|
||||
Err(e) => return fail(&format!("falha ao importar feed NVD: {e}")),
|
||||
};
|
||||
|
||||
let kev = if let Some(kf) = &kev_file {
|
||||
if kf.exists() {
|
||||
match import_kev(kf) {
|
||||
Ok(c) => c,
|
||||
Err(e) => return fail(&format!("falha ao importar feed CISA KEV: {e}")),
|
||||
}
|
||||
} else {
|
||||
KevCatalog::default()
|
||||
}
|
||||
} else {
|
||||
KevCatalog::default()
|
||||
};
|
||||
|
||||
let db = VulnDatabase { nvd, kev };
|
||||
let db_path = data_dir.join("vuln_db.json");
|
||||
if let Err(e) = db.save_to_file(&db_path) {
|
||||
return fail(&format!(
|
||||
"falha ao salvar base de vulnerabilidades em {}: {e}",
|
||||
db_path.display()
|
||||
));
|
||||
}
|
||||
|
||||
println!(
|
||||
"Base de vulnerabilidades importada com sucesso: {} CVEs ({} no KEV) salvos em {}",
|
||||
db.cve_count(),
|
||||
db.kev_count(),
|
||||
db_path.display()
|
||||
);
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
|
||||
async fn run_feeds_sync(data_dir: &Path) -> ExitCode {
|
||||
let db_path = data_dir.join("vuln_db.json");
|
||||
let mut db = if db_path.exists() {
|
||||
match VulnDatabase::load_from_file(&db_path) {
|
||||
Ok(loaded) => loaded,
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"aviso: não foi possível carregar base anterior em {}: {e}; iniciando base nova",
|
||||
db_path.display()
|
||||
);
|
||||
VulnDatabase::default()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
VulnDatabase::default()
|
||||
};
|
||||
|
||||
let sync_options = SyncOptions::default();
|
||||
println!("Sincronizando feeds de vulnerabilidade (NVD e CISA KEV)...");
|
||||
|
||||
let downloaded = match sync_feeds(&sync_options).await {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
eprintln!("falha na sincronização dos feeds: {e}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
|
||||
db.merge(downloaded);
|
||||
|
||||
if let Err(e) = db.save_to_file(&db_path) {
|
||||
return fail(&format!(
|
||||
"falha ao salvar base atualizada em {}: {e}",
|
||||
db_path.display()
|
||||
));
|
||||
}
|
||||
|
||||
println!(
|
||||
"Sincronização de feeds concluída: {} CVEs totais ({} no KEV) gravados em {}",
|
||||
db.cve_count(),
|
||||
db.kev_count(),
|
||||
db_path.display()
|
||||
);
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
|
||||
async fn shutdown_signal() {
|
||||
let ctrl_c = async {
|
||||
tokio::signal::ctrl_c()
|
||||
|
||||
@@ -0,0 +1,505 @@
|
||||
use std::fs;
|
||||
use std::io::{BufRead, BufReader, Read, Write};
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use tempfile::TempDir;
|
||||
|
||||
struct ChildGuard(std::process::Child);
|
||||
|
||||
impl Drop for ChildGuard {
|
||||
fn drop(&mut self) {
|
||||
let _ = self.0.kill();
|
||||
let _ = self.0.wait();
|
||||
}
|
||||
}
|
||||
|
||||
fn http_get(addr: &str, path: &str) -> (u16, String) {
|
||||
let mut stream = TcpStream::connect(addr).expect("connect to server");
|
||||
stream
|
||||
.set_read_timeout(Some(Duration::from_secs(3)))
|
||||
.expect("set read timeout");
|
||||
let request = format!("GET {path} HTTP/1.1\r\nHost: {addr}\r\nConnection: close\r\n\r\n");
|
||||
stream.write_all(request.as_bytes()).expect("write request");
|
||||
let mut response = String::new();
|
||||
stream.read_to_string(&mut response).expect("read response");
|
||||
let status_line = response.lines().next().unwrap_or("");
|
||||
let code: u16 = status_line
|
||||
.split_whitespace()
|
||||
.nth(1)
|
||||
.unwrap_or("0")
|
||||
.parse()
|
||||
.unwrap_or(0);
|
||||
let body = response.split("\r\n\r\n").nth(1).unwrap_or("").to_string();
|
||||
(code, body)
|
||||
}
|
||||
|
||||
fn start_mock_feed_server() -> (String, std::thread::JoinHandle<()>) {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").expect("bind mock server");
|
||||
let addr = listener.local_addr().expect("mock address").to_string();
|
||||
|
||||
let handle = std::thread::spawn(move || {
|
||||
for stream in listener.incoming() {
|
||||
let mut stream = match stream {
|
||||
Ok(s) => s,
|
||||
Err(_) => break,
|
||||
};
|
||||
let mut buf = [0u8; 2048];
|
||||
let n = stream.read(&mut buf).unwrap_or(0);
|
||||
let req = String::from_utf8_lossy(&buf[..n]);
|
||||
|
||||
if req.contains("/cves") {
|
||||
let body = r#"{
|
||||
"format": "NVD_CVE",
|
||||
"version": "2.0",
|
||||
"vulnerabilities": [
|
||||
{
|
||||
"cve": {
|
||||
"id": "CVE-2021-41773",
|
||||
"descriptions": [
|
||||
{"lang": "en", "value": "Apache HTTP Server path traversal"}
|
||||
],
|
||||
"metrics": {
|
||||
"cvssMetricV31": [
|
||||
{"cvssData": {"baseScore": 7.5}}
|
||||
]
|
||||
},
|
||||
"configurations": [
|
||||
{
|
||||
"nodes": [
|
||||
{
|
||||
"cpeMatch": [
|
||||
{
|
||||
"criteria": "cpe:2.3:a:apache:http_server:2.4.49:*:*:*:*:*:*:*",
|
||||
"vulnerable": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}"#;
|
||||
let resp = format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}",
|
||||
body.len(),
|
||||
body
|
||||
);
|
||||
let _ = stream.write_all(resp.as_bytes());
|
||||
} else if req.contains("/kev") {
|
||||
let body = r#"{
|
||||
"title": "CISA KEV",
|
||||
"vulnerabilities": [
|
||||
{"cveID": "CVE-2021-41773"}
|
||||
]
|
||||
}"#;
|
||||
let resp = format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}",
|
||||
body.len(),
|
||||
body
|
||||
);
|
||||
let _ = stream.write_all(resp.as_bytes());
|
||||
} else {
|
||||
let resp =
|
||||
"HTTP/1.1 404 NOT FOUND\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
|
||||
let _ = stream.write_all(resp.as_bytes());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
(addr, handle)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feeds_import_command_and_serve_loads_database() {
|
||||
let workspace = TempDir::new().expect("temporary directory");
|
||||
let feeds_dir = workspace.path().join("feeds_in");
|
||||
let data_dir = workspace.path().join("data");
|
||||
let config_path = workspace.path().join("xexeu.toml");
|
||||
let sweeps_dir = workspace.path().join("sweeps");
|
||||
fs::create_dir_all(&feeds_dir).expect("create feeds dir");
|
||||
|
||||
let nvd_content = r#"{
|
||||
"format": "NVD_CVE",
|
||||
"version": "2.0",
|
||||
"vulnerabilities": [
|
||||
{
|
||||
"cve": {
|
||||
"id": "CVE-2024-6387",
|
||||
"descriptions": [{"lang": "en", "value": "regreSSHion"}],
|
||||
"configurations": []
|
||||
}
|
||||
},
|
||||
{
|
||||
"cve": {
|
||||
"id": "CVE-2021-41773",
|
||||
"descriptions": [{"lang": "en", "value": "Apache traversal"}],
|
||||
"configurations": []
|
||||
}
|
||||
}
|
||||
]
|
||||
}"#;
|
||||
fs::write(feeds_dir.join("nvd.json"), nvd_content).expect("write nvd.json");
|
||||
|
||||
let kev_content = r#"{"vulnerabilities": [{"cveID": "CVE-2021-41773"}]}"#;
|
||||
fs::write(feeds_dir.join("kev.json"), kev_content).expect("write kev.json");
|
||||
|
||||
fs::write(
|
||||
&config_path,
|
||||
r#"
|
||||
[escopo]
|
||||
autorizado = ["127.0.0.1/32"]
|
||||
responsavel = "teste"
|
||||
|
||||
[padrao]
|
||||
cron = "@daily"
|
||||
|
||||
[perfis.padrao]
|
||||
tcp = "80"
|
||||
|
||||
[[grupo]]
|
||||
nome = "local"
|
||||
alvos = ["127.0.0.1/32"]
|
||||
"#,
|
||||
)
|
||||
.expect("write config");
|
||||
|
||||
// 1. Run `xexeu feeds import <feeds_dir> --data-dir <data_dir>`
|
||||
let import_output = Command::new(env!("CARGO_BIN_EXE_xexeu"))
|
||||
.args([
|
||||
"feeds",
|
||||
"import",
|
||||
feeds_dir.to_str().expect("feeds dir"),
|
||||
"--data-dir",
|
||||
data_dir.to_str().expect("data dir"),
|
||||
"--config",
|
||||
config_path.to_str().expect("config path"),
|
||||
])
|
||||
.output()
|
||||
.expect("run feeds import");
|
||||
|
||||
assert!(
|
||||
import_output.status.success(),
|
||||
"import failed: {}",
|
||||
String::from_utf8_lossy(&import_output.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&import_output.stdout);
|
||||
assert!(stdout.contains("2 CVEs (1 no KEV)"), "stdout: {stdout}");
|
||||
|
||||
let db_path = data_dir.join("vuln_db.json");
|
||||
assert!(db_path.exists(), "vuln_db.json must exist");
|
||||
|
||||
// 2. Start `xexeu serve` and ensure /api/status displays the imported database
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_xexeu"))
|
||||
.args([
|
||||
"serve",
|
||||
"--bind",
|
||||
"127.0.0.1:0",
|
||||
"--config",
|
||||
config_path.to_str().expect("config path"),
|
||||
"--sweeps",
|
||||
sweeps_dir.to_str().expect("sweeps path"),
|
||||
"--data-dir",
|
||||
data_dir.to_str().expect("data dir"),
|
||||
])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::inherit())
|
||||
.spawn()
|
||||
.expect("spawn xexeu serve");
|
||||
|
||||
let stdout_pipe = child.stdout.take().expect("take stdout");
|
||||
let mut reader = BufReader::new(stdout_pipe);
|
||||
let mut server_addr = None;
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
|
||||
let mut line = String::new();
|
||||
while Instant::now() < deadline {
|
||||
line.clear();
|
||||
match reader.read_line(&mut line) {
|
||||
Ok(n) if n > 0 => {
|
||||
if line.contains("listening on http://") {
|
||||
let addr = line
|
||||
.split("http://")
|
||||
.nth(1)
|
||||
.expect("server address part")
|
||||
.trim();
|
||||
server_addr = Some(addr.to_string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(_) => std::thread::sleep(Duration::from_millis(50)),
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
|
||||
let _guard = ChildGuard(child);
|
||||
let server_addr = server_addr.expect("server must print address");
|
||||
|
||||
let (status, body) = http_get(&server_addr, "/api/status");
|
||||
assert_eq!(status, 200);
|
||||
assert!(body.contains(r#""feeds_cve_count":2"#), "body: {body}");
|
||||
assert!(body.contains(r#""feeds_kev_count":1"#), "body: {body}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feeds_sync_mock_http_and_periodic_serve_timer() {
|
||||
let (mock_addr, _mock_handle) = start_mock_feed_server();
|
||||
|
||||
let workspace = TempDir::new().expect("temporary directory");
|
||||
let data_dir = workspace.path().join("data");
|
||||
let sweeps_dir = workspace.path().join("sweeps");
|
||||
let config_path = workspace.path().join("xexeu.toml");
|
||||
|
||||
fs::write(
|
||||
&config_path,
|
||||
r#"
|
||||
[escopo]
|
||||
autorizado = ["127.0.0.1/32"]
|
||||
responsavel = "teste"
|
||||
|
||||
[padrao]
|
||||
cron = "@daily"
|
||||
|
||||
[padrao.feeds]
|
||||
sincronizar_automaticamente = true
|
||||
intervalo_sincronizacao = "1s"
|
||||
|
||||
[perfis.padrao]
|
||||
tcp = "80"
|
||||
|
||||
[[grupo]]
|
||||
nome = "local"
|
||||
alvos = ["127.0.0.1/32"]
|
||||
"#,
|
||||
)
|
||||
.expect("write config");
|
||||
|
||||
// 1. Run `xexeu feeds sync` using mock endpoints
|
||||
let sync_output = Command::new(env!("CARGO_BIN_EXE_xexeu"))
|
||||
.args([
|
||||
"feeds",
|
||||
"sync",
|
||||
"--data-dir",
|
||||
data_dir.to_str().expect("data dir"),
|
||||
"--config",
|
||||
config_path.to_str().expect("config path"),
|
||||
])
|
||||
.env("XEXEU_NVD_URL", format!("http://{mock_addr}/cves"))
|
||||
.env("XEXEU_KEV_URL", format!("http://{mock_addr}/kev"))
|
||||
.output()
|
||||
.expect("run feeds sync");
|
||||
|
||||
assert!(
|
||||
sync_output.status.success(),
|
||||
"sync failed: {}",
|
||||
String::from_utf8_lossy(&sync_output.stderr)
|
||||
);
|
||||
let stdout = String::from_utf8_lossy(&sync_output.stdout);
|
||||
assert!(
|
||||
stdout.contains("1 CVEs totais (1 no KEV)"),
|
||||
"stdout: {stdout}"
|
||||
);
|
||||
|
||||
// 2. Start `xexeu serve` with auto-sync enabled
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_xexeu"))
|
||||
.args([
|
||||
"serve",
|
||||
"--bind",
|
||||
"127.0.0.1:0",
|
||||
"--config",
|
||||
config_path.to_str().expect("config path"),
|
||||
"--sweeps",
|
||||
sweeps_dir.to_str().expect("sweeps path"),
|
||||
"--data-dir",
|
||||
data_dir.to_str().expect("data dir"),
|
||||
])
|
||||
.env("XEXEU_NVD_URL", format!("http://{mock_addr}/cves"))
|
||||
.env("XEXEU_KEV_URL", format!("http://{mock_addr}/kev"))
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::inherit())
|
||||
.spawn()
|
||||
.expect("spawn xexeu serve");
|
||||
|
||||
let stdout_pipe = child.stdout.take().expect("take stdout");
|
||||
let mut reader = BufReader::new(stdout_pipe);
|
||||
let mut server_addr = None;
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
|
||||
let mut line = String::new();
|
||||
while Instant::now() < deadline {
|
||||
line.clear();
|
||||
match reader.read_line(&mut line) {
|
||||
Ok(n) if n > 0 => {
|
||||
if line.contains("listening on http://") {
|
||||
let addr = line
|
||||
.split("http://")
|
||||
.nth(1)
|
||||
.expect("server address part")
|
||||
.trim();
|
||||
server_addr = Some(addr.to_string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(_) => std::thread::sleep(Duration::from_millis(50)),
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
|
||||
let _guard = ChildGuard(child);
|
||||
let server_addr = server_addr.expect("server must print address");
|
||||
|
||||
// Wait 1.5s for the 1s auto-sync timer to fire
|
||||
std::thread::sleep(Duration::from_millis(1500));
|
||||
|
||||
let (status, body) = http_get(&server_addr, "/api/status");
|
||||
assert_eq!(status, 200);
|
||||
assert!(body.contains(r#""feeds_cve_count":1"#), "body: {body}");
|
||||
assert!(
|
||||
body.contains(r#""feeds_last_sync":""#),
|
||||
"body must have last sync timestamp: {body}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn feeds_sync_network_failure_does_not_corrupt_existing_database_and_server_stays_healthy() {
|
||||
let workspace = TempDir::new().expect("temporary directory");
|
||||
let data_dir = workspace.path().join("data");
|
||||
let sweeps_dir = workspace.path().join("sweeps");
|
||||
let config_path = workspace.path().join("xexeu.toml");
|
||||
fs::create_dir_all(&data_dir).expect("create data dir");
|
||||
|
||||
// Pre-populate with initial database
|
||||
let initial_db_content = r#"{
|
||||
"nvd": {
|
||||
"records": {
|
||||
"CVE-1999-0001": {
|
||||
"id": "CVE-1999-0001",
|
||||
"description": "Historical vulnerability",
|
||||
"cvss_score": 5.0,
|
||||
"cvss_vector": null,
|
||||
"cpe_matches": []
|
||||
}
|
||||
}
|
||||
},
|
||||
"kev": {
|
||||
"cve_ids": []
|
||||
}
|
||||
}"#;
|
||||
fs::write(data_dir.join("vuln_db.json"), initial_db_content).expect("write initial db");
|
||||
|
||||
fs::write(
|
||||
&config_path,
|
||||
r#"
|
||||
[escopo]
|
||||
autorizado = ["127.0.0.1/32"]
|
||||
responsavel = "teste"
|
||||
|
||||
[padrao]
|
||||
cron = "@daily"
|
||||
|
||||
[padrao.feeds]
|
||||
sincronizar_automaticamente = true
|
||||
intervalo_sincronizacao = "1s"
|
||||
|
||||
[perfis.padrao]
|
||||
tcp = "80"
|
||||
|
||||
[[grupo]]
|
||||
nome = "local"
|
||||
alvos = ["127.0.0.1/32"]
|
||||
"#,
|
||||
)
|
||||
.expect("write config");
|
||||
|
||||
// 1. Run `xexeu feeds sync` pointing to an unreachable port (e.g. 127.0.0.1:1)
|
||||
let sync_output = Command::new(env!("CARGO_BIN_EXE_xexeu"))
|
||||
.args([
|
||||
"feeds",
|
||||
"sync",
|
||||
"--data-dir",
|
||||
data_dir.to_str().expect("data dir"),
|
||||
"--config",
|
||||
config_path.to_str().expect("config path"),
|
||||
])
|
||||
.env("XEXEU_NVD_URL", "http://127.0.0.1:1/nonexistent")
|
||||
.env("XEXEU_KEV_URL", "http://127.0.0.1:1/nonexistent")
|
||||
.output()
|
||||
.expect("run feeds sync");
|
||||
|
||||
// Must exit with failure
|
||||
assert!(
|
||||
!sync_output.status.success(),
|
||||
"sync to unreachable address must fail with error code"
|
||||
);
|
||||
|
||||
// Existing database must NOT be corrupted
|
||||
let db_content = fs::read_to_string(data_dir.join("vuln_db.json")).expect("read db");
|
||||
assert!(
|
||||
db_content.contains("CVE-1999-0001"),
|
||||
"original db must remain intact"
|
||||
);
|
||||
|
||||
// 2. Start `xexeu serve` pointing to unreachable port for auto_sync
|
||||
let mut child = Command::new(env!("CARGO_BIN_EXE_xexeu"))
|
||||
.args([
|
||||
"serve",
|
||||
"--bind",
|
||||
"127.0.0.1:0",
|
||||
"--config",
|
||||
config_path.to_str().expect("config path"),
|
||||
"--sweeps",
|
||||
sweeps_dir.to_str().expect("sweeps path"),
|
||||
"--data-dir",
|
||||
data_dir.to_str().expect("data dir"),
|
||||
])
|
||||
.env("XEXEU_NVD_URL", "http://127.0.0.1:1/nonexistent")
|
||||
.env("XEXEU_KEV_URL", "http://127.0.0.1:1/nonexistent")
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::inherit())
|
||||
.spawn()
|
||||
.expect("spawn xexeu serve");
|
||||
|
||||
let stdout_pipe = child.stdout.take().expect("take stdout");
|
||||
let mut reader = BufReader::new(stdout_pipe);
|
||||
let mut server_addr = None;
|
||||
let deadline = Instant::now() + Duration::from_secs(5);
|
||||
|
||||
let mut line = String::new();
|
||||
while Instant::now() < deadline {
|
||||
line.clear();
|
||||
match reader.read_line(&mut line) {
|
||||
Ok(n) if n > 0 => {
|
||||
if line.contains("listening on http://") {
|
||||
let addr = line
|
||||
.split("http://")
|
||||
.nth(1)
|
||||
.expect("server address part")
|
||||
.trim();
|
||||
server_addr = Some(addr.to_string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(_) => std::thread::sleep(Duration::from_millis(50)),
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
|
||||
let _guard = ChildGuard(child);
|
||||
let server_addr = server_addr.expect("server must print address");
|
||||
|
||||
// Wait 1.5s for the timer to tick and fail network call
|
||||
std::thread::sleep(Duration::from_millis(1500));
|
||||
|
||||
// Server must still be alive and respond HTTP 200 OK
|
||||
let (health_status, health_body) = http_get(&server_addr, "/api/health");
|
||||
assert_eq!(health_status, 200);
|
||||
assert!(health_body.contains(r#""status":"ok""#));
|
||||
|
||||
// Status must still show the intact database
|
||||
let (status_code, status_body) = http_get(&server_addr, "/api/status");
|
||||
assert_eq!(status_code, 200);
|
||||
assert!(status_body.contains(r#""feeds_cve_count":1"#));
|
||||
}
|
||||
@@ -15,6 +15,7 @@ chrono = { version = "0.4", default-features = false, features = ["clock", "serd
|
||||
croner = "4"
|
||||
ipnet = "2"
|
||||
parquet = { version = "60", default-features = false, features = ["arrow", "snap"] }
|
||||
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
|
||||
rusqlite = { version = "0.41", features = ["bundled"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
|
||||
@@ -63,6 +63,37 @@ pub struct DefaultsConfig {
|
||||
/// Consecutive unanswered scans before a host is considered gone.
|
||||
#[serde(rename = "ausencias_para_sumir", default)]
|
||||
pub absences_before_disappear: Option<u32>,
|
||||
/// Vulnerability feeds synchronization settings.
|
||||
#[serde(rename = "feeds", default)]
|
||||
pub feeds: FeedsConfig,
|
||||
}
|
||||
|
||||
/// Vulnerability feeds synchronization settings under `[padrao.feeds]`.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Deserialize)]
|
||||
pub struct FeedsConfig {
|
||||
/// Whether to automatically sync vulnerability feeds periodically in the server.
|
||||
#[serde(rename = "sincronizar_automaticamente", default = "default_false")]
|
||||
pub auto_sync: bool,
|
||||
/// Interval between automatic synchronizations (e.g. "24h", "12h").
|
||||
#[serde(rename = "intervalo_sincronizacao", default = "default_sync_interval")]
|
||||
pub sync_interval: String,
|
||||
}
|
||||
|
||||
fn default_false() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn default_sync_interval() -> String {
|
||||
"24h".to_string()
|
||||
}
|
||||
|
||||
impl Default for FeedsConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
auto_sync: false,
|
||||
sync_interval: default_sync_interval(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for DefaultsConfig {
|
||||
@@ -74,6 +105,7 @@ impl Default for DefaultsConfig {
|
||||
max_pps: None,
|
||||
simultaneous_hosts: None,
|
||||
absences_before_disappear: None,
|
||||
feeds: FeedsConfig::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
//! This module provides deterministic parsers for local NVD and CISA KEV feeds,
|
||||
//! indexing them into memory for fast lookup during service banner correlation.
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::io::{BufRead, BufReader, Read};
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use thiserror::Error;
|
||||
|
||||
/// Error encountered during feed import.
|
||||
@@ -27,6 +29,8 @@ pub enum FeedError {
|
||||
},
|
||||
#[error("Invalid feed format in '{path}': {detail}")]
|
||||
Format { path: String, detail: String },
|
||||
#[error("Network error fetching feed from '{url}': {detail}")]
|
||||
Network { url: String, detail: String },
|
||||
}
|
||||
|
||||
/// Structured Common Platform Enumeration (CPE) representation.
|
||||
@@ -111,19 +115,19 @@ pub struct CveRecord {
|
||||
}
|
||||
|
||||
/// In-memory catalog of NVD vulnerabilities.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct NvdCatalog {
|
||||
pub records: HashMap<String, CveRecord>,
|
||||
}
|
||||
|
||||
/// In-memory catalog of CISA Known Exploited Vulnerabilities (KEV).
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct KevCatalog {
|
||||
pub cve_ids: HashSet<String>,
|
||||
}
|
||||
|
||||
/// Combined local vulnerability database.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct VulnDatabase {
|
||||
pub nvd: NvdCatalog,
|
||||
pub kev: KevCatalog,
|
||||
@@ -145,6 +149,61 @@ impl VulnDatabase {
|
||||
pub fn is_in_kev(&self, cve_id: &str) -> bool {
|
||||
self.kev.cve_ids.contains(cve_id)
|
||||
}
|
||||
|
||||
/// Merges another vulnerability database into this one without duplicating entries.
|
||||
pub fn merge(&mut self, other: VulnDatabase) {
|
||||
for (id, record) in other.nvd.records {
|
||||
self.nvd.records.insert(id, record);
|
||||
}
|
||||
for id in other.kev.cve_ids {
|
||||
self.kev.cve_ids.insert(id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the number of CVE records in the NVD catalog.
|
||||
pub fn cve_count(&self) -> usize {
|
||||
self.nvd.records.len()
|
||||
}
|
||||
|
||||
/// Returns the number of CVE IDs in the CISA KEV catalog.
|
||||
pub fn kev_count(&self) -> usize {
|
||||
self.kev.cve_ids.len()
|
||||
}
|
||||
|
||||
/// Saves the combined database to a JSON file on disk.
|
||||
pub fn save_to_file(&self, path: &Path) -> Result<(), FeedError> {
|
||||
if let Some(parent) = path.parent() {
|
||||
if !parent.as_os_str().is_empty() {
|
||||
std::fs::create_dir_all(parent).map_err(|e| FeedError::Io {
|
||||
path: parent.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
}
|
||||
}
|
||||
let file = File::create(path).map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
let writer = std::io::BufWriter::new(file);
|
||||
serde_json::to_writer(writer, self).map_err(|e| FeedError::Json {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Loads the combined database from a JSON file on disk.
|
||||
pub fn load_from_file(path: &Path) -> Result<Self, FeedError> {
|
||||
let file = File::open(path).map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
let reader = BufReader::new(file);
|
||||
serde_json::from_reader(reader).map_err(|e| FeedError::Json {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -240,16 +299,10 @@ fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Imports an NVD CVE JSON 2.0 file from disk.
|
||||
pub fn import_nvd(path: &Path) -> Result<NvdCatalog, FeedError> {
|
||||
let file = File::open(path).map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
/// Parses an NVD CVE JSON 2.0 payload from any reader.
|
||||
pub fn parse_nvd_json<R: Read>(reader: R) -> Result<NvdCatalog, FeedError> {
|
||||
let dto: NvdFeedDto = serde_json::from_reader(reader).map_err(|e| FeedError::Json {
|
||||
path: path.display().to_string(),
|
||||
path: "payload".to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
|
||||
@@ -323,6 +376,22 @@ pub fn import_nvd(path: &Path) -> Result<NvdCatalog, FeedError> {
|
||||
Ok(NvdCatalog { records })
|
||||
}
|
||||
|
||||
/// Imports an NVD CVE JSON 2.0 file from disk.
|
||||
pub fn import_nvd(path: &Path) -> Result<NvdCatalog, FeedError> {
|
||||
let file = File::open(path).map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
let reader = BufReader::new(file);
|
||||
parse_nvd_json(reader).map_err(|e| match e {
|
||||
FeedError::Json { source, .. } => FeedError::Json {
|
||||
path: path.display().to_string(),
|
||||
source,
|
||||
},
|
||||
other => other,
|
||||
})
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CISA KEV Ingestion (JSON and CSV)
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -339,20 +408,13 @@ struct KevItemDto {
|
||||
cve_id: String,
|
||||
}
|
||||
|
||||
/// Imports CISA Known Exploited Vulnerabilities from a JSON or CSV file.
|
||||
pub fn import_kev(path: &Path) -> Result<KevCatalog, FeedError> {
|
||||
let file = File::open(path).map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
let mut reader = BufReader::new(file);
|
||||
|
||||
// Peek the first non-whitespace character to distinguish JSON from CSV
|
||||
/// Parses CISA KEV data from a reader (handles both JSON and CSV formats).
|
||||
pub fn parse_kev_reader<R: BufRead>(mut reader: R) -> Result<KevCatalog, FeedError> {
|
||||
let mut first_line = String::new();
|
||||
reader
|
||||
.read_line(&mut first_line)
|
||||
.map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
path: "reader".to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
|
||||
@@ -360,16 +422,11 @@ pub fn import_kev(path: &Path) -> Result<KevCatalog, FeedError> {
|
||||
let mut cve_ids = HashSet::new();
|
||||
|
||||
if trimmed.starts_with('{') {
|
||||
// Re-read entire JSON
|
||||
let file = File::open(path).map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
let chained = std::io::Cursor::new(first_line).chain(reader);
|
||||
let dto: KevJsonDto = serde_json::from_reader(chained).map_err(|e| FeedError::Json {
|
||||
path: "reader".to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
let dto: KevJsonDto =
|
||||
serde_json::from_reader(BufReader::new(file)).map_err(|e| FeedError::Json {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
for item in dto.vulnerabilities {
|
||||
cve_ids.insert(item.cve_id);
|
||||
}
|
||||
@@ -382,7 +439,7 @@ pub fn import_kev(path: &Path) -> Result<KevCatalog, FeedError> {
|
||||
}
|
||||
for line_res in reader.lines() {
|
||||
let line = line_res.map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
path: "reader".to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
if let Some(id) = extract_cve_from_line(&line) {
|
||||
@@ -394,6 +451,26 @@ pub fn import_kev(path: &Path) -> Result<KevCatalog, FeedError> {
|
||||
Ok(KevCatalog { cve_ids })
|
||||
}
|
||||
|
||||
/// Imports CISA Known Exploited Vulnerabilities from a JSON or CSV file.
|
||||
pub fn import_kev(path: &Path) -> Result<KevCatalog, FeedError> {
|
||||
let file = File::open(path).map_err(|e| FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
let reader = BufReader::new(file);
|
||||
parse_kev_reader(reader).map_err(|e| match e {
|
||||
FeedError::Io { source, .. } => FeedError::Io {
|
||||
path: path.display().to_string(),
|
||||
source,
|
||||
},
|
||||
FeedError::Json { source, .. } => FeedError::Json {
|
||||
path: path.display().to_string(),
|
||||
source,
|
||||
},
|
||||
other => other,
|
||||
})
|
||||
}
|
||||
|
||||
fn extract_cve_from_line(line: &str) -> Option<String> {
|
||||
let col = line.split(',').next()?.trim().trim_matches('"');
|
||||
if col.starts_with("CVE-") {
|
||||
@@ -403,6 +480,130 @@ fn extract_cve_from_line(line: &str) -> Option<String> {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// HTTP Synchronization (NVD CVE 2.0 API & CISA KEV)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/// Default official endpoint for NVD CVE API 2.0.
|
||||
pub const NVD_CVE_API_URL: &str = "https://services.nvd.nist.gov/rest/json/cves/2.0";
|
||||
|
||||
/// Default official endpoint for CISA KEV JSON catalog.
|
||||
pub const CISA_KEV_API_URL: &str =
|
||||
"https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json";
|
||||
|
||||
/// Options for synchronizing vulnerability feeds.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SyncOptions {
|
||||
/// NVD CVE 2.0 API URL (overrideable for testing or custom proxies).
|
||||
pub nvd_url: String,
|
||||
/// CISA KEV JSON URL (overrideable for testing).
|
||||
pub kev_url: String,
|
||||
/// Timeout for HTTP calls.
|
||||
pub timeout: Duration,
|
||||
/// Optional incremental start date for NVD changes (`lastModStartDate`).
|
||||
pub last_mod_start: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl Default for SyncOptions {
|
||||
fn default() -> Self {
|
||||
let nvd_url =
|
||||
std::env::var("XEXEU_NVD_URL").unwrap_or_else(|_| NVD_CVE_API_URL.to_string());
|
||||
let kev_url =
|
||||
std::env::var("XEXEU_KEV_URL").unwrap_or_else(|_| CISA_KEV_API_URL.to_string());
|
||||
Self {
|
||||
nvd_url,
|
||||
kev_url,
|
||||
timeout: Duration::from_secs(30),
|
||||
last_mod_start: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Downloads and parses NVD CVE records from an API endpoint.
|
||||
pub async fn sync_nvd(client: &reqwest::Client, url: &str) -> Result<NvdCatalog, FeedError> {
|
||||
let resp = client
|
||||
.get(url)
|
||||
.header("User-Agent", "Xexeu-Vuln-Sync/0.1.0")
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| FeedError::Network {
|
||||
url: url.to_string(),
|
||||
detail: e.to_string(),
|
||||
})?;
|
||||
|
||||
if !resp.status().is_success() {
|
||||
return Err(FeedError::Network {
|
||||
url: url.to_string(),
|
||||
detail: format!("status HTTP {}", resp.status()),
|
||||
});
|
||||
}
|
||||
|
||||
let bytes = resp.bytes().await.map_err(|e| FeedError::Network {
|
||||
url: url.to_string(),
|
||||
detail: format!("falha ao ler corpo da resposta: {e}"),
|
||||
})?;
|
||||
|
||||
parse_nvd_json(bytes.as_ref())
|
||||
}
|
||||
|
||||
/// Downloads and parses CISA KEV catalog from an HTTP endpoint.
|
||||
pub async fn sync_kev(client: &reqwest::Client, url: &str) -> Result<KevCatalog, FeedError> {
|
||||
let resp = client
|
||||
.get(url)
|
||||
.header("User-Agent", "Xexeu-Vuln-Sync/0.1.0")
|
||||
.send()
|
||||
.await
|
||||
.map_err(|e| FeedError::Network {
|
||||
url: url.to_string(),
|
||||
detail: e.to_string(),
|
||||
})?;
|
||||
|
||||
if !resp.status().is_success() {
|
||||
return Err(FeedError::Network {
|
||||
url: url.to_string(),
|
||||
detail: format!("status HTTP {}", resp.status()),
|
||||
});
|
||||
}
|
||||
|
||||
let bytes = resp.bytes().await.map_err(|e| FeedError::Network {
|
||||
url: url.to_string(),
|
||||
detail: format!("falha ao ler corpo da resposta: {e}"),
|
||||
})?;
|
||||
|
||||
parse_kev_reader(BufReader::new(bytes.as_ref()))
|
||||
}
|
||||
|
||||
/// Synchronizes both NVD and CISA KEV feeds over HTTP according to `options`.
|
||||
pub async fn sync_feeds(options: &SyncOptions) -> Result<VulnDatabase, FeedError> {
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(options.timeout)
|
||||
.build()
|
||||
.map_err(|e| FeedError::Network {
|
||||
url: "client_builder".to_string(),
|
||||
detail: e.to_string(),
|
||||
})?;
|
||||
|
||||
let effective_nvd_url = if let Some(start) = options.last_mod_start {
|
||||
let start_str = start.format("%Y-%m-%dT%H:%M:%S.000").to_string();
|
||||
let end_str = Utc::now().format("%Y-%m-%dT%H:%M:%S.000").to_string();
|
||||
let sep = if options.nvd_url.contains('?') {
|
||||
'&'
|
||||
} else {
|
||||
'?'
|
||||
};
|
||||
format!(
|
||||
"{}{}lastModStartDate={}&lastModEndDate={}",
|
||||
options.nvd_url, sep, start_str, end_str
|
||||
)
|
||||
} else {
|
||||
options.nvd_url.clone()
|
||||
};
|
||||
|
||||
let nvd = sync_nvd(&client, &effective_nvd_url).await?;
|
||||
let kev = sync_kev(&client, &options.kev_url).await?;
|
||||
Ok(VulnDatabase { nvd, kev })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -546,4 +747,117 @@ mod tests {
|
||||
let kev_csv_parsed = import_kev(f_csv.path()).unwrap();
|
||||
assert!(kev_csv_parsed.cve_ids.contains("CVE-2024-6387"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_vuln_database_merge_and_disk_roundtrip() {
|
||||
let mut db1 = VulnDatabase::default();
|
||||
let mut db2 = VulnDatabase::default();
|
||||
|
||||
let rec1 = CveRecord {
|
||||
id: "CVE-2021-41773".to_string(),
|
||||
description: "Apache flaw".to_string(),
|
||||
cvss_score: Some(7.5),
|
||||
cvss_vector: None,
|
||||
cpe_matches: vec![],
|
||||
};
|
||||
let rec2 = CveRecord {
|
||||
id: "CVE-2024-6387".to_string(),
|
||||
description: "OpenSSH flaw".to_string(),
|
||||
cvss_score: Some(8.1),
|
||||
cvss_vector: None,
|
||||
cpe_matches: vec![],
|
||||
};
|
||||
|
||||
db1.nvd.records.insert(rec1.id.clone(), rec1);
|
||||
db1.kev.cve_ids.insert("CVE-2021-41773".to_string());
|
||||
|
||||
db2.nvd.records.insert(rec2.id.clone(), rec2);
|
||||
db2.kev.cve_ids.insert("CVE-2024-6387".to_string());
|
||||
|
||||
db1.merge(db2);
|
||||
assert_eq!(db1.cve_count(), 2);
|
||||
assert_eq!(db1.kev_count(), 2);
|
||||
assert!(db1.is_in_kev("CVE-2021-41773"));
|
||||
assert!(db1.is_in_kev("CVE-2024-6387"));
|
||||
|
||||
let temp_dir = tempfile::tempdir().unwrap();
|
||||
let db_path = temp_dir.path().join("vuln_db.json");
|
||||
db1.save_to_file(&db_path).unwrap();
|
||||
|
||||
let loaded = VulnDatabase::load_from_file(&db_path).unwrap();
|
||||
assert_eq!(loaded.cve_count(), 2);
|
||||
assert_eq!(loaded.kev_count(), 2);
|
||||
assert!(loaded.is_in_kev("CVE-2021-41773"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_sync_feeds_mock_http_success_and_failure() {
|
||||
use std::io::Read;
|
||||
use std::net::TcpListener;
|
||||
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
|
||||
std::thread::spawn(move || {
|
||||
for stream in listener.incoming() {
|
||||
let mut stream = match stream {
|
||||
Ok(s) => s,
|
||||
Err(_) => break,
|
||||
};
|
||||
let mut buf = [0u8; 1024];
|
||||
let n = stream.read(&mut buf).unwrap_or(0);
|
||||
let req = String::from_utf8_lossy(&buf[..n]);
|
||||
|
||||
if req.contains("/cves") {
|
||||
let body = r#"{"format":"NVD_CVE","version":"2.0","vulnerabilities":[{"cve":{"id":"CVE-2021-41773","descriptions":[{"lang":"en","value":"Apache"}]}}]}"#;
|
||||
let resp = format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}",
|
||||
body.len(),
|
||||
body
|
||||
);
|
||||
let _ = stream.write_all(resp.as_bytes());
|
||||
} else if req.contains("/kev") {
|
||||
let body = r#"{"vulnerabilities":[{"cveID":"CVE-2021-41773"}]}"#;
|
||||
let resp = format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}",
|
||||
body.len(),
|
||||
body
|
||||
);
|
||||
let _ = stream.write_all(resp.as_bytes());
|
||||
} else {
|
||||
let resp =
|
||||
"HTTP/1.1 404 NOT FOUND\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
|
||||
let _ = stream.write_all(resp.as_bytes());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let options = SyncOptions {
|
||||
nvd_url: format!("http://127.0.0.1:{port}/cves"),
|
||||
kev_url: format!("http://127.0.0.1:{port}/kev"),
|
||||
timeout: Duration::from_secs(2),
|
||||
last_mod_start: None,
|
||||
};
|
||||
|
||||
let db = sync_feeds(&options).await.expect("sync should succeed");
|
||||
assert_eq!(db.cve_count(), 1);
|
||||
assert!(db.nvd.records.contains_key("CVE-2021-41773"));
|
||||
assert!(db.is_in_kev("CVE-2021-41773"));
|
||||
|
||||
// Test network failure with bad URL
|
||||
let bad_options = SyncOptions {
|
||||
nvd_url: "http://127.0.0.1:1/nonexistent".to_string(),
|
||||
kev_url: format!("http://127.0.0.1:{port}/kev"),
|
||||
timeout: Duration::from_millis(500),
|
||||
last_mod_start: None,
|
||||
};
|
||||
let err = sync_feeds(&bad_options).await;
|
||||
assert!(err.is_err());
|
||||
match err {
|
||||
Err(FeedError::Network { url, .. }) => {
|
||||
assert!(url.contains("127.0.0.1:1"));
|
||||
}
|
||||
other => panic!("expected Network error, got {:?}", other),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,9 @@ pub use checks::{
|
||||
probe_unencrypted_admin_service, CheckError, COMMON_ADMIN_PORTS,
|
||||
};
|
||||
pub use feeds::{
|
||||
import_kev, import_nvd, Cpe, CpeMatchCriteria, CveRecord, FeedError, KevCatalog, NvdCatalog,
|
||||
VulnDatabase,
|
||||
import_kev, import_nvd, parse_kev_reader, parse_nvd_json, sync_feeds, sync_kev, sync_nvd, Cpe,
|
||||
CpeMatchCriteria, CveRecord, FeedError, KevCatalog, NvdCatalog, SyncOptions, VulnDatabase,
|
||||
CISA_KEV_API_URL, NVD_CVE_API_URL,
|
||||
};
|
||||
pub use matcher::{
|
||||
match_banner, parse_banner_to_cpe, BannerInfo, Confidence, Finding, FindingType,
|
||||
|
||||
Reference in new issue
Block a user