Visualizzazione risultati 1 fino 10 di 10

Discussione: Problema connessione via socket dal mio software...

  1. #1
    devtheboss non è connesso Utente Blog
    Data registrazione
    16-05-2022
    Messaggi
    3

    Predefinito Problema connessione via socket dal mio software...

    Salve sono un programmatore di visual studio c++... stavo facendo dei test per connettere il mio software per comunicare da PHP a C++ e viceversa

    Scusate per il mio cattivo italiano manco dal italia da circa 22 anni.

    source per la richiesta c++

    Codice:
    string cTool::SendRequest(string Host, string Path, string Params)
    {
    	if (sockets->Connection(Host, 80))
    	{
    		char* szHeader = new char[1024];
    		help->strcpy(szHeader,"GET ");
    		help->strcat(szHeader, Path.c_str());
    		help->strcat(szHeader,"?");
    		help->strcat(szHeader, Params.c_str());
    		help->strcat(szHeader," HTTP/1.0");
    
    		char szHost[256] = "";
    		help->strcpy(szHost,"Host: ");
    		help->strcat(szHost, Host.c_str());
    
    		sockets->SendLine(szHeader);
    		sockets->SendLine(szHost);
    
    		sockets->SendLine("User-Agent: GHClient");
    		sockets->SendLine("Accept: text/html");
    		sockets->SendLine("Keep-Alive: 300");
    		sockets->SendLine("Connection: keep-alive");
    		sockets->SendLine("");
    
    
    		string ret = sockets->ReceiveBytes();
    		ret = ret.substr(ret.find("\r\n\r\n") + 4);
    
    		sockets->Close();
    		return ret;
    	}
    }
    
    
    #define STRING_SOCKET_HOST           "devtheboss.altervista.org"
    #define STRING_SOCKET_PATH           "/streamer/stream.php"
    
    string hUrl = tool->SendRequest(STRING_SOCKET_HOST,STRING_SOCKET_PATH,base64(base64(Data)));
    
    
    logs->add_log("hUrl Reponse (%s) ", hUrl.c_str()); // Quando il risultato della risposta ricevo 
    
    
    hUrl Reponse (<html><title>Bad request</title><head></head><body><p>Anomalia nella richiesta al sito, se il problema persiste <b>cancella i cookie</b>, <a href='https://support.google.com/accounts/answer/32050?hl=it' target='_blank'>maggiori informazioni<

    P.S tutte la richieste sono cryptate in base64 per evitare propio questo. però non riesco lo stesso a ricevere la risposta esetta, pero lo stesso url aperto dal browser funziona. ( Quando avevo cloudflare attivo funzionava perchè sicuramente mi manca qualche header nella richiesta ).

    ho provato a loggarmi gli header inviati dal browser ed emularli alla stessa maniera. pero niente.

    l'errore che ricevo nella risposta e Bad request
    ho controllarlo l'url ed e perfetto non ci stanno simboli strani o caratteri speciali.
    però niente.
    Ultima modifica di devtheboss : 09-08-2022 alle ore 18.16.02

  2. #2
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,247

    Predefinito

    Hai provato eliminando il parametro User-Agent?

    Hai modo di indicarmi tutta la stringa della richiesta? (stringa generata).

    Ciao!

  3. #3
    devtheboss non è connesso Utente Blog
    Data registrazione
    16-05-2022
    Messaggi
    3

    Predefinito

    certo ecco la stringa da browser se la apro funziona bene
    se l'avvio con il socket returna bad request,

    L'userAgent Poco importa in questo caso.

    cmq ho provato molteplice header e come la richiesta generata dai socket non viene accettata si dovrebbe vedere la risposta nel server principale x.x

    sotto il base 64 ci si trova anche L'AES 256 CBC però la encodo in base64 2 volte propio x evitare i caratteri speciali .

    http://devtheboss.altervista.org/GHL...pwRS9zUkE9PQ==


    P.S quando c'era cloudflare la richiesta entrava una bomba. sicuramente sarà qualcosa nel server principale che filtra la richiesta. forse perchè il server l'identifica come una minaccia e capisce che non sia un browser.


    adesso tipo sto provando con altri api winnet però sono limitate e ritardate. però queste api sono molto limitate e non posso fare quello che vorrei ... tipo l'internetreadfile non legge grossi buffer neanche loppando dal php to c++ because of this reason i can't handle my test ... maybe you guys can help me around to fix it, by checking originary server request ? thank you so much

    Codice:
    int UrlGetPage(char* link, char* buffer, int maxsize)
    {
    	HINTERNET hSession;
    	HINTERNET hURL;
    	DWORD dwBYTEsRead = 0;
    	int ok;
    	ok = 0;
    	buffer = new char [maxsize];
    	hSession = InternetOpenA("GHClient", 0x1, NULL, NULL, 0);
    	if (hSession)
    	{
    		hURL = InternetOpenUrl(hSession, link, NULL, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0);
    		if (hURL)
    		{
    
    		BOOL hInternet = InternetReadFile(hURL, (LPSTR)buffer, (DWORD)maxsize, &dwBYTEsRead);
    
    		if (!hInternet)
    			logs->add_log("GetLastError %d", GetLastError());
    
    
    			InternetCloseHandle(hURL);
    			buffer[dwBYTEsRead] = 0;
    			ok = (int)dwBYTEsRead;
    		}
    		InternetCloseHandle(hSession);
    	}
    	return ok;
    }
    Ultima modifica di devtheboss : 09-08-2022 alle ore 21.32.25

  4. #4
    devtheboss non è connesso Utente Blog
    Data registrazione
    16-05-2022
    Messaggi
    3

    Predefinito

    Se è possibie sapere che tipo di richieste http accetta il server principale in modo tale da poter sistemare il codice .

  5. #5
    devtheboss non è connesso Utente Blog
    Data registrazione
    16-05-2022
    Messaggi
    3

    Predefinito

    credo che sia per via del https che non si può disattivare

    GET /GHLoader/stream.php?Ve=RU9kajNDREFJdElFRy9ZdnBTNUxaZ0JWRWRM RklTNjQrSSsyTmlKcGxDVzFFVGlrWVZRcDd5VWlCL2lhVmY2Zn U5VVA5WmV6eXlOMmNqTTZ6SFVyOEE9PQ== HTTP/1.0

    Host: devtheboss.altervista.org

    Accept: text/html

    Keep-Alive: 300

    Connection: keep-alive



    reponse <html><title>Bad request</title><head></head><body><p>Anomalia nella richiesta al sito, se il problema persiste <b>cancella i cookie</b>, <a href='https://support.google.com/accounts/answer/32050?hl=it' target='_blank'>maggiori informazioni</a></l

  6. #6
    devtheboss non è connesso Utente Blog
    Data registrazione
    16-05-2022
    Messaggi
    3

    Predefinito

    Codice:
    cosi effettuo la connessione al host. devtheboss,altervista.org nella porta 80
    
    bool cSocket :: Connection ( const  string host, int port )
    {
    	WSADATA info;
    	if (WSAStartup(MAKEWORD(2,0),&info))
    	   return false;
    
    	hostent *he = gethostbyname(host.c_str());
    	if(!he)
           return false;
    
        s_ = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    
    	sockaddr_in addr;
    	addr.sin_family = AF_INET;
    	addr.sin_port = htons(port);
    	addr.sin_addr = *((in_addr *)he->h_addr);
    	help->memset(&(addr.sin_zero),0,8); 
    
    	if ( connect(s_,(sockaddr *)&addr,sizeof(sockaddr)) ) 
    		return false;
    
    	return true;
    }

  7. #7
    devtheboss non è connesso Utente Blog
    Data registrazione
    16-05-2022
    Messaggi
    3

    Predefinito

    Problema risolto.

    Issue fixed

    thank you so much.

    i just change header and sent them as browser.

  8. #8
    L'avatar di alemoppo
    alemoppo non è connesso Staff AV
    Data registrazione
    24-08-2008
    Residenza
    PU / BO
    Messaggi
    22,247

    Predefinito

    Citazione Originalmente inviato da devtheboss Visualizza messaggio
    i just change header and sent them as browser.
    Ottimo! Il problema era quindi l'User-Agent?

    Ciao!

  9. #9
    devtheboss non è connesso Utente Blog
    Data registrazione
    16-05-2022
    Messaggi
    3

    Predefinito

    si ti confermo nella richiesta non arrivava l'user agent me ne sono accorto in locale nelle richieste e log del apache.

  10. #10
    devtheboss non è connesso Utente Blog
    Data registrazione
    16-05-2022
    Messaggi
    3

    Predefinito

    ecco anche il re work out. con la fix applicata e il modo di inviare la richiesta diversa.
    Codice:
     
    string cTool :: SendRequest ( string Host, string Path, string Params  )
    {
    	VMProtectBeginMutation("SendRequest");
    	if ( sockets->Connection (Host,80) )
    	{
    		char * szHeader = new char [1024];
    
    		sprintf(szHeader,"GET %s?%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: GHClient\r\nAccept: text/html\r\nAccept-Language: en-us,en;q=0.5\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nKeep-Alive: 300\r\nConnection: keep-alive\r\nCache-Control: no-cache\r\n\r\n", Path.c_str(),Params.c_str(),Host.c_str());	
    		sockets->SendLine(szHeader);
    
    		string ret = sockets->ReceiveBytes();
    		ret = ret.substr(ret.find("\r\n\r\n")+4);
    		
    		sockets->Close();
    		return ret;
    	}
    	VMProtectEnd();
    }

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •