4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
#include "include/nast.h"
27
/* run complex plugins here */
29
/* r: reset a connection
30
* s: follow tcp stream
32
* S: single port_scanner
35
int runcplx (char what, char *dev, int l)
37
u_long ip_dst, ip_src;
38
u_short port_dst, port_src;
39
libnet_plist_t plist, *plist_p;
43
char errbuf[PCAP_ERRBUF_SIZE];
46
if ((L = libnet_init (LIBNET_LINK, NULL, errbuf))==NULL)
48
w_error(1,"Error loading libnet core!\n");
54
/* don't touch here */
56
puts ("Type connection extremes");
57
puts ("------------------------");
60
if (i) printf ("Cannot resolve input address, type again!\n");
61
printf ("1 ip / hostname : ");
62
fgets (buff, 50, stdin);
63
if ((ip_src = libnet_name2addr4(L, dn (buff), LIBNET_RESOLVE))==-1)
65
w_error(1,"Error: %s\n", libnet_geterror(L));
72
printf ("1 port (0 to autodetect) : ");
73
fgets (buff, 50, stdin);
74
port_src = atoi(buff);
77
if (i) printf ("Cannot resolve input address, type again!\n");
78
printf ("2 ip / hostname : ");
79
fgets (buff, 50, stdin);
80
if ((ip_dst = libnet_name2addr4(L, dn (buff), LIBNET_RESOLVE))==-1)
82
w_error(1, "Error: %s\n", libnet_geterror(L));
89
printf ("2 port (0 to autodetect) : ");
90
fgets (buff, 50, stdin);
91
port_dst = atoi(buff);
92
if (!port_src && !port_dst)
94
printf ("\nOnly one port can be zero\n");
103
printf ("Is very useless demonize me now! Omit\n\n");
105
rst (dev, ip_src, ip_dst, port_src, port_dst);
109
puts ("Type connection extremes");
110
puts ("------------------------");
113
if (i) printf ("Cannot resolve input address, type again!\n");
114
printf ("1st ip : ");
115
fgets (buff, 50, stdin);
116
if ((ip_src = libnet_name2addr4(L, dn (buff), LIBNET_RESOLVE))==-1)
118
w_error(1,"Error: %s\n", libnet_geterror(L));
122
while (ip_src == -1);
123
printf ("1st port : ");
124
fgets (buff, 50, stdin);
125
port_src = atoi(buff);
130
if (i) printf ("Cannot resolve input address, type again!\n");
132
fgets (buff, 50, stdin);
133
if ((ip_dst = libnet_name2addr4(L, dn (buff), LIBNET_RESOLVE))==-1)
135
w_error(1, "Error: %s\n", libnet_geterror(L));
140
while (ip_dst == -1);
141
printf ("2nd port : ");
142
fgets (buff, 50, stdin);
143
port_dst = atoi(buff);
151
stream (dev, ip_src, ip_dst, port_src, port_dst,l);
155
printf("Port Scanner extremes\n");
156
printf("Insert IP to scan : ");
157
fgets(buff ,50 ,stdin);
158
if ((ip_dst = libnet_name2addr4(L, dn(buff), LIBNET_RESOLVE))==-1)
160
w_error(1, "Error: %s\n", libnet_geterror(L));
165
printf("Insert Port range : ");
166
fgets(buff ,50 ,stdin);
168
while (atoi(dn(buff)) < 1 || atoi(dn(buff)) > 65536);
170
if (libnet_plist_chain_new(L, &plist_p, dn(buff)) == -1)
172
w_error(1, "Bad token in port list: %s\n",libnet_geterror(L));
178
printf ("Is very useless demonize for single portscan! Omit\n\n");
180
port(dev,ip_dst,plist_p,l);
184
printf("Port Scanner extremes\n");
187
printf("Insert Port range : ");
188
fgets(buff ,50 ,stdin);
190
while (atoi(dn(buff)) < 1 || atoi(dn(buff)) > 65536);
192
if (libnet_plist_chain_new(L, &plist_p, dn(buff) )== -1)
194
w_error(1, "Bad token in port list: %s\n",libnet_geterror(L));
202
mhport (dev,plist_p,l);
206
if (L) libnet_destroy(L);
214
if (s[strlen(s)-1]=='\n')
219
/* open a file to log to */
222
if ((logd = (fopen(logname,"w"))) == NULL)
224
w_error(1, "Unable to open logfile descriptor: %s\n\n", strerror(errno));
231
#ifdef HAVE_LIBNCURSES
232
# include <ncurses.h>
236
printf("Thank you for using NAST\n\n");
242
if (!tr && sniff_glob)
244
if (pcap_stats(descr,&statistic) < 0)
245
w_error(1, "Error: pcap_stats: %s\n", pcap_geterr(descr));
248
printf("\n\nPackets Received:\t\t%d\n", statistic.ps_recv);
249
printf("Packets Dropped by kernel:\t%d\n", statistic.ps_drop);
254
pcap_dump_close(dumper);
262
/* demonize process */
266
printf ("\nRunning in background with PID %d\n", getpid());
271
/* convert u_char to "##:##:##...##" format */
272
char * nast_hex_ntoa (u_char *s)
274
char *r = calloc (18, sizeof (char));
276
sprintf (r, "%02X:%02X:%02X:%02X:%02X:%02X",
277
s[0], s[1], s[2], s[3], s[4], s[5]);
282
/* convert u_char[4] to "###.###.###.###" format */
283
char * nast_atoda (u_char *s) /* array to dot array */
285
char *r = calloc (16, sizeof (char));
287
sprintf (r, "%d.%d.%d.%d", s[0], s[1], s[2], s[3]);
292
void n_print(char *wins, int y, int x, int lg, char *string, ...)
298
va_start(ap, string);
299
n = vsnprintf(msg, 2048, string, ap);
310
fprintf(logd,"%s\n",msg);
315
#ifdef HAVE_LIBNCURSES
318
fprintf(logd,"%s",msg);
319
ng_print(wins,y,x,msg);
323
ng_print(wins,y,x,msg);