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

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