|
OpenVAS Scanner 23.32.3
|
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>
Go to the source code of this file.
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) |
| #define | UNFIX(n) |
| #define | rnd_tcp_port() |
Functions | |
| static int | np_in_cksum (u_short *p, int n) |
| tree_cell * | forge_ip_v6_packet (lex_ctxt *lexic) |
| Forge an IPv6 packet. | |
| tree_cell * | get_ip_v6_element (lex_ctxt *lexic) |
| Obtain IPv6 header element. | |
| tree_cell * | set_ip_v6_elements (lex_ctxt *lexic) |
| Set IPv6 header element. | |
| tree_cell * | dump_ip_v6_packet (lex_ctxt *lexic) |
| Print IPv6 Header. | |
| tree_cell * | insert_ip_v6_options (lex_ctxt *lexic) |
| Adds an IPv6 option to the datagram. | |
| struct v6pseudohdr | __attribute__ ((packed)) |
| tree_cell * | forge_tcp_v6_packet (lex_ctxt *lexic) |
| Forge TCP packet. | |
| tree_cell * | get_tcp_v6_element (lex_ctxt *lexic) |
| Get TCP Header element. | |
| static void | get_tcp_options (char *options, struct tcp_options *tcp_all_options) |
| Extract all TCP option from an IP datagram. | |
| 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. | |
| tree_cell * | set_tcp_v6_elements (lex_ctxt *lexic) |
| Set TCP Header element. | |
| 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. | |
| tree_cell * | dump_tcp_v6_packet (lex_ctxt *lexic) |
| Dump TCP part of an IPv6 Datagram. | |
| tree_cell * | forge_udp_v6_packet (lex_ctxt *lexic) |
| tree_cell * | get_udp_v6_element (lex_ctxt *lexic) |
| tree_cell * | set_udp_v6_elements (lex_ctxt *lexic) |
| tree_cell * | dump_udp_v6_packet (lex_ctxt *lexic) |
| tree_cell * | forge_icmp_v6_packet (lex_ctxt *lexic) |
| tree_cell * | get_icmp_v6_element (lex_ctxt *lexic) |
| tree_cell * | dump_icmp_v6_packet (lex_ctxt *lexic) |
| Dump the ICMP part of a IP Datagram. | |
| tree_cell * | forge_igmp_v6_packet (lex_ctxt *lexic) |
| tree_cell * | nasl_tcp_v6_ping (lex_ctxt *lexic) |
| Performs TCP Connect to test if host is alive. | |
| tree_cell * | nasl_send_v6packet (lex_ctxt *lexic) |
| Send forged IPv6 Packets. | |
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__ |
NASL IPv6 Packet Forgery functions.
Provides IPv6 Packet Forgery functionalities The API set offers forgery for,
Definition in file nasl_packet_forgery_v6.c.
| #define FIX | ( | n | ) |
Definition at line 62 of file nasl_packet_forgery_v6.c.
Referenced by __attribute__(), forge_icmp_v6_packet(), forge_igmp_v6_packet(), forge_ip_v6_packet(), forge_tcp_v6_packet(), forge_udp_v6_packet(), insert_tcp_v6_options(), nasl_tcp_v6_ping(), set_tcp_v6_elements(), and set_udp_v6_elements().
| #define rnd_tcp_port | ( | ) |
Referenced by nasl_tcp_v6_ping().
| #define UNFIX | ( | n | ) |
Definition at line 63 of file nasl_packet_forgery_v6.c.
Referenced by __attribute__(), dump_icmp_v6_packet(), dump_tcp_v6_packet(), get_ip_v6_element(), get_tcp_v6_element(), insert_tcp_v6_options(), and set_tcp_v6_elements().
| struct v6pseudohdr __attribute__ | ( | (packed) | ) |
References alloc_typed_cell(), code, CONST_DATA, FIX, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), len, nasl_perror(), TC::size, TC::str_val, UNFIX, TC::x, and zero.

Dump the ICMP part of a IP Datagram.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | ... | IP datagrams to dump the ICMP part from. |
Definition at line 2053 of file nasl_packet_forgery_v6.c.
References get_str_var_by_num(), get_var_size_by_num(), and UNFIX.

