OpenVAS Libraries  8.0.3
Data Structures | Macros | Functions
nasl_socket.c File Reference

The NASL socket API. More...

#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
#include <gnutls/gnutls.h>
#include "network.h"
#include "openvas_networking.h"
#include "plugutils.h"
#include "../misc/openvas_logging.h"
#include "nasl.h"
#include "nasl_tree.h"
#include "nasl_global_ctxt.h"
#include "nasl_func.h"
#include "nasl_var.h"
#include "nasl_lex_ctxt.h"
#include "exec.h"
#include "nasl_packet_forgery.h"
#include "nasl_debug.h"

Data Structures

struct  udp_record
 
struct  jmg
 

Macros

#define EADDRNOTAVAIL   EADDRINUSE
 

Functions

tree_cellnasl_open_priv_sock_tcp (lex_ctxt *lexic)
 
tree_cellnasl_open_priv_sock_udp (lex_ctxt *lexic)
 
tree_cellnasl_open_sock_tcp_bufsz (lex_ctxt *lexic, int bufsz)
 
tree_cellnasl_open_sock_tcp (lex_ctxt *lexic)
 Open a TCP socket to the target host. More...
 
tree_cellnasl_open_sock_udp (lex_ctxt *lexic)
 
tree_cellnasl_socket_negotiate_ssl (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_cert (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_ssl_session_id (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_ssl_compression (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_ssl_version (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_ssl_ciphersuite (lex_ctxt *lexic)
 
tree_cellnasl_recv (lex_ctxt *lexic)
 
tree_cellnasl_recv_line (lex_ctxt *lexic)
 
tree_cellnasl_send (lex_ctxt *lexic)
 
tree_cellnasl_close_socket (lex_ctxt *lexic)
 
tree_cellnasl_join_multicast_group (lex_ctxt *lexic)
 
tree_cellnasl_leave_multicast_group (lex_ctxt *lexic)
 
tree_cellnasl_get_source_port (lex_ctxt *lexic)
 
tree_cellnasl_socket_get_error (lex_ctxt *lexic)
 
tree_cellnasl_get_sock_info (lex_ctxt *lexic)
 Get info pertaining to a socket. More...
 

Detailed Description

The NASL socket API.

This file contains all the functions related to the handling of the sockets within a NASL script - for example the implementation of the NASL built-ins open_sock_tcp, send, recv, recv_line, and close.

Macro Definition Documentation

#define EADDRNOTAVAIL   EADDRINUSE

Function Documentation

tree_cell* nasl_close_socket ( lex_ctxt lexic)
tree_cell* nasl_get_sock_info ( lex_ctxt lexic)

Get info pertaining to a socket.

NASL Function: get_sock_info

This function is used to retrieve various information about an active socket. It requires the NASL socket number and a string to select the information to retrieve.

Supported keywords are:

  • dport Return the destination port. This is an integer. NOTE: Not yet implemented.
  • sport Return the source port. This is an integer. NOTE: Not yet implemented.
  • encaps Return the encapsulation of the socket. Example output: "TLScustom".
  • tls-proto Return a string with the actual TLS protocol in use. n/a" is returned if no SSL/TLS session is active. Example output: "TLSv1".
  • tls-kx Return a string describing the key exchange algorithm. Example output: "RSA".
  • tls-certtype Return the type of the certificate in use by the session. Example output: "X.509"
  • tls-cipher Return the cipher algorithm in use by the session; Example output: "AES-256-CBC".
  • tls-mac Return the message authentication algorithms used by the session. Example output: "SHA1".
  • tls-comp Return the compression algorithms in use by the session. Example output: "DEFLATE".
  • tls-auth Return the peer's authentication type. Example output: "CERT".
  • tls-cert Return the peer's certificates for an SSL or TLS connection. This is an array of binary strings or NULL if no certificate is known.
NASL Unnamed Parameters:
  • A NASL socket
  • A string keyword; see above.
NASL Named Parameters:
  • asstring If true return a human readable string instead of an integer. Used only with these keywords: encaps.
NASL Returns:
An integer or a string or NULL on error.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.
tree_cell* nasl_get_source_port ( lex_ctxt lexic)
tree_cell* nasl_join_multicast_group ( lex_ctxt lexic)
tree_cell* nasl_leave_multicast_group ( lex_ctxt lexic)
tree_cell* nasl_open_priv_sock_tcp ( lex_ctxt lexic)
tree_cell* nasl_open_priv_sock_udp ( lex_ctxt lexic)
tree_cell* nasl_open_sock_tcp ( lex_ctxt lexic)

Open a TCP socket to the target host.

NASL Function: open_sock_tcp

This function is used to create a TCP connection to the target host. It requires the port number as its argument and has various optional named arguments to control encapsulation, timeout and buffering.

NASL Unnamed Parameters:
  • A non-negative integer with the TCP port number.
NASL Named Parameters:
  • bufsz An integer with the the size buffer size. Note that by default, no buffering is used.
  • timeout An integer with the timeout value in seconds. The default timeout is controlled by a global value.
  • transport One of the ENCAPS_* constants to force a specific encapsulation mode or force trying of all modes (ENCAPS_AUTO). This is for example useful to select a specific TLS or SSL version or use specific TLS connection setup priorities. See get_port_transport for a description of the ENCAPS constants.
  • priority A string value with priorities for an TLS encapsulation. For the syntax of the priority string see the GNUTLS manual. This argument is only used in ENCAPS_TLScustom encapsulation.
NASL Returns:
A positive integer as a NASL socket, 0 on connection error or NULL on other errors.
Parameters
[in]lexicLexical context of the NASL interpreter.
Returns
A tree cell.
tree_cell* nasl_open_sock_tcp_bufsz ( lex_ctxt lexic,
int  bufsz 
)
tree_cell* nasl_open_sock_udp ( lex_ctxt lexic)
tree_cell* nasl_recv ( lex_ctxt lexic)
tree_cell* nasl_recv_line ( lex_ctxt lexic)
tree_cell* nasl_send ( lex_ctxt lexic)
tree_cell* nasl_socket_get_cert ( lex_ctxt lexic)
tree_cell* nasl_socket_get_error ( lex_ctxt lexic)
tree_cell* nasl_socket_get_ssl_ciphersuite ( lex_ctxt lexic)
tree_cell* nasl_socket_get_ssl_compression ( lex_ctxt lexic)
tree_cell* nasl_socket_get_ssl_session_id ( lex_ctxt lexic)
tree_cell* nasl_socket_get_ssl_version ( lex_ctxt lexic)
tree_cell* nasl_socket_negotiate_ssl ( lex_ctxt lexic)