2013-04-27 20 views
8

Desidero accedere al mio account Facebook con Indy. La versione è 9.00.10 e utilizzo OpenSSL con TIDHTTP e gli ho assegnato un cookie manager. Tutto funziona benissimo (posso inviare una richiesta POST a GET, ecc)Accedi a Facebook con Indy

ho fiutato il login reale con i tuoi amici e ho le seguenti informazioni:

  • AgenteUtente: Mozilla/5.0 (Windows; U ; Windows NT 6.0; en-US; rv: 1.9.2) Gecko/Firefox 20.100.115/3.6 (.NET CLR 3.5.30729)

  • ci sono diversi parametri POST:

    • LSD = ho non ho idea di cosa sia.
    • email = L'effettivo nome utente/email di Facebook.
    • pass = La password (non crittografata) -> Sono rimasto scioccato nel vedere testo in chiaro.
    • default_persistent = (0 o 1) per "mantieni il login"
    • timezone = Codice fuso orario.
    • lgnrnd = Non ho idea di cosa sia.
    • lgnjs = Non ho idea di cosa sia.
    • locale = posizione GeoIP (e.x. en_US)

Il post è effettuata sulla https://www.facebook.com/login.php?login_attempt=1. Tuttavia, quando provo ad accedere, restituisco che ho inserito un'e-mail errata. Sono sicuro di aver usato l'eMail e la password giuste.

Ecco il mio codice:

procedure TForm1.Button1Click(Sender: TObject); 
var 
    TEST : STRING; 
    lParamList: TStringList; 
    i : Integer; 
begin 
    lParamList := TStringList.Create; 
    lparamlist.Add('lsd=AVoBzJ5G'); 
    lparamlist.Add('email=myeMail%40mysite.com'); 
    lparamlist.Add('pass=mypass'); 
    lparamlist.Add('default_persistent=0'); 
    lparamlist.Add('timezone=240'); 
    lparamlist.Add('lgnrnd=210302_FeQV'); 
    lparamlist.Add('lgnjs=1367035381'); 
    lparamlist.Add('locale=en_US'); 
    IDHTTP1.Request.UserAgent := 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; 
    Test := IdHTTP1.Get('https://www.facebook.com'); // To get the first cookies. 
    for i := 0 to IDHTTP1.CookieManager.CookieCollection.Count - 1 do begin 
    ShowMessage(IDHTTP1.CookieManager.CookieCollection.Items[i].CookieText); // Show me the cookies. 
    end; 
    TEST := IDHTTP1.Post('https://www.facebook.com/login.php?login_attempt=1', lParamList); 
    StrToFile ('text.html', test); 
    ShellExecute (0, 'open', 'text.html', '', '', SW_SHOW); 
end; 

ho usato i parametri che ho ricevuto da livehttpheaders. Come posso accedere a Facebook con Indy?

EDIT: provato con XE2 e Indy 10 ma ottengo l'errore 'e-mail non corretta':

unit Unit1; 

interface 

uses 
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdCookieManager, IdIOHandler, 
    IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL, IdBaseComponent, 
    IdComponent, DateUtils, ShellAPI, IdTCPConnection, IdTCPClient, IdHTTP, Vcl.StdCtrls; 

type 
    TForm1 = class(TForm) 
    IdHTTP1: TIdHTTP; 
    IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL; 
    IdCookieManager1: TIdCookieManager; 
    Button1: TButton; 
    Memo1: TMemo; 
    procedure Button1Click(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

function GetBetween (Str: String; StrStart : String; StrEnd : String) : String; 
var 
    iPos : Integer; 
    BackUp : String; 
begin 
    result := ''; 
    iPos := Pos (StrStart, Str); 
    if iPos <> 0 then begin 
    Delete (Str, 1, iPos + Length (StrStart) - 1); 
    iPos := Pos (StrEnd, Str); 
    if iPos <> 0 then begin 
     result := Copy(Str,1, iPos - 1); 
    end; 
    end; 
end; 

function StrToFile(szFilePath:string; dwPosition:DWORD; szInput:string):Boolean; 
var 
    hFile:  DWORD; 
    dwSize:  DWORD; 
    dwWritten: DWORD; 
begin 
    Result := FALSE; 
    hFile := CreateFileW(PWideChar(szFilePath), GENERIC_WRITE, 0, nil, CREATE_ALWAYS, 0, 0); 
    if hFile <> INVALID_HANDLE_VALUE then 
    begin 
    dwSize := Length(szInput) * 2; 
    if dwSize > 0 then 
    begin 
     SetFilePointer(hFile, dwPosition, nil, FILE_BEGIN); 
     WriteFile(hFile, szInput[1], dwSize, dwWritten, nil); 
     if dwWritten = dwSize then 
     Result := TRUE; 
    end; 
    CloseHandle(hFile); 
    end; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
var 
    Response  : String; 
    lparamList : TStringList; 
begin 
    IDHTTP1.Request.UserAgent := 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)'; 
    try 
    Response := IDHTTP1.Get('https://www.facebook.com/'); 
    except 

    end; 
    lParamList := TStringList.Create; 
    lParamList.Add('lsd='+GetBetween (Response, 'name="lsd" value="', '"')); 
    lParamList.Add('[email protected]'); 
    lParamList.Add('pass=myPassword'); 
    lParamList.Add('default_persistent'+GetBetween (Response, 'name="default_persistent" value="', '"')); 
    lParamList.Add('timezone=240'); 
    lParamList.Add('lgnrnd='+GetBetween (Response, 'name="lgnrnd" value="', '"')); 
    lParamList.Add('lgnjs='+inttostr(DateTimeToUnix(Now))); 
    lParamList.Add('locale=en_US'); 
    IDHTTP1.Request.Referer := 'https://www.facebook.com/'; 
    try 
    Response := IDHTTP1.Post('https://www.facebook.com/login.php?login_attempt=1', lparamList); 
    except 

    end; 
    StrToFile ('test.html', 0, Response); 
    ShellExecute (0, 'open', 'test.html', '', '', SW_SHOW); 
