OpenVAS Scanner 21.4.1
Data Structures | Macros | Functions | Variables
nasl_packet_forgery_v6.c File Reference

NASL IPv6 Packet Forgery functions. More...

#include <arpa/inet.h>
#include <ctype.h>
#include <pcap.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
#include <sys/time.h>
#include <unistd.h>
#include "../misc/bpf_share.h"
#include "../misc/pcap_openvas.h"
#include "../misc/plugutils.h"
#include "capture_packet.h"
#include "exec.h"
#include "nasl_debug.h"
#include "nasl_func.h"
#include "nasl_global_ctxt.h"
#include "nasl_lex_ctxt.h"
#include "nasl_packet_forgery_v6.h"
#include "nasl_raw.h"
#include "nasl_socket.h"
#include "nasl_tree.h"
#include "nasl_var.h"
#include <netinet/icmp6.h>

Data Structures

struct  v6pseudohdr
 
struct  tcp_opt_mss
 
struct  tcp_opt_wscale
 
struct  tcp_opt_sack_perm
 
struct  tcp_opt_tstamp
 
struct  tcp_options
 
struct  v6pseudo_udp_hdr
 
struct  v6pseudo_icmp_hdr
 
struct  igmp6_hdr
 

Macros

#define FIX(n)   htons (n)
 
#define UNFIX(n)   ntohs (n)
 
#define rnd_tcp_port()   (rand () % 65535 + 1024)
 

Functions

static int np_in_cksum (u_short *p, int n)
 
tree_cellforge_ip_v6_packet (lex_ctxt *lexic)
 Forge an IPv6 packet. More...
 
tree_cellget_ip_v6_element (lex_ctxt *lexic)
 Obtain IPv6 header element. More...
 
tree_cellset_ip_v6_elements (lex_ctxt *lexic)
 Set IPv6 header element. More...
 
tree_celldump_ip_v6_packet (lex_ctxt *lexic)
 Print IPv6 Header. More...
 
tree_cellinsert_ip_v6_options (lex_ctxt *lexic)
 Adds an IPv6 option to the datagram. More...
 
struct v6pseudohdr __attribute__ ((packed))
 
tree_cellforge_tcp_v6_packet (lex_ctxt *lexic)
 Forge TCP packet. More...
 
tree_cellget_tcp_v6_element (lex_ctxt *lexic)
 Get TCP Header element. More...
 
static void get_tcp_options (char *options, struct tcp_options *tcp_all_options)
 Extract all TCP option from an IP datagram. More...
 
tree_cellget_tcp_v6_option (lex_ctxt *lexic)
 Get a TCP option from an IP datagram if present. Possible options are: TCPOPT_MAXSEG (2), values between 536 and 65535 TCPOPT_WINDOW (3), with values between 0 and 14 TCPOPT_SACK_PERMITTED (4), no value required. TCPOPT_TIMESTAMP (8), 8 bytes value for timestamp and echo timestamp, 4 bytes each one. More...
 
tree_cellset_tcp_v6_elements (lex_ctxt *lexic)
 Set TCP Header element. More...
 
tree_cellinsert_tcp_v6_options (lex_ctxt *lexic)
 Add options to a TCP segment header. Possible options are: TCPOPT_MAXSEG (2), values between 536 and 65535 TCPOPT_WINDOW (3), with values between 0 and 14 TCPOPT_SACK_PERMITTED (4), no value required. TCPOPT_TIMESTAMP (8), 8 bytes value for timestamp and echo timestamp, 4 bytes each one. More...
 
tree_celldump_tcp_v6_packet (lex_ctxt *lexic)
 Dump TCP part of an IPv6 Datagram. More...
 
tree_cellforge_udp_v6_packet (lex_ctxt *lexic)
 
tree_cellget_udp_v6_element (lex_ctxt *lexic)
 
tree_cellset_udp_v6_elements (lex_ctxt *lexic)
 
tree_celldump_udp_v6_packet (lex_ctxt *lexic)
 
tree_cellforge_icmp_v6_packet (lex_ctxt *lexic)
 
tree_cellget_icmp_v6_element (lex_ctxt *lexic)
 
tree_celldump_icmp_v6_packet (lex_ctxt *lexic)
 Dump the ICMP part of a IP Datagram. More...
 
tree_cellforge_igmp_v6_packet (lex_ctxt *lexic)
 
tree_cellnasl_tcp_v6_ping (lex_ctxt *lexic)
 Performs TCP Connect to test if host is alive. More...
 
tree_cellnasl_send_v6packet (lex_ctxt *lexic)
 Send forged IPv6 Packets. More...
 

Variables

struct in6_addr s6addr
 
struct in6_addr d6addr
 
u_short length
 
u_char zero1
 
u_char zero2
 
u_char zero3
 
u_char protocol
 
struct tcphdr tcpheader
 
uint8_t kind
 
uint8_t len
 
uint16_t mss
 
uint8_t wscale
 
uint32_t tstamp
 
uint32_t e_tstamp
 
struct tcp_opt_sack_perm sack_perm
 
struct v6pseudo_udp_hdr __attribute__
 

Detailed Description

NASL IPv6 Packet Forgery functions.

Provides IPv6 Packet Forgery functionalities The API set offers forgery for,

  1. TCP
  2. IPv6

Macro Definition Documentation

◆ FIX

#define FIX (   n)    htons (n)
Todo:
: It still needs to be taken care BSD_BYTE_ORDERING gets here if defined (e.g. by config.h)

◆ rnd_tcp_port

#define rnd_tcp_port ( )    (rand () % 65535 + 1024)

◆ UNFIX

#define UNFIX (   n)    ntohs (n)

Function Documentation

◆ __attribute__()

struct v6pseudohdr __attribute__ ( (packed)  )

◆ dump_icmp_v6_packet()

tree_cell * dump_icmp_v6_packet ( lex_ctxt lexic)

Dump the ICMP part of a IP Datagram.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]...IP datagrams to dump the ICMP part from.

◆ dump_ip_v6_packet()

tree_cell * dump_ip_v6_packet ( lex_ctxt lexic)

Print IPv6 Header.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]...IPv6 datagrams to dump.
Returns
Print and returns FAKE_CELL.

◆ dump_tcp_v6_packet()

tree_cell * dump_tcp_v6_packet ( lex_ctxt lexic)

Dump TCP part of an IPv6 Datagram.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]...IPv6 datagrams to dump.
Returns
Print and return FAKE_CELL.

◆ dump_udp_v6_packet()

tree_cell * dump_udp_v6_packet ( lex_ctxt lexic)

◆ forge_icmp_v6_packet()

tree_cell * forge_icmp_v6_packet ( lex_ctxt lexic)

◆ forge_igmp_v6_packet()

tree_cell * forge_igmp_v6_packet ( lex_ctxt lexic)

◆ forge_ip_v6_packet()

tree_cell * forge_ip_v6_packet ( lex_ctxt lexic)

Forge an IPv6 packet.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]dataData payload
[in]ip6_vVersion. 6 by default.
[in]ip6_tcTraffic class. 0 by default.
[in]ip6_flFlow label. 0 by default.
[in]ip6_pIP protocol. 0 by default.
[in]ip6_hlimHop limit. Max. 255. 64 by default.
[in]ip6_srcSource address.
[in]ip6_dstDestination address.
Returns
Forged IP packet.

◆ forge_tcp_v6_packet()

tree_cell * forge_tcp_v6_packet ( lex_ctxt lexic)

Forge TCP packet.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]ip6IPv6 packet.
[in]dataData.
[in]th_sportSource port. 0 by default.
[in]th_dportDestination port. 0 by default.
[in]th_seqSequence number. Random by default.
[in]th_ackAcknowledgement number. 0 by default.
[in]th_x20 by default.
[in]th_offData offset. 5 by default.
[in]th_flagsFlags. 0 by default.
[in]th_winWindow. 0 by default.
[in]th_sumChecksum. Is filled in automatically by default
[in]th_urpUrgent pointer. 0 by default.
Returns
tree_cell with the forged TCP packet containing IPv6 header.

◆ forge_udp_v6_packet()

tree_cell * forge_udp_v6_packet ( lex_ctxt lexic)

◆ get_icmp_v6_element()

tree_cell * get_icmp_v6_element ( lex_ctxt lexic)

◆ get_ip_v6_element()

tree_cell * get_ip_v6_element ( lex_ctxt lexic)

Obtain IPv6 header element.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]ipv6IPv6 header. TODO: Once versions older than 20.08 are no longer in use the parameter name can be changed to 'ip6'.
[in]elementElement to extract from the header.
Returns
tree_cell with the IP header element.

◆ get_tcp_options()

static void get_tcp_options ( char *  options,
struct tcp_options tcp_all_options 
)
static

Extract all TCP option from an IP datagram.

Parameters
[in]optionsAll options present in the TCP segment.
[out]tcp_all_optionsContainer for the options to return.

◆ get_tcp_v6_element()

tree_cell * get_tcp_v6_element ( lex_ctxt lexic)

Get TCP Header element.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]tcpIPv6 packet
[in]elementElement to extract from the header (see forge_tcp_v6_packet()).
Returns
tree_cell with the forged IP packet.

◆ get_tcp_v6_option()

tree_cell * get_tcp_v6_option ( lex_ctxt lexic)

Get a TCP option from an IP datagram if present. Possible options are: TCPOPT_MAXSEG (2), values between 536 and 65535 TCPOPT_WINDOW (3), with values between 0 and 14 TCPOPT_SACK_PERMITTED (4), no value required. TCPOPT_TIMESTAMP (8), 8 bytes value for timestamp and echo timestamp, 4 bytes each one.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]tcpThe full IP datagram (IP + TCP).
[in]optionOption to get.
Returns
Integer or array given the case.

◆ get_udp_v6_element()

tree_cell * get_udp_v6_element ( lex_ctxt lexic)

◆ insert_ip_v6_options()

tree_cell * insert_ip_v6_options ( lex_ctxt lexic)

Adds an IPv6 option to the datagram.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]ip6IPv6 packet.
[in]dataData payload.
[in]codeCode of option.
[in]lengthLength of value.
[in]valueValue of the option.
Returns
the modified datagram.

◆ insert_tcp_v6_options()

tree_cell * insert_tcp_v6_options ( lex_ctxt lexic)

Add options to a TCP segment header. Possible options are: TCPOPT_MAXSEG (2), values between 536 and 65535 TCPOPT_WINDOW (3), with values between 0 and 14 TCPOPT_SACK_PERMITTED (4), no value required. TCPOPT_TIMESTAMP (8), 8 bytes value for timestamp and echo timestamp, 4 bytes each one.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]tcpIP datagram.
[in]data(optional) TCP data payload.
[in]unnamedoption.
[in]Valuefor unnamed option if required.
Returns
The modified IP datagram.

◆ nasl_send_v6packet()

tree_cell * nasl_send_v6packet ( lex_ctxt lexic)

Send forged IPv6 Packets.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]...IPv6 packets to send.
[in]lengthLength of each packet by default.
[in]pcap_activeTRUE by default. Otherwise, NASL does not listen for the answers.
[in]pcap_filterBPF filter.
[in]pcap_timeoutCapture timeout. 5 by default.
[in]allow_multicastDefault 0.
Returns
tree_cell with the response to the sent packet.

◆ nasl_tcp_v6_ping()

tree_cell * nasl_tcp_v6_ping ( lex_ctxt lexic)

Performs TCP Connect to test if host is alive.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]portPort to ping. Internal list of common ports is used as default.
Returns
tree_cell > 0 if host is alive, 0 otherwise.

◆ np_in_cksum()

static int np_in_cksum ( u_short *  p,
int  n 
)
static

◆ set_ip_v6_elements()

tree_cell * set_ip_v6_elements ( lex_ctxt lexic)

Set IPv6 header element.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]ip6IP v6 header.
[in]ip6_plenPayload length.
[in]ip6_hlimHop limit. Max. 255
[in]ip6_nxtNext packet.
[in]ip6_srcSource address
Returns
tree_cell with the forged IP packet.

◆ set_tcp_v6_elements()

tree_cell * set_tcp_v6_elements ( lex_ctxt lexic)

Set TCP Header element.

Parameters
[in]lexicLexical context of NASL interpreter.
[in]tcpIPv6 packet to modify.
[in]dataData.
[in]th_sportSource port.
[in]th_dportDestination port.
[in]th_seqSequence number.
[in]th_ackAcknowledgement number.
[in]th_x2
[in]th_offData offset.
[in]th_flagsFlags.
[in]th_winWindow.
[in]th_sumChecksum.
[in]th_urpUrgent pointer.
[in]update_ip_lenFlag (TRUE by default). If set, NASL will recompute the size field of the IP datagram.
Returns
tree_cell with the modified IPv6 datagram.

◆ set_udp_v6_elements()

tree_cell * set_udp_v6_elements ( lex_ctxt lexic)

Variable Documentation

◆ __attribute__

struct v6pseudo_udp_hdr __attribute__

◆ d6addr

struct in6_addr d6addr

◆ e_tstamp

uint32_t e_tstamp

◆ kind

uint8_t kind

◆ len

uint8_t len

◆ length

u_short length

◆ mss

struct tcp_opt_mss mss

◆ protocol

u_char protocol

◆ s6addr

struct in6_addr s6addr

◆ sack_perm

struct tcp_opt_sack_perm sack_perm

◆ tcpheader

struct tcphdr tcpheader

◆ tstamp

struct tcp_opt_tstamp tstamp

◆ wscale

struct tcp_opt_wscale wscale

◆ zero1

u_char zero1

◆ zero2

u_char zero2

◆ zero3

u_char zero3