37 #include <arpa/inet.h> 38 #include <netinet/in.h> 39 #include <sys/select.h> 40 #include <sys/socket.h> 42 #include <sys/types.h> 51 #include <glib/gstdio.h> 59 #include "../misc/plugutils.h" 60 #include "../base/kb.h" 62 #include "../misc/network.h" 63 #include "../misc/openvas_logging.h" 64 #include "../misc/prefs.h" 65 #include "../misc/openvas_ssh.h" 71 # define DIM(v) (sizeof(v)/sizeof((v)[0])) 72 # define DIMof(type,member) DIM(((type *)0)->member) 77 # error Oops, libssh ABI changed 122 #define MAX_SSH_SESSIONS 10 127 static int nasl_ssh_close_hook (
int);
130 g_string_comma_str (GString *gstr,
const char *str)
133 g_string_append (gstr,
",");
134 g_string_append (gstr, str);
141 #if LIBSSH_VERSION_INT < SSH_VERSION_INT (0, 6, 0) 144 ssh_private_key privkey;
146 ssh_string pubkey_string;
148 typedef struct my_ssh_key_s *my_ssh_key;
152 my_ssh_key_free (my_ssh_key key)
156 privatekey_free (key->privkey);
157 ssh_string_free (key->pubkey_string);
163 remove_and_free_temp_key_file (
char *filename)
167 if (g_remove (filename) && errno != ENOENT)
169 filename, strerror (errno));
170 p = strrchr (filename,
'/');
173 if (g_rmdir (filename))
175 filename, strerror (errno));
196 my_ssh_pki_import_privkey_base64(ssh_session session,
199 const char *passphrase,
204 ssh_private_key ssh_privkey;
205 ssh_public_key ssh_pubkey;
206 gchar *privkey_filename;
207 char key_dir[] =
"/tmp/openvas_key_XXXXXX";
210 char *pkcs8_buffer = NULL;
213 if (!g_mkdtemp_full (key_dir, S_IRUSR|S_IWUSR|S_IXUSR))
216 return SSH_AUTH_ERROR;
219 privkey_filename = g_strdup_printf (
"%s/key", key_dir);
223 g_file_set_contents (privkey_filename, b64_key, strlen (b64_key), &error);
228 g_error_free (error);
229 remove_and_free_temp_key_file (privkey_filename);
230 g_free (pkcs8_buffer);
231 return SSH_AUTH_ERROR;
236 g_chmod (privkey_filename, S_IRUSR | S_IWUSR);
238 ssh_privkey = privatekey_from_file (session, privkey_filename, 0, passphrase);
239 if (!ssh_privkey && verbose)
241 privkey_filename, ssh_get_error (session));
242 if (!ssh_privkey && !pkcs8_buffer)
250 b64_key = pkcs8_buffer;
251 g_remove (privkey_filename);
257 g_free (pkcs8_buffer);
263 remove_and_free_temp_key_file (privkey_filename);
264 privkey_filename = NULL;
266 return SSH_AUTH_ERROR;
269 pkey = g_try_malloc0 (
sizeof *pkey);
272 privatekey_free (ssh_privkey);
274 return SSH_AUTH_ERROR;
276 pkey->privkey = ssh_privkey;
277 pkey->type = ssh_privatekey_type (ssh_privkey);
278 if (pkey->type == SSH_KEYTYPE_UNKNOWN)
280 my_ssh_key_free (pkey);
283 return SSH_AUTH_ERROR;
287 ssh_pubkey = publickey_from_privatekey (ssh_privkey);
290 my_ssh_key_free (pkey);
294 return SSH_AUTH_ERROR;
296 pkey->pubkey_string = publickey_to_string (ssh_pubkey);
297 publickey_free (ssh_pubkey);
298 if (!pkey->pubkey_string)
300 my_ssh_key_free (pkey);
303 return SSH_AUTH_ERROR;
307 return SSH_AUTH_SUCCESS;
338 my_ssh_userauth_try_publickey (ssh_session session,
339 const char *username,
340 const my_ssh_key key)
346 rc = ssh_userauth_offer_pubkey (session, NULL, key->type, key->pubkey_string);
373 my_ssh_userauth_publickey(ssh_session session,
374 const char *username,
375 const my_ssh_key key)
381 rc = ssh_userauth_pubkey (session, NULL, key->pubkey_string, key->privkey);
393 next_session_id (
void)
395 static int initialized;
396 static int last = 9000;
416 for (i=0; i <
DIM (session_table); i++)
417 if (session_table[i].session_id == last)
427 static unsigned short 436 if (value && (port = (
unsigned short)strtoul (value, NULL, 10)) > 0)
442 port = GPOINTER_TO_SIZE (port_str);
444 if (type ==
KB_TYPE_INT && (port = GPOINTER_TO_SIZE (port_str)) > 0)
490 const char *hostname, *key_type, *csciphers, *scciphers;
495 int forced_sock = -1;
504 port = get_ssh_port (lexic);
517 session = ssh_new ();
524 if ((s = getenv (
"OPENVAS_LIBSSH_DEBUG")))
529 int intval = atoi (s);
531 ssh_options_set (session, SSH_OPTIONS_LOG_VERBOSITY, &intval);
535 if (ssh_options_set (session, SSH_OPTIONS_HOST, hostname))
538 hostname, ssh_get_error (session));
544 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0) 545 if (key_type && ssh_options_set (session, SSH_OPTIONS_HOSTKEYS, key_type))
548 key_type, ssh_get_error (session));
562 if (csciphers && ssh_options_set (session, SSH_OPTIONS_CIPHERS_C_S, csciphers))
565 csciphers, ssh_get_error (session));
570 if (scciphers && ssh_options_set (session, SSH_OPTIONS_CIPHERS_S_C, scciphers))
573 scciphers, ssh_get_error (session));
580 unsigned int my_port = port;
582 if (ssh_options_set (session, SSH_OPTIONS_PORT, &my_port))
585 hostname, port, ssh_get_error (session));
596 hostname, my_fd, sock);
597 if (ssh_options_set (session, SSH_OPTIONS_FD, &my_fd))
600 (
"Failed to set SSH fd for '%s' to %d (NASL sock=%d): %s\n",
601 hostname, my_fd, sock, ssh_get_error (session));
610 for (tbl_slot=0; tbl_slot <
DIM (session_table); tbl_slot++)
611 if (!session_table[tbl_slot].session_id)
613 if (!(tbl_slot <
DIM (session_table)))
622 session_table[tbl_slot].
session = session;
624 session_table[tbl_slot].
user_set = 0;
625 session_table[tbl_slot].
verbose = verbose;
630 hostname, port, sock);
631 if (ssh_connect (session))
635 " (port %d, sock %d, f=%d): %s\n", hostname, port,
636 sock, forced_sock, ssh_get_error (session));
637 if (forced_sock != -1)
643 session_table[tbl_slot].
session_id = next_session_id ();
644 session_table[tbl_slot].
sock = forced_sock;
657 session_table[tbl_slot].
session_id = next_session_id ();
658 session_table[tbl_slot].
sock =
659 forced_sock != -1? forced_sock : ssh_get_fd (session);
674 verify_session_id (
int session_id,
const char *funcname,
681 nasl_perror (lexic,
"Invalid SSH session id %d passed to %s\n",
682 session_id, funcname);
685 for (tbl_slot=0; tbl_slot <
DIM (session_table); tbl_slot++)
686 if (session_table[tbl_slot].session_id == session_id)
688 if (!(tbl_slot <
DIM (session_table)))
691 nasl_perror (lexic,
"Bad SSH session id %d passed to %s\n",
692 session_id, funcname);
703 do_nasl_ssh_disconnect (
int tbl_slot)
705 if (session_table[tbl_slot].channel)
706 ssh_channel_free (session_table[tbl_slot].channel);
707 ssh_disconnect (session_table[tbl_slot].session);
708 ssh_free (session_table[tbl_slot].session);
710 session_table[tbl_slot].
session = NULL;
711 session_table[tbl_slot].
channel = NULL;
712 session_table[tbl_slot].
sock = -1;
743 if (!verify_session_id (session_id, NULL, &tbl_slot, lexic))
745 do_nasl_ssh_disconnect (tbl_slot);
765 nasl_ssh_close_hook (
int sock)
767 int tbl_slot, session_id;
773 for (tbl_slot=0; tbl_slot <
DIM (session_table); tbl_slot++)
775 if (session_table[tbl_slot].sock == sock
776 && session_table[tbl_slot].session_id) {
777 session_id = session_table[tbl_slot].
session_id;
783 do_nasl_ssh_disconnect (tbl_slot);
804 int tbl_slot, sock, session_id;
811 for (tbl_slot=0; tbl_slot <
DIM (session_table); tbl_slot++)
812 if (session_table[tbl_slot].sock == sock
813 && session_table[tbl_slot].session_id) {
814 session_id = session_table[tbl_slot].
session_id;
820 retc->
x.
i_val = session_id;
846 int tbl_slot, sock, session_id;
850 if (!verify_session_id (session_id,
"ssh_get_sock", &tbl_slot, lexic))
853 sock = session_table[tbl_slot].
sock;
864 get_authmethods (
int tbl_slot)
872 session = session_table[tbl_slot].
session;
873 verbose = session_table[tbl_slot].
verbose;
875 rc = ssh_userauth_none (session, NULL);
876 if (rc == SSH_AUTH_SUCCESS)
879 "should not happen; very old server?\n");
884 else if (rc == SSH_AUTH_DENIED)
886 methods = ssh_userauth_list (session, NULL);
892 (
"SSH server did not return a list of authentication methods" 894 methods = (SSH_AUTH_METHOD_NONE
895 | SSH_AUTH_METHOD_PASSWORD
896 | SSH_AUTH_METHOD_PUBLICKEY
897 | SSH_AUTH_METHOD_HOSTBASED
898 | SSH_AUTH_METHOD_INTERACTIVE);
903 fputs (
"SSH available authentication methods:", stderr);
904 if ((methods & SSH_AUTH_METHOD_NONE))
905 fputs (
" none", stderr);
906 if ((methods & SSH_AUTH_METHOD_PASSWORD))
907 fputs (
" password", stderr);
908 if ((methods & SSH_AUTH_METHOD_PUBLICKEY))
909 fputs (
" publickey", stderr);
910 if ((methods & SSH_AUTH_METHOD_HOSTBASED))
911 fputs (
" hostbased", stderr);
912 if ((methods & SSH_AUTH_METHOD_INTERACTIVE))
913 fputs (
" keyboard-interactive", stderr);
914 fputs (
"\n", stderr);
958 int tbl_slot, session_id;
961 if (!verify_session_id (session_id,
"ssh_set_login", &tbl_slot, lexic))
963 if (!session_table[tbl_slot].user_set)
965 ssh_session session = session_table[tbl_slot].
session;
973 username = kb_item_get_str (
kb,
"Secret/SSH/login");
975 if (username && *username &&
976 ssh_options_set (session, SSH_OPTIONS_USER, username))
979 username, ssh_get_error (session));
983 session_table[tbl_slot].
user_set = 1;
1051 ssh_session session;
1052 const char *password = NULL;
1053 const char *privkeystr = NULL;
1054 const char *privkeypass = NULL;
1062 if (!verify_session_id (session_id,
"ssh_userauth", &tbl_slot, lexic))
1064 session = session_table[tbl_slot].
session;
1065 verbose = session_table[tbl_slot].
verbose;
1076 if (!password && !privkeystr && !privkeypass)
1078 password = kb_item_get_str (
kb,
"Secret/SSH/password");
1079 privkeystr = kb_item_get_str (
kb,
"Secret/SSH/privatekey");
1080 privkeypass = kb_item_get_str (
kb,
"Secret/SSH/passphrase");
1084 if (!session_table[tbl_slot].authmethods_valid)
1086 if (!get_authmethods (tbl_slot))
1100 if (password && (methods & SSH_AUTH_METHOD_PASSWORD))
1102 rc = ssh_userauth_password (session, NULL, password);
1103 if (rc == SSH_AUTH_SUCCESS)
1111 " %d: %s\n", session_id, ssh_get_error (session));
1115 if (password && (methods & SSH_AUTH_METHOD_INTERACTIVE))
1119 while ((rc = ssh_userauth_kbdint (session, NULL, NULL)) == SSH_AUTH_INFO)
1124 int found_prompt = 0;
1128 s = ssh_userauth_kbdint_getname (session);
1131 s = ssh_userauth_kbdint_getinstruction (session);
1135 nprompt = ssh_userauth_kbdint_getnprompts (session);
1136 for (n=0; n < nprompt; n++)
1138 s = ssh_userauth_kbdint_getprompt (session, n, &echoflag);
1139 if (s && *s && verbose)
1141 s, echoflag ?
"" :
" [hide input]");
1142 if (s && *s && !echoflag && !found_prompt)
1145 rc = ssh_userauth_kbdint_setanswer (session, n, password);
1146 if (rc != SSH_AUTH_SUCCESS)
1150 (
"SSH keyboard-interactive authentication " 1151 "failed at prompt %d for session %d: %s\n",
1152 n, session_id, ssh_get_error (session));
1158 if (rc == SSH_AUTH_SUCCESS)
1166 (
"SSH keyboard-interactive authentication failed for session %d" 1167 ": %s\n", session_id, ssh_get_error (session));
1172 if (privkeystr && *privkeystr && (methods & SSH_AUTH_METHOD_PUBLICKEY))
1174 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0) 1177 if (ssh_pki_import_privkey_base64 (privkeystr, privkeypass, NULL, NULL,
1182 (
"SSH public key authentication failed for " 1183 "session %d: %s\n", session_id,
"Error converting provided key");
1185 else if (ssh_userauth_try_publickey (session, NULL, key)
1186 != SSH_AUTH_SUCCESS)
1190 (
"SSH public key authentication failed for " 1191 "session %d: %s\n", session_id,
"Server does not want our key");
1193 else if (ssh_userauth_publickey (session, NULL, key) == SSH_AUTH_SUCCESS)
1203 my_ssh_key key = NULL;
1206 if (my_ssh_pki_import_privkey_base64 (session, verbose,
1207 privkeystr, privkeypass,
1212 (
"SSH public key authentication failed for " 1213 "session %d: %s\n", session_id,
"Error converting provided key");
1215 else if (my_ssh_userauth_try_publickey (session, NULL, key)
1216 != SSH_AUTH_SUCCESS)
1220 (
"SSH public key authentication failed for " 1221 "session %d: %s\n", session_id,
"Server does not want our key");
1223 else if (my_ssh_userauth_publickey (session, NULL, key)
1224 == SSH_AUTH_SUCCESS)
1227 my_ssh_key_free (key);
1230 my_ssh_key_free (key);
1237 session_id,
"No more authentication methods to try");
1243 retc->
x.
i_val = retc_val;
1279 ssh_session session;
1281 const char *s = NULL;
1286 if (!verify_session_id (session_id,
"ssh_login_interactive",
1289 session = session_table[tbl_slot].
session;
1290 verbose = session_table[tbl_slot].
verbose;
1298 if (!session_table[tbl_slot].authmethods_valid)
1300 if (!get_authmethods (tbl_slot))
1308 if (methods & SSH_AUTH_METHOD_INTERACTIVE)
1312 while ((rc = ssh_userauth_kbdint (session, NULL, NULL)) == SSH_AUTH_INFO)
1316 int found_prompt = 0;
1320 s = ssh_userauth_kbdint_getname (session);
1322 g_message (
"SSH kbdint name='%s'", s);
1323 s = ssh_userauth_kbdint_getinstruction (session);
1325 g_message (
"SSH kbdint instruction='%s'", s);
1328 nprompt = ssh_userauth_kbdint_getnprompts (session);
1329 for (n=0; n < nprompt; n++)
1331 s = ssh_userauth_kbdint_getprompt (session, n, &echoflag);
1332 if (s && *s && verbose)
1333 g_message (
"SSH kbdint prompt='%s'%s",
1334 s, echoflag ?
"" :
" [hide input]");
1335 if (s && *s && !echoflag && !found_prompt)
1341 (
"SSH keyboard-interactive authentication failed for session %d" 1342 ": %s", session_id, ssh_get_error (session));
1354 retc->
size = strlen (s);
1391 ssh_session session;
1392 const char *password = NULL;
1398 if (!verify_session_id (session_id,
"ssh_login_interactive_pass",
1401 session = session_table[tbl_slot].
session;
1402 verbose = session_table[tbl_slot].
verbose;
1408 rc = ssh_userauth_kbdint_setanswer (session, 0, password);
1413 g_message (
"SSH keyboard-interactive authentication " 1414 "failed at prompt %d for session %d: %s",
1415 0, session_id, ssh_get_error (session));
1423 while ((rc = ssh_userauth_kbdint (session, NULL, NULL)) == SSH_AUTH_INFO)
1425 ssh_userauth_kbdint_getnprompts (session);
1427 if (rc == SSH_AUTH_SUCCESS)
1432 if (rc != SSH_AUTH_SUCCESS)
1444 retc->
x.
i_val = retc_val;
1451 exec_ssh_cmd_alarm (
int signal)
1472 exec_ssh_cmd (ssh_session session,
char *cmd,
int verbose,
int compat_mode,
1473 int to_stdout,
int to_stderr, GString *response,
1474 GString *compat_buf)
1477 ssh_channel channel;
1480 signal (SIGALRM, exec_ssh_cmd_alarm);
1482 if ((channel = ssh_channel_new (session)) == NULL)
1485 ssh_get_error (session));
1489 if (ssh_channel_open_session (channel))
1494 ssh_get_error (session));
1495 ssh_channel_free (channel);
1499 if (ssh_channel_request_pty (channel) && verbose)
1500 g_message (
"ssh_channel_request_pty failed: %s", ssh_get_error (session));
1502 if (ssh_channel_request_exec (channel, cmd))
1507 cmd, ssh_get_error (session));
1508 ssh_channel_free (channel);
1512 signal (SIGALRM, _exit);
1514 while (ssh_channel_is_open (channel) && !ssh_channel_is_eof (channel)
1519 memset (buffer,
'\0',
sizeof (buffer));
1520 if ((rc = ssh_channel_read_nonblocking
1521 (channel, buffer,
sizeof (buffer), 1)) > 0)
1524 g_string_append_len (response, buffer, rc);
1526 g_string_append_len (compat_buf, buffer, rc);
1528 if (rc == SSH_ERROR)
1530 if ((rc = ssh_channel_read_nonblocking
1531 (channel, buffer,
sizeof (buffer), 0)) > 0)
1535 g_string_append_len (response, buffer, rc);
1537 if (rc == SSH_ERROR)
1547 ssh_channel_free (channel);
1607 ssh_session session;
1611 GString *response, *compat_buf;
1615 int to_stdout, to_stderr, compat_mode, compat_buf_inuse;
1618 if (!verify_session_id (session_id,
"ssh_request_exec", &tbl_slot, lexic))
1620 session = session_table[tbl_slot].
session;
1622 verbose = session_table[tbl_slot].
verbose;
1634 if (to_stdout == -1 && to_stderr == -1)
1639 else if (to_stdout == 0 && to_stderr == 0)
1652 memset (&compat_buf,
'\0',
sizeof (compat_buf));
1656 response = g_string_sized_new (512);
1659 compat_buf = g_string_sized_new (512);
1660 compat_buf_inuse = 1;
1663 compat_buf_inuse = 0;
1665 rc = exec_ssh_cmd (session, cmd, verbose, compat_mode, to_stdout, to_stderr,
1666 response, compat_buf);
1667 if (rc == SSH_ERROR)
1669 if (compat_buf_inuse)
1670 g_string_free (compat_buf, TRUE);
1671 g_string_free (response, TRUE);
1676 if (compat_buf_inuse)
1678 len = compat_buf->len;
1679 p = g_string_free (compat_buf, FALSE);
1682 g_string_append_len (response, p, len);
1688 len = response->len;
1689 p = g_string_free (response, FALSE);
1725 int tbl_slot, session_id;
1726 ssh_session session;
1731 if (!verify_session_id (session_id,
"ssh_get_issue_banner", &tbl_slot, lexic))
1733 session = session_table[tbl_slot].
session;
1739 if (!session_table[tbl_slot].authmethods_valid)
1740 get_authmethods (tbl_slot);
1742 banner = ssh_get_issue_banner (session);
1747 retc->
x.
str_val = g_strdup (banner);
1748 retc->
size = strlen (banner);
1749 ssh_string_free_char (banner);
1754 #if LIBSSH_VERSION_INT >= SSH_VERSION_INT (0, 6, 0) 1776 int tbl_slot, session_id;
1777 ssh_session session;
1782 if (!verify_session_id (session_id,
"ssh_get_server_banner",
1785 session = session_table[tbl_slot].
session;
1788 banner = (
char*) ssh_get_serverbanner (session);
1793 retc->
x.
str_val = g_strdup (banner);
1794 retc->
size = strlen (banner);
1821 int tbl_slot, session_id;
1822 ssh_session session;
1827 if (!verify_session_id (session_id,
"ssh_get_host_key", &tbl_slot, lexic))
1829 session = session_table[tbl_slot].
session;
1831 sstring = ssh_get_pubkey (session);
1836 retc->
x.
str_val = ssh_string_to_char (sstring);
1837 retc->
size = ssh_string_len (sstring);
1838 ssh_string_free (sstring);
1865 int tbl_slot, methods, session_id;
1871 if (!verify_session_id (session_id,
"ssh_get_auth_methods", &tbl_slot, lexic))
1876 if (!session_table[tbl_slot].authmethods_valid)
1877 get_authmethods (tbl_slot);
1881 buffer = g_string_sized_new (128);
1882 if ((methods & SSH_AUTH_METHOD_NONE))
1883 g_string_comma_str (buffer,
"none");
1884 if ((methods & SSH_AUTH_METHOD_PASSWORD))
1885 g_string_comma_str (buffer,
"password");
1886 if ((methods & SSH_AUTH_METHOD_PUBLICKEY))
1887 g_string_comma_str (buffer,
"publickey");
1888 if ((methods & SSH_AUTH_METHOD_HOSTBASED))
1889 g_string_comma_str (buffer,
"hostbased");
1890 if ((methods & SSH_AUTH_METHOD_INTERACTIVE))
1891 g_string_comma_str (buffer,
"keyboard-interactive");
1892 g_string_append_c (buffer, 0x00);
1893 p = g_string_free (buffer, FALSE);
1899 retc->
size = strlen (p);
1904 request_ssh_shell_alarm (
int signal)
1917 request_ssh_shell (ssh_channel channel)
1922 signal (SIGALRM, request_ssh_shell_alarm);
1924 if (ssh_channel_request_pty (channel))
1926 if (ssh_channel_change_pty_size (channel, 80, 24))
1928 if (ssh_channel_request_shell (channel))
1931 signal (SIGALRM, _exit);
1953 int tbl_slot, session_id;
1954 ssh_channel channel;
1955 ssh_session session;
1959 if (!verify_session_id (session_id,
"ssh_shell_open", &tbl_slot, lexic))
1961 session = session_table[tbl_slot].
session;
1962 channel = ssh_channel_new (session);
1965 if (ssh_channel_open_session (channel))
1968 ssh_get_error (session));
1969 ssh_channel_free (channel);
1973 if (request_ssh_shell (channel))
1976 ssh_channel_free (channel);
1979 if (session_table[tbl_slot].channel)
1980 ssh_channel_free (session_table[tbl_slot].channel);
1981 session_table[tbl_slot].
channel = channel;
1997 read_ssh_nonblocking (ssh_channel channel, GString *response)
2002 if (!ssh_channel_is_open (channel) || ssh_channel_is_eof (channel))
2005 if ((rc = ssh_channel_read_nonblocking
2006 (channel, buffer,
sizeof (buffer), 1)) > 0)
2007 g_string_append_len (response, buffer, rc);
2008 if (rc == SSH_ERROR)
2010 if ((rc = ssh_channel_read_nonblocking
2011 (channel, buffer,
sizeof (buffer), 0)) > 0)
2012 g_string_append_len (response, buffer, rc);
2013 if (rc == SSH_ERROR)
2035 int tbl_slot, session_id;
2036 ssh_channel channel;
2041 if (!verify_session_id (session_id,
"ssh_shell_read", &tbl_slot, lexic))
2043 channel = session_table[tbl_slot].
channel;
2045 response = g_string_new (NULL);
2046 if (read_ssh_nonblocking (channel, response))
2049 retc->
size = response->len;
2050 retc->
x.
str_val = g_string_free (response, FALSE);
2072 int tbl_slot, rc = -1, len, session_id;
2073 ssh_channel channel;
2078 if (!verify_session_id (session_id,
"ssh_shell_write", &tbl_slot, lexic))
2080 if (!(channel = session_table[tbl_slot].channel))
2093 if (ssh_channel_write (channel, cmd, len) != len)
2096 ssh_get_error (session_table[tbl_slot].session));
2120 int tbl_slot, session_id;
2123 if (!verify_session_id (session_id,
"ssh_shell_close", &tbl_slot, lexic))
2125 if (session_table[tbl_slot].channel)
2127 ssh_channel_free (session_table[tbl_slot].channel);
2128 session_table[tbl_slot].
channel = NULL;
tree_cell * nasl_ssh_get_server_banner(lex_ctxt *lexic)
Get the server banner.
tree_cell * nasl_ssh_shell_open(lex_ctxt *lexic)
Request an ssh shell.
tree_cell * nasl_ssh_login_interactive(lex_ctxt *lexic)
Authenticate a user on an ssh connection.
Protos and data structures for SSH functions used by NASL scripts.
tree_cell * nasl_ssh_connect(lex_ctxt *lexic)
Connect to the target host via TCP and setup an ssh connection.
void * plug_get_key(struct arglist *args, char *name, int *type, int single)
tree_cell * nasl_ssh_shell_close(lex_ctxt *lexic)
Close an ssh shell.
int openvas_get_socket_from_connection(int fd)
void log_legacy_write(const char *format,...)
Legacy function to write a log message.
long int get_int_local_var_by_name(lex_ctxt *, const char *, int)
const gchar * prefs_get(const gchar *key)
Get a string preference value via a key.
char * get_str_local_var_by_name(lex_ctxt *, const char *)
tree_cell * nasl_ssh_request_exec(lex_ctxt *lexic)
Run a command via ssh.
tree_cell * alloc_typed_cell(int typ)
tree_cell * nasl_ssh_userauth(lex_ctxt *lexic)
Authenticate a user on an ssh connection.
void add_close_stream_connection_hook(int(*fnc)(int fd))
Register a hook function for close_stream_connection.
tree_cell * nasl_ssh_get_host_key(lex_ctxt *lexic)
Get the host key.
kb_t plug_get_kb(struct arglist *args)
tree_cell * nasl_ssh_login_interactive_pass(lex_ctxt *lexic)
Authenticate a user on an ssh connection.
Top-level KB. This is to be inherited by KB implementations.
tree_cell * nasl_ssh_shell_write(lex_ctxt *lexic)
Write string to ssh shell.
tree_cell * nasl_ssh_get_issue_banner(lex_ctxt *lexic)
Get the issue banner.
char * openvas_ssh_pkcs8_decrypt(const char *pkcs8_key, const char *passphrase)
Decrypts a base64 encrypted ssh private key.
tree_cell * nasl_ssh_session_id_from_sock(lex_ctxt *lexic)
Given a socket, return the corresponding session id.
unsigned int authmethods_valid
tree_cell * nasl_ssh_set_login(lex_ctxt *lexic)
Set the login name for the authentication.
long int get_int_var_by_num(lex_ctxt *, int, int)
void nasl_perror(lex_ctxt *lexic, char *msg,...)
tree_cell * nasl_ssh_get_auth_methods(lex_ctxt *lexic)
Get the list of authmethods.
tree_cell * nasl_ssh_get_sock(lex_ctxt *lexic)
Given a session id, return the corresponding socket.
tree_cell * nasl_ssh_disconnect(lex_ctxt *lexic)
Disconnect an ssh connection.
struct arglist * script_infos
const char * plug_get_hostname(struct arglist *desc)
tree_cell * nasl_ssh_shell_read(lex_ctxt *lexic)
Read the output of an ssh shell.