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

Handle addition of ID to NVT preferences. #413

Merged
merged 7 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
38 changes: 32 additions & 6 deletions src/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ command_disabled (gmp_parser_t *gmp_parser, const gchar *name)
/**
* @brief Create a new preference.
*
* @param[in] id ID of preference.
* @param[in] name Name of preference.
* @param[in] type Type of preference.
* @param[in] value Value of preference.
Expand All @@ -568,13 +569,14 @@ command_disabled (gmp_parser_t *gmp_parser, const gchar *name)
* @return Newly allocated preference.
*/
static gpointer
preference_new (char *name, char *type, char *value, char *nvt_name,
preference_new (char *id, char *name, char *type, char *value, char *nvt_name,
char *nvt_oid, array_t *alts, char* default_value,
char *hr_name)
{
preference_t *preference;

preference = (preference_t*) g_malloc0 (sizeof (preference_t));
preference->id = id;
preference->name = name;
preference->type = type;
preference->value = value;
Expand Down Expand Up @@ -693,6 +695,7 @@ typedef struct
char *preference_alt; ///< Single radio alternative in PREFERENCE.
char *preference_default; ///< Default value in PREFERENCE.
char *preference_hr_name; ///< Human readable name in PREFERENCE.
char *preference_id; ///< ID in PREFERENCE.
char *preference_name; ///< Name in PREFERENCE.
char *preference_nvt_name; ///< NVT name in PREFERENCE.
char *preference_nvt_oid; ///< NVT OID in PREFERENCE.
Expand Down Expand Up @@ -749,8 +752,9 @@ create_config_data_reset (create_config_data_t *data)
}

g_free (import->preference_alt);
g_free (import->preference_id);
g_free (import->preference_name);
g_free (import->preference_name);
g_free (import->preference_hr_name);
kroosec marked this conversation as resolved.
Show resolved Hide resolved
g_free (import->preference_nvt_name);
g_free (import->preference_nvt_oid);
g_free (import->preference_type);
Expand Down Expand Up @@ -2879,6 +2883,7 @@ typedef struct
array_t *nvt_selection; ///< OID array. New NVT set for config.
char *nvt_selection_family; ///< Family of NVT selection.
char *nvt_selection_nvt_oid; ///< OID during NVT_selection/NVT.
char *preference_id; ///< Config preference to modify.
char *preference_name; ///< Config preference to modify.
char *preference_nvt_oid; ///< OID of NVT of preference.
char *preference_value; ///< New value for preference.
Expand Down Expand Up @@ -3112,6 +3117,7 @@ modify_config_data_reset (modify_config_data_t *data)
array_free (data->nvt_selection);
free (data->nvt_selection_family);
free (data->nvt_selection_nvt_oid);
free (data->preference_id);
free (data->preference_name);
free (data->preference_nvt_oid);
free (data->preference_value);
Expand Down Expand Up @@ -4914,6 +4920,7 @@ typedef enum
CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_DEFAULT,
CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_HR_NAME,
CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_NAME,
CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_ID,
CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_NVT,
CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_NVT_NAME,
CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_TYPE,
Expand Down Expand Up @@ -5288,6 +5295,7 @@ typedef enum
CLIENT_MODIFY_CONFIG_NVT_SELECTION_FAMILY,
CLIENT_MODIFY_CONFIG_NVT_SELECTION_NVT,
CLIENT_MODIFY_CONFIG_PREFERENCE,
CLIENT_MODIFY_CONFIG_PREFERENCE_ID,
CLIENT_MODIFY_CONFIG_PREFERENCE_NAME,
CLIENT_MODIFY_CONFIG_PREFERENCE_NVT,
CLIENT_MODIFY_CONFIG_PREFERENCE_VALUE,
Expand Down Expand Up @@ -7235,6 +7243,7 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
}
else if (strcasecmp ("PREFERENCE", element_name) == 0)
{
gvm_free_string_var (&modify_config_data->preference_id);
gvm_free_string_var (&modify_config_data->preference_name);
gvm_free_string_var (&modify_config_data->preference_nvt_oid);
gvm_free_string_var (&modify_config_data->preference_value);
Expand Down Expand Up @@ -8084,6 +8093,9 @@ gmp_xml_handle_start_element (/* unused */ GMarkupParseContext* context,
else if (strcasecmp ("HR_NAME", element_name) == 0)
set_client_state
(CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_HR_NAME);
else if (strcasecmp ("ID", element_name) == 0)
set_client_state
(CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_ID);
else if (strcasecmp ("NAME", element_name) == 0)
set_client_state
(CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_NAME);
Expand Down Expand Up @@ -10120,25 +10132,28 @@ void
buffer_config_preference_xml (GString *buffer, iterator_t *prefs,
config_t config, int hide_passwords)
{
char *real_name, *type, *value, *oid, *nvt = NULL;
char *real_name, *type, *value, *oid, *id, *nvt = NULL;
const char *default_value;

oid = nvt_preference_iterator_oid (prefs);
type = nvt_preference_iterator_type (prefs);
real_name = nvt_preference_iterator_real_name (prefs);
default_value = nvt_preference_iterator_value (prefs);
value = nvt_preference_iterator_config_value (prefs, config);
id = nvt_preference_iterator_id (prefs);

if (oid)
nvt = nvt_name (oid);
buffer_xml_append_printf (buffer,
"<preference>"
"<nvt oid=\"%s\"><name>%s</name></nvt>"
"<id>%s</id>"
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
kroosec marked this conversation as resolved.
Show resolved Hide resolved
"<hr_name>%s</hr_name>"
"<name>%s</name>"
"<type>%s</type>",
oid ? oid : "",
nvt ? nvt : "",
id ? id : "",
real_name ? real_name : "",
real_name ? real_name : "",
type ? type : "");
Expand Down Expand Up @@ -13369,6 +13384,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error)
("<preference>"
"<nvt oid=\"\"><name/></nvt>"
"<hr_name>%s</hr_name>"
"<id/>"
"<name>%s</name>"
"<type>osp_%s</type>"
"<value>%s</value>"
Expand Down Expand Up @@ -13404,6 +13420,7 @@ handle_get_configs (gmp_parser_t *gmp_parser, GError **error)
"<nvt oid=\"%s\">"
"<name>%s</name>"
"</nvt>"
"<id>0</id>"
"<name>Timeout</name>"
"<type>entry</type>"
"<value>%s</value>"
Expand Down Expand Up @@ -15100,8 +15117,8 @@ handle_get_nvts (gmp_parser_t *gmp_parser, GError **error)

if (get_nvts_data->preference_count)
{
const char *nvt_name = nvt_iterator_name (&nvts);
pref_count = nvt_preference_count (nvt_name);
const char *nvt_oid = nvt_iterator_oid (&nvts);
pref_count = nvt_preference_count (nvt_oid);
}
if (send_nvt (&nvts, 1, get_nvts_data->preferences,
pref_count, timeout, config,
Expand Down Expand Up @@ -21529,14 +21546,16 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
}

array_add (import_config_data->preferences,
preference_new (import_config_data->preference_name,
preference_new (import_config_data->preference_id,
import_config_data->preference_name,
import_config_data->preference_type,
import_config_data->preference_value,
import_config_data->preference_nvt_name,
import_config_data->preference_nvt_oid,
import_config_data->preference_alts,
import_config_data->preference_default,
preference_hr_name));
import_config_data->preference_id = NULL;
import_config_data->preference_name = NULL;
import_config_data->preference_type = NULL;
import_config_data->preference_value = NULL;
Expand All @@ -21556,6 +21575,7 @@ gmp_xml_handle_end_element (/* unused */ GMarkupParseContext* context,
CLOSE (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE, DEFAULT);
CLOSE (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE, HR_NAME);
CLOSE (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE, NAME);
CLOSE (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE, ID);
CLOSE (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE, NVT);
CLOSE (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_NVT, NAME);
CLOSE (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE, TYPE);
Expand Down Expand Up @@ -28963,6 +28983,9 @@ gmp_xml_handle_text (/* unused */ GMarkupParseContext* context,
APPEND (CLIENT_MODIFY_CONFIG_PREFERENCE_NAME,
&modify_config_data->preference_name);

APPEND (CLIENT_MODIFY_CONFIG_PREFERENCE_ID,
&modify_config_data->preference_id);

APPEND (CLIENT_MODIFY_CONFIG_PREFERENCE_VALUE,
&modify_config_data->preference_value);

Expand Down Expand Up @@ -29121,6 +29144,9 @@ gmp_xml_handle_text (/* unused */ GMarkupParseContext* context,
APPEND (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_HR_NAME,
&import_config_data->preference_hr_name);

APPEND (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_ID,
&import_config_data->preference_id);

APPEND (CLIENT_C_C_GCR_CONFIG_PREFERENCES_PREFERENCE_NAME,
&import_config_data->preference_name);

Expand Down
65 changes: 31 additions & 34 deletions src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1621,15 +1621,11 @@ nvt_selector_plugins (config_t config)
static gchar*
preference_value (const char* name, const char* full_value)
{
char *bracket = strchr (name, ':');
if (bracket)
if (g_strrstr (name, ":radio:"))
{
if (strncmp (bracket, ":radio:", strlen (":radio:")) == 0)
{
char *semicolon = strchr (full_value, ';');
if (semicolon)
return g_strndup (full_value, semicolon - full_value);
}
char *semicolon = strchr (full_value, ';');
if (semicolon)
return g_strndup (full_value, semicolon - full_value);
}
return g_strdup (full_value);
}
Expand Down Expand Up @@ -1678,10 +1674,10 @@ send_config_preferences (config_t config, const char* section_name,
{
char **splits;
int is_file = 0;
/* OID:PrefType:PrefName value */
splits = g_strsplit (pref_name, ":", 3);
if (splits && g_strv_length (splits) == 3
&& strcmp (splits[1], "file") == 0)
/* OID:PrefID:PrefType:PrefName value */
splits = g_strsplit (pref_name, ":", 4);
if (splits && g_strv_length (splits) == 4
&& strcmp (splits[2], "file") == 0)
is_file = 1;
g_strfreev (splits);
if (is_file)
Expand Down Expand Up @@ -2094,42 +2090,42 @@ send_alive_test_preferences (target_t target)
if (alive_test == 0)
return 0;

if (sendf_to_server (OID_PING_HOST ":checkbox:Do a TCP ping <|> %s\n",
if (sendf_to_server (OID_PING_HOST ":1:checkbox:Do a TCP ping <|> %s\n",
alive_test & ALIVE_TEST_TCP_ACK_SERVICE
|| alive_test & ALIVE_TEST_TCP_SYN_SERVICE
? "yes"
: "no"))
return -1;

if (sendf_to_server (OID_PING_HOST ":checkbox:TCP ping tries also TCP-SYN ping"
if (sendf_to_server (OID_PING_HOST ":2:checkbox:TCP ping tries also TCP-SYN ping"
" <|> %s\n",
((alive_test & ALIVE_TEST_TCP_SYN_SERVICE)
&& (alive_test & ALIVE_TEST_TCP_ACK_SERVICE))
? "yes"
: "no"))
return -1;

if (sendf_to_server (OID_PING_HOST ":checkbox:TCP ping tries only TCP-SYN ping"
kroosec marked this conversation as resolved.
Show resolved Hide resolved
if (sendf_to_server (OID_PING_HOST ":7:checkbox:TCP ping tries only TCP-SYN ping"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The id:7 for this preference was added to ping_host.nasl today.

" <|> %s\n",
((alive_test & ALIVE_TEST_TCP_SYN_SERVICE)
&& !(alive_test & ALIVE_TEST_TCP_ACK_SERVICE))
? "yes"
: "no"))
return -1;

if (sendf_to_server (OID_PING_HOST ":checkbox:Do an ICMP ping <|> %s\n",
if (sendf_to_server (OID_PING_HOST ":3:checkbox:Do an ICMP ping <|> %s\n",
(alive_test & ALIVE_TEST_ICMP)
? "yes"
: "no"))
return -1;

if (sendf_to_server (OID_PING_HOST ":checkbox:Use ARP <|> %s\n",
if (sendf_to_server (OID_PING_HOST ":4:checkbox:Use ARP <|> %s\n",
(alive_test & ALIVE_TEST_ARP)
? "yes"
: "no"))
return -1;

if (sendf_to_server (OID_PING_HOST ":checkbox:"
if (sendf_to_server (OID_PING_HOST ":5:checkbox:"
"Mark unrechable Hosts as dead (not scanning) <|> %s\n",
(alive_test & ALIVE_TEST_CONSIDER_ALIVE)
? "no"
Expand All @@ -2139,7 +2135,7 @@ send_alive_test_preferences (target_t target)
if (alive_test == ALIVE_TEST_CONSIDER_ALIVE)
{
/* Also select a method, otherwise Ping Host logs a warning. */
if (sendf_to_server (OID_PING_HOST ":checkbox:Do a TCP ping <|> yes\n"))
if (sendf_to_server (OID_PING_HOST ":1:checkbox:Do a TCP ping <|> yes\n"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ids where added to ping_host.nasl today.

return -1;
}

Expand Down Expand Up @@ -3243,6 +3239,7 @@ slave_setup (gvm_connection_t *connection, const char *name, task_t task,
"<name>%s</name>"
"</nvt>"
"<name>Timeout</name>"
"<id>0</id>"
"<type>entry</type>"
"<value>%s</value>"
"</preference>",
Expand Down Expand Up @@ -3794,7 +3791,7 @@ handle_slave_task (task_t task, target_t target,
"",
port_string,
/* NVT: Global variable settings. */
"1.3.6.1.4.1.25623.1.0.12288",
OID_GLOBAL_SETTINGS,
"Error Message",
"Authentication with the slave failed.");
g_free (port_string);
Expand Down Expand Up @@ -5354,15 +5351,15 @@ run_otp_task (task_t task, scanner_t scanner, int from, char **report_id)
const char *user = credential_iterator_login (&credentials);
const char *password = credential_iterator_password (&credentials);

if (sendf_to_server (OID_SSH_AUTH ":entry:SSH login name:"
if (sendf_to_server (OID_SSH_AUTH ":1:entry:SSH login name:"
" <|> %s\n",
user ? user : "")
|| (credential_iterator_private_key (&credentials)
? sendf_to_server (OID_SSH_AUTH ":password:"
? sendf_to_server (OID_SSH_AUTH ":2:password:"
"SSH key passphrase:"
" <|> %s\n",
password ? password : "")
: sendf_to_server (OID_SSH_AUTH ":password:"
: sendf_to_server (OID_SSH_AUTH ":3:password:"
"SSH password (unsafe!):"
" <|> %s\n",
password ? password : "")))
Expand Down Expand Up @@ -5393,7 +5390,7 @@ run_otp_task (task_t task, scanner_t scanner, int from, char **report_id)
(gpointer) g_strdup (credential_iterator_private_key
(&credentials)));

if (sendf_to_server (OID_SSH_AUTH ":file:SSH private key:"
if (sendf_to_server (OID_SSH_AUTH ":4:file:SSH private key:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ids where added to ssh_authorization_init.nasl today.

" <|> %s\n",
file_uuid))
goto fail;
Expand All @@ -5412,9 +5409,9 @@ run_otp_task (task_t task, scanner_t scanner, int from, char **report_id)
const char *user = credential_iterator_login (&credentials);
const char *password = credential_iterator_password (&credentials);

if (sendf_to_server (OID_SMB_AUTH ":entry:SMB login: <|> %s\n",
if (sendf_to_server (OID_SMB_AUTH ":1:entry:SMB login: <|> %s\n",
user ? user : "")
|| sendf_to_server (OID_SMB_AUTH ":password:SMB password:"
|| sendf_to_server (OID_SMB_AUTH ":2:password:SMB password:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ids where added to smb_authorization.nasl today.

" <|> %s\n",
password ? password : ""))
{
Expand Down Expand Up @@ -5443,10 +5440,10 @@ run_otp_task (task_t task, scanner_t scanner, int from, char **report_id)
const char *user = credential_iterator_login (&credentials);
const char *password = credential_iterator_password (&credentials);

if (sendf_to_server (OID_ESXI_AUTH ":entry:ESXi login name:"
if (sendf_to_server (OID_ESXI_AUTH ":1:entry:ESXi login name:"
" <|> %s\n",
user ? user : "")
|| sendf_to_server (OID_ESXI_AUTH ":password:ESXi login password:"
|| sendf_to_server (OID_ESXI_AUTH ":2:password:ESXi login password:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ids where added to gb_esxi_authorization.nasl today.

" <|> %s\n",
password ? password : ""))
{
Expand Down Expand Up @@ -5482,25 +5479,25 @@ run_otp_task (task_t task, scanner_t scanner, int from, char **report_id)
const char *privacy_algorithm
= credential_iterator_privacy_algorithm (&credentials);

if (sendf_to_server (OID_SNMP_AUTH ":password:SNMP Community:"
if (sendf_to_server (OID_SNMP_AUTH ":1:password:SNMP Community:"
" <|> %s\n",
community ? community : "")
|| sendf_to_server (OID_SNMP_AUTH ":entry:SNMPv3 Username:"
|| sendf_to_server (OID_SNMP_AUTH ":2:entry:SNMPv3 Username:"
" <|> %s\n",
user ? user : "")
|| sendf_to_server (OID_SNMP_AUTH ":password:"
|| sendf_to_server (OID_SNMP_AUTH ":3:password:"
"SNMPv3 Password:"
" <|> %s\n",
password ? password : "")
|| sendf_to_server (OID_SNMP_AUTH ":radio:"
|| sendf_to_server (OID_SNMP_AUTH ":4:radio:"
"SNMPv3 Authentication Algorithm:"
" <|> %s\n",
auth_algorithm ? auth_algorithm : "")
|| sendf_to_server (OID_SNMP_AUTH ":password:"
|| sendf_to_server (OID_SNMP_AUTH ":5:password:"
"SNMPv3 Privacy Password:"
" <|> %s\n",
privacy_password ? privacy_password : "")
|| sendf_to_server (OID_SNMP_AUTH ":radio:"
|| sendf_to_server (OID_SNMP_AUTH ":6:radio:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ids where added to gb_snmp_authorization.nasl today.

"SNMPv3 Privacy Algorithm:"
" <|> %s\n",
privacy_algorithm ? privacy_algorithm : ""))
Expand Down
Loading