Проблемы с ПМ на phpbb {DELPHI}

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by Tip.the.besT, 4 Jan 2013.

  1. Tip.the.besT

    Tip.the.besT Member

    Joined:
    24 Jun 2009
    Messages:
    267
    Likes Received:
    10
    Reputations:
    4
    В общих чертах проблема в следующим. Набросал я код по авторизации и отправке сообщения на пхпбб. С авторизацией всё нормально, а вот сообщение не оправляет, запарился уже. 302 выдаёт и всё. А должен 200. Дак вот я уже по разному попробовал.

    Непосредственно код:
    Code:
    var
    http:thttpsend;
    list:tstringlist;
    s,ss,sss,login,pass,name,mail,time,token,sid,change,user:string;
    i,ii,iii:integer;
    stream:tstringstream;
    begin
    http:=thttpsend.Create;
    list:=tstringlist.Create;
    stream:=tstringstream.Create;
    http.MimeType:='application/x-www-form-urlencoded';
    http.UserAgent:='Mozilla/5.0 (Windows NT 6.2; rv:12.0) Gecko/20100101 Firefox/12.0';
    http.AddPortNumberToHost:=false;
    
    while swork=true do begin
    
    synchronize(procedure begin
    
    pass:=form1.slogpass.Lines[0];
    login:=copy(pass,1,pos(';',pass)-1);
    delete(pass,1,pos(';',pass));
    form1.slogpass.Lines.Delete(0);
    user:=form1.sspam.Lines[0];
    form1.sspam.Lines.Delete(0);
    
    end);
    
    repeat
      http.Document.Clear;
      http.Headers.Clear;
      http.Cookies.Clear;
      http.MimeType:='application/x-www-form-urlencoded';
    until http.HTTPMethod('GET','http://gotovim-doma.ru/forum/ucp.php?mode=login');
    list.Clear; list.LoadFromStream(http.Document); s:=utf8decode(list.Text);
    
    delete(s,1,pos('name="sid"',s)+10);
    delete(s,1,pos('"',s));
    sid:=copy(s,1,pos('"',s)-1);
    
    
    stream.Clear;
    stream.WriteString('username='+login+'&password='+pass+'&sid='+sid+'&redirect=index.php&login=%D0%92%D1%85%D0%BE%D0%B4');
    
    repeat
      http.Document.Clear;
      http.Headers.Clear;
      http.Document.LoadFromStream(stream);
      http.MimeType:='application/x-www-form-urlencoded';
    until http.HTTPMethod('post','http://gotovim-doma.ru/forum/ucp.php?mode=login&redirect=.%2Fucp.php%3Fmode%3Dlogin');
    list.Clear;
    
    if pos('Location',http.Headers.Text)<>0 then begin
    
    repeat
      http.Document.Clear;
      http.Headers.Clear;
      http.MimeType:='application/x-www-form-urlencoded';
    until http.HTTPMethod('GET','http://gotovim-doma.ru/forum/ucp.php?i=pm&mode=compose');
    list.Clear; list.LoadFromStream(http.Document); s:=utf8decode(list.Text);
    delete(s,1,pos('./ucp.php?mode=logout&amp;sid=',s));
    delete(s,1,pos('sid=',s)+3);
    sid:=copy(s,1,pos('"',s)-1);
    delete(s,1,pos('creation_time',s));
    delete(s,1,pos('=',s)+1);
    time:=copy(s,1,pos('"',s)-1);
    delete(s,1,pos('form_token',s));
    delete(s,1,pos('=',s)+1);
    token:=copy(s,1,pos('"',s)-1);
    
    change:=inttostr(RandomRange(11111, 99999))+inttostr(RandomRange(11111, 99999))+inttostr(RandomRange(11111, 99999));
    
    stream.clear;
    stream.WriteString(utf8encode('-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="username_list"' +
                       #13#10#13#10+user +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="add_to"' +
                       #13#10#13#10'Добавить' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="icon"' +
                       #13#10#13#10'0' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="subject"' +
                       #13#10#13#10#13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="addbbcode20"' +
                       #13#10#13#10'0' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="message"' +
                       #13#10#13#10#13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="lastclick"' +
                       #13#10#13#10''+time+
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="status_switch"' +
                       #13#10#13#10'0' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="attach_sig"' +
                       #13#10#13#10'on' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="fileupload"; filename=""' +
                       #13#10'Content-Type: application/octet-stream' +
                       #13#10#13#10#13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="filecomment"' +
                       #13#10#13#10#13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="creation_time"' +
                       #13#10#13#10''+time+
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="form_token"' +
                       #13#10#13#10''+token+
                       #13#10'-----------------------------'+change+'--'));
    repeat
      http.Document.Clear;
      http.Headers.Clear;
      http.Document.LoadFromStream(stream);
      http.MimeType:='multipart/form-data; boundary=---------------------------'+change;
    until http.HTTPMethod('POST','http://gotovim-doma.ru/forum/ucp.php?i=pm&mode=compose&action=post&sid='+sid);
    list.Clear; list.LoadFromStream(http.Document); s:=utf8decode(list.Text);
    
    delete(s,1,pos('./ucp.php?mode=logout&amp;sid=',s));
    delete(s,1,pos('sid=',s)+3);
    sid:=copy(s,1,pos('"',s)-1);
    delete(s,1,pos('address_list',s)-1);
    sss:=copy(s,1,pos('"',s)-1);
    delete(s,1,pos('lastclick',s));
    delete(s,1,pos('=',s)+1);
    time:=copy(s,1,pos('"',s)-1);
    delete(s,1,pos('form_token',s));
    delete(s,1,pos('=',s)+1);
    token:=copy(s,1,pos('"',s)-1);
    
    change:=inttostr(RandomRange(11111, 99999))+inttostr(RandomRange(11111, 99999))+inttostr(RandomRange(11111, 99999));
    
    
    stream.clear;
    stream.WriteString('-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="username_list"' +
                       #13#10#13#10''+user+
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="icon"' +
                       #13#10#13#10'0' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="subject"' +
                       #13#10#13#10'ТЕМА' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="addbbcode20"' +
                       #13#10#13#10'100' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="message"' +
                       #13#10#13#10'Сообщение' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="'+sss+'"' +
                       #13#10#13#10'to' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="lastclick"' +
                       #13#10#13#10''+time +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="status_switch"' +
                       #13#10#13#10'0' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="post"' +
                       #13#10#13#10'Отправить' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="attach_sig"' +
                       #13#10#13#10'on' +
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="fileupload"; filename=""' +
                       #13#10'Content-Type: application/octet-stream' +
                       #13#10#13#10#13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="filecomment"' +
                       #13#10#13#10#13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="creation_time"' +
                       #13#10#13#10''+time+
                       #13#10'-----------------------------'+change+
                       #13#10'Content-Disposition: form-data; name="form_token"' +
                       #13#10#13#10''+token+
                       #13#10'-----------------------------'+change+'--');
    repeat
      http.Document.Clear;
      http.Headers.Clear;
      http.Document.LoadFromStream(stream);
      http.Headers.Add('Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
      http.Headers.Add('Accept-Language:ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3');
      http.Headers.Add('Referer:http://gotovim-doma.ru/forum/ucp.php?i=pm&mode=compose&action=post&sid='+sid);
      http.MimeType:='multipart/form-data; boundary=---------------------------'+change;
    until http.HTTPMethod('POST','http://gotovim-doma.ru/forum/ucp.php?i=pm&mode=compose&action=post&sid='+sid);
    list.Clear; list.LoadFromStream(http.Document); s:=utf8decode(list.Text);
    
    form1.slog.Text:=s; sleep(10000);
    end;//условие авторизации
    
    end;//////////////цикл while end
    
    
    http.Free;
    list.Free;
    stream.Free;
    
    Ещё данные передаются методом multipart/form-data, я думаю моет и в этом беда. Кому не лень, гляньте.
     
  2. Tip.the.besT

    Tip.the.besT Member

    Joined:
    24 Jun 2009
    Messages:
    267
    Likes Received:
    10
    Reputations:
    4
    Вот не могу понять, точно копирую как в снифере, но когда браузер отправляет, то ему страница возвращается, а когда я - 302 и редирект на входящие. Очень интересно в чём проблема, да и работы довольно много уже сделано, поэтому готов заплатить 200р., тому кто поможет разобраться.

    З.Ы. Прошу не переносить тему в торговый раздел.
     
  3. Chrome~

    Chrome~ Elder - Старейшина

    Joined:
    13 Dec 2008
    Messages:
    936
    Likes Received:
    162
    Reputations:
    27
    multipart/form-data не правильно формируется. Смотри здесь пример запроса:
    http://ru.wikipedia.org/wiki/Multipart/form-data

    Не советую вручную формировать multipart/form-data запросы. Используй Indy класс TIdMultiPartFormDataStream, несмотря на то, что ты используешь здесь Synapse.