OpenVAS Scanner 23.23.1
nasl_frame_forgery.c File Reference

Functions to forge and manipulate datalink layer frames. More...

#include "nasl_frame_forgery.h"
#include "../misc/bpf_share.h"
#include "../misc/pcap_openvas.h"
#include "../misc/plugutils.h"
#include "capture_packet.h"
#include "nasl_debug.h"
#include <errno.h>
#include <gvm/base/networking.h>
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <netinet/ether.h>
#include <netinet/if_ether.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>

Data Structures

struct  pseudo_eth_arp
struct  pseudo_frame

Macros

#define G_LOG_DOMAIN   "lib misc"
 GLib logging domain.

Functions

struct pseudo_eth_arp __attribute__ ((packed))
static void dump_frame (const u_char *frame, int frame_sz)
 Dump a datalink layer frame.
static void prepare_sockaddr_ll (struct sockaddr_ll *soc_addr_ll, int ifindex, const u_char *ether_dst_addr)
 Prepare message header to be sent with sendmsg().
static void prepare_message (u_char *msg, struct sockaddr_ll *soc_addr_ll, u_char *payload, int payload_sz)
 Prepare message header to be sent with sendmsg().
static int send_frame (const u_char *frame, int frame_sz, int use_pcap, int timeout, char *filter, struct in6_addr *ipaddr, u_char **answer)
 Send a frame and listen to the answer.
static int forge_frame (const u_char *ether_src_addr, const u_char *ether_dst_addr, int ether_proto, u_char *payload, int payload_sz, struct pseudo_frame **frame)
 Forge a datalink layer frame.
tree_cellnasl_forge_frame (lex_ctxt *lexic)
 Forge a datalink layer frame.
tree_cellnasl_send_frame (lex_ctxt *lexic)
 Send a frame and listen to the answer.
tree_cellnasl_dump_frame (lex_ctxt *lexic)
 Dump a datalink layer frame.
static int get_local_mac_address_from_ip (char *ip_address, u_char *mac)
 Get the MAC address of host.
tree_cellnasl_get_local_mac_address_from_ip (lex_ctxt *lexic)
 Get the MAC address of host.
tree_cellnasl_send_arp_request (lex_ctxt *lexic)
 Send an arp request to an IP host.

Variables

struct arphdr arp_header
u_char __ar_sha [ETH_ALEN]
u_char __ar_sip [4]
u_char __ar_tha [ETH_ALEN]
u_char __ar_tip [4]
u_char __zero_padding [18]
struct ethhdr framehdr
u_char * payload

Detailed Description

Functions to forge and manipulate datalink layer frames.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib misc"

GLib logging domain.

Function Documentation

◆ __attribute__()

struct pseudo_eth_arp __attribute__ ( (packed) )

◆ dump_frame()

void dump_frame ( const u_char * frame,
int frame_sz )
static

Dump a datalink layer frame.

Parameters
frameThe frame to be dumped.
frame_szThe frame's size.

◆ forge_frame()

int forge_frame ( const u_char * ether_src_addr,
const u_char * ether_dst_addr,
int ether_proto,
u_char * payload,
int payload_sz,
struct pseudo_frame ** frame )
static

Forge a datalink layer frame.

Parameters
[in]src_haddrSource MAC address to use.
[in]dst_haddrDestination MAC address to use.
[in]ether_protoEthernet type integer in hex format. Default 0x0800 (ETHER_P_IP)
[in]payloadPayload to be attached to the frame. E.g a forged tcp datagram, or arp header
[out]framethe forge frame
Returns
the forged frame size.

◆ get_local_mac_address_from_ip()

int get_local_mac_address_from_ip ( char * ip_address,
u_char * mac )
static

Get the MAC address of host.

Parameters
[in]ip_addressLocal IP address
[out]macThe MAC address
Returns
0 on success. MAC address is put into buffer. -1 on error.

◆ nasl_dump_frame()

tree_cell * nasl_dump_frame ( lex_ctxt * lexic)

Dump a datalink layer frame.

@naslparam


  • frame The frame to be dumped.
Parameters
lexicLexical context of NASL interpreter.
Returns
Null

◆ nasl_forge_frame()

tree_cell * nasl_forge_frame ( lex_ctxt * lexic)

Forge a datalink layer frame.

@naslparams


  • src_haddr Source MAC address to use.

  • dst_haddr Destination MAC address to use.

  • ether_proto Ethernet type integer in hex format. Default 0x0800 (ETHER_P_IP)

  • payload Payload to be attached to the frame. E.g a forged tcp datagram.
  • @naslreturn the forged frame.
Parameters
lexicLexical context of NASL interpreter.
Returns
tree_cell element or null.

◆ nasl_get_local_mac_address_from_ip()

tree_cell * nasl_get_local_mac_address_from_ip ( lex_ctxt * lexic)

Get the MAC address of host.

@naslparam

  • ip_address Local IP address

    @naslreturn The MAC address of the host. NULL otherwise

Parameters
[in]lexicLexical context of NASL interpreter.

◆ nasl_send_arp_request()

tree_cell * nasl_send_arp_request ( lex_ctxt * lexic)

Send an arp request to an IP host.

NASL Returns:\n The MAC address of the target. NULL otherwise
Parameters
[in]lexicLexical context of NASL interpreter.
Returns
A tree cell or NULL.

◆ nasl_send_frame()

tree_cell * nasl_send_frame ( lex_ctxt * lexic)

Send a frame and listen to the answer.

@naslparams


  • frame The frame to be sent.

  • pcap_active TRUE by default. Otherwise, NASL does not listen for the answers.

  • pcap_filter BPF filter.

  • pcap_timeout Capture timeout. 5 by default.
  • @naslreturn Sniffed answer.
Parameters
lexicLexical context of NASL interpreter.
Returns
tree_cell element or null.

◆ prepare_message()

void prepare_message ( u_char * msg,
struct sockaddr_ll * soc_addr_ll,
u_char * payload,
int payload_sz )
static

Prepare message header to be sent with sendmsg().

Parameters
[out]msgThe packaged messages to be sent
[in]soc_addr_llThe sockaddr_ll structure for capturing
[in]payloadThe payload, a datalink layer frame with payload
[in]payload_szThe payload size.

◆ prepare_sockaddr_ll()

void prepare_sockaddr_ll ( struct sockaddr_ll * soc_addr_ll,
int ifindex,
const u_char * ether_dst_addr )
static

Prepare message header to be sent with sendmsg().

Parameters
[out]soc_addr_llThe sockaddr_ll structure to be prepared
[in]ifindexThe interface index to be use for capturing.
[in]ether_dst_addrThe dst MAC address.

◆ send_frame()

int send_frame ( const u_char * frame,
int frame_sz,
int use_pcap,
int timeout,
char * filter,
struct in6_addr * ipaddr,
u_char ** answer )
static

Send a frame and listen to the answer.

Parameters
[in]

The frame to be sent.

Parameters
[in]

The frame's size.

Parameters
[in]

TRUE by default. Otherwise, NASL does not listen for the answers.

Parameters
[in]

BPF filter.

Parameters
[in]

Capture timeout. 5 by default.

Parameters
[in]

Destination address, used for calculating the ethernet index

Parameters
[out]

Sniffed answer.

Returns
Bits received in the answer or 0 on success, -1 if no answer, -2 error sending the message.

Variable Documentation

◆ __ar_sha

u_char __ar_sha[ETH_ALEN]

◆ __ar_sip

u_char __ar_sip[4]

◆ __ar_tha

u_char __ar_tha[ETH_ALEN]

◆ __ar_tip

u_char __ar_tip[4]

◆ __zero_padding

u_char __zero_padding[18]

◆ arp_header

struct arphdr arp_header

◆ framehdr

struct ethhdr framehdr

◆ payload

u_char* payload