Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: krb5 kerberos credential #1011

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
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
47 changes: 47 additions & 0 deletions ospd_openvas/preferencehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
OID_ESXI_AUTH = "1.3.6.1.4.1.25623.1.0.105058"
OID_SNMP_AUTH = "1.3.6.1.4.1.25623.1.0.105076"
OID_PING_HOST = "1.3.6.1.4.1.25623.1.0.100315"
OID_KRB5_AUTH = "1.3.6.1.4.1.25623.1.81.0"

BOREAS_ALIVE_TEST = "ALIVE_TEST"
BOREAS_ALIVE_TEST_PORTS = "ALIVE_TEST_PORTS"
Expand Down Expand Up @@ -576,6 +577,11 @@ def prepare_scan_params_for_openvas(self, ospd_params: Dict[str, Dict]):
if prefs_val:
self.kbdb.add_scan_preferences(self.scan_id, prefs_val)

def disable_message(self, disabled: str) -> str:
"""Return a string with the message for exclusive services."""
disabled = f"Disabled {disabled}"
return disabled + ": KRB5 and SMB credentials are mutually exclusive."

def build_credentials_as_prefs(self, credentials: Dict) -> List[str]:
"""Parse the credential dictionary.
Arguments:
Expand All @@ -585,10 +591,18 @@ def build_credentials_as_prefs(self, credentials: Dict) -> List[str]:
A list with the credentials in string format to be
added to the redis KB.
"""

cred_prefs_list = []
krb5_set = False
smb_set = False
for credential in credentials.items():
service = credential[0]
cred_params = credentials.get(service)
if not cred_params:
logger.warning(
"No credentials parameter found for service %s", service
)
continue
cred_type = cred_params.get('type', '')
username = cred_params.get('username', '')
password = cred_params.get('password', '')
Expand Down Expand Up @@ -659,12 +673,45 @@ def build_credentials_as_prefs(self, credentials: Dict) -> List[str]:
)
# Check servic smb
elif service == 'smb':
if krb5_set:
self.errors.append(self.disable_message("SMB"))
continue
smb_set = True
cred_prefs_list.append(
f'{OID_SMB_AUTH}:1:entry:SMB login:|||{username}'
)
cred_prefs_list.append(
f'{OID_SMB_AUTH}:2:password:SMB password:|||{password}'
)
elif service == 'krb5':
if smb_set:
self.errors.append(self.disable_message("KRB5"))
continue
jjnicola marked this conversation as resolved.
Show resolved Hide resolved
krb5_set = True
realm = cred_params.get('realm', '')
if not realm:
self.errors.append(
"Missing realm for Kerberos authentication."
)
continue
kdc = cred_params.get('kdc', '')
if not kdc:
self.errors.append(
"Missing KDC for Kerberos authentication."
)
continue
cred_prefs_list.append(
f'{OID_KRB5_AUTH}:1:entry:KRB5 login:|||{username}'
)
cred_prefs_list.append(
f'{OID_KRB5_AUTH}:2:password:KRB5 password:|||{password}'
)
cred_prefs_list.append(
f'{OID_KRB5_AUTH}:3:entry:KRB5 realm:|||{realm}'
)
cred_prefs_list.append(
f'{OID_KRB5_AUTH}:4:entry:KRB5 kdc:|||{kdc}'
)
# Check service esxi
elif service == 'esxi':
cred_prefs_list.append(
Expand Down
Loading