OpenVAS Scanner  7.0.0~git
nasl_ssh.h File Reference

Protos and data structures for SSH functions used by NASL scripts. More...

#include "nasl_lex_ctxt.h"
#include <libssh/libssh.h>
Include dependency graph for nasl_ssh.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

tree_cellnasl_ssh_connect (lex_ctxt *lexic)
 Connect to the target host via TCP and setup an ssh connection. More...
 
tree_cellnasl_ssh_disconnect (lex_ctxt *lexic)
 Disconnect an ssh connection. More...
 
tree_cellnasl_ssh_session_id_from_sock (lex_ctxt *lexic)
 Given a socket, return the corresponding session id. More...
 
tree_cellnasl_ssh_get_sock (lex_ctxt *lexic)
 Given a session id, return the corresponding socket. More...
 
tree_cellnasl_ssh_set_login (lex_ctxt *lexic)
 Set the login name for the authentication. More...
 
tree_cellnasl_ssh_userauth (lex_ctxt *lexic)
 Authenticate a user on an ssh connection. More...
 
tree_cellnasl_ssh_request_exec (lex_ctxt *lexic)
 Run a command via ssh. More...
 
tree_cellnasl_ssh_shell_open (lex_ctxt *lexic)
 Request an ssh shell. More...
 
tree_cellnasl_ssh_shell_read (lex_ctxt *lexic)
 Read the output of an ssh shell. More...
 
tree_cellnasl_ssh_shell_write (lex_ctxt *lexic)
 Write string to ssh shell. More...
 
tree_cellnasl_ssh_shell_close (lex_ctxt *lexic)
 Close an ssh shell. More...
 
tree_cellnasl_ssh_login_interactive (lex_ctxt *lexic)
 Authenticate a user on an ssh connection. More...
 
tree_cellnasl_ssh_login_interactive_pass (lex_ctxt *lexic)
 Authenticate a user on an ssh connection. More...
 
tree_cellnasl_ssh_exec (lex_ctxt *)
 
tree_cellnasl_ssh_get_issue_banner (lex_ctxt *lexic)
 Get the issue banner. More...
 
tree_cellnasl_ssh_get_server_banner (lex_ctxt *lexic)
 Get the server banner. More...
 
tree_cellnasl_ssh_get_auth_methods (lex_ctxt *lexic)
 Get the list of authmethods. More...
 
tree_cellnasl_ssh_get_host_key (lex_ctxt *lexic)
 Get the host key. More...
 

Detailed Description

Protos and data structures for SSH functions used by NASL scripts.

This file contains the protos for nasl_ssh.c

Definition in file nasl_ssh.h.

Function Documentation

◆ nasl_ssh_connect()

tree_cell* nasl_ssh_connect ( lex_ctxt lexic)

Connect to the target host via TCP and setup an ssh connection.

NASL Function: ssh_connect\n

If the named argument "socket" is given, that socket will be used instead of a creating a new TCP connection. If socket is not given or 0, the port is looked up in the preferences and the KB unless overridden by the named parameter "port".

On success an ssh session to the host has been established; the caller may then run an authentication function. If the connection is no longer needed, ssh_disconnect may be used to disconnect and close the socket.

NASL Named Parameters:\n
  • socket If given, this socket will be used instead of creating a new connection.
  • port A non-standard port to connect to. This is only used if socket is not given or 0.
  • keytype List of the preferred server host key types. Example: "ssh-rsa,ssh-dss"
  • csciphers SSH client-to-server ciphers.
  • scciphers SSH server-to-client ciphers.
NASL Returns:\n An integer to identify the ssh session. Zero on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
On success the function returns a tree-cell with a non-zero integer identifying that ssh session; zero is returned on a connection error. In case of an internal error NULL is returned.

Definition at line 235 of file nasl_ssh.c.

