home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / E-zine / Magazines / b4b0 / b4b0-06 / qps.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-05-27  |  4.1 KB  |  188 lines

  1. /*  POPScan QPOP/UCB/SCO scanner by KKR
  2.     kkr@engulf.com
  3.  
  4.     takes list of ip's from stdin
  5.     
  6.    The hosts gathered by this scanner are 
  7.    almost 100% vulnerable to a remote
  8.    root attack.  The exploits used to root
  9.    the vulnerable machines can all be found by
  10.    searching bugtraq.  UCB pop is 100% of the
  11.    time vulnerable to the qpop exploit (it's a very
  12.    old version of qpop).  The QPOP version is 
  13.    filitered to make sure that non-vulnerable 
  14.    versions do not show up in the scan.
  15.    Common offsets for the bsd qpop exploit are:
  16.     621, 1500, 500, 300, 900, 0
  17.  
  18. Example usage:
  19.  
  20. ./z0ne -o ac.uk | ./pops > ac.uk.log &
  21. would scan ac.uk for vulnerabilities.
  22.  
  23. much help from jsbach    
  24.  
  25.  
  26. */
  27.  
  28. #include <stdio.h>
  29. #include <sys/socket.h>
  30. #include <sys/types.h>
  31. #include <netinet/in.h>
  32. #include <signal.h>
  33.  
  34. int ADMtelnet (u_long, int port);
  35. char domain[50];
  36. int NUMCHILDREN = 150, currchilds = 0; /* change numchildren to taste */
  37. char ip[16];
  38. int temp1 = 0;
  39. void scan(char *ip);
  40. void alrm(void) { return; }
  41.  
  42. main()
  43. {
  44.  
  45.    while( (fgets(ip, sizeof(ip), stdin)) != NULL)
  46.           switch(fork()) {
  47.             case 0: {
  48.         scan(ip); exit(0);
  49.             }
  50.             case -1: {
  51.               printf("cannot fork so many timez@!@^&\n");
  52.               exit(0);
  53.               break;
  54.               }
  55.             default:
  56.                 {
  57.                 currchilds++;
  58.                 if (currchilds > NUMCHILDREN)
  59.                   wait(NULL);
  60.                 break;
  61.                 }
  62.       }
  63.  
  64. }
  65.  
  66. void scan(char *ip)
  67. {
  68. char printip[16];
  69. struct sockaddr_in addr;
  70. int sockfd;
  71. char buf[512];
  72.  
  73. bzero((struct sockaddr_in *)&addr, sizeof(addr));
  74. sockfd = socket(AF_INET, SOCK_STREAM, 0);
  75.  
  76. addr.sin_addr.s_addr = inet_addr(ip);
  77. addr.sin_port = htons(110);
  78. addr.sin_family = AF_INET;
  79. signal(SIGALRM, alrm);
  80. alarm(5);
  81. if ( (connect(sockfd, (struct sockaddr *)&addr, sizeof(addr)) != -1))
  82. {
  83. recv(sockfd, (char *)buf, sizeof(buf), 0);
  84.  
  85. if ( (strstr(buf, "QPOP") ) != NULL && (strstr(buf, "2.5")) == NULL && (strstr(buf, "krb")) == NULL)
  86.  {
  87.  checkos(ip,1);
  88. }
  89.  
  90. if((strstr(buf, "UCB")) != NULL)
  91. checkos(ip,2);
  92.  
  93. if((strstr(buf, "SCO")) != NULL)
  94.  {
  95.   strcpy(printip, ip);
  96.   if ((temp1=strrchr(printip, '\n')) != NULL)
  97.    bzero(temp1, 1);
  98.    printf("%s: SCO Unix box running SCO pop.\n",printip);
  99.   } 
  100. }
  101. return;
  102. }
  103. // }
  104.  
  105.  
  106. checkos(char *ip, int spl)
  107. {
  108. int temp2;
  109. char printip[16];
  110. unsigned long temp;
  111. temp = inet_addr(ip);
  112. temp2 = ADMtelnet(temp, 23);
  113.   strcpy(printip, ip);
  114.   if ((temp1=strrchr(printip, '\n')) != NULL)
  115.    bzero(temp1, 1);
  116.  
  117. if ((temp2 == 1)&&(spl==1))
  118.  printf("%s: OpenBSD box running vuln QPOP\n",printip);
  119. if ((temp2 == 1)&&(spl==2))
  120.  printf("%s: OpenBSD box running vuln UCB pop\n",printip);
  121. if ((temp2 == 2)&&(spl==1))
  122.  printf("%s: FreeBSD box running vuln QPOP\n",printip);
  123. if ((temp2 == 2)&&(spl==2))
  124.  printf("%s: FreeBSD box running vuln UCB pop\n",printip);
  125. if ((temp2 == 3)&&(spl==1))
  126.  printf("%s: BSDi box running vuln QPOP\n",printip);
  127. if ((temp2 == 3)&&(spl==2))
  128.  printf("%s: BSDi box running vuln UCB pop\n",printip);
  129.  
  130. }
  131.  
  132. int ADMtelnet (u_long ip, int port)
  133. {
  134.   struct sockaddr_in sin;
  135.   u_char buf[4000];
  136.   int dasock, len;
  137.   int longueur = sizeof (struct sockaddr_in);
  138.  
  139.   dasock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);    /* gimme a socket */
  140.  
  141.   sin.sin_family = AF_INET;
  142.   sin.sin_port = htons (port);
  143.   sin.sin_addr.s_addr = ip;
  144.  
  145.   if (connect (dasock, (struct sockaddr *) &sin, longueur) == -1)
  146.     return (-1);
  147.  
  148.   while (1)
  149.     {
  150.       memset (buf, 0, sizeof (buf));
  151.  
  152.       if ((len = read (dasock, buf, 1)) <= 0)
  153.     break;
  154.  
  155.       if (*buf == (unsigned int) 255)
  156.     {
  157.       read (dasock, (buf + 1), 2);
  158.       if (*(buf + 1) == (unsigned int) 253 && !(u_char) * (buf + 2));
  159.       else if ((u_char) * (buf + 1) == (unsigned int) 253)
  160.         {
  161.           *(buf + 1) = 252;
  162.           write (dasock, buf, 3);
  163.         }
  164.     }
  165.       else
  166.     {
  167.       if (*buf != 0)
  168.         {
  169.           bzero (buf, sizeof (buf));
  170.           read (dasock, buf, sizeof (buf));
  171.           usleep(40000);
  172.  
  173.         if((strstr(buf, "OpenBSD") != NULL)) 
  174.          return 1;
  175.         if((strstr(buf, "FreeBSD") != NULL)) 
  176.          return 2;
  177.         if((strstr(buf, "BSDI") != NULL)) 
  178.         return 3;
  179.    
  180.           sleep (1);
  181.         }
  182.  
  183.     }
  184.  
  185.     }
  186.   return 0;
  187. }
  188.