OpenVAS Scanner  7.0.1~git
nasl_ssh.c
Go to the documentation of this file.
1 /* Portions Copyright (C) 2011-2019 Greenbone Networks GmbH
2  *
3  * SPDX-License-Identifier: GPL-2.0-or-later
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
29 #include "nasl_ssh.h"
30 
31 #include "../misc/network.h" /* for openvas_get_socket_from_connection */
32 #include "../misc/plugutils.h"
33 #include "exec.h"
34 #include "nasl_debug.h"
35 #include "nasl_func.h"
36 #include "nasl_global_ctxt.h"
37 #include "nasl_lex_ctxt.h"
38 #include "nasl_tree.h"
39 #include "nasl_var.h"
40 
41 #include <arpa/inet.h>
42 #include <ctype.h>
43 #include <errno.h>
44 #include <fcntl.h>
45 #include <glib.h>
46 #include <glib/gstdio.h>
47 #include <gvm/base/logging.h>
48 #include <gvm/base/networking.h>
49 #include <gvm/base/prefs.h> /* for prefs_get() */
50 #include <gvm/util/kb.h>
51 #include <netinet/in.h>
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <sys/select.h>
56 #include <sys/socket.h>
57 #include <sys/time.h>
58 #include <sys/types.h>
59 #include <unistd.h>
60 
61 #ifndef DIM
62 #define DIM(v) (sizeof (v) / sizeof ((v)[0]))
63 #define DIMof(type, member) DIM (((type *) 0)->member)
64 #endif
65 
66 #if SSH_OK != 0
67 #error Oops, libssh ABI changed
68 #endif
69 
70 #undef G_LOG_DOMAIN
71 
74 #define G_LOG_DOMAIN "lib nasl"
75 
76 /* This object is used to keep track of libssh contexts. Because they
77  are pointers they can't be mapped easily to the NASL type system.
78  We would need to define a new type featuring a callback which would
79  be called when that variable will be freed. This is not easy and
80  has several implications. A clean solution requires a decent
81  garbage collector system with an interface to flange arbitrary C
82  subsystems to it. After all we would end up with a complete VM
83  and FFI. We don't want to do that now.
84 
85  Our solution is to track those contexts here and clean up any left
86  over context at the end of a script run. We could use undocumented
87  "on_exit" feature but that one is not well implemented; thus we use
88  explicit code in the interpreter for the cleanup. The scripts are
89  expected to close the sessions, but as long as they don't open too
90  many of them, the system will take care of it at script termination
91  time.
92 
93  We associate each context with a session id, which is a global
94  counter of this process. The simpler version of using slot numbers
95  won't allow for better consistency checks. A session id of 0 marks
96  an unused table entry.
97 
98  Note that we can't reuse a session for another connection. To use a
99  session is always an active or meanwhile broken connection to the
100  server.
101  */
103 {
105  ssh_session session;
106  ssh_channel channel;
107  int sock; /* The associated socket. */
108  int authmethods; /* Bit fields with available
109  authentication methods. */
110  unsigned int authmethods_valid : 1; /* Indicating that methods is valid. */
111  unsigned int user_set : 1; /* Set if a user has been set for
112  the session. */
113  unsigned int verbose : 1; /* Verbose diagnostics. */
114 };
115 
116 #define MAX_SSH_SESSIONS 10
118 
119 /* Local prototypes. */
120 static int
121 nasl_ssh_close_hook (int);
122 
123 static void
124 g_string_comma_str (GString *gstr, const char *str)
125 {
126  if (gstr->len)
127  g_string_append (gstr, ",");
128  g_string_append (gstr, str);
129 }
130 
131 /* Return the next session id. Note that the first session ID we will
132  hand out is an arbitrary high number, this is only to help
133  debugging. This function is also used to setup a hook to the
134  network layer. */
135 static int
137 {
138  static int initialized;
139  static int last = 9000;
140  unsigned int i;
141 
142  if (!initialized)
143  {
145  initialized = 1;
146  }
147 
148 again:
149  last++;
150  /* Because we don't have an unsigned type, it is better to avoid
151  negative values. Thus if LAST turns negative we wrap around to
152  1; this also avoids the verboten zero. */
153  if (last <= 0)
154  last = 1;
155  /* Now it may happen that after wrapping there is still a session id
156  with that new value in use. We can't allow that and check for
157  it. */
158  for (i = 0; i < DIM (session_table); i++)
159  if (session_table[i].session_id == last)
160  goto again;
161 
162  return last;
163 }
164 
165 /* Return the port for an SSH connection. It first looks up the port
166  in the preferences, then falls back to the KB, and finally resorts
167  to the standard port. */
168 static unsigned short
170 {
171  const char *value;
172  int type = KB_TYPE_INT;
173  unsigned short port, *port_aux = NULL;
174 
175  value = prefs_get ("auth_port_ssh");
176  if (value && (port = (unsigned short) strtoul (value, NULL, 10)) > 0)
177  return port;
178 
179  port_aux = (unsigned short *) plug_get_key (lexic->script_infos,
180  "Services/ssh", &type, NULL, 0);
181 
182  if (port_aux)
183  {
184  port = *port_aux;
185  g_free (port_aux);
186  if (type == KB_TYPE_INT && port > 0)
187  return port;
188  }
189 
190  return 22;
191 }
192 
193 extern int lowest_socket;
194 
234 tree_cell *
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 }
425 
426 /* Helper function to find and validate the session id. On error 0 is
427  returned, on success the session id and in this case the slot number
428  from the table is stored at R_SLOT. */
429 static int
430 verify_session_id (int session_id, const char *funcname, int *r_slot,
431  lex_ctxt *lexic)
432 {
433  unsigned int tbl_slot;
434  if (session_id <= 0)
435  {
436  if (funcname)
437  nasl_perror (lexic, "Invalid SSH session id %d passed to %s",
438  session_id, funcname);
439  return 0;
440  }
441  for (tbl_slot = 0; tbl_slot < DIM (session_table); tbl_slot++)
442  if (session_table[tbl_slot].session_id == session_id)
443  break;
444  if (!(tbl_slot < DIM (session_table)))
445  {
446  if (funcname)
447  nasl_perror (lexic, "Bad SSH session id %d passed to %s", session_id,
448  funcname);
449  return 0;
450  }
451 
452  *r_slot = tbl_slot;
453  return session_id;
454 }
455 
456 /* Helper for nasl_ssh_disconnect et al. */
457 static void
459 {
460  if (session_table[tbl_slot].channel)
461  ssh_channel_free (session_table[tbl_slot].channel);
462  ssh_disconnect (session_table[tbl_slot].session);
463  ssh_free (session_table[tbl_slot].session);
464  session_table[tbl_slot].session_id = 0;
465  session_table[tbl_slot].session = NULL;
466  session_table[tbl_slot].channel = NULL;
467  session_table[tbl_slot].sock = -1;
468 }
469 
490 tree_cell *
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 }
502 
517 static int
519 {
520  int session_id;
521  unsigned int tbl_slot;
522 
523  if (sock == -1)
524  return -1;
525 
526  session_id = 0;
527  for (tbl_slot = 0; tbl_slot < DIM (session_table); tbl_slot++)
528  {
529  if (session_table[tbl_slot].sock == sock
530  && session_table[tbl_slot].session_id)
531  {
532  session_id = session_table[tbl_slot].session_id;
533  break;
534  }
535  }
536  if (!session_id || tbl_slot >= DIM (session_table))
537  return -1;
538  do_nasl_ssh_disconnect (tbl_slot);
539  return 0;
540 }
541 
555 tree_cell *
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 }
579 
598 tree_cell *
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 }
614 
615 /* Get the list of supported authentication schemes. Returns 0 if no
616  authentication is required; otherwise non-zero. */
617 static int
618 get_authmethods (int tbl_slot)
619 {
620  int rc;
621  int retc_val = -1;
622  ssh_session session;
623  int verbose;
624  int methods;
625 
626  session = session_table[tbl_slot].session;
627  verbose = session_table[tbl_slot].verbose;
628 
629  rc = ssh_userauth_none (session, NULL);
630  if (rc == SSH_AUTH_SUCCESS)
631  {
632  g_message ("SSH authentication succeeded using the none method - "
633  "should not happen; very old server?");
634  retc_val = 0;
635  methods = 0;
636  goto leave;
637  }
638  else if (rc == SSH_AUTH_DENIED)
639  {
640  methods = ssh_userauth_list (session, NULL);
641  }
642  else
643  {
644  if (verbose)
645  g_message ("SSH server did not return a list of authentication methods"
646  " - trying all");
647  methods = (SSH_AUTH_METHOD_NONE | SSH_AUTH_METHOD_PASSWORD
648  | SSH_AUTH_METHOD_PUBLICKEY | SSH_AUTH_METHOD_HOSTBASED
649  | SSH_AUTH_METHOD_INTERACTIVE);
650  }
651 
652  if (verbose)
653  {
654  fputs ("SSH available authentication methods:", stderr);
655  if ((methods & SSH_AUTH_METHOD_NONE))
656  fputs (" none", stderr);
657  if ((methods & SSH_AUTH_METHOD_PASSWORD))
658  fputs (" password", stderr);
659  if ((methods & SSH_AUTH_METHOD_PUBLICKEY))
660  fputs (" publickey", stderr);
661  if ((methods & SSH_AUTH_METHOD_HOSTBASED))
662  fputs (" hostbased", stderr);
663  if ((methods & SSH_AUTH_METHOD_INTERACTIVE))
664  fputs (" keyboard-interactive", stderr);
665  fputs ("\n", stderr);
666  }
667 
668 leave:
669  session_table[tbl_slot].authmethods = methods;
670  session_table[tbl_slot].authmethods_valid = 1;
671 
672  return retc_val;
673 }
674 
705 tree_cell *
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 }
741 
799 tree_cell *
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 }
964 
990 tree_cell *
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 }
1075 
1102 tree_cell *
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 }
1164 
1165 static void
1167 {
1168  (void) signal;
1169  g_message ("exec_ssh_cmd: Timeout");
1170 }
1171 
1187 static int
1188 exec_ssh_cmd (ssh_session session, char *cmd, int verbose, int compat_mode,
1189  int to_stdout, int to_stderr, GString *response,
1190  GString *compat_buf)
1191 {
1192  int rc = 1;
1193  ssh_channel channel;
1194  char buffer[4096];
1195 
1196  /* Work-around for LibSSH calling poll() with an infinite timeout. */
1197  signal (SIGALRM, exec_ssh_cmd_alarm);
1198  alarm (30);
1199  if ((channel = ssh_channel_new (session)) == NULL)
1200  {
1201  g_message ("Function %s called from %s: ssh_channel_new failed: %s",
1203  ssh_get_error (session));
1204  return SSH_ERROR;
1205  }
1206 
1207  if (ssh_channel_open_session (channel))
1208  {
1209  /* FIXME: Handle SSH_AGAIN. */
1210  if (verbose)
1211  g_message ("ssh_channel_open_session failed: %s",
1212  ssh_get_error (session));
1213  ssh_channel_free (channel);
1214  return SSH_ERROR;
1215  }
1216 
1217  if (ssh_channel_request_pty (channel) && verbose)
1218  g_message ("ssh_channel_request_pty failed: %s", ssh_get_error (session));
1219 
1220  if (ssh_channel_request_exec (channel, cmd))
1221  {
1222  /* FIXME: Handle SSH_AGAIN. */
1223  if (verbose)
1224  g_message ("ssh_channel_request_exec failed for '%s': %s", cmd,
1225  ssh_get_error (session));
1226  ssh_channel_free (channel);
1227  return SSH_ERROR;
1228  }
1229  alarm (0);
1230  signal (SIGALRM, _exit);
1231  while (rc > 0)
1232  {
1233  if ((rc = ssh_channel_read_timeout (channel, buffer, sizeof (buffer), 1,
1234  15000))
1235  > 0)
1236  {
1237  if (to_stderr)
1238  g_string_append_len (response, buffer, rc);
1239  if (compat_mode)
1240  g_string_append_len (compat_buf, buffer, rc);
1241  }
1242  if (rc == SSH_ERROR)
1243  goto exec_err;
1244  }
1245  rc = 1;
1246  while (rc > 0)
1247  {
1248  if ((rc = ssh_channel_read_timeout (channel, buffer, sizeof (buffer), 0,
1249  15000))
1250  > 0)
1251  {
1252  if (to_stdout)
1253  g_string_append_len (response, buffer, rc);
1254  }
1255  if (rc == SSH_ERROR)
1256  goto exec_err;
1257  }
1258  rc = SSH_OK;
1259 
1260 exec_err:
1261  ssh_channel_free (channel);
1262  return rc;
1263 }
1264 
1316 tree_cell *
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 }
1417 
1437 tree_cell *
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 }
1467 
1486 tree_cell *
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 }
1509 
1527 tree_cell *
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 }
1550 
1571 tree_cell *
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 }
1611 
1612 static void
1614 {
1615  (void) signal;
1616  g_message ("request_ssh_shell: Timeout");
1617 }
1618 
1626 static int
1628 {
1629  assert (channel);
1630 
1631  /* Work-around for LibSSH calling poll() with an infinite timeout. */
1632  signal (SIGALRM, request_ssh_shell_alarm);
1633  alarm (30);
1634  if (ssh_channel_request_pty (channel))
1635  return -1;
1636  if (ssh_channel_change_pty_size (channel, 80, 24))
1637  return -1;
1638  if (ssh_channel_request_shell (channel))
1639  return -1;
1640  alarm (0);
1641  signal (SIGALRM, _exit);
1642 
1643  return 0;
1644 }
1645 
1660 tree_cell *
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 }
1700 
1709 static int
1710 read_ssh_nonblocking (ssh_channel channel, GString *response)
1711 {
1712  int rc;
1713  char buffer[4096];
1714 
1715  if (!ssh_channel_is_open (channel) || ssh_channel_is_eof (channel))
1716  return -1;
1717 
1718  if ((rc = ssh_channel_read_nonblocking (channel, buffer, sizeof (buffer), 1))
1719  > 0)
1720  g_string_append_len (response, buffer, rc);
1721  if (rc == SSH_ERROR)
1722  return -1;
1723  if ((rc = ssh_channel_read_nonblocking (channel, buffer, sizeof (buffer), 0))
1724  > 0)
1725  g_string_append_len (response, buffer, rc);
1726  if (rc == SSH_ERROR)
1727  return -1;
1728  return 0;
1729 }
1730 
1745 tree_cell *
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 }
1766 
1782 tree_cell *
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 }
1821 
1832 tree_cell *
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 }
nasl_ssh_close_hook
static int nasl_ssh_close_hook(int)
Hook to close a socket associated with an ssh connection.
Definition: nasl_ssh.c:518
CONST_DATA
@ CONST_DATA
Definition: nasl_tree.h:93
plug_get_key
void * plug_get_key(struct script_infos *args, char *name, int *type, size_t *len, int single)
Get values from a kb under the given key name.
Definition: plugutils.c:730
nasl_ssh_get_auth_methods
tree_cell * nasl_ssh_get_auth_methods(lex_ctxt *lexic)
Get the list of authmethods.
Definition: nasl_ssh.c:1572
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:658
nasl_ssh.h
Protos and data structures for SSH functions used by NASL scripts.
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
nasl_ssh_shell_close
tree_cell * nasl_ssh_shell_close(lex_ctxt *lexic)
Close an ssh shell.
Definition: nasl_ssh.c:1833
nasl_ssh_userauth
tree_cell * nasl_ssh_userauth(lex_ctxt *lexic)
Authenticate a user on an ssh connection.
Definition: nasl_ssh.c:800
nasl_ssh_request_exec
tree_cell * nasl_ssh_request_exec(lex_ctxt *lexic)
Run a command via ssh.
Definition: nasl_ssh.c:1317
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
nasl_ssh_get_server_banner
tree_cell * nasl_ssh_get_server_banner(lex_ctxt *lexic)
Get the server banner.
Definition: nasl_ssh.c:1487
TC::x
union TC::@2 x
next_session_id
static int next_session_id(void)
Definition: nasl_ssh.c:136
nasl_ssh_shell_write
tree_cell * nasl_ssh_shell_write(lex_ctxt *lexic)
Write string to ssh shell.
Definition: nasl_ssh.c:1783
nasl_ssh_shell_read
tree_cell * nasl_ssh_shell_read(lex_ctxt *lexic)
Read the output of an ssh shell.
Definition: nasl_ssh.c:1746
get_str_var_by_name
char * get_str_var_by_name(lex_ctxt *, const char *)
Definition: nasl_var.c:1127
exec.h
session_table_item_s::session
ssh_session session
Definition: nasl_ssh.c:105
add_close_stream_connection_hook
void add_close_stream_connection_hook(int(*fnc)(int fd))
Register a hook function for close_stream_connection.
Definition: network.c:1479
session_table_item_s
Definition: nasl_ssh.c:102
nasl_debug.h
nasl_perror
void nasl_perror(lex_ctxt *lexic, char *msg,...)
Definition: nasl_debug.c:120
nasl_ssh_connect
tree_cell * nasl_ssh_connect(lex_ctxt *lexic)
Connect to the target host via TCP and setup an ssh connection.
Definition: nasl_ssh.c:235
TC::size
int size
Definition: nasl_tree.h:109
nasl_lex_ctxt.h
DIM
#define DIM(v)
Definition: nasl_ssh.c:62
nasl_ssh_disconnect
tree_cell * nasl_ssh_disconnect(lex_ctxt *lexic)
Disconnect an ssh connection.
Definition: nasl_ssh.c:491
nasl_ssh_shell_open
tree_cell * nasl_ssh_shell_open(lex_ctxt *lexic)
Request an ssh shell.
Definition: nasl_ssh.c:1661
MAX_SSH_SESSIONS
#define MAX_SSH_SESSIONS
Definition: nasl_ssh.c:116
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
nasl_func.h
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
request_ssh_shell_alarm
static void request_ssh_shell_alarm(int signal)
Definition: nasl_ssh.c:1613
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
struct_lex_ctxt
Definition: nasl_lex_ctxt.h:33
nasl_ssh_login_interactive_pass
tree_cell * nasl_ssh_login_interactive_pass(lex_ctxt *lexic)
Authenticate a user on an ssh connection.
Definition: nasl_ssh.c:1103
nasl_var.h
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
nasl_ssh_get_sock
tree_cell * nasl_ssh_get_sock(lex_ctxt *lexic)
Given a session id, return the corresponding socket.
Definition: nasl_ssh.c:599
nasl_global_ctxt.h
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
nasl_ssh_get_host_key
tree_cell * nasl_ssh_get_host_key(lex_ctxt *lexic)
Get the host key.
Definition: nasl_ssh.c:1528
session_table
static struct session_table_item_s session_table[MAX_SSH_SESSIONS]
Definition: nasl_ssh.c:117
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.
Definition: nasl_ssh.c:556
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
exec_ssh_cmd_alarm
static void exec_ssh_cmd_alarm(int signal)
Definition: nasl_ssh.c:1166
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
nasl_ssh_login_interactive
tree_cell * nasl_ssh_login_interactive(lex_ctxt *lexic)
Authenticate a user on an ssh connection.
Definition: nasl_ssh.c:991
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
nasl_ssh_get_issue_banner
tree_cell * nasl_ssh_get_issue_banner(lex_ctxt *lexic)
Get the issue banner.
Definition: nasl_ssh.c:1438
nasl_tree.h
TC::i_val
long int i_val
Definition: nasl_tree.h:113