Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
5162537
move store_file() from src/ to misc/
jjnicola Nov 17, 2026
a4e9d1e
minor fix
jjnicola Nov 17, 2026
9f92b82
Add: functions for handling credential override
jjnicola Nov 17, 2026
9b2cb65
Adjust dependencies for building
jjnicola Nov 17, 2026
31b1b31
Add credentials list into the globals struct
jjnicola Nov 17, 2026
b0d84c9
parse received credential
jjnicola Nov 17, 2026
61efe11
accept multiple credentials for the same service
jjnicola Nov 17, 2026
ae000e1
accept hosts field in credential struct, which tied the credential to…
jjnicola Nov 17, 2026
5ef383f
use as default credetial of each service, the first one found without…
jjnicola Nov 17, 2026
7beffa7
parse the crendetials host item and store it in the credential struct…
jjnicola Nov 17, 2026
fb0b582
Check for empty host list too
jjnicola Nov 18, 2026
5884043
Create a comma separated string with credential hosts and init the gv…
jjnicola Nov 18, 2026
a1c3982
set explicitely an empty string if the an optional credential value i…
jjnicola Nov 18, 2026
d4e21c8
cleanup json object after use
jjnicola Nov 18, 2026
5ccdb96
fix format and other minor stuff
jjnicola Nov 18, 2026
a729ad3
fix auth_port_ssh. Set it as null if not set.
jjnicola Nov 18, 2026
c85afed
Doc: multiple credentials override
jjnicola Nov 18, 2026
de2193e
resolve hostnames in the credentials host list
jjnicola Nov 19, 2026
410ff13
missing optional fields in crdential are set to NULL instead of ""
jjnicola Nov 19, 2026
1373a86
Clone the credential for each target string
jjnicola Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/install-openvas-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ apt-get install --no-install-recommends --no-install-suggests -y \
libpopt0 \
libcurl4 \
libcurl4-gnutls-dev \
libcjson-dev \
libhiredis-dev \
libmagic-dev

Expand Down
47 changes: 47 additions & 0 deletions doc/multiple-credentials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Multiple credentials per service

A scan target can carry several credentials for the same service (SSH, SMB,
SNMP, KRB5, ESXi). Each credential may be restricted to a list of hosts.
When a host is scanned, the credential matching that host is selected and
published as the scan preferences read by the NASL scripts.

Credentials are part of the target in the scan JSON. The optional `hosts`
field ties a credential to specific hosts.

```json
"credentials": [
{ "service": "ssh", "port": 22,
"up": { "username": "default", "password": "pass" } },
{ "service": "ssh", "port": 2222,
"hosts": ["192.168.1.0/24", "web.example.com"],
"usk": { "username": "admin", "password": "passphrase",
"private": "<base64 key>" } },
{ "service": "smb", "hosts": ["10.0.0.1-10"],
"up": { "username": "user", "password": "pass" } }
]
```

**openvasd** handles scan preferences. The first credential without
`hosts` field (missing or empty) of each service is written as the regular default
preferences (the samepreferences used before this feature). Credentials with
`hosts` and later credentials without `hosts` are not written as defaults.
The complete credential list is serialized into one scan preference,
`multi-credentials`, as a JSON string.
**openvas** gets the scan preferences and process them. If `multi-credentials` is set,
parses it and stores the credential list in `globals->credentials`.
Later, when a new host process is started and before any plugin
runs, a function for credential overriding is called. Then, for each
credential service, iterates over the list of host in a credential and
the first credential whose `hosts` list contains the current scanned host is stored
and will be used for the rest of host scan.
This only affects the forked per host process, so other hosts are unaffected.
If nothing matches, the default credential stays in place.

Summarizing, this are the important rules:
- Matching is , in the order given in the JSON.
- A credential without `hosts` never matches in C; it can only be the default,
the first one without hosts, per service, set in **openvasd**.
- Each service is selected independently. E.g. an SSH match doesn't influence SMB.
- A matching credential replaces all values of that service. Missing
optional values are set to an empty NULL, so nothing leaks from the
default credential.
5 changes: 3 additions & 2 deletions misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pkg_check_modules (GLIB REQUIRED glib-2.0>=2.42)
pkg_check_modules (GLIB_JSON REQUIRED json-glib-1.0>=1.4.4)
pkg_check_modules (GNUTLS REQUIRED gnutls>=3.6.4)
pkg_check_modules (CURL REQUIRED libcurl>=7.74.0)
pkg_check_modules(CJSON REQUIRED libcjson>=1.7.14)

pkg_check_modules (KRB5 REQUIRED mit-krb5)
pkg_check_modules (KRB5_GSSAPI REQUIRED mit-krb5-gssapi)
Expand Down Expand Up @@ -87,7 +88,7 @@ include_directories (${GLIB_INCLUDE_DIRS} ${GLIB_JSON_INCLUDE_DIRS}

set (FILES bpf_share.c ftp_funcs.c vendorversion.c network.c plugutils.c pcap.c
scan_id.c strutils.c table_driven_lsc.c ipc.c ipc_openvas.c ipc_pipe.c
user_agent.c scanneraux.c kb_cache.c heartbeat.c openvas-krb5.c)
user_agent.c scanneraux.c kb_cache.c heartbeat.c openvas-krb5.c credentials.c)

# On windows we are always PIC and stack-protector is replaces by DEP
# Also stack protection needs a shared library to work
Expand All @@ -105,7 +106,7 @@ set_target_properties (openvas_misc_shared PROPERTIES VERSION "${PROJECT_VERSION
target_link_libraries (openvas_misc_shared LINK_PRIVATE
${GNUTLS_LDFLAGS} ${UUID_LDFLAGS}
${GLIB_LDFLAGS} ${GLIB_JSON_LDFLAGS} ${MAGIC_LDFLAGS}
${PCAP_LDFLAGS} ${LIBGVM_BOREAS_LDFLAGS} ${CURL_LDFLAGS} ${KRB5_LDFLAGS} ${KRB5_GSSAPI_LDFLAGS}
${PCAP_LDFLAGS} ${LIBGVM_BOREAS_LDFLAGS} ${CURL_LDFLAGS} ${CJSON_LDFLAGS} ${KRB5_LDFLAGS} ${KRB5_GSSAPI_LDFLAGS}
${LINKER_HARDENING_FLAGS})

if (OPENVAS_STATE_DIR)
Expand Down
Loading
Loading