Print IPv6 Header.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | ... | IPv6 datagrams to dump. |
Definition at line 336 of file nasl_packet_forgery_v6.c.
References FAKE_CELL, get_str_var_by_num(), and UNFIX.

Dump TCP part of an IPv6 Datagram.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | ... | IPv6 datagrams to dump. |
Definition at line 1249 of file nasl_packet_forgery_v6.c.
References tcp_opt_tstamp::e_tstamp, get_str_var_by_num(), get_tcp_options(), get_var_size_by_num(), tcp_opt_sack_perm::kind, tcp_opt_mss::mss, tcp_options::mss, tcp_options::sack_perm, tcp_opt_tstamp::tstamp, tcp_options::tstamp, UNFIX, tcp_opt_wscale::wscale, and tcp_options::wscale.

Definition at line 1661 of file nasl_packet_forgery_v6.c.
References get_str_var_by_num(), and get_var_size_by_num().

Definition at line 1725 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, FIX, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), len, nasl_perror(), np_in_cksum(), TC::size, TC::str_val, UNFIX, and TC::x.

Definition at line 2110 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), igmp::cksum, igmp::code, CONST_DATA, FIX, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), igmp::group, len, nasl_perror(), np_in_cksum(), TC::size, TC::str_val, igmp::type, UNFIX, and TC::x.

Forge an IPv6 packet.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | data | Data payload |
| [in] | ip6_v | Version. 6 by default. |
| [in] | ip6_tc | Traffic class. 0 by default. |
| [in] | ip6_fl | Flow label. 0 by default. |
| [in] | ip6_p | IP protocol. 0 by default. |
| [in] | ip6_hlim | Hop limit. Max. 255. 64 by default. |
| [in] | ip6_src | Source address. |
| [in] | ip6_dst | Destination address. |
Definition at line 118 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, FIX, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), plug_get_host_ip(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, and TC::x.

Forge TCP packet.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | ip6 | IPv6 packet. |
| [in] | data | Data. |
| [in] | th_sport | Source port. 0 by default. |
| [in] | th_dport | Destination port. 0 by default. |
| [in] | th_seq | Sequence number. Random by default. |
| [in] | th_ack | Acknowledgement number. 0 by default. |
| [in] | th_x2 | 0 by default. |
| [in] | th_off | Data offset. 5 by default. |
| [in] | th_flags | Flags. 0 by default. |
| [in] | th_win | Window. 0 by default. |
| [in] | th_sum | Checksum. Is filled in automatically by default |
| [in] | th_urp | Urgent pointer. 0 by default. |
Definition at line 530 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, v6pseudohdr::d6addr, FIX, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), len, v6pseudohdr::length, nasl_perror(), np_in_cksum(), v6pseudohdr::protocol, v6pseudohdr::s6addr, TC::size, TC::str_val, v6pseudohdr::tcpheader, and TC::x.

Definition at line 1395 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, FIX, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), nasl_perror(), np_in_cksum(), TC::size, TC::str_val, UNFIX, and TC::x.

Definition at line 1984 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, CONST_INT, get_str_var_by_name(), get_var_size_by_name(), TC::i_val, nasl_perror(), TC::size, TC::str_val, and TC::x.

Obtain IPv6 header element.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | ipv6 | IPv6 header. TODO: Once versions older than 20.08 are no longer in use the parameter name can be changed to 'ip6'. |
| [in] | element | Element to extract from the header. |
Definition at line 190 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, CONST_INT, get_str_var_by_name(), TC::i_val, nasl_perror(), TC::size, TC::str_val, UNFIX, and TC::x.

|
static |
Extract all TCP option from an IP datagram.
| [in] | options | All options present in the TCP segment. |
| [out] | tcp_all_options | Container for the options to return. |
Definition at line 706 of file nasl_packet_forgery_v6.c.
References tcp_opt_tstamp::e_tstamp, tcp_opt_mss::kind, tcp_opt_sack_perm::kind, tcp_opt_tstamp::kind, tcp_opt_wscale::kind, tcp_opt_mss::len, tcp_opt_sack_perm::len, tcp_opt_tstamp::len, tcp_opt_wscale::len, tcp_opt_mss::mss, tcp_options::mss, tcp_options::sack_perm, tcp_opt_tstamp::tstamp, tcp_options::tstamp, tcp_opt_wscale::wscale, and tcp_options::wscale.
Referenced by dump_tcp_v6_packet(), and get_tcp_v6_option().

