Main of the standalone nasl interpretor.
157 static gchar *target = NULL;
158 gchar *default_target =
"127.0.0.1";
159 int mode = 0, n = 0,
err = 0;
162 static gboolean display_version = FALSE;
163 static gboolean nasl_debug = FALSE;
164 static gboolean description_only = FALSE;
165 static gboolean both_modes = FALSE;
166 static gboolean parse_only = FALSE;
167 static gboolean do_lint = FALSE;
168 static gchar *trace_file = NULL;
169 static gchar *config_file = NULL;
170 static gchar *source_iface = NULL;
171 static gchar *vendor_version_string = NULL;
172 static gboolean with_safe_checks = FALSE;
173 static gboolean authenticated_mode = FALSE;
174 static gchar *include_dir = NULL;
175 static gchar **nasl_filenames = NULL;
176 static gchar **kb_values = NULL;
177 static int debug_tls = 0;
178 GError *error = NULL;
179 GOptionContext *option_context;
180 static GOptionEntry entries[] = {
181 {
"version",
'V', 0, G_OPTION_ARG_NONE, &display_version,
182 "Display version information", NULL},
183 {
"debug",
'd', 0, G_OPTION_ARG_NONE, &nasl_debug,
184 "Output debug information to stderr.", NULL},
185 {
"description",
'D', 0, G_OPTION_ARG_NONE, &description_only,
186 "Only run the 'description' part of the script", NULL},
187 {
"both",
'B', 0, G_OPTION_ARG_NONE, &both_modes,
188 "Run in description mode before running the script.", NULL},
189 {
"parse",
'p', 0, G_OPTION_ARG_NONE, &parse_only,
190 "Only parse the script, don't execute it", NULL},
191 {
"lint",
'L', 0, G_OPTION_ARG_NONE, &do_lint,
192 "'lint' the script (extended checks)", NULL},
193 {
"target",
't', 0, G_OPTION_ARG_STRING, &target,
194 "Execute the scripts against <target>",
"<target>"},
195 {
"trace",
'T', 0, G_OPTION_ARG_FILENAME, &trace_file,
196 "Log actions to <file> (or '-' for stderr)",
"<file>"},
197 {
"config-file",
'c', 0, G_OPTION_ARG_FILENAME, &config_file,
198 "Configuration file",
"<filename>"},
199 {
"source-iface",
'e', 0, G_OPTION_ARG_STRING, &source_iface,
200 "Source network interface for established connections.",
202 {
"vendor-version",
'\0', 0, G_OPTION_ARG_STRING, &vendor_version_string,
203 "Use <string> as vendor version.",
"<string>"},
204 {
"safe",
's', 0, G_OPTION_ARG_NONE, &with_safe_checks,
205 "Specifies that the script should be run with 'safe checks' enabled",
207 {
"authenticated",
'X', 0, G_OPTION_ARG_NONE, &authenticated_mode,
208 "Run the script in 'authenticated' mode", NULL},
209 {
"include-dir",
'i', 0, G_OPTION_ARG_STRING, &include_dir,
210 "Search for includes in <dir>",
"<dir>"},
211 {
"debug-tls", 0, 0, G_OPTION_ARG_INT, &debug_tls,
212 "Enable TLS debugging at <level>",
"<level>"},
213 {
"kb",
'k', 0, G_OPTION_ARG_STRING_ARRAY, &kb_values,
214 "Set KB key to vaue. Can be used multiple times",
"<key=value>"},
215 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &nasl_filenames,
216 "Absolute path to one or more nasl scripts",
"NASL_FILE..."},
221 g_option_context_new (
"- standalone NASL interpreter for OpenVAS");
222 g_option_context_add_main_entries (option_context, entries, NULL);
223 if (!g_option_context_parse (option_context, &argc, &argv, &error))
225 g_print (
"%s\n\n", error->message);
228 g_option_context_free (option_context);
238 printf (
"gnutls %s\n", gnutls_check_version (NULL));
239 printf (
"libssh %s\n", ssh_version (0));
240 printf (
"gpgme %s\n", gpgme_check_version (NULL));
244 printf (
"Copyright (C) 2002 - 2004 Tenable Network Security\n");
245 printf (
"Copyright (C) 2013 Greenbone Networks GmbH\n\n");
251 if (authenticated_mode)
253 if (description_only)
261 if (!strcmp (trace_file,
"-"))
265 FILE *fp = fopen (trace_file,
"w");
271 setvbuf (fp, NULL, _IOLBF, BUFSIZ);
275 if (with_safe_checks)
282 fprintf (stderr,
"Error. No input file(s) specified !\n");
286 if (vendor_version_string)
292 fprintf (stderr,
"** WARNING : packet forgery will not work\n");
293 fprintf (stderr,
"** as NASL is not running as root\n");
297 signal (SIGPIPE, SIG_IGN);
302 fprintf (stderr,
"Erroneous network source interface: %s\n",
308 gnutls_global_set_log_function (my_gnutls_log_func);
309 gnutls_global_set_log_level (debug_tls);
313 target = g_strdup (default_target);
320 if (include_dir != NULL)
329 char *hostname, *fqdn;
336 fprintf (stderr,
"Couldn't resolve %s\n", hostname);
347 script_infos =
init (hostname, &ip6, fqdn ?: hostname,
kb);
349 while (nasl_filenames[n])
353 if (both_modes || with_safe_checks)
355 nvti_t *
nvti = parse_script_infos (nasl_filenames[n],
363 else if (with_safe_checks
366 printf (
"%s isn't safe\n", nasl_filenames[n]);
378 gchar **splits = g_strsplit (*kb_values,
"=", -1);
379 if (splits[2] || !splits[1])
381 fprintf (stderr,
"Erroneous --kb entry %s\n", *kb_values);
384 kb_item_add_str (
kb, splits[0], splits[1]);
390 if ((pid = fork ()) == 0)
400 fprintf (stderr,
"fork(): %s\n", strerror (errno));
406 waitpid (pid, &status, 0);
The structure for a single host object.
void nvti_free(nvti_t *n)
Free memory of a nvti structure.
gchar * openvas_host_value_str(const openvas_host_t *host)
Gets a host's value in printable format.
void openvas_hosts_free(openvas_hosts_t *hosts)
Frees memory occupied by an openvas_hosts_t structure.
#define NASL_EXEC_PARSE_ONLY
The structure of a information record that corresponds to a NVT.
gint nvti_category(const nvti_t *n)
Get the category for this NVT.
openvas_host_t * openvas_hosts_next(openvas_hosts_t *hosts)
Gets the next openvas_host_t from a openvas_hosts_t structure. The state of iteration is kept interna...
char * nasl_version(void)
struct arglist * init(char *hostname, struct in6_addr *ip, char *fqdn, kb_t kb)
int openvas_SSL_init()
Initializes SSL support.
const gchar * prefs_get(const gchar *key)
Get a string preference value via a key.
#define KB_PATH_DEFAULT
Default KB location.
openvas_hosts_t * openvas_hosts_new(const gchar *hosts_str)
Creates a new openvas_hosts_t structure and the associated hosts objects from the provided hosts_str...
int exec_nasl_script(struct arglist *script_infos, const char *name, const char *oid, int mode)
Execute a NASL script.
#define NASL_COMMAND_LINE
Top-level KB. This is to be inherited by KB implementations.
void prefs_set(const gchar *key, const gchar *value)
Set a string preference value via a key.
void prefs_config(const char *config)
Apply the configs from given file as preferences.
#define NASL_ALWAYS_SIGNED
The structure for Hosts collection.
int openvas_host_get_addr6(const openvas_host_t *host, struct in6_addr *ip6)
Gives a host object's value as an IPv6 address. If the host type is hostname, it resolves the IPv4 ad...
int openvas_source_iface_init(const char *iface)
Initializes the source network interface name and related information.
void * arg_get_value(struct arglist *args, const char *name)
void vendor_version_set(const gchar *version)
Set vendor version.
int add_nasl_inc_dir(const char *)
Adds the given string as directory for searching for includes.
char * openvas_host_reverse_lookup(openvas_host_t *host)
Checks for a host object reverse dns lookup existence.