1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/* $Id: xprobe.h,v 1.18 2001/10/20 15:23:55 fygrave Exp $ */
/*
** Copyright (C) 2001 Fyodor Yarochkin <fygrave@tigerteam.net>,
** Ofir Arkin <ofir@sys-security.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** All material for nonprofit, educational use only.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef XPROBE_H
#define XPROBE_H
#include "config.h"
#include <stdio.h>
#include <time.h>
#define IP_VERSION 4
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include <sys/param.h>
#ifndef bzero
#ifdef NOBZERO
#define bzero(x,y) memset((void *)x,(int)0,(size_t) y)
#define bcopy(x,y,z) memcpy((void *)y, (const void *)x, (size_t) z)
#endif /* NOBZERO */
#endif /* bzero*/
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <errno.h>
#ifdef __linux__
#ifdef HAVE_GLIB_H
#include <glib.h>
#endif
#endif
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <time.h>
#include <sys/time.h>
#ifdef __linux__
#define __FAVOR_BSD
#endif
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#ifndef __linux__
#include <netinet/ip_var.h>
#else /* __linux__ */
#include <sys/time.h>
#endif /* __linux__ */
#include <netinet/ip_icmp.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <net/if.h>
#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(SOLARIS) && !defined(__sgi)
#include <net/ethernet.h>
#endif
#ifdef SOLARIS
#include <sys/sockio.h>
#ifndef INADDR_NONE
#define INADDR_NONE -1
#endif
#endif
#include <netinet/if_ether.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <math.h>
#include <signal.h>
#include <pcap.h>
/* some types correction */
#if defined(__FreeBSD__) || defined(__linux__)
#define TIMEZONE_T struct timezone
#else
#define TIMEZONE_T unsigned long
#endif
/* packet pointers calculation */
#define VOIDPTR_T long
typedef struct _rpack {
ssize_t packsize;
void *pkt;
void *orig_pkt;
struct ip *ip, *orig_ip;
struct icmp *icmp;
} rpack_t;
/*
* for portability reasons we maintain ipovly header here.
*/
typedef struct _ipovly {
u_char ih_x1[9]; /* (unused) */
u_char ih_pr; /* protocol */
u_short ih_len; /* protocol length */
struct in_addr ih_src; /* source internet address */
struct in_addr ih_dst; /* destination internet address */
} ipovly_t;
typedef struct _interf {
struct in_addr addr;
struct in_addr net;
struct in_addr netmask;
char iname[IFNAMSIZ + 1];
} inter_t;
typedef struct _hstnet {
unsigned long addr;
unsigned long netmask;
} hstnet_t;
/* external vars */
extern char *optarg;
extern int optind;
extern inter_t interf;
/* locally defined external vars (for ref. from other modules */
extern char *iname; /* interface name we run on, could be NULL */
extern FILE *logfn; /* logfile */
extern char verbose; /* verbosity flag */
extern unsigned short udp_portno;
extern int receive_timeout;
/* function prototypes */
/* general use */
extern void usage(char *);
extern int resolve_target(char *, struct sockaddr_in *);
extern int parse_hostname(char *, hstnet_t *);
extern unsigned long parsemask(char *);
extern unsigned short in_cksum(unsigned short *,int);
struct in_addr get_iface_addr(char *);
unsigned short udp_cksum_calc(struct ip *, struct udphdr *, unsigned short );
void free_res(rpack_t **);
void make_ippkt(struct ip *, unsigned char, struct in_addr, struct in_addr ,
unsigned short, unsigned short, unsigned short);
extern int scan_host(unsigned long);
extern void do_scan(hstnet_t *);
/* icmp routines */
extern int wait_icmp(int , struct sockaddr_in *, unsigned char *, int );
extern int udp_find_closed(struct sockaddr_in);
extern rpack_t *send_udp(struct sockaddr_in);
extern rpack_t *send_icmpts_req(struct sockaddr_in);
extern rpack_t *send_icmpmaskreq_req(struct sockaddr_in);
extern rpack_t *send_icmpireq_req(struct sockaddr_in);
extern rpack_t *send_icmpecho_req(struct sockaddr_in);
rpack_t *send_icmpecho_var_req(struct sockaddr_in, int);
extern int do_logic(struct sockaddr_in);
void tree_message(const char *,...);
void fin_message(const char *,...);
void log_message(const char *,...);
void hexdump(unsigned char *, ssize_t);
int init_pcap(char *, char *, hstnet_t *);
unsigned char *next_pack(ssize_t *);
unsigned char *read_icmp(ssize_t *, int, int);
void read_icmp_timeout(int sig);
/* packet test routines (pkt_exams.c) */
int udp_checksum_ver(rpack_t *);
int icmp_unreach_lencheck(rpack_t *);
int frag_bits_flipped(rpack_t *);
int ip_checksum_ok(rpack_t *);
#include "defines.h"
#endif /* XPROBE_H */
|