Skip to content

Commit

Permalink
Merge pull request #352 from jjnicola/stop-scan
Browse files Browse the repository at this point in the history
Add option --scan-stop=<scan_id>.
  • Loading branch information
jjnicola committed Jul 8, 2019
2 parents 4d31605 + 271fd4d commit cbdd24c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/openvas.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Show a summary of the commands
.BI "--scan-start=" <scan-uuid>
ID for a single scan task. The scanner will start the scan with the data already loaded in a redis KB, which will be found using the given scan-id.

.TP
.BI "--scan-stop=" <scan-uuid>
ID for a single scan task. The scanner will search the redis kb associated to the given scan_id. It takes the pid from the kb and sends the SIGUSR2 kill signal to stop the scan.

.TP
.B "-u, --update-vt-info"
Updates VT info into redis store from VT files.
Expand Down
1 change: 1 addition & 0 deletions src/hosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ hosts_stop_host (struct host *h)

g_message ("Stopping host %s scan", h->name);
kill (h->pid, SIGUSR1);
kb_delete (h->host_kb);
return 0;
}

Expand Down
38 changes: 38 additions & 0 deletions src/openvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,33 @@ start_single_task_scan ()
scanner_thread (globals);
exit (0);
}
/**
* @brief Search in redis the process ID of a running scan and
* sends it the kill signal SIGUSR2, which will stop the scan.
* To find the process ID, it uses the scan_id passed with the
* --scan-stop option.
*/
static void
stop_single_task_scan ()
{
char key[1024];
kb_t kb;
int pid;

if (!global_scan_id)
exit (1);

snprintf (key, sizeof (key), "internal/%s/scanprefs", global_scan_id);
kb = kb_find (prefs_get ("db_address"), key);

if (!kb)
exit (1);

pid = kb_item_get_int (kb, "internal/ovas_pid");
kill (pid, SIGUSR2);

exit (0);
}

/**
* @brief openvas.
Expand All @@ -388,6 +415,7 @@ openvas (int argc, char *argv[])
static gchar *config_file = NULL;
static gchar *vendor_version_string = NULL;
static gchar *scan_id = NULL;
static gchar *stop_scan_id = NULL;
static gboolean print_specs = FALSE;
static gboolean print_sysconfdir = FALSE;
static gboolean update_vt_info = FALSE;
Expand All @@ -410,6 +438,9 @@ openvas (int argc, char *argv[])
"ID of scan to start. ID and related data must be stored into redis "
"before.",
"<string>"},
{"scan-stop", '\0', 0, G_OPTION_ARG_STRING, &stop_scan_id,
"ID of scan to stop", "<string>"},

{NULL, 0, 0, 0, NULL, NULL, NULL}};

option_context =
Expand Down Expand Up @@ -473,6 +504,13 @@ openvas (int argc, char *argv[])
if (init_openvas (config_file))
return 1;

if (stop_scan_id)
{
global_scan_id = g_strdup (stop_scan_id);
stop_single_task_scan ();
exit (0);
}

if (scan_id)
{
global_scan_id = g_strdup (scan_id);
Expand Down

0 comments on commit cbdd24c

Please sign in to comment.