Get TCP Header element.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | tcp | IPv6 packet |
| [in] | element | Element to extract from the header (see forge_tcp_v6_packet()). |
Definition at line 618 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, CONST_INT, deref_cell(), get_str_var_by_name(), get_var_size_by_name(), TC::i_val, nasl_perror(), TC::size, TC::str_val, UNFIX, and TC::x.

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.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | tcp | The full IP datagram (IP + TCP). |
| [in] | option | Option to get. |
Definition at line 775 of file nasl_packet_forgery_v6.c.
References add_var_to_array(), alloc_typed_cell(), CONST_INT, DYN_ARRAY, tcp_opt_tstamp::e_tstamp, get_int_var_by_name(), get_str_var_by_name(), get_tcp_options(), get_var_size_by_name(), TC::i_val, tcp_opt_sack_perm::kind, tcp_opt_mss::mss, tcp_options::mss, nasl_perror(), TC::ref_val, tcp_options::sack_perm, tcp_opt_tstamp::tstamp, tcp_options::tstamp, UNFIX, st_a_nasl_var::v, st_a_nasl_var::v_int, VAR2_INT, st_a_nasl_var::var_type, tcp_opt_wscale::wscale, tcp_options::wscale, and TC::x.

Definition at line 1479 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, CONST_INT, get_str_var_by_name(), get_var_size_by_name(), TC::i_val, nasl_perror(), TC::size, TC::str_val, and TC::x.

Adds an IPv6 option to the datagram.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | ip6 | IPv6 packet. |
| [in] | data | Data payload. |
| [in] | code | Code of option. |
| [in] | length | Length of value. |
| [in] | value | Value of the option. |
Definition at line 394 of file nasl_packet_forgery_v6.c.
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.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | tcp | IP datagram. |
| [in] | data | (optional) TCP data payload. |
| [in] | unnamed | option. |
| [in] | Value | for unnamed option if required. |
Definition at line 999 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, v6pseudohdr::d6addr, tcp_opt_tstamp::e_tstamp, FIX, get_int_var_by_num(), get_str_var_by_name(), get_var_size_by_name(), tcp_opt_mss::kind, tcp_opt_sack_perm::kind, tcp_opt_tstamp::kind, tcp_opt_wscale::kind, tcp_opt_mss::len, tcp_opt_sack_perm::len, tcp_opt_tstamp::len, tcp_opt_wscale::len, v6pseudohdr::length, tcp_opt_mss::mss, nasl_perror(), np_in_cksum(), v6pseudohdr::protocol, v6pseudohdr::s6addr, TC::size, TC::str_val, v6pseudohdr::tcpheader, tcp_opt_tstamp::tstamp, UNFIX, tcp_opt_wscale::wscale, and TC::x.

Send forged IPv6 Packets.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | ... | IPv6 packets to send. |
| [in] | length | Length of each packet by default. |
| [in] | pcap_active | TRUE by default. Otherwise, NASL does not listen for the answers. |
| [in] | pcap_filter | BPF filter. |
| [in] | pcap_timeout | Capture timeout. 5 by default. |
| [in] | allow_multicast | Default 0. |
Definition at line 2323 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), bpf_close(), capture_next_v6_packet(), CONST_DATA, FAKE_CELL, get_int_var_by_name(), get_str_var_by_name(), get_str_var_by_num(), get_var_size_by_num(), init_v6_capture_device(), len, name, nasl_perror(), plug_get_host_ip(), struct_lex_ctxt::script_infos, TC::size, TC::str_val, v6_islocalhost(), and TC::x.