236 {
237  ssh_session session;
238  tree_cell *retc;
239  const char *key_type, *csciphers, *scciphers, *s;
240  char ip_str[INET6_ADDRSTRLEN];
241  int port, sock;
242  unsigned int tbl_slot;
243  int verbose = 0;
244  int forced_sock = -1;
245 
246  sock = get_int_var_by_name (lexic, "socket", 0);
247  if (sock)
248  port = 0; /* The port is ignored if "socket" is given. */
249  else
250  {
251  port = get_int_var_by_name (lexic, "port", 0);
252  if (port <= 0)
253  port = get_ssh_port (lexic);
254  }
255 
256  addr6_to_str (plug_get_host_ip (lexic->script_infos), ip_str);
257  session = ssh_new ();
258  if (!session)
259  {
260  g_message ("Function %s called from %s: "
261  "Failed to allocate a new SSH session",
263  return NULL;
264  }
265 
266  if ((s = getenv ("OPENVAS_LIBSSH_DEBUG")))
267  {
268  verbose = 1;
269  if (*s)
270  {
271  int intval = atoi (s);
272 
273  ssh_options_set (session, SSH_OPTIONS_LOG_VERBOSITY, &intval);
274  }
275  }
276 
277  if (ssh_options_set (session, SSH_OPTIONS_HOST, ip_str))
278  {
279  g_message ("Function %s called from %s: "
280  "Failed to set SSH hostname '%s': %s",
282  ssh_get_error (session));
283  ssh_free (session);
284  return NULL;
285  }
286 
287  if (ssh_options_set (session, SSH_OPTIONS_KNOWNHOSTS, "/dev/null"))
288  {
289  g_message ("Function %s called from %s: "
290  "Failed to disable SSH known_hosts: %s",
292  ssh_get_error (session));
293  ssh_free (session);
294  return NULL;
295  }
296 
297  key_type = get_str_var_by_name (lexic, "keytype");
298 
299  if (key_type && ssh_options_set (session, SSH_OPTIONS_HOSTKEYS, key_type))
300  {
301  g_message ("Function %s called from %s: "
302  "Failed to set SSH key type '%s': %s",
304  key_type, ssh_get_error (session));
305  ssh_free (session);
306  return NULL;
307  }
308 
309  csciphers = get_str_var_by_name (lexic, "csciphers");
310  if (csciphers
311  && ssh_options_set (session, SSH_OPTIONS_CIPHERS_C_S, csciphers))
312  {
313  g_message ("Function %s called from %s: "
314  "Failed to set SSH client to server ciphers '%s': %s",
316  csciphers, ssh_get_error (session));
317  ssh_free (session);
318  return NULL;
319  }
320  scciphers = get_str_var_by_name (lexic, "scciphers");
321  if (scciphers
322  && ssh_options_set (session, SSH_OPTIONS_CIPHERS_S_C, scciphers))
323  {
324  g_message ("Function %s called from %s: "
325  "Failed to set SSH server to client ciphers '%s': %s",
327  scciphers, ssh_get_error (session));
328  ssh_free (session);
329  return NULL;
330  }
331 
332  if (port)
333  {
334  unsigned int my_port = port;
335 
336  if (ssh_options_set (session, SSH_OPTIONS_PORT, &my_port))
337  {
338  g_message ("Function %s called from %s: "
339  "Failed to set SSH port for '%s' to %d: %s",
341  ip_str, port, ssh_get_error (session));
342  ssh_free (session);
343  return NULL;
344  }
345  }
346  if (sock)
347  {
348  socket_t my_fd = openvas_get_socket_from_connection (sock);
349 
350  if (verbose)
351  g_message ("Setting SSH fd for '%s' to %d (NASL sock=%d)", ip_str,
352  my_fd, sock);
353  if (ssh_options_set (session, SSH_OPTIONS_FD, &my_fd))
354  {
355  g_message ("Function %s called from %s: "
356  "Failed to set SSH fd for '%s' to %d (NASL sock=%d): %s",
358  ip_str, my_fd, sock, ssh_get_error (session));
359  ssh_free (session);
360  return NULL;
361  }
362  /* Remember the NASL socket. */
363  forced_sock = sock;
364  }
365 
366  /* Find a place in the table to save the session. */
367  for (tbl_slot = 0; tbl_slot < DIM (session_table); tbl_slot++)
368  if (!session_table[tbl_slot].session_id)
369  break;
370  if (!(tbl_slot < DIM (session_table)))
371  {
372  if (verbose)
373  g_message ("No space left in SSH session table");
374  ssh_free (session);
375  return NULL;
376  }
377 
378  /* Prepare the session table entry. */
379  session_table[tbl_slot].session = session;
380  session_table[tbl_slot].authmethods_valid = 0;
381  session_table[tbl_slot].user_set = 0;
382  session_table[tbl_slot].verbose = verbose;
383 
384  /* Connect to the host. */
385  if (verbose)
386  g_message ("Connecting to SSH server '%s' (port %d, sock %d)", ip_str, port,
387  sock);
388  if (ssh_connect (session))
389  {
390  if (verbose)
391  g_message ("Failed to connect to SSH server '%s'"
392  " (port %d, sock %d, f=%d): %s",
393  ip_str, port, sock, forced_sock, ssh_get_error (session));
394  if (forced_sock != -1)
395  {
396  /* If the caller passed us a socket we can't call ssh_free
397  on it because we expect the caller to close that socket
398  himself. Instead we need to setup a table entry so that
399  it will then be close it via nasl_ssh_internal_close. */
401  session_table[tbl_slot].sock = forced_sock;
402  }
403  else
404  ssh_free (session);
405 
406  /* return 0 to indicate the error. */
407  /* FIXME: Set the last error string. */
408  retc = alloc_typed_cell (CONST_INT);
409  retc->x.i_val = 0;
410  return retc;
411  }
412 
413  /* How that we are connected, save the session. */
415  session_table[tbl_slot].sock =
416  forced_sock != -1 ? forced_sock : ssh_get_fd (session);
417  if (lowest_socket == 0 && session_table[tbl_slot].sock > 0)
418  lowest_socket = session_table[tbl_slot].sock;
419 
420  /* Return the session id. */
421  retc = alloc_typed_cell (CONST_INT);
422  retc->x.i_val = session_table[tbl_slot].session_id;
423  return retc;
424 }

References alloc_typed_cell(), session_table_item_s::authmethods_valid, CONST_INT, DIM, get_int_var_by_name(), get_ssh_port(), get_str_var_by_name(), TC::i_val, lowest_socket, nasl_get_function_name(), nasl_get_plugin_filename(), next_session_id(), openvas_get_socket_from_connection(), plug_get_host_ip(), struct_lex_ctxt::script_infos, session_table_item_s::session, session_table_item_s::session_id, session_table, session_table_item_s::sock, session_table_item_s::user_set, session_table_item_s::verbose, and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_disconnect()

tree_cell* nasl_ssh_disconnect ( lex_ctxt lexic)

Disconnect an ssh connection.

NASL Function: ssh_disconnect\n

This function takes the ssh session id (as returned by ssh_connect) as its only unnamed argument. Passing 0 as session id is explicitly allowed and does nothing. If there are any open channels they are closed as well and their ids will be marked as invalid.

NASL Unnamed Parameters:\n
  • An ssh session id. A value of 0 is allowed and acts as a NOP.
NASL Returns:\n Nothing
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
Nothing.

Definition at line 491 of file nasl_ssh.c.

492 {
493  int tbl_slot;
494  int session_id;
495 
496  session_id = get_int_var_by_num (lexic, 0, -1);
497  if (!verify_session_id (session_id, NULL, &tbl_slot, lexic))
498  return FAKE_CELL;
499  do_nasl_ssh_disconnect (tbl_slot);
500  return FAKE_CELL;
501 }

References do_nasl_ssh_disconnect(), FAKE_CELL, get_int_var_by_num(), session_table_item_s::session_id, and verify_session_id().

Here is the call graph for this function:

◆ nasl_ssh_exec()

tree_cell* nasl_ssh_exec ( lex_ctxt )

◆ nasl_ssh_get_auth_methods()

tree_cell* nasl_ssh_get_auth_methods ( lex_ctxt lexic)

Get the list of authmethods.

NASL Function: ssh_get_auth_methods\n

The function returns a string with comma separated authentication methods. This is basically the same as returned by SSH_MSG_USERAUTH_FAILURE protocol element; however, it has been screened and put into a definitive order.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Returns:\n A string on success or NULL on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
A string is returned on success. NULL indicates that the connection has not yet been established.

Definition at line 1572 of file nasl_ssh.c.

1573 {
1574  int tbl_slot, methods, session_id;
1575  GString *buffer;
1576  char *p;
1577  tree_cell *retc;
1578 
1579  session_id = get_int_var_by_num (lexic, 0, -1);
1580  if (!verify_session_id (session_id, "ssh_get_auth_methods", &tbl_slot, lexic))
1581  return NULL;
1582 
1583  if (!session_table[tbl_slot].user_set && !nasl_ssh_set_login (lexic))
1584  return NULL;
1585  if (!session_table[tbl_slot].authmethods_valid)
1586  get_authmethods (tbl_slot);
1587 
1588  methods = session_table[tbl_slot].authmethods;
1589 
1590  buffer = g_string_sized_new (128);
1591  if ((methods & SSH_AUTH_METHOD_NONE))
1592  g_string_comma_str (buffer, "none");
1593  if ((methods & SSH_AUTH_METHOD_PASSWORD))
1594  g_string_comma_str (buffer, "password");
1595  if ((methods & SSH_AUTH_METHOD_PUBLICKEY))
1596  g_string_comma_str (buffer, "publickey");
1597  if ((methods & SSH_AUTH_METHOD_HOSTBASED))
1598  g_string_comma_str (buffer, "hostbased");
1599  if ((methods & SSH_AUTH_METHOD_INTERACTIVE))
1600  g_string_comma_str (buffer, "keyboard-interactive");
1601  g_string_append_c (buffer, 0x00);
1602  p = g_string_free (buffer, FALSE);
1603  if (!p)
1604  return NULL;
1605 
1606  retc = alloc_typed_cell (CONST_DATA);
1607  retc->x.str_val = p;
1608  retc->size = strlen (p);
1609  return retc;
1610 }

References alloc_typed_cell(), session_table_item_s::authmethods, session_table_item_s::authmethods_valid, CONST_DATA, g_string_comma_str(), get_authmethods(), get_int_var_by_num(), nasl_ssh_set_login(), session_table_item_s::session_id, session_table, TC::size, TC::str_val, session_table_item_s::user_set, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_get_host_key()

tree_cell* nasl_ssh_get_host_key ( lex_ctxt lexic)

Get the host key.

NASL Function: ssh_get_host_key\n

The function returns a string with the MD5 host key. *

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Returns:\n A data block on success or NULL on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
A string is returned on success. NULL indicates that the connection has not yet been established.

Definition at line 1528 of file nasl_ssh.c.

1529 {
1530  int tbl_slot, session_id;
1531  ssh_session session;
1532  ssh_string sstring;
1533  tree_cell *retc;
1534 
1535  session_id = get_int_var_by_num (lexic, 0, -1);
1536  if (!verify_session_id (session_id, "ssh_get_host_key", &tbl_slot, lexic))
1537  return NULL;
1538  session = session_table[tbl_slot].session;
1539 
1540  sstring = ssh_get_pubkey (session);
1541  if (!sstring)
1542  return NULL;
1543 
1544  retc = alloc_typed_cell (CONST_DATA);
1545  retc->x.str_val = ssh_string_to_char (sstring);
1546  retc->size = ssh_string_len (sstring);
1547  ssh_string_free (sstring);
1548  return retc;
1549 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_num(), session_table_item_s::session, session_table_item_s::session_id, session_table, TC::size, TC::str_val, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_get_issue_banner()

tree_cell* nasl_ssh_get_issue_banner ( lex_ctxt lexic)

Get the issue banner.

NASL Function: ssh_get_issue_banner\n

The function returns a string with the issue banner. This is usually displayed before authentication.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Returns:\n A data block on success or NULL on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
A string is returned on success. NULL indicates that the server did not send a banner or that the connection has not yet been established.

Definition at line 1438 of file nasl_ssh.c.

1439 {
1440  int tbl_slot, session_id;
1441  ssh_session session;
1442  char *banner;
1443  tree_cell *retc;
1444 
1445  session_id = get_int_var_by_num (lexic, 0, -1);
1446  if (!verify_session_id (session_id, "ssh_get_issue_banner", &tbl_slot, lexic))
1447  return NULL;
1448  session = session_table[tbl_slot].session;
1449 
1450  /* We need to make sure that we got the auth methods so that libssh
1451  has the banner. */
1452  if (!session_table[tbl_slot].user_set && !nasl_ssh_set_login (lexic))
1453  return NULL;
1454  if (!session_table[tbl_slot].authmethods_valid)
1455  get_authmethods (tbl_slot);
1456 
1457  banner = ssh_get_issue_banner (session);
1458  if (!banner)
1459  return NULL;
1460 
1461  retc = alloc_typed_cell (CONST_DATA);
1462  retc->x.str_val = g_strdup (banner);
1463  retc->size = strlen (banner);
1464  ssh_string_free_char (banner);
1465  return retc;
1466 }

References alloc_typed_cell(), session_table_item_s::authmethods_valid, CONST_DATA, get_authmethods(), get_int_var_by_num(), nasl_ssh_set_login(), session_table_item_s::session, session_table_item_s::session_id, session_table, TC::size, TC::str_val, session_table_item_s::user_set, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_get_server_banner()

tree_cell* nasl_ssh_get_server_banner ( lex_ctxt lexic)

Get the server banner.

NASL Function: ssh_get_server_banner\n

The function returns a string with the server banner. This is usually the first data sent by the server.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Returns:\n A data block on success or NULL on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
A string is returned on success. NULL indicates that the connection has not yet been established.

Definition at line 1487 of file nasl_ssh.c.

1488 {
1489  int tbl_slot, session_id;
1490  ssh_session session;
1491  const char *banner;
1492  tree_cell *retc;
1493 
1494  session_id = get_int_var_by_num (lexic, 0, -1);
1495  if (!verify_session_id (session_id, "ssh_get_server_banner", &tbl_slot,
1496  lexic))
1497  return NULL;
1498  session = session_table[tbl_slot].session;
1499 
1500  banner = ssh_get_serverbanner (session);
1501  if (!banner)
1502  return NULL;
1503 
1504  retc = alloc_typed_cell (CONST_DATA);
1505  retc->x.str_val = g_strdup (banner);
1506  retc->size = strlen (banner);
1507  return retc;
1508 }

References alloc_typed_cell(), CONST_DATA, get_int_var_by_num(), session_table_item_s::session, session_table_item_s::session_id, session_table, TC::size, TC::str_val, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_get_sock()

tree_cell* nasl_ssh_get_sock ( lex_ctxt lexic)

Given a session id, return the corresponding socket.

NASL Function: ssh_get_sock\n

The socket is either a native file descriptor or a NASL connection socket (if a open socket was passed to ssh_connect). The NASL network code handles both of them.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Returns:\n An integer representing the socket or -1 on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
The socket or -1 on error.

Definition at line 599 of file nasl_ssh.c.

600 {
601  int tbl_slot, sock, session_id;
602  tree_cell *retc;
603 
604  session_id = get_int_var_by_num (lexic, 0, -1);
605  if (!verify_session_id (session_id, "ssh_get_sock", &tbl_slot, lexic))
606  sock = -1;
607  else
608  sock = session_table[tbl_slot].sock;
609 
610  retc = alloc_typed_cell (CONST_INT);
611  retc->x.i_val = sock;
612  return retc;
613 }

References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), TC::i_val, session_table_item_s::session_id, session_table, session_table_item_s::sock, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_login_interactive()

tree_cell* nasl_ssh_login_interactive ( lex_ctxt lexic)

Authenticate a user on an ssh connection.

NASL Function: ssh_login_intenteractive\n

The function starts the authentication process and pauses it when it finds the first non-echo prompt. The function expects the session id as its first unnamed argument. The first time this function is called for a session id, the named argument "login" is also expected.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Named Parameters:\n
  • login A string with the login name.
NASL Returns:\n A data block on success or NULL on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
A string containing the prompt is returned on success. NULL indicates that the error.

Definition at line 991 of file nasl_ssh.c.

992 {
993  int tbl_slot;
994  int session_id;
995  ssh_session session;
996  int rc;
997  const char *s = NULL;
998  int methods;
999  int verbose;
1000 
1001  session_id = get_int_var_by_num (lexic, 0, -1);
1002  if (!verify_session_id (session_id, "ssh_login_interactive", &tbl_slot,
1003  lexic))
1004  return NULL; /* Ooops. */
1005  session = session_table[tbl_slot].session;
1006  verbose = session_table[tbl_slot].verbose;
1007 
1008  /* Check if we need to set the user. This is done only once per
1009  session. */
1010  if (!session_table[tbl_slot].user_set && !nasl_ssh_set_login (lexic))
1011  return NULL;
1012 
1013  /* Get the authentication methods onlye once per session. */
1014  if (!session_table[tbl_slot].authmethods_valid)
1015  {
1016  if (!get_authmethods (tbl_slot))
1017  {
1018  s = g_strdup ("");
1019  goto leave;
1020  }
1021  }
1022  methods = session_table[tbl_slot].authmethods;
1023 
1024  if (methods & SSH_AUTH_METHOD_INTERACTIVE)
1025  {
1026  /* Our strategy for kbint is to send the password to the first
1027  prompt marked as non-echo. */
1028  while ((rc = ssh_userauth_kbdint (session, NULL, NULL)) == SSH_AUTH_INFO)
1029  {
1030  int n, nprompt;
1031  char echoflag;
1032  int found_prompt = 0;
1033 
1034  if (verbose)
1035  {
1036  s = ssh_userauth_kbdint_getname (session);
1037  if (s && *s)
1038  g_message ("SSH kbdint name='%s'", s);
1039  s = ssh_userauth_kbdint_getinstruction (session);
1040  if (s && *s)
1041  g_message ("SSH kbdint instruction='%s'", s);
1042  }
1043 
1044  nprompt = ssh_userauth_kbdint_getnprompts (session);
1045  for (n = 0; n < nprompt; n++)
1046  {
1047  s = ssh_userauth_kbdint_getprompt (session, n, &echoflag);
1048  if (s && *s && verbose)
1049  g_message ("SSH kbdint prompt='%s'%s", s,
1050  echoflag ? "" : " [hide input]");
1051  if (s && *s && !echoflag && !found_prompt)
1052  goto leave;
1053  }
1054  }
1055  if (verbose)
1056  g_message (
1057  "SSH keyboard-interactive authentication failed for session %d"
1058  ": %s",
1059  session_id, ssh_get_error (session));
1060  }
1061 
1062  if (!s)
1063  return NULL;
1064 
1065 leave:
1066  {
1067  tree_cell *retc;
1068 
1069  retc = alloc_typed_cell (CONST_DATA);
1070  retc->x.str_val = g_strdup (s);
1071  retc->size = strlen (s);
1072  return retc;
1073  }
1074 }

References alloc_typed_cell(), session_table_item_s::authmethods, session_table_item_s::authmethods_valid, CONST_DATA, get_authmethods(), get_int_var_by_num(), nasl_ssh_set_login(), session_table_item_s::session, session_table_item_s::session_id, session_table, TC::size, TC::str_val, session_table_item_s::user_set, session_table_item_s::verbose, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_login_interactive_pass()

tree_cell* nasl_ssh_login_interactive_pass ( lex_ctxt lexic)

Authenticate a user on an ssh connection.

NASL Function: ssh_login_intenteractive_pass\n

The function finishes the authentication process started by ssh_login_interactive. The function expects the session id as its first unnamed argument.

To finish the password, the named argument "password" must contain a password.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Named Parameters:\n
  • password A string with the password.
NASL Returns:\n An integer as status value; 0 indicates success.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
An integer is returned on success. -1 indicates an error.

Definition at line 1103 of file nasl_ssh.c.

1104 {
1105  int tbl_slot;
1106  int session_id;
1107  ssh_session session;
1108  const char *password = NULL;
1109  int rc;
1110  int retc_val = -1;
1111  int verbose;
1112 
1113  session_id = get_int_var_by_num (lexic, 0, -1);
1114  if (!verify_session_id (session_id, "ssh_login_interactive_pass", &tbl_slot,
1115  lexic))
1116  return NULL; /* Ooops. */
1117  session = session_table[tbl_slot].session;
1118  verbose = session_table[tbl_slot].verbose;
1119 
1120  /* A prompt is waiting for the password. */
1121  if ((password = get_str_var_by_name (lexic, "password")) == NULL)
1122  return NULL;
1123 
1124  rc = ssh_userauth_kbdint_setanswer (session, 0, password);
1125 
1126  if (rc < 0)
1127  {
1128  if (verbose)
1129  g_message ("SSH keyboard-interactive authentication "
1130  "failed at prompt %d for session %d: %s",
1131  0, session_id, ssh_get_error (session));
1132  retc_val = -1;
1133  goto leave;
1134  }
1135 
1136  if (rc == 0)
1137  {
1138  /* I need to do that to finish the auth process. */
1139  while ((rc = ssh_userauth_kbdint (session, NULL, NULL)) == SSH_AUTH_INFO)
1140  {
1141  ssh_userauth_kbdint_getnprompts (session);
1142  }
1143  if (rc == SSH_AUTH_SUCCESS)
1144  {
1145  retc_val = 0;
1146  goto leave;
1147  }
1148  if (rc != SSH_AUTH_SUCCESS)
1149  {
1150  retc_val = -1;
1151  goto leave;
1152  }
1153  }
1154 
1155 leave:
1156  {
1157  tree_cell *retc;
1158 
1159  retc = alloc_typed_cell (CONST_INT);
1160  retc->x.i_val = retc_val;
1161  return retc;
1162  }
1163 }

References alloc_typed_cell(), CONST_INT, get_int_var_by_num(), get_str_var_by_name(), TC::i_val, session_table_item_s::session, session_table_item_s::session_id, session_table, session_table_item_s::verbose, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_request_exec()

tree_cell* nasl_ssh_request_exec ( lex_ctxt lexic)

Run a command via ssh.

NASL Function: ssh_request_exec\n

The function opens a channel to the remote end and ask it to execute a command. The output of the command is then returned as a data block. The first unnamed argument is the session id. The command itself is expected as string in the named argument "cmd".

Regarding the handling of the stderr and stdout stream, this function may be used in different modes.

If either the named arguments stdout or stderr are given and that one is set to 1, only the output of the specified stream is returned.

If stdout and stderr are both given and set to 1, the output of both is returned interleaved. NOTE: The following feature has not yet been implemented: The output is guaranteed not to switch between stderr and stdout within a line.

If stdout and stderr are both given but set to 0, a special backward compatibility mode is used: First all output to stderr is collected up until any output to stdout is received. Then all output to stdout is returned while ignoring all further stderr output; at EOF the initial collected data from stderr is returned.

If the named parameters stdout and stderr are not given, the function acts exactly as if only stdout has been set to 1.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Named Parameters:\n
  • cmd A string with the command to execute.
  • stdout An integer with value 0 or 1; see above for a full description.
  • stderr An integer with value 0 or 1; see above for a full description.
NASL Returns:\n A data block on success or NULL on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
A data/string is returned on success. NULL indicates an error.

Definition at line 1317 of file nasl_ssh.c.

1318 {
1319  int tbl_slot;
1320  int session_id;
1321  ssh_session session;
1322  int verbose;
1323  char *cmd;
1324  int rc;
1325  GString *response, *compat_buf;
1326  size_t len = 0;
1327  tree_cell *retc;
1328  char *p;
1329  int to_stdout, to_stderr, compat_mode, compat_buf_inuse;
1330 
1331  session_id = get_int_var_by_num (lexic, 0, -1);
1332  if (!verify_session_id (session_id, "ssh_request_exec", &tbl_slot, lexic))
1333  return NULL;
1334  session = session_table[tbl_slot].session;
1335 
1336  verbose = session_table[tbl_slot].verbose;
1337 
1338  cmd = get_str_var_by_name (lexic, "cmd");
1339  if (!cmd || !*cmd)
1340  {
1341  g_message ("Function %s called from %s: No command passed",
1343  return NULL;
1344  }
1345 
1346  to_stdout = get_int_var_by_name (lexic, "stdout", -1);
1347  to_stderr = get_int_var_by_name (lexic, "stderr", -1);
1348  compat_mode = 0;
1349  if (to_stdout == -1 && to_stderr == -1)
1350  {
1351  /* None of the two named args are given. */
1352  to_stdout = 1;
1353  }
1354  else if (to_stdout == 0 && to_stderr == 0)
1355  {
1356  /* Compatibility mode. */
1357  to_stdout = 1;
1358  compat_mode = 1;
1359  }
1360 
1361  if (to_stdout < 0)
1362  to_stdout = 0;
1363  if (to_stderr < 0)
1364  to_stderr = 0;
1365 
1366  memset (&compat_buf, '\0', sizeof (compat_buf));
1367  /* Allocate some space in advance. Most commands won't output too
1368  much and thus 512 bytes (6 standard terminal lines) should often
1369  be sufficient. */
1370  response = g_string_sized_new (512);
1371  if (compat_mode)
1372  {
1373  compat_buf = g_string_sized_new (512);
1374  compat_buf_inuse = 1;
1375  }
1376  else
1377  compat_buf_inuse = 0;
1378 
1379  rc = exec_ssh_cmd (session, cmd, verbose, compat_mode, to_stdout, to_stderr,
1380  response, compat_buf);
1381  if (rc == SSH_ERROR)
1382  {
1383  if (compat_buf_inuse)
1384  g_string_free (compat_buf, TRUE);
1385  g_string_free (response, TRUE);
1386  return NULL;
1387  }
1388 
1389  /* Append the compatibility buffer to the output. */
1390  if (compat_buf_inuse)
1391  {
1392  len = compat_buf->len;
1393  p = g_string_free (compat_buf, FALSE);
1394  if (p)
1395  {
1396  g_string_append_len (response, p, len);
1397  g_free (p);
1398  }
1399  }
1400 
1401  /* Return the the output. */
1402  len = response->len;
1403  p = g_string_free (response, FALSE);
1404  if (!p)
1405  {
1406  g_message ("Function %s called from %s: memory problem: %s",
1408  strerror (-1));
1409  return NULL;
1410  }
1411 
1412  retc = alloc_typed_cell (CONST_DATA);
1413  retc->size = len;
1414  retc->x.str_val = p;
1415  return retc;
1416 }

References alloc_typed_cell(), CONST_DATA, exec_ssh_cmd(), get_int_var_by_name(), get_int_var_by_num(), get_str_var_by_name(), nasl_get_function_name(), nasl_get_plugin_filename(), session_table_item_s::session, session_table_item_s::session_id, session_table, TC::size, TC::str_val, session_table_item_s::verbose, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_session_id_from_sock()

tree_cell* nasl_ssh_session_id_from_sock ( lex_ctxt lexic)

Given a socket, return the corresponding session id.

NASL Function: ssh_session_id_from_sock\n
NASL Unnamed Parameters:\n
  • A NASL socket value
NASL Returns:\n An integer with the corresponding ssh session id or 0 if
no session id is known for the given socket.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
The session id on success or 0 if not found.

Definition at line 556 of file nasl_ssh.c.

557 {
558  int sock, session_id;
559  unsigned int tbl_slot;
560  tree_cell *retc;
561 
562  session_id = 0;
563  sock = get_int_var_by_num (lexic, 0, -1);
564  if (sock != -1)
565  {
566  for (tbl_slot = 0; tbl_slot < DIM (session_table); tbl_slot++)
567  if (session_table[tbl_slot].sock == sock
568  && session_table[tbl_slot].session_id)
569  {
570  session_id = session_table[tbl_slot].session_id;
571  break;
572  }
573  }
574 
575  retc = alloc_typed_cell (CONST_INT);
576  retc->x.i_val = session_id;
577  return retc;
578 }

References alloc_typed_cell(), CONST_INT, DIM, get_int_var_by_num(), TC::i_val, session_table_item_s::session_id, session_table, session_table_item_s::sock, and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_set_login()

tree_cell* nasl_ssh_set_login ( lex_ctxt lexic)

Set the login name for the authentication.

NASL Function: ssh_set_login\n

This is an optional function and usuallay not required. However, if you want to get the banner before starting the authentication, you need to tell libssh the user because it is often not possible to change the user after the first call to an authentication methods - getting the banner uses an authentication function.

The named argument "login" is used for the login name; it defaults the KB entry "Secret/SSH/login". It should contain the user name to login. Given that many servers don't allow changing the login for an established connection, the "login" parameter is silently ignored on all further calls.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Named Parameters:\n
  • login A string with the login name (optional).
NASL Returns:\n None
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
none.

Definition at line 706 of file nasl_ssh.c.

707 {
708  int tbl_slot, session_id;
709 
710  session_id = get_int_var_by_num (lexic, 0, -1);
711  if (!verify_session_id (session_id, "ssh_set_login", &tbl_slot, lexic))
712  return NULL; /* Ooops. */
713  if (!session_table[tbl_slot].user_set)
714  {
715  ssh_session session = session_table[tbl_slot].session;
716  kb_t kb;
717  char *username;
718 
719  username = g_strdup (get_str_var_by_name (lexic, "login"));
720  if (!username)
721  {
722  kb = plug_get_kb (lexic->script_infos);
723  username = kb_item_get_str (kb, "Secret/SSH/login");
724  }
725  if (username && *username
726  && ssh_options_set (session, SSH_OPTIONS_USER, username))
727  {
728  g_message ("Function %s called from %s: "
729  "Failed to set SSH username '%s': %s",
731  username, ssh_get_error (session));
732  g_free (username);
733  return NULL; /* Ooops. */
734  }
735  /* In any case mark the user has set. */
736  session_table[tbl_slot].user_set = 1;
737  g_free (username);
738  }
739  return FAKE_CELL;
740 }

References FAKE_CELL, get_int_var_by_num(), get_str_var_by_name(), nasl_get_function_name(), nasl_get_plugin_filename(), plug_get_kb(), struct_lex_ctxt::script_infos, session_table_item_s::session, session_table_item_s::session_id, session_table, session_table_item_s::user_set, and verify_session_id().

Referenced by nasl_ssh_get_auth_methods(), nasl_ssh_get_issue_banner(), nasl_ssh_login_interactive(), and nasl_ssh_userauth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nasl_ssh_shell_close()

tree_cell* nasl_ssh_shell_close ( lex_ctxt lexic)

Close an ssh shell.

NASL Function: ssh_shell_close\n
NASL Unnamed Parameters:\n
  • An ssh session id.
Parameters
[in]lexicLexical context of NASL interpreter.

Definition at line 1833 of file nasl_ssh.c.

1834 {
1835  int tbl_slot, session_id;
1836 
1837  session_id = get_int_var_by_num (lexic, 0, -1);
1838  if (!verify_session_id (session_id, "ssh_shell_close", &tbl_slot, lexic))
1839  return NULL;
1840  if (session_table[tbl_slot].channel)
1841  {
1842  ssh_channel_free (session_table[tbl_slot].channel);
1843  session_table[tbl_slot].channel = NULL;
1844  }
1845 
1846  return NULL;
1847 }

References session_table_item_s::channel, get_int_var_by_num(), session_table_item_s::session_id, session_table, and verify_session_id().

Here is the call graph for this function:

◆ nasl_ssh_shell_open()

tree_cell* nasl_ssh_shell_open ( lex_ctxt lexic)

Request an ssh shell.

NASL Function: ssh_shell_open\n
NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Returns:\n An int on success or NULL on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
Session ID on success, NULL on failure.

Definition at line 1661 of file nasl_ssh.c.

1662 {
1663  int tbl_slot, session_id;
1664  ssh_channel channel;
1665  ssh_session session;
1666  tree_cell *retc;
1667 
1668  session_id = get_int_var_by_num (lexic, 0, -1);
1669  if (!verify_session_id (session_id, "ssh_shell_open", &tbl_slot, lexic))
1670  return NULL;
1671  session = session_table[tbl_slot].session;
1672  channel = ssh_channel_new (session);
1673  if (!channel)
1674  return NULL;
1675  if (ssh_channel_open_session (channel))
1676  {
1677  g_message ("Function %s called from %s: ssh_channel_open_session: %s",
1679  ssh_get_error (session));
1680  ssh_channel_free (channel);
1681  return NULL;
1682  }
1683 
1684  if (request_ssh_shell (channel))
1685  {
1686  g_message ("Function %s called from %s: request_ssh_shell: %s",
1688  ssh_get_error (session));
1689  ssh_channel_free (channel);
1690  return NULL;
1691  }
1692  if (session_table[tbl_slot].channel)
1693  ssh_channel_free (session_table[tbl_slot].channel);
1694  session_table[tbl_slot].channel = channel;
1695 
1696  retc = alloc_typed_cell (CONST_INT);
1697  retc->x.i_val = session_table[tbl_slot].session_id;
1698  return retc;
1699 }

References alloc_typed_cell(), session_table_item_s::channel, CONST_INT, get_int_var_by_num(), TC::i_val, nasl_get_function_name(), nasl_get_plugin_filename(), request_ssh_shell(), session_table_item_s::session, session_table_item_s::session_id, session_table, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_shell_read()

tree_cell* nasl_ssh_shell_read ( lex_ctxt lexic)

Read the output of an ssh shell.

NASL Function: ssh_shell_read\n
NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Returns:\n A string on success or NULL on error.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
Data read from shell on success, NULL on failure.

Definition at line 1746 of file nasl_ssh.c.

1747 {
1748  int tbl_slot, session_id;
1749  ssh_channel channel;
1750  tree_cell *retc;
1751  GString *response;
1752 
1753  session_id = get_int_var_by_num (lexic, 0, -1);
1754  if (!verify_session_id (session_id, "ssh_shell_read", &tbl_slot, lexic))
1755  return NULL;
1756  channel = session_table[tbl_slot].channel;
1757 
1758  response = g_string_new (NULL);
1759  if (read_ssh_nonblocking (channel, response))
1760  return NULL;
1761  retc = alloc_typed_cell (CONST_DATA);
1762  retc->size = response->len;
1763  retc->x.str_val = g_string_free (response, FALSE);
1764  return retc;
1765 }

References alloc_typed_cell(), session_table_item_s::channel, CONST_DATA, get_int_var_by_num(), read_ssh_nonblocking(), session_table_item_s::session_id, session_table, TC::size, TC::str_val, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_shell_write()

tree_cell* nasl_ssh_shell_write ( lex_ctxt lexic)

Write string to ssh shell.

NASL Function: ssh_shell_write\n
NASL Unnamed Parameters:\n
  • An ssh session id.
  • A string to write to shell.
NASL Returns:\n An integer: 0 on success, -1 on failure.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
0 on success, -1 on failure.

Definition at line 1783 of file nasl_ssh.c.

1784 {
1785  int tbl_slot, rc = -1, len, session_id;
1786  ssh_channel channel;
1787  tree_cell *retc;
1788  char *cmd;
1789 
1790  session_id = get_int_var_by_num (lexic, 0, -1);
1791  if (!verify_session_id (session_id, "ssh_shell_write", &tbl_slot, lexic))
1792  goto write_ret;
1793  if (!(channel = session_table[tbl_slot].channel))
1794  {
1795  g_message ("ssh_shell_write: No shell channel found");
1796  goto write_ret;
1797  }
1798 
1799  cmd = get_str_var_by_name (lexic, "cmd");
1800  if (!cmd || !*cmd)
1801  {
1802  g_message ("Function %s called from %s: No command passed",
1804  goto write_ret;
1805  }
1806  len = strlen (cmd);
1807  if (ssh_channel_write (channel, cmd, len) != len)
1808  {
1809  g_message ("Function %s called from %s: %s", nasl_get_function_name (),
1811  ssh_get_error (session_table[tbl_slot].session));
1812  goto write_ret;
1813  }
1814  rc = 0;
1815 
1816 write_ret:
1817  retc = alloc_typed_cell (CONST_INT);
1818  retc->x.i_val = rc;
1819  return retc;
1820 }

References alloc_typed_cell(), session_table_item_s::channel, CONST_INT, get_int_var_by_num(), get_str_var_by_name(), TC::i_val, nasl_get_function_name(), nasl_get_plugin_filename(), session_table_item_s::session, session_table_item_s::session_id, session_table, verify_session_id(), and TC::x.

Here is the call graph for this function:

◆ nasl_ssh_userauth()

tree_cell* nasl_ssh_userauth ( lex_ctxt lexic)

Authenticate a user on an ssh connection.

NASL Function: ssh_userauth\n

The function expects the session id as its first unnamed argument. The first time this function is called for a session id, the named argument "login" is also expected; it defaults the KB entry "Secret/SSH/login". It should contain the user name to login. Given that many servers don't allow changing the login for an established connection, the "login" parameter is silently ignored on all further calls.

To perform a password based authentication, the named argument "password" must contain a password.

To perform a public key based authentication, the named argument "privatekey" must contain a base64 encoded private key in ssh native or in PKCS#8 format.

If both, "password" and "privatekey" are given as named arguments only "password" is used. If neither are given the values are taken from the KB ("Secret/SSH/password" and "Secret/SSH/privatekey") and tried in the order {password, privatekey}. Note well, that if one of the named arguments are given, only those are used and the KB is not consulted.

If the private key is protected, its passphrase is taken from the named argument "passphrase" or, if not given, taken from the KB ("Secret/SSH/passphrase").

Note that the named argument "publickey" and the KB item ("Secret/SSH/publickey") are ignored - they are not longer required because they can be derived from the private key.

NASL Unnamed Parameters:\n
  • An ssh session id.
NASL Named Parameters:\n
  • login A string with the login name.
  • password A string with the password.
  • privatekey A base64 encoded private key in ssh native or in pkcs#8 format. This parameter is ignored if password is given.
  • passphrase A string with the passphrase used to unprotect privatekey.
NASL Returns:\n An integer as status value; 0 indicates success.
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
0 is returned on success. Any other value indicates an error.

Definition at line 800 of file nasl_ssh.c.

801 {
802  int rc, retc_val = -1, methods, verbose, tbl_slot, session_id;
803  ssh_session session;
804  char *password = NULL;
805  char *privkeystr = NULL;
806  char *privkeypass = NULL;
807  kb_t kb;
808  tree_cell *retc;
809 
810  session_id = get_int_var_by_num (lexic, 0, -1);
811  if (!verify_session_id (session_id, "ssh_userauth", &tbl_slot, lexic))
812  return NULL; /* Ooops. */
813  session = session_table[tbl_slot].session;
814  verbose = session_table[tbl_slot].verbose;
815 
816  /* Check if we need to set the user. This is done only once per
817  session. */
818  if (!session_table[tbl_slot].user_set && !nasl_ssh_set_login (lexic))
819  return NULL;
820 
821  kb = plug_get_kb (lexic->script_infos);
822  password = g_strdup (get_str_var_by_name (lexic, "password"));
823  privkeystr = g_strdup (get_str_var_by_name (lexic, "privatekey"));
824  privkeypass = g_strdup (get_str_var_by_name (lexic, "passphrase"));
825  if (!password && !privkeystr && !privkeypass)
826  {
827  password = kb_item_get_str (kb, "Secret/SSH/password");
828  privkeystr = kb_item_get_str (kb, "Secret/SSH/privatekey");
829  privkeypass = kb_item_get_str (kb, "Secret/SSH/passphrase");
830  }
831 
832  /* Get the authentication methods onlye once per session. */
833  if (!session_table[tbl_slot].authmethods_valid)
834  {
835  if (!get_authmethods (tbl_slot))
836  {
837  retc_val = 0;
838  goto leave;
839  }
840  }
841  methods = session_table[tbl_slot].authmethods;
842 
843  /* Check whether a password has been given. If so, try to
844  authenticate using that password. Note that the OpenSSH client
845  uses a different order it first tries the public key and then the
846  password. However, the old NASL SSH protocol implementation tries
847  the password before the public key authentication. Because we
848  want to be compatible, we do it in that order. */
849  if (password && (methods & SSH_AUTH_METHOD_PASSWORD))
850  {
851  rc = ssh_userauth_password (session, NULL, password);
852  if (rc == SSH_AUTH_SUCCESS)
853  {
854  retc_val = 0;
855  goto leave;
856  }
857 
858  if (verbose)
859  g_message ("SSH password authentication failed for session"
860  " %d: %s",
861  session_id, ssh_get_error (session));
862  /* Keep on trying. */
863  }
864 
865  if (password && (methods & SSH_AUTH_METHOD_INTERACTIVE))
866  {
867  /* Our strategy for kbint is to send the password to the first
868  prompt marked as non-echo. */
869  while ((rc = ssh_userauth_kbdint (session, NULL, NULL)) == SSH_AUTH_INFO)
870  {
871  const char *s;
872  int n, nprompt;
873  char echoflag;
874  int found_prompt = 0;
875 
876  if (verbose)
877  {
878  s = ssh_userauth_kbdint_getname (session);
879  if (s && *s)
880  g_message ("SSH kbdint name='%s'", s);
881  s = ssh_userauth_kbdint_getinstruction (session);
882  if (s && *s)
883  g_message ("SSH kbdint instruction='%s'", s);
884  }
885  nprompt = ssh_userauth_kbdint_getnprompts (session);
886  for (n = 0; n < nprompt; n++)
887  {
888  s = ssh_userauth_kbdint_getprompt (session, n, &echoflag);
889  if (s && *s && verbose)
890  g_message ("SSH kbdint prompt='%s'%s", s,
891  echoflag ? "" : " [hide input]");
892  if (s && *s && !echoflag && !found_prompt)
893  {
894  found_prompt = 1;
895  rc = ssh_userauth_kbdint_setanswer (session, n, password);
896  if (rc != SSH_AUTH_SUCCESS)
897  {
898  if (verbose)
899  g_message ("SSH keyboard-interactive authentication "
900  "failed at prompt %d for session %d: %s",
901  n, session_id, ssh_get_error (session));
902  }
903  }
904  }
905  }
906 
907  if (rc == SSH_AUTH_SUCCESS)
908  {
909  retc_val = 0;
910  goto leave;
911  }
912 
913  if (verbose)
914  g_message (
915  "SSH keyboard-interactive authentication failed for session %d"
916  ": %s",
917  session_id, ssh_get_error (session));
918  /* Keep on trying. */
919  }
920 
921  /* If we have a private key, try public key authentication. */
922  if (privkeystr && *privkeystr && (methods & SSH_AUTH_METHOD_PUBLICKEY))
923  {
924  ssh_key key = NULL;
925 
926  if (ssh_pki_import_privkey_base64 (privkeystr, privkeypass, NULL, NULL,
927  &key))
928  {
929  if (verbose)
930  g_message ("SSH public key authentication failed for "
931  "session %d: %s",
932  session_id, "Error converting provided key");
933  }
934  else if (ssh_userauth_try_publickey (session, NULL, key)
935  != SSH_AUTH_SUCCESS)
936  {
937  if (verbose)
938  g_message ("SSH public key authentication failed for "
939  "session %d: %s",
940  session_id, "Server does not want our key");
941  }
942  else if (ssh_userauth_publickey (session, NULL, key) == SSH_AUTH_SUCCESS)
943  {
944  retc_val = 0;
945  ssh_key_free (key);
946  goto leave;
947  }
948  ssh_key_free (key);
949  /* Keep on trying. */
950  }
951 
952  if (verbose)
953  g_message ("SSH authentication failed for session %d: %s", session_id,
954  "No more authentication methods to try");
955 
956 leave:
957  g_free (password);
958  g_free (privkeystr);
959  g_free (privkeypass);
960  retc = alloc_typed_cell (CONST_INT);
961  retc->x.i_val = retc_val;
962  return retc;
963 }

References alloc_typed_cell(), session_table_item_s::authmethods, session_table_item_s::authmethods_valid, CONST_INT, get_authmethods(), get_int_var_by_num(), get_str_var_by_name(), TC::i_val, nasl_ssh_set_login(), plug_get_kb(), struct_lex_ctxt::script_infos, session_table_item_s::session, session_table_item_s::session_id, session_table, session_table_item_s::user_set, session_table_item_s::verbose, verify_session_id(), and TC::x.

Here is the call graph for this function:
CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:93
plug_get_host_ip
struct in6_addr * plug_get_host_ip(struct script_infos *args)
Definition: plugutils.c:285
plug_get_kb
kb_t plug_get_kb(struct script_infos *args)
Definition: plugutils.c:627
TC::str_val
char * str_val
Definition: nasl_tree.h:112
nasl_get_function_name
const char * nasl_get_function_name()
Definition: nasl_debug.c:91
session_table_item_s::user_set
unsigned int user_set
Definition: nasl_ssh.c:111
openvas_get_socket_from_connection
int openvas_get_socket_from_connection(int fd)
Definition: network.c:367
session_table_item_s::channel
ssh_channel channel
Definition: nasl_ssh.c:106
lowest_socket
int lowest_socket
Definition: nasl_socket.c:220
FAKE_CELL
#define FAKE_CELL
Definition: nasl_tree.h:119
TC::x
union TC::@2 x
next_session_id
static int next_session_id(void)
Definition: nasl_ssh.c:136
get_str_var_by_name
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
session_table_item_s::session
ssh_session session
Definition: nasl_ssh.c:105
TC::size
int size
Definition: nasl_tree.h:109
DIM
#define DIM(v)
Definition: nasl_ssh.c:62
exec_ssh_cmd
static int exec_ssh_cmd(ssh_session session, char *cmd, int verbose, int compat_mode, int to_stdout, int to_stderr, GString *response, GString *compat_buf)
Execute an ssh command.
Definition: nasl_ssh.c:1188
get_int_var_by_name
long int get_int_var_by_name(lex_ctxt *, const char *, int)
Definition: nasl_var.c:1113
session_table_item_s::session_id
int session_id
Definition: nasl_ssh.c:104
session_table_item_s::authmethods_valid
unsigned int authmethods_valid
Definition: nasl_ssh.c:110
get_int_var_by_num
long int get_int_var_by_num(lex_ctxt *, int, int)
Definition: nasl_var.c:1106
nasl_get_plugin_filename
const char * nasl_get_plugin_filename()
Get the current launched plugin filename.
Definition: nasl_debug.c:52
struct_lex_ctxt::script_infos
struct script_infos * script_infos
Definition: nasl_lex_ctxt.h:41
verify_session_id
static int verify_session_id(int session_id, const char *funcname, int *r_slot, lex_ctxt *lexic)
Definition: nasl_ssh.c:430
TC
Definition: nasl_tree.h:104
do_nasl_ssh_disconnect
static void do_nasl_ssh_disconnect(int tbl_slot)
Definition: nasl_ssh.c:458
session_table_item_s::authmethods
int authmethods
Definition: nasl_ssh.c:108
CONST_INT
@ CONST_INT
Definition: nasl_tree.h:90
read_ssh_nonblocking
static int read_ssh_nonblocking(ssh_channel channel, GString *response)
read from an ssh channel without blocking.
Definition: nasl_ssh.c:1710
g_string_comma_str
static void g_string_comma_str(GString *gstr, const char *str)
Definition: nasl_ssh.c:124
session_table
static struct session_table_item_s session_table[MAX_SSH_SESSIONS]
Definition: nasl_ssh.c:117
get_ssh_port
static unsigned short get_ssh_port(lex_ctxt *lexic)
Definition: nasl_ssh.c:169
session_table_item_s::verbose
unsigned int verbose
Definition: nasl_ssh.c:113
session_table_item_s::sock
int sock
Definition: nasl_ssh.c:107
nasl_ssh_set_login
tree_cell * nasl_ssh_set_login(lex_ctxt *lexic)
Set the login name for the authentication.
Definition: nasl_ssh.c:706
request_ssh_shell
static int request_ssh_shell(ssh_channel channel)
Open a shell on an ssh channel.
Definition: nasl_ssh.c:1627
get_authmethods
static int get_authmethods(int tbl_slot)
Definition: nasl_ssh.c:618
alloc_typed_cell
tree_cell * alloc_typed_cell(int typ)
Definition: nasl_tree.c:40
TC::i_val
long int i_val
Definition: nasl_tree.h:113