33 #include <openvas/misc/network.h> 34 #include <openvas/misc/internal_com.h> 35 #include <openvas/misc/prefs.h> 45 #define MIN(x,y) ((x) < (y) ? (x):(y)) 49 static int ntp_read_prefs (
int);
50 static int ntp_long_attack (
int);
51 static int ntp_recv_file (
struct arglist *);
61 int soc = arg_get_value_int (globals,
"global_socket");
65 str = strstr (input,
" <|> ");
71 if (strcmp (input,
"CLIENT") == 0)
74 str = strchr (input,
' ');
78 if (input[strlen (input) - 1] ==
'\n')
79 input[strlen (input) - 1] =
'\0';
84 ntp_recv_file (globals);
88 result = ntp_long_attack (soc);
96 log_write (
"Stopping the whole test (requested by client)");
116 ntp_long_attack (
int soc)
123 n = recv_line (soc, input,
sizeof (input) - 1);
130 if (!strncmp (input,
"<|> CLIENT",
sizeof (
"<|> CLIENT")))
133 target = g_malloc0 (size + 1);
139 e = nrecv (soc, target + n, size - n, 0);
149 prefs_set (
"TARGET", target);
163 ntp_read_prefs (
int soc)
166 int input_sz = 1024 * 1024 * 2;
169 input = g_malloc0 (input_sz);
174 n = recv_line (soc, input, input_sz - 1);
176 if (n < 0 || input[0] ==
'\0')
178 log_write (
"Empty data string -- closing comm. channel");
182 if (strstr (input,
"<|> CLIENT") != NULL)
190 v = strchr (input,
'<');
204 if (value[0] !=
'\0')
205 value[strlen (value) - 1] =
'\0';
207 prefs_set (pref, value);
229 files_add_translation (
struct arglist *globals,
const char *remotename,
232 GHashTable *trans = arg_get_value (globals,
"files_translation");
236 trans = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
237 arg_add_value (globals,
"files_translation", ARG_PTR, trans);
240 g_hash_table_insert (trans, g_strdup (remotename), contents);
256 files_add_size_translation (
struct arglist *globals,
const char *remotename,
259 GHashTable *trans = arg_get_value (globals,
"files_size_translation");
260 gchar *filesize_str = g_strdup_printf (
"%ld", filesize);
265 trans = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
266 arg_add_value (globals,
"files_size_translation", ARG_PTR, trans);
269 g_hash_table_insert (trans, g_strdup (remotename), g_strdup (filesize_str));
278 ntp_recv_file (
struct arglist *globals)
280 int soc = arg_get_value_int (globals,
"global_socket");
282 char *origname, *contents;
283 gchar *cont_ptr = NULL;
285 size_t bytes = 0, tot = 0;
287 n = recv_line (soc, input,
sizeof (input) - 1);
291 if (strncmp (input,
"name: ", strlen (
"name: ")) == 0)
293 origname = g_strdup (input +
sizeof (
"name: ") - 1);
294 if (origname[strlen (origname) - 1] ==
'\n')
295 origname[strlen (origname) - 1] =
'\0';
300 n = recv_line (soc, input,
sizeof (input) - 1);
308 n = recv_line (soc, input,
sizeof (input) - 1);
315 if (strncmp (input,
"bytes: ",
sizeof (
"bytes: ") - 1) == 0)
317 char *t = input +
sizeof (
"bytes: ") - 1;
328 contents = g_try_malloc0 (bytes);
330 if (contents == NULL)
332 log_write (
"ntp_recv_file: Failed to allocate memory for uploaded file.");
340 bzero (input,
sizeof (input));
341 n = nrecv (soc, input,
MIN (
sizeof (input) - 1, bytes - tot), 0);
344 log_write (
"11_recv_file: nrecv(%d)", soc);
349 memcpy ((cont_ptr + (tot *
sizeof (
char))), &input, n);
353 send_printf (soc,
"SERVER <|> FILE_ACCEPTED <|> SERVER\n");
356 files_add_translation (globals, origname, contents);
357 files_add_size_translation (globals, origname, bytes);
371 __ntp_timestamp_scan (
int soc,
char *msg)
380 timestr[
sizeof (timestr) - 1] =
'\0';
381 strncpy (timestr, tmp,
sizeof (timestr) - 1);
382 len = strlen (timestr);
383 if (timestr[len - 1] ==
'\n')
384 timestr[len - 1] =
'\0';
386 send_printf (soc,
"SERVER <|> TIME <|> %s <|> %s <|> SERVER\n", msg, timestr);
392 __ntp_timestamp_scan_host (
int soc,
char *msg,
char *
host)
402 timestr[
sizeof (timestr) - 1] =
'\0';
403 strncpy (timestr, tmp,
sizeof (timestr) - 1);
404 len = strlen (timestr);
405 if (timestr[len - 1] ==
'\n')
406 timestr[len - 1] =
'\0';
408 snprintf (buf,
sizeof (buf),
409 "SERVER <|> TIME <|> %s <|> %s <|> %s <|> SERVER\n", msg,
host,
412 internal_send (soc, buf, INTERNAL_COMM_MSG_TYPE_DATA);
421 return __ntp_timestamp_scan (soc,
"SCAN_START");
427 return __ntp_timestamp_scan (soc,
"SCAN_END");
433 return __ntp_timestamp_scan_host (soc,
"HOST_START",
host);
439 return __ntp_timestamp_scan_host (soc,
"HOST_END",
host);
void hosts_stop_all(void)
void log_write(const char *str,...)
Write into the logfile / syslog.
void send_printf(int soc, char *data,...)
Writes data to a socket.
int ntp_timestamp_scan_ends(int soc)
int ntp_timestamp_host_scan_starts(int soc, char *host)
void comm_send_nvt_info(int soc)
Send the OTP NVT_INFO message and then handle any COMPLETE_LIST.
void comm_send_preferences(int soc)
Sends the preferences of the scanner.
int ntp_timestamp_host_scan_ends(int soc, char *host)
Host information, implemented as doubly linked list.
int is_scanner_only_pref(const char *pref)
int ntp_parse_input(struct arglist *globals, char *input)
Parses the input sent by the client before the NEW_ATTACK message.
int ntp_timestamp_scan_starts(int soc)
client_request_t otp_get_client_request(char *str)
Find the enum identifier for the client request which is given.