Performs TCP Connect to test if host is alive.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | port | Port to ping. Internal list of common ports is used as default. |
Definition at line 2177 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), bpf_close(), bpf_next_tv(), CONST_INT, v6pseudohdr::d6addr, FIX, get_int_var_by_name(), TC::i_val, init_v6_capture_device(), len, v6pseudohdr::length, np_in_cksum(), plug_get_host_ip(), plug_get_host_open_port(), v6pseudohdr::protocol, rnd_tcp_port, v6pseudohdr::s6addr, struct_lex_ctxt::script_infos, v6pseudohdr::tcpheader, timeval(), v6_islocalhost(), v6_routethrough(), and TC::x.
Referenced by nasl_tcp_ping().


|
static |
Definition at line 73 of file nasl_packet_forgery_v6.c.
Referenced by forge_icmp_v6_packet(), forge_igmp_v6_packet(), forge_tcp_v6_packet(), forge_udp_v6_packet(), insert_tcp_v6_options(), nasl_tcp_v6_ping(), set_tcp_v6_elements(), and set_udp_v6_elements().

Set IPv6 header element.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | ip6 | IP v6 header. |
| [in] | ip6_plen | Payload length. |
| [in] | ip6_hlim | Hop limit. Max. 255 |
| [in] | ip6_nxt | Next packet. |
| [in] | ip6_src | Source address |
Definition at line 295 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), nasl_perror(), TC::size, TC::str_val, and TC::x.

Set TCP Header element.
| [in] | lexic | Lexical context of NASL interpreter. |
| [in] | tcp | IPv6 packet to modify. |
| [in] | data | Data. |
| [in] | th_sport | Source port. |
| [in] | th_dport | Destination port. |
| [in] | th_seq | Sequence number. |
| [in] | th_ack | Acknowledgement number. |
| [in] | th_x2 | |
| [in] | th_off | Data offset. |
| [in] | th_flags | Flags. |
| [in] | th_win | Window. |
| [in] | th_sum | Checksum. |
| [in] | th_urp | Urgent pointer. |
| [in] | update_ip_len | Flag (TRUE by default). If set, NASL will recompute the size field of the IP datagram. |
Definition at line 894 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, v6pseudohdr::d6addr, FIX, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), v6pseudohdr::length, nasl_perror(), np_in_cksum(), v6pseudohdr::protocol, v6pseudohdr::s6addr, TC::size, TC::str_val, v6pseudohdr::tcpheader, UNFIX, and TC::x.

Definition at line 1551 of file nasl_packet_forgery_v6.c.
References alloc_typed_cell(), CONST_DATA, FIX, get_int_var_by_name(), get_str_var_by_name(), get_var_size_by_name(), len, nasl_perror(), np_in_cksum(), TC::size, TC::str_val, and TC::x.

| struct v6pseudo_udp_hdr __attribute__ |
| struct in6_addr d6addr |
Definition at line 1 of file nasl_packet_forgery_v6.c.
| uint32_t e_tstamp |
Definition at line 3 of file nasl_packet_forgery_v6.c.
| uint8_t kind |
Definition at line 0 of file nasl_packet_forgery_v6.c.
| uint8_t len |
Definition at line 1 of file nasl_packet_forgery_v6.c.
| u_short length |
Definition at line 2 of file nasl_packet_forgery_v6.c.
| struct tcp_opt_mss mss |
Definition at line 2 of file nasl_packet_forgery_v6.c.
| u_char protocol |
Definition at line 6 of file nasl_packet_forgery_v6.c.
| struct in6_addr s6addr |
Definition at line 0 of file nasl_packet_forgery_v6.c.
Referenced by v6_getinterfaces().
| struct tcp_opt_sack_perm sack_perm |
Definition at line 2 of file nasl_packet_forgery_v6.c.
| struct tcphdr tcpheader |
Definition at line 7 of file nasl_packet_forgery_v6.c.
| struct tcp_opt_tstamp tstamp |
Definition at line 2 of file nasl_packet_forgery_v6.c.
| struct tcp_opt_wscale wscale |
Definition at line 2 of file nasl_packet_forgery_v6.c.
| u_char zero1 |
Definition at line 3 of file nasl_packet_forgery_v6.c.
| u_char zero2 |
Definition at line 4 of file nasl_packet_forgery_v6.c.
| u_char zero3 |
Definition at line 5 of file nasl_packet_forgery_v6.c.