OpenVAS Scanner 23.23.1
nasl_builtin_synscan.c File Reference

Port scanner Synscan. More...

#include "../misc/bpf_share.h"
#include "../misc/network.h"
#include "../misc/pcap_openvas.h"
#include "../misc/plugutils.h"
#include "nasl_builtin_plugins.h"
#include "nasl_lex_ctxt.h"
#include <arpa/inet.h>
#include <gvm/base/logging.h>
#include <gvm/base/prefs.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

Data Structures

struct  pseudohdr
struct  list

Macros

#define _BSD_SOURCE   1
#define _DEFAULT_SOURCE   1
#define NUM_RETRIES   2
#define G_LOG_DOMAIN   "lib nasl"
 GLib logging domain.

Functions

static int in_cksum (u_short *p, int n)
static unsigned long maketime ()
static struct timeval timeval (unsigned long val)
static unsigned long compute_rtt (unsigned long then)
static int packetdead (unsigned long then)
static int rawsocket (int family)
 Opens and returns a raw socket.
static int openbpf (struct in_addr dst, struct in_addr *src, int magic)
 Opens a packet filter, grabs packets from dst to port magic.
static int v6_openbpf (struct in6_addr *dst, struct in6_addr *src, int magic)
static struct listget_packet (struct list *l, unsigned short dport)
static struct listadd_packet (struct list *l, unsigned short dport, unsigned long ack)
 If no packet with dport is in list, prepends a "packet" to the.
static struct listrm_packet (struct list *l, unsigned short dport)
static struct listrm_dead_packets (struct list *l, int *retry)
static struct tcphdr * extracttcp (char *pkt, unsigned int len)
static struct tcphdr * v6_extracttcp (char *pkt)
static unsigned long extractack (char *pkt, int len, int family)
static unsigned short extractsport (char *pkt, int len, int family)
static int issynack (char *pkt, int len, int family)
static char * mktcp (struct in_addr src, int sport, struct in_addr dst, int dport, unsigned long th_ack, unsigned char flag)
static char * mktcpv6 (int sport, int dport, unsigned long th_ack, unsigned char flag)
static struct listsendpacket (int soc, int bpf, int skip, struct in_addr dst, struct in_addr src, int dport, int magic, struct list *packets, unsigned long *rtt, int sniff, struct script_infos *env)
static struct listv6_sendpacket (int soc, int bpf, int skip, struct in6_addr *dst, int dport, int magic, struct list *packets, unsigned long *rtt, int sniff, struct script_infos *env)
static int scan (struct script_infos *env, char *portrange, struct in6_addr *dst6, unsigned long rtt)
tree_cellplugin_run_synscan (lex_ctxt *lexic)

Detailed Description

Port scanner Synscan.

Macro Definition Documentation

◆ _BSD_SOURCE

#define _BSD_SOURCE   1

◆ _DEFAULT_SOURCE

#define _DEFAULT_SOURCE   1

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "lib nasl"

GLib logging domain.

◆ NUM_RETRIES

#define NUM_RETRIES   2

Function Documentation

◆ add_packet()

struct list * add_packet ( struct list * l,
unsigned short dport,
unsigned long ack )
static

If no packet with dport is in list, prepends a "packet" to the.

list l.

◆ compute_rtt()

unsigned long compute_rtt ( unsigned long then)
static

◆ extractack()

unsigned long extractack ( char * pkt,
int len,
int family )
static

◆ extractsport()

unsigned short extractsport ( char * pkt,
int len,
int family )
static

◆ extracttcp()

struct tcphdr * extracttcp ( char * pkt,
unsigned int len )
static

◆ get_packet()

struct list * get_packet ( struct list * l,
unsigned short dport )
static
Returns
First pointer to list in l with the given dport , NULL if no such list item could be found.

◆ in_cksum()

int in_cksum ( u_short * p,
int n )
static

◆ issynack()

int issynack ( char * pkt,
int len,
int family )
static

◆ maketime()

unsigned long maketime ( )
static

◆ mktcp()

char * mktcp ( struct in_addr src,
int sport,
struct in_addr dst,
int dport,
unsigned long th_ack,
unsigned char flag )
static

◆ mktcpv6()

char * mktcpv6 ( int sport,
int dport,
unsigned long th_ack,
unsigned char flag )
static

◆ openbpf()

int openbpf ( struct in_addr dst,
struct in_addr * src,
int magic )
static

Opens a packet filter, grabs packets from dst to port magic.

Parameters
[out]srcin_addr of source.
[in]dstDestination.
[in]magicDestination port on src to listen to.
Returns
A bpf that listens to tcp packets coming from dst to port magic.

◆ packetdead()

int packetdead ( unsigned long then)
static

◆ plugin_run_synscan()

tree_cell * plugin_run_synscan ( lex_ctxt * lexic)

◆ rawsocket()

int rawsocket ( int family)
static

Opens and returns a raw socket.

◆ rm_dead_packets()

struct list * rm_dead_packets ( struct list * l,
int * retry )
static

◆ rm_packet()

struct list * rm_packet ( struct list * l,
unsigned short dport )
static

◆ scan()

int scan ( struct script_infos * env,
char * portrange,
struct in6_addr * dst6,
unsigned long rtt )
static
Returns
-1 if the socket could not be opened (error), 0 otherwise.

This will send packets to ports not in ports list, will it?

Todo
How to do this for ipv6? This causes much scan delay for IPv6.

◆ sendpacket()

struct list * sendpacket ( int soc,
int bpf,
int skip,
struct in_addr dst,
struct in_addr src,
int dport,
int magic,
struct list * packets,
unsigned long * rtt,
int sniff,
struct script_infos * env )
static
Parameters
sniffIf != 0, "sniff" (listen to incoming packages), else just add packet.

◆ timeval()

struct timeval timeval ( unsigned long val)
static

◆ v6_extracttcp()

struct tcphdr * v6_extracttcp ( char * pkt)
static

◆ v6_openbpf()

int v6_openbpf ( struct in6_addr * dst,
struct in6_addr * src,
int magic )
static

◆ v6_sendpacket()

struct list * v6_sendpacket ( int soc,
int bpf,
int skip,
struct in6_addr * dst,
int dport,
int magic,
struct list * packets,
unsigned long * rtt,
int sniff,
struct script_infos * env )
static