143 static gchar *target = NULL;
144 gchar *default_target =
"127.0.0.1";
145 int mode = 0, err = 0, pos;
149 static gboolean display_version = FALSE;
150 static gboolean nasl_debug = FALSE;
151 static gboolean description_only = FALSE;
152 static gboolean both_modes = FALSE;
153 static gboolean parse_only = FALSE;
154 static gboolean do_lint = FALSE;
155 static gchar *trace_file = NULL;
156 static gchar *config_file = NULL;
157 static gchar *source_iface = NULL;
158 static gchar *port_range = NULL;
159 static gboolean with_safe_checks = FALSE;
160 static gboolean signing_mode = FALSE;
161 static gchar *include_dir = NULL;
162 static gchar **nasl_filenames = NULL;
163 static gchar **kb_values = NULL;
164 static int debug_tls = 0;
165 GError *error = NULL;
166 GOptionContext *option_context;
167 static GOptionEntry entries[] = {
168 {
"version",
'V', 0, G_OPTION_ARG_NONE, &display_version,
169 "Display version information", NULL},
170 {
"debug",
'd', 0, G_OPTION_ARG_NONE, &nasl_debug,
171 "Output debug information to stderr.", NULL},
172 {
"description",
'D', 0, G_OPTION_ARG_NONE, &description_only,
173 "Only run the 'description' part of the script", NULL},
174 {
"both",
'B', 0, G_OPTION_ARG_NONE, &both_modes,
175 "Run in description mode before running the script.", NULL},
176 {
"parse",
'p', 0, G_OPTION_ARG_NONE, &parse_only,
177 "Only parse the script, don't execute it", NULL},
178 {
"lint",
'L', 0, G_OPTION_ARG_NONE, &do_lint,
179 "'lint' the script (extended checks)", NULL},
180 {
"target",
't', 0, G_OPTION_ARG_STRING, &target,
181 "Execute the scripts against <target>",
"<target>"},
182 {
"trace",
'T', 0, G_OPTION_ARG_FILENAME, &trace_file,
183 "Log actions to <file> (or '-' for stderr)",
"<file>"},
184 {
"config-file",
'c', 0, G_OPTION_ARG_FILENAME, &config_file,
185 "Configuration file",
"<filename>"},
186 {
"source-iface",
'e', 0, G_OPTION_ARG_STRING, &source_iface,
187 "Source network interface for established connections.",
"<iface_name>"},
188 {
"safe",
's', 0, G_OPTION_ARG_NONE, &with_safe_checks,
189 "Specifies that the script should be run with 'safe checks' enabled",
191 {
"disable-signing",
'X', 0, G_OPTION_ARG_NONE, &signing_mode,
192 "Run the script with disabled signature verification", NULL},
193 {
"include-dir",
'i', 0, G_OPTION_ARG_STRING, &include_dir,
194 "Search for includes in <dir>",
"<dir>"},
195 {
"debug-tls", 0, 0, G_OPTION_ARG_INT, &debug_tls,
196 "Enable TLS debugging at <level>",
"<level>"},
197 {
"kb",
'k', 0, G_OPTION_ARG_STRING_ARRAY, &kb_values,
198 "Set KB key to value. Can be used multiple times",
"<key=value>"},
199 {
"port-range",
'r', 0, G_OPTION_ARG_STRING, &port_range,
200 "Set the <port-range> used by nasl scripts. ",
"<port-range>"},
201 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &nasl_filenames,
202 "Absolute path to one or more nasl scripts",
"NASL_FILE..."},
203 {NULL, 0, 0, 0, NULL, NULL, NULL}};
206 g_option_context_new (
"- standalone NASL interpreter for OpenVAS");
207 g_option_context_add_main_entries (option_context, entries, NULL);
208 if (!g_option_context_parse (option_context, &argc, &argv, &error))
210 g_print (
"%s\n\n", error->message);
213 g_option_context_free (option_context);
223 printf (
"gnutls %s\n", gnutls_check_version (NULL));
224 printf (
"libssh %s\n", ssh_version (0));
225 printf (
"gpgme %s\n", gpgme_check_version (NULL));
229 printf (
"Copyright (C) 2002 - 2004 Tenable Network Security\n");
230 printf (
"Copyright (C) 2024 Greenbone AG\n\n");
238 if (description_only)
246 if (!strcmp (trace_file,
"-"))
250 FILE *fp = fopen (trace_file,
"w");
256 setvbuf (fp, NULL, _IOLBF, BUFSIZ);
265 fprintf (stderr,
"Error. No input file(s) specified !\n");
271 fprintf (stderr,
"** WARNING : packet forgery will not work\n");
272 fprintf (stderr,
"** as NASL is not running as root\n");
274 signal (SIGPIPE, SIG_IGN);
276 if (source_iface && gvm_source_iface_init (source_iface))
278 fprintf (stderr,
"Erroneous network source interface: %s\n",
285 gnutls_global_set_log_level (debug_tls);
289 target = g_strdup (default_target);
291 hosts = gvm_hosts_new (target);
294 fprintf (stderr,
"Erroneous target %s\n", target);
297 unresolved = gvm_hosts_resolve (
hosts);
300 g_warning (
"Couldn't resolve hostname '%s'", (
char *) unresolved->data);
301 unresolved = unresolved->next;
303 g_slist_free_full (unresolved, g_free);
308 if (include_dir != NULL)
313 prefs_config (config_file ? config_file : OPENVAS_CONF);
315 if (prefs_get (
"vendor_version") != NULL)
318 if (port_range != NULL)
320 prefs_set (
"port_range", port_range);
324 if (with_safe_checks)
325 prefs_set (
"safe_checks",
"yes");
335 if (prefs_get_bool (
"expand_vhosts"))
336 gvm_host_add_reverse_lookup (
host);
337 gvm_vhosts_exclude (
host, prefs_get (
"exclude_hosts"));
338 gvm_host_get_addr6 (
host, &ip6);
339 rc = kb_new (&kb, prefs_get (
"db_address") ? prefs_get (
"db_address")
345 process_id = getpid ();
348 for (
int i = 0; nasl_filenames[i] != NULL; i++)
351 if (both_modes || with_safe_checks)
359 else if (with_safe_checks
362 printf (
"%s isn't safe\n", nasl_filenames[i]);
371 gchar **kb_values_aux = kb_values;
372 while (*kb_values_aux)
374 gchar **splits = g_strsplit (*kb_values_aux,
"=", -1);
375 if (splits[2] || !splits[1])
377 fprintf (stderr,
"Erroneous --kb entry %s\n",
381 kb_item_add_str_unique (kb, splits[0], splits[1], 0, pos);
390 if (process_id != getpid ())
402 gvm_hosts_free (
hosts);