⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graph.c

📁 Nast是一个基于Libnet 和Libpcap的sniffer包和LAN分析器。它可以在通常模式或混合模式下检查通过网络接口的数据包
💻 C
字号:
/*    NAST    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.    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.*//* Menu working *//* -- don't touch please -- *//* Some code has been ripped by vida * http://freshmeat.net/projects/vida */#include <ncurses.h>#include "include/nast.h"#include <stdarg.h>#define l 25#define OFFSETY 6#define OFFSETX 3/* private funz declaration */void goplugin();void error();void print(const char *format, ...);int build_menu(){   /* TITLE */   char TITLE[30];   char errbuf[PCAP_ERRBUF_SIZE];   libnet_t *L;   u_short pos, i;   u_short promisc, data, hex, lg, f, ld;   char string[20], *ldname, *filter, *logfile, *dev;   u_short ports[] =     {	21,22,23,25,43,53,79,80,110,119,143,220,513,514     };   char *menu[l]=     {	"Sniff packets over the LAN",	  "Specify interface",	  "Set promiscous mode",	  "Print ascii data",	  "Print ascii-hex data",	  "Log data into a file",	  "Apply filter to sniffer or traffic counting",	  "",	  "Check for promiscous node in the LAN",	  "Build hosts list of the LAN",	  "Follow TCP Stream",	  "Try to find a valid gateway",	  "Reset a connection (use with caution)",	  "Port Scanner -SYN style-",	  "Port Scanner all LAN's host -SYN style-",	  "Try to resolve if there's a HUB or a Switch in the LAN",	  "Catch daemon banner for the hosts in the LAN",	  "Follow ARP answer and find possibles ARP poisoning",	  "Run traffic counting (you must set a filter first, set \"any\" to disable it)",	  "",	  "Log common reports to file",	  "",	  "Help",	  "About",	  "Exit"     };   /* end of declaration */   if (demonize)     {	printf ("Can't demonize nast if runned with ncurses menu (-G)!\n");	sleep (2);     }   signal (SIGINT, error);   if (!initscr())     {	perror("\n Error while initializate ncurses: ");	fprintf(stderr,"\n\n");     }   /* find interface */   L = libnet_init (LIBNET_LINK, NULL, errbuf);   /* try to find a suitable device */   dev = libnet_getdevice(L);   libnet_destroy(L);   noecho();   keypad(stdscr,TRUE);   setbuf(stdout, NULL);   setbuf(stderr, NULL);   ldname = filter = logfile = NULL;   pos=0;   promisc=0;   data=0;   hex=0;   lg=0;   ld=0;   f=0;   sprintf (TITLE, "Nast, Network Analizer Sniffer Tool - Version %s", PACKAGE_VERSION);   /* log to stdout for default */   log = stdout;   while (1)     {     	/* title */	attrset (A_BOLD);	mvaddstr (1, (COLS - strlen(TITLE))/2, TITLE);	attrset (A_UNDERLINE);	mvaddstr (4, OFFSETX, "Sniffer/Plugins Options");	attrset (A_NORMAL);	mvaddstr (LINES-3, OFFSETX, "Cmd line : ");        /* graphics */	mvhline (2, 2, 0, COLS-4);	box (stdscr, 0, 0);	/* draw il menu */	for (i=0; i<l; i++)	  {	     if (i==pos)	       {		  attrset (A_REVERSE);		  mvaddstr (i+OFFSETY, OFFSETX, menu[i]);		  attrset (A_NORMAL);	       }	     else	       mvaddstr (i+OFFSETY, OFFSETX, menu[i]);	  }	refresh();	/* enable menu scrolling */	switch (i=getch())	  {	   case KEY_UP:	     pos = pos==0 ? l-1 : pos-1;	     if (pos==7 || pos==19 || pos==21) pos--;	     break;	   case KEY_DOWN:	     pos = pos==l-1 ? 0 : pos+1;	     if (pos==7 || pos==19 || pos==21) pos++;	     break;	   case 'x':	   case 'X':	     endwin();	     system ("clear");	     exit (0);	     break;	   case 'h':	   case 'H':	     goplugin();	     system ("man nast");	     break;	   /* return */	   case 10:	     switch(pos)	       {		/* run sniffer */		case 0:		  goplugin();		  run_sniffer (promisc, data, hex, f, lg, filter, dev, ldname);		  break;		/* interface */		case 1:		  echo();		  print ("Specify device (current is %s) > ", dev);		  getnstr (dev, 10);		  print ("\n");		  noecho();		  break;		/* promiscous mode in sniffing ? */		case 2:		  echo();		  do		    {		       print ("Enable/disable sniffer promiscous mode? (current is %d) > ", promisc);		       getnstr (string, 20);		       print ("\n");		       promisc=atoi(string);		    }		  while (promisc!=0 && promisc!=1);		  noecho();		  break;		/* ascii data */		case 3:		  echo();		  do		    {		       print ("Enable/disable printing ASCII data (current is %d) > ", data);		       getnstr(string, 20);		       print("\n");		       data=atoi(string);		    }		  while (data!=0 && data!=1);		  noecho();		  break;		/* ascii hex data */		case 4:		  echo();		  do		    {		       print ("Enable/disable printing ASCII-HEX data (current is %d) > ", hex);		       getnstr(string, 20);		       print("\n");		       hex=atoi(string);		    }		  while (hex!=0 && hex!=1);		  noecho();		  break;		/* data sniffed logging */		case 5:		  echo();		  do		    {		       print ("Enable/disable sniffed data (current is %d) > ", ld);		       getnstr (string, 20);		       print ("\n");		       ld = atoi (string);		    }		  while (ld!=0 && ld!=1);		  if (ld)		    {		       if (ldname==NULL) ldname=calloc(30, sizeof(char));		       print ("Specify logfile name (current is %s) > ", ldname);		       getnstr(ldname, 30);		    }		  print ("\n");		  noecho();		  break;		/* Filter */		case 6:		  echo();		  if (!f) f=1;		  if (filter==NULL) filter=calloc(30, sizeof(char));		  print ("Apply filter (current is %s) > ", filter);		  getstr(filter);		  print("\n");		  noecho();		  break;		/* check prom */		case 8:		  echo();		  print ("IP (type all for query all hosts) > ");		  getnstr (string, 20);		  print ("\n");		  noecho();		  goplugin();		  if (strcmp (string, "all")) psearch(dev, libnet_name2addr4(NULL, string, LIBNET_RESOLVE), lg);		  else psearch(dev, 0, lg);		  printf ("\nWe have done, press a key");		  getchar();		  break;           	/* map host lan */		case 9:		  goplugin();		  map_lan (dev, 1, NULL);		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* tcp stream */		case 10:		  goplugin();		  runcplx ('s', dev ,lg );		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* find gw */		case 11:		  goplugin();		  fgw(dev);		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* reset connection */		case 12:		  goplugin();		  runcplx ('r', dev ,lg );		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* port scanner */		case 13:		  goplugin();		  runcplx ('S', dev, lg );		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* multi-host port scanner */		case 14:		  goplugin();		  runcplx ('M', dev, lg );		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* find the LINK */		case 15:		  goplugin();		  flink (dev);		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* BANNER */		case 16:		  goplugin();		  mport (dev, ports,lg);		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* CAR */		case 17:		  goplugin();		  car (dev,lg);		  printf ("\nWe have done, press a key");		  getchar();		  break;		/* tc */		case 18:		  if (!f)		    {		       print ("You must specify pattern before!");		       sleep (1);		       echo();		       f=1;		       if (filter==NULL) filter=calloc(30, sizeof(char));		       print ("Apply filter (current is %s) > ", filter);		       getstr(filter);		       print("\n");		       noecho();		    }		  goplugin();		  run_bc (dev, filter);		  break;	        /* Sniffer logging */		case 20:		  echo();		  do		    {		       print ("Enable/disable logging (current is %d) > ",lg);		       getnstr (string, 20);		       print ("\n");		       lg = atoi (string);		    }		  while (lg!=0 && lg!=1);		  if (lg)		    {		       if (logfile==NULL) logfile=calloc(30, sizeof(char));		       print ("Specify logfile name (current is %s) > ", logfile);		       getnstr(logfile, 30);		       logname = logfile;		    }		  print ("\n");		  noecho();		  break;      		/* help */		case l-3:		  goplugin();		  system ("man nast");		  break;		/* About */		case l-2:		  mvaddstr (LINES-3, OFFSETX, "- NAST IS DEVELOPED FOR FUN AND PROFIT UNDER GPL LICENSE (EMBYTE, SNIFTH) -");		  refresh();		  getchar(); print("\n");		  break;		/* quit */		case l-1:		  endwin();		  system ("clear");		  exit (0);		  break;	       }	  }     }   return 1;}void goplugin(){   clear();   refresh();   endwin();   system ("clear");}/* catch ctrl+C (SIGINT signal) */void error(){   clear();   refresh();   endwin();   system ("clear");   exit (0);}void print (const char *format, ...){   char s[100];   va_list  ap;   va_start (ap, format);   vsprintf (s, format, ap);   mvaddstr(LINES-3, OFFSETX+11, "\n");   mvaddstr(LINES-3, OFFSETX+11, s);   refresh();   va_end (ap);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -