Automatisches Einloggen über WSA bei Space Pioneers



  • Guten Morgen.
    ich habe letztens dieses kleine Programm programmiert, was mich bei Space Pioneers einloggen soll. Ich bin jetzt soweit, dass mir der Server die Url sagt, in der ich eingeloggt bin. Doch wenn ich jetzt versuche die per WSA auzurufen, schickt er mir wieder die selbe Meldung...
    und zwar, dass ich jetzt eingeloggt bin... Anschließend setzt er die Cookies nochmal🙄
    hier ist der source:

    #include <cstdlib>
    #include <iostream>
    #include <winsock2.h>
    #include <string>
    #include <fstream>
    
    using namespace std;
    
    int WSAStart()
    {
        WSADATA wsa;
        return WSAStartup(MAKEWORD(2,0), &wsa);
    }
    
    string StringBetween(const string& input, const string& left, const string& right)
    {
        size_t posLeft, posRight;
    
        posLeft = input.find(left);
        posRight = input.find(right);
    
        if (posLeft == string::npos || posRight == string::npos)
        {
            return ""; // Nicht gefunden
        }
    
        posLeft += left.length();
        posRight += right.length();
        string ergebnis1 = input.substr(posLeft, input.length() - right.length() - left.length());
        int formel = (input.find(right) - posLeft);
        string ergebnis2 = ergebnis1.substr(0, formel);
        return ergebnis2;
    } //=======>GRÖßTER TEIL NICHT VON MIR
    
    const string GetCookieData(const string Cookie, string cookie_name)
    {
        const size_t found_pos(Cookie.find(cookie_name));
        string ReturnString;
    
        if(found_pos != std::string::npos)
            for(size_t i(found_pos + cookie_name.length()); // std::string("spgdex")::size() == 6
                Cookie[i] != ';';
                ++i)
                    ReturnString.push_back(Cookie[i]);
    
        return ReturnString;
    } //=====>NICHT VON MIR SONDERN VON Kóyaánasqatsi
    
    void gebaus(char array[])
    {
         for (int i=0;array[i]!=0;i++)
         {
             cout << array[i];
         }
         cout << endl;
    }
    
    string WSAgetDataGet(string ip, string host, string ref = "", string seite = "", string cookie_str = "")
    {
           string data =  "GET " + seite + " HTTP/1.0\r\n"
           "Host: " + host + "\r\n"
           "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.16) Gecko/2009120208 Firefox/3.0.16 (.NET CLR 3.5.30729)\r\n"
           "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
           "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3\r\n"
           "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"
           "Keep-Alive: 300\r\n"
           //"Content-Type: application/x-www-form-urlencoded\r\n"
           "Connection: keep-alive\r\n";
           if (ref!="")
           {
                       data = data + "Referer: " + ref +"\r\n";
           }
           else
           {
               data = data + "\r\n";
           }
           if (cookie_str!="")
           {
           data = data + cookie_str;
           }
           data = data + "\r\n\r\n";
           return data;
    
           return data;
    }
    
    string itostring(int a)
    {
           char length[10];
           itoa(a, length, 10);
           string help;
           help.assign(length);
           return help;
    }
    
    string WSAgetDataPost(string ip, string host, string post, string seite = "", string cookie_str = "")
    {
           string data = "";
           //=======================>länge des Stringes ermitteln
           string help = itostring(post.length());
           //========================>länge des Stringes ermitteln ENDE
           if (cookie_str!="")
           {
           data = "POST " + seite + " HTTP/1.0\r\n"
           "Host: " + host + "\r\n"
           "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.16) Gecko/2009120208 Firefox/3.0.16 (.NET CLR 3.5.30729)\r\n"
           "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
           "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3\r\n"
           "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"
           "Keep-Alive: 300\r\n"
           "Connection: keep-alive\r\n" + cookie_str + "\r\n"
           "Content-Type: application/x-www-form-urlencoded\r\n"
           "Content-Length: "+help+"\r\n\r\n" + post;
           }
           else
           {
           data = "POST " + seite + " HTTP/1.0\r\n"
           "Host: " + host + "\r\n"
           "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.16) Gecko/2009120208 Firefox/3.0.16 (.NET CLR 3.5.30729)\r\n"
           "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"
           "Accept-Language: de-de,de;q=0.8,en-us;q=0.5,en;q=0.3\r\n"
           "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n"
           "Keep-Alive: 300\r\n"
           "Connection: keep-alive\r\n"
           "Content-Type: application/x-www-form-urlencoded\r\n"
           "Content-Length: "+help+"\r\n\r\n" + post;
           }
    
           return data;
    }
    
    string WSARequest(string ip, string host, string seite = "", string ref = "", string post = "", string data = "", string cookie_str = "")
    {
           SOCKET sock;
           if (WSAStart()!=0)
           {
                             cout << "WSA konnte nicht gestartet werden!" << endl;
                             system("pause");
                             return "-1";
           }
           sock = socket(AF_INET, SOCK_STREAM, 0);
           if (sock==INVALID_SOCKET)
           {
                    cout << "Socket konnte nicht erstellt werden!" << endl;     
                    system("pause");
                    return "-1";    
           }
           //================>Ip Adresse konvertieren
           char inet_address[30];
           strcpy(inet_address, ip.c_str());
           //==================>Ip Adresse konvertieren ENDE
           sockaddr_in addr;
           addr.sin_family = AF_INET;
           addr.sin_port = htons(80);
           addr.sin_addr.s_addr = inet_addr(inet_address);
           long rc = connect(sock, (SOCKADDR*)&addr, sizeof(sockaddr));
           if (rc==SOCKET_ERROR)
           {
                                cout << "SOCKET_ERROR: Error beim Verbinden mit " << ip << endl;
                                system("pause");
                                return "-1";
           }
           else
           {
               cout << "Verbindung wurde erfolgreich hergestellt!" << endl;
           }
           //=======================================================================>
           //=================>Verbunden mit Server<================================>
           //=======================================================================>
           if (data=="") {
           if (post=="") //wenn kein Post benutzt werden soll
           {
                data = WSAgetDataGet(ip, host, ref,seite, cookie_str);         
           }
           else
           {
               data = WSAgetDataPost(ip, host, post, seite, cookie_str);
           }
           }
           //===>Senden anfang
           char buffer[data.length()+1];
           strcpy(buffer, data.c_str());
           cout << data << endl;
           rc = send(sock, buffer, sizeof(buffer), 0);
           if (rc==SOCKET_ERROR)
           {
                                cout << "Daten konnten nicht versendet werden!" << endl;
                                system("pause");
                                return "-1";
           }
           //=============>SENDEN ENDE 
           //=======>EMPFANGEN ANFANG
           string source = "";
           strcpy(buffer, "");
           for(;;)
         {
          rc = recv(sock, buffer, sizeof(buffer), 0);
          if(rc == -1)
          {
          cout << "Fehler: " << WSAGetLastError() << '\n';
          break;
          }
    
          if(rc == 0)
          {
           break;
          }
          source.append(buffer, rc);
         } 
         return source;
    
    }
    
    string MakeCookieString(string array[])
    {
           string cookie_string = "Cookie:";
           int counter = atoi(array[0].c_str()) +1;
           string help;
           for (int i = 1;i<counter;i++)
           {
               help = " " + array[i] + ";";
               cookie_string = cookie_string + help;
           }
           cookie_string = cookie_string.substr(0, cookie_string.length() -1);
           return cookie_string;
    }
    
    string getRealLocation(string a)
    {
           return a.substr(0, a.length() - 2);
    }
    
    int main(int argc, char *argv[])
    {
        string post = "anmelden=true&pid=0&zz=-60&old=&x=12&y=3&login=loldgd%40web.de&passwd=test123";
        string seite = "/glogin.shtml";
        string host = "gde.sp.looki.de";
        string ip = "213.202.233.12";
        string source = WSARequest(ip, host, seite);
        string spcheck = StringBetween(source, "Set-Cookie: ", ";");
        //=================================>andere cokkies + location hab ich jetzt
        string cookie_string = "Cookie: " + spcheck + ";";
        source = WSARequest("213.202.233.12", host, seite,"", post, "", cookie_string);
        string location = StringBetween(source, "location: ", "Vary:");
        //=======>cookies extrahieren
        string spgdex = "spgdex" + GetCookieData(source, "spgdex");
        string gsp = "gsp=" + GetCookieData(source, "gsp=");
        string splogin = "splogin" + GetCookieData(source, "splogin");
        string param_array[5];
        param_array[0] = "4";
        param_array[1] = spcheck;
        param_array[2] = gsp;
        param_array[3] = splogin;
        param_array[4] = spgdex;
        cookie_string = MakeCookieString(param_array);
        location = getRealLocation(location);
        //=========>alles nötige extrahiert--->weiter gehts
        system("cls");
        cout << cookie_string << endl;
        system("pause");
        WSARequest(ip, host, location, "http://gde.sp.looki.de/glogin.shtml", "", "", cookie_string);
       //=====>in datei schreiben
        fstream f;
        f.open("hello.html");
        f << source << endl;
        f.close();
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    

    mfg
    @night@


Anmelden zum Antworten