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
|
/* $Id: xprobe.c,v 1.12 2001/10/14 18:48:01 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.
*/
#include "xprobe.h"
TIMEZONE_T tz;
/* global flags */
int receive_timeout = DEF_TIMEOUT;
char verbose = 0;
unsigned short udp_portno = 0;
FILE *logfn = NULL;
int main(int argc, char **argv) {
hstnet_t targnet;
int c;
char *iname = NULL;
char *logfile = NULL;
fprintf(stderr,"%s\n",BANNER);
while((c = getopt(argc, argv, "vi:p:ho:t:")) !=EOF)
switch(c) {
case 'v':
verbose++;
break;
case 'o':
logfile = optarg;
break;
case 'i':
iname = optarg;
break;
case 't':
receive_timeout = atoi(optarg);
if (receive_timeout <1) {
fprintf(stderr,"Incorrect receive timeout %s\n", optarg);
usage(argv[0]);
}
break;
case 'p':
udp_portno = (unsigned short)atoi(optarg);
if (!udp_portno) {
fprintf(stderr,"Incorrect port number %s!\n", optarg);
usage(argv[0]);
}
break;
case 'h':
default:
usage(argv[0]);
}
if (argc < optind + 1)
usage(argv[0]);
if (parse_hostname(argv[optind],&targnet)<0) {
fprintf(stderr,"error while parsing/resolving: %s\n",
argv[optind]);
exit(1);
}
if(init_pcap(iname, argv[optind], &targnet) < 0) {
fprintf(stderr,"Failed to initialize lipcap!\n");
exit(1);
}
if (logfile) {
if (( logfn = fopen(logfile,"a")) == NULL) {
fprintf(stderr,"Error opening file %s: %s\n",
logfile, strerror(errno));
exit(1);
}
if (verbose)
printf("Logging into: %s\n", logfile);
} else {
logfn = stderr;
}
srand(time(NULL)); /* let us look random abit */
do_scan(&targnet);
if (logfile)
fclose(logfn);
return 0;
}
void usage(char *name) {
fprintf(stderr,"usage: %s [-p portnum] [-i interface] [-v]"
" host[/netmask] [-o logfile]\n", name);
exit(1);
}
void do_scan(hstnet_t *targ) {
struct sockaddr_in to;
unsigned long targhost;
to.sin_family = AF_INET;
bcopy((void *)&targ->addr,(void *)&to.sin_addr,
sizeof(struct in_addr));
log_message("Target: %s", inet_ntoa(to.sin_addr));
bcopy((void *)&targ->netmask,(void *)&to.sin_addr,
sizeof(struct in_addr));
log_message("Netmask: %s", inet_ntoa(to.sin_addr));
targhost = ntohl(targ->addr);
do {
scan_host(htonl(targhost));
} while(htonl(targhost++) != (targ->addr|
(targ->netmask^0xffffffff)));
}
int scan_host(unsigned long host) {
struct sockaddr_in to;
to.sin_family = AF_INET;
bcopy((void *)&host,(void *)&to.sin_addr,
sizeof(struct in_addr));
log_message("probing: %s", inet_ntoa(to.sin_addr));
return(do_logic(to));
}
|