home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz KrOnIcKLeZ 3 / HaCKeRz_KrOnIcKLeZ.iso / ircscripts / warirc / eprobe2.c < prev    next >
C/C++ Source or Header  |  1996-04-23  |  3KB  |  93 lines

  1. #include "tcpip.h"
  2.  
  3. void ssyn(int sendsock, u_long srcaddr, u_long dstaddr, u_short srcport, 
  4.     u_short dstport, u_long seq)
  5. {
  6.   char *pack, *tpack;
  7.   int sent;
  8.   struct sockaddr_in stuffz;
  9.  
  10.   tpack = create_tcp(srcaddr, dstaddr, htons(srcport),
  11.             htons(dstport), htonl(seq), 0, TH_SYN, NULL, 0);
  12.   pack  = create_ip (srcaddr, dstaddr, IPPROTO_TCP, 75, 1,
  13.             tpack, 20);
  14.   stuffz.sin_family      = AF_INET;
  15.   stuffz.sin_port        = htons(dstport);
  16.   stuffz.sin_addr.s_addr = dstaddr;
  17.   sent  = sendto(sendsock, pack, 40, 0, (struct sockaddr *)&stuffz, 
  18.             sizeof(stuffz));
  19.   if (sent != 40) { perror("sending SYN"); exit(-1); }
  20. }
  21. int getpack(int listsock, u_long srcaddr, u_long dstaddr, u_short srcport, 
  22.     u_short dstport, u_long seq)
  23. {
  24.  return 1;
  25. }
  26.  
  27. main (int c, char *v[])
  28. {
  29.   int ssock, lsock;
  30.   struct hostent *hent;
  31.   struct servent *srvent;
  32.   u_long us, them, fuckk;
  33.   u_short sport, eport;
  34.   u_short skrap;
  35.   u_char flags;
  36.   char mahname[80];
  37.   struct tcphdr *tcphead;
  38.  
  39.   if (c!=4) { printf("usage: %s <host> <start port> <end port>\n", v[0]);
  40.      exit(-1); }
  41.   gethostname(mahname, 79);
  42.   hent = gethostbyname(mahname);
  43.   if (hent == NULL) {
  44.     printf("couldn't get my hostname!@#\n");
  45.     exit(-1);
  46.   }
  47.   bcopy(hent->h_addr, (char *)&us, hent->h_length);
  48.   hent = gethostbyname(v[1]);
  49.   if (hent!=NULL)
  50.     bcopy(hent->h_addr, (char *)&them, hent->h_length);
  51.   else {
  52.     printf("could not resolve: %s\n", v[1]);
  53.     exit(-1);
  54.   }
  55.   sport = atoi(v[2]);
  56.   if (sport==0) {
  57.     printf("can't use %s as a starting port..\n", v[2]);
  58.     exit(-1);
  59.   }
  60.   eport = atoi(v[3]);
  61.   if (eport==0) {
  62.     printf("can't use %s as an ending port..\n", v[3]);
  63.     exit(-1);
  64.   }
  65.   ssock = socket(AF_INET, SOCK_RAW, 255);
  66.   if (ssock == -1) { perror("getting send socket"); exit(-1); }
  67.   lsock = socket(AF_INET, SOCK_RAW, 6);
  68.   if (lsock == -1) { perror("getting listen socket"); exit(-1); }
  69.   printf("active ports between: %d and %d:\n", sport, eport);
  70.   for (skrap=sport;skrap<eport+1; skrap++) {
  71.     ssyn(ssock, us, them, getpid()+skrap, skrap, 10000000+skrap+getpid());
  72.     usleep(100);
  73.     tcphead = read_tcp();
  74.     while ((ntohs(tcphead->th_sport) != getpid()+skrap) & 
  75.       (ntohs(tcphead->th_dport) != skrap) & ((tcphead->th_flags == TH_SYN) || 
  76.       (tcphead->th_flags == TH_RST))) {
  77.         tcphead = read_tcp();
  78.       }
  79.     if (tcphead->th_flags & TH_SYN) {
  80.       fuckk = tcphead->th_ack - ntohs(tcphead->th_sport) - getpid();
  81.       if (fuckk = 26777216) {
  82.         srvent = getservbyport(tcphead->th_sport, "tcp");
  83.         if (srvent != 0) 
  84.           printf("%s.%d(%s)\n", v[1], ntohs(tcphead->th_sport), srvent->s_name);
  85.         else
  86.           printf("%s.%d\n", v[1], ntohs(tcphead->th_sport));
  87.         execl("rst %s %d %s %d %ul", gethostbyname(mahname), getpid()+skrap, gethostbyname(v[1]), skrap, htonl(seqnum));
  88.  
  89.       }
  90.     } 
  91.   }
  92. }
  93.