end; 

end. 
+2

Hai uno sniffer. Annusa i dati trasmessi da Indy e li confronta con i dati trasmessi da un browser web. –

+2

È possibile utilizzare Fiddler per annusare i dati SSL, poiché funge da proxy locale. Configura automaticamente le app basate su WinInet, incluso Internet Explorer, per connettersi attraverso esso mentre è in esecuzione. Devi configurare altre app manualmente, incluso 'TIdHTTP' (che ha una proprietà' ProxyParams'). –

+2

Uso Fiddler per sniffare il traffico SSL, compreso il traffico 'TIdHTTP', quindi so per certo che funziona. Assicurati di configurare la proprietà 'TIdHTTP.ProxyParams' per dire a' TIdHTTP' di connettersi a Fiddler e non direttamente al server HTTPS. –

risposta

5

Se il flag hoForceEncodeParams è abilitato nel TIdHTTP.HTTPOptions proprietà (che lo è di default), allora si è necessario compilare il TStringList inviato con un valori codificati. TIdHTTP.Post() quindi codificherà i valori per te quando li trasmetti.

Supponendo bandiera hoForceEncodeParams è abilitata, lparamlist.Add('email=myeMail%40mysite.com'); dovrebbe essere trasmesso come email=myeMail%2540mysite.com perché il carattere % viene codificato come %25. Facebook lo decodificherà come email=myeMail%40mysite.com e lo rifiuterà come email non valida.

è possibile:

  1. disattivare il flag hoForceEncodeParams in modo che i valori TStringList vengono trasmessi così come sono. Saresti quindi responsabile della codifica manuale.

  2. lasciare il flag hoForceEncodeParams attivato e modificare lparamlist.Add('email=myeMail%40mysite.com'); a lparamlist.Add('[email protected]'); invece. TIdHTTP.Post() in Indy 9 lo trasmetterà come [email protected] perché Indy 9 non codifica il carattere @. Potrebbe funzionare o meno, a seconda di quanto Facebook è indulgente.

Se si esegue l'aggiornamento a Indy 10, TIdHTTP.Post() codificherà il carattere @ come %40 come previsto quando è attivato il flag hoForceEncodeParams.

+0

Ok, l'ho considerato e ora sono un po 'più vicino. Sebbene io abbia il gestore dei cookie, ora mi dà la necessità di abilitare i cookie. –

+0

BTW. Indy 9 converte con successo '@' a '% 40' –

+1

@BenjaminWeiss: Il supporto dei cookie di Indy 9 non era molto buono. Il supporto dei cookie di Indy 10 è molto meglio. 'TIdHTTP.Post()' in Indy 9 non codifica '@'. Usa 'TIdURI.ParamsEncode()' per la codifica attuale, e '@' è sulla lista dei caratteri * safe * che 'ParamsEncode()' non codifica. Ma poi, sto guardando il codice per Indy 9.0.50, e invece stai usando 9.0.10, quindi forse 9.0.10 era diverso. –

0

Per chiunque sia interessato, il codice dell'OP funziona perfettamente con le versioni mobili di Facebook, quindi basta sostituire www.facebook.com con touch/m.facebook.com.

Ora, se l'OP fosse anche abbastanza gentile da condividere come ha ottenuto la versione completa per funzionare (almeno la parte Cookie non abilitata), sono sicuro che saremo tutti grati.