Пример #1
0
/*-
-- net:device()

Get the device name, maybe be nil.
*/
static int lnet_getdevice(lua_State* L)
{ 
    libnet_t* ud = checkudata(L);
    const char* device = libnet_getdevice(ud);
    if(device)
      lua_pushstring(L, device);
    else
      lua_pushnil(L);

    return 1;
}
Пример #2
0
int main(int argc,char *argv[]){
	int c;
	u_long i;
	libnet_t *l;
	char *device = NULL;
	struct libnet_ether_addr *e;
	char errbuf[LIBNET_ERRBUF_SIZE];

	printf("libnet 1.1 address getter\n");

	while((c = getopt(argc,argv,"i:")) != EOF){
		switch(c){
			case 'i':
				device = optarg;
				break;
			default:
				exit(EXIT_FAILURE);
		}
	}

	//Initialize the library.Root Priviledges are requried.
	l = libnet_init(
			LIBNET_LINK,		/* injection type */
			device,				/* network interface */
			errbuf);			/* errbuf */

	if(l == NULL){
		fprintf(stderr,"libnet_init() failed:%s",errbuf);
		exit(EXIT_FAILURE);
	}

	printf("Interface:\t%s\n",libnet_getdevice(l));
	e = libnet_get_hwaddr(l);
	if(e == NULL){
		fprintf(stderr,"Can't get hardware address:%s\n",libnet_geterror(l));
	}else{
		printf("MAC address:\t");
		for(c=0;c < 6;c++){
			printf("%2.2x",e->ether_addr_octet[c]);
			if(c !=5 )
				printf(":");
		}
		printf("\n");
	}
}
Пример #3
0
int
main (int argc, char **argv)
{
  libnet_t *l;
  char err_buf[LIBNET_ERRBUF_SIZE];
  char *iface = NULL;
  char *src_s = NULL, *victim_s = NULL, *plist_s = NULL;
  libnet_plist_t *plist=NULL;
  struct libnet_in6_addr src, victim;
  int s = 0, d = 0, i = 0, p = 0, opt;
  libnet_ptag_t tcp_tag;
  u_long seq;
  extern char *optarg;
  extern int opterr;

  printf
    ("\n6pack - IPv6 Port Scanner - v0.0002 ( http://genhex.org/projects/6pack/ )\n(c) 2003 Bruno Morisson <*****@*****.**>\n\n");

  while ((opt = getopt (argc, argv, "vTUb:t:i:p:s:d:")) != -1)
    {
      switch (opt)
	{
	case 's':
	  if (s)
	    usage ();
	  src_s = optarg;
	  s++;
	  break;
	case 'd':
	  if (d)
	    usage ();
	  victim_s = optarg;
	  d++;
	  break;
	case 'i':
	  if (i)
	    usage ();
	  iface = optarg;
	  i++;
	  break;
	case 'p':
	  if (p)
	    usage ();
	  plist_s = optarg;
	  p++;
	  break;
	case 'v':
	  verbose++;
	  break;
	case 't':
	  timeout = atoi (optarg);
	  break;
	default:
	  usage ();
	}
    }
  if (d != 1 || p != 1)
    usage ();

  if (!(l = libnet_init (LIBNET_RAW6, iface, err_buf)))
    {
      fprintf (stderr, "error opening raw sock: %s\n", err_buf);
      exit (-1);
    }
  if (!iface)
    iface = libnet_getdevice (l);
  if (libnet_plist_chain_new (l, &plist, plist_s) == -1)
    {
      fprintf (stderr, "invalid portlist %s\n", libnet_geterror (l));
      exit (-1);
    }

  if(s) 
   src = libnet_name2addr6 (l, src_s, LIBNET_RESOLVE);
  else 
   src = libnet_get_ipaddr6(l);

  if (!memcmp
      ((char *) &src, (char *) &in6addr_error, sizeof (in6addr_error)))
    {
      fprintf (stderr, "error in address: %s\n", libnet_geterror (l));
      exit (-1);
    }
  
  victim = libnet_name2addr6 (l, victim_s, LIBNET_RESOLVE);
  if (!memcmp
      ((char *) &victim, (char *) &in6addr_error, sizeof (in6addr_error)))
    {
      fprintf (stderr, "error in address: %s\n", libnet_geterror (l));
      exit (-1);
    }


  printf ("Using device: %s\n", iface);

  tcp_tag = build_pkt (l, &seq, src, victim);

  signal (SIGCHLD, SIG_IGN); /* We really shouldn't do this... */
  if (!collect (iface, seq))
    return -1;

  printf ("Scanning ports %s on %s\n",
	  libnet_plist_chain_dump_string (plist), victim_s);
  send_tcp_pkts (l, plist, tcp_tag, seq);

  return 0;
}