0
Answer

HTTP POST with Facebook Captcha

Dashing Boy

Dashing Boy

11y
3.3k
1
I'm trying to get the facebook captcha image in c# and then display it in my app and send the response back to facebook. My app works fine which basically communicates with facebook but after a while it asks for captcha. I incorporated the functionality for entering the captcha and when I send it to facebook using webclient it just sens another captcha in the response. I have double checked with the TemperData inn Firefox I'm setting the correct header information and all the fields, but still I'm not being redirected to the right page. As a matter of fact in the response header one field I could see is missing as compare to the TemperData.

req = (HttpWebRequest)WebRequest.Create("https://www.facebook.com/recover/initiate");
        req.Host = "www.facebook.com";
        req.CookieContainer = cookies;
        req.Method = "GET";
        req.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefenter code hereox/22.0";
    req.KeepAlive = true;
    resp = req.GetResponse();
    streamReader = new StreamReader(resp.GetResponseStream());
    s = streamReader.ReadToEnd().Trim();

    index = s.IndexOf("https://www.facebook.com/captcha/tfbimage.php?");
    if (index == -1)
        continue;
    string uri = s.Substring(index);
    uri = uri.Substring(0, uri.IndexOf("\\\"") - 1);

    string captcha_persist_data = s.Substring(s.IndexOf("captcha_persist_data"));                    
    captcha_persist_data = captcha_persist_data.Substring(captcha_persist_data.IndexOf("value") + 7);
    captcha_persist_data = captcha_persist_data.Substring(0, 1156);

    string lsd = s.Substring(s.IndexOf("lsd"));
    lsd = lsd.Substring(lsd.IndexOf("value") + 7);
    lsd = lsd.Substring(0, 8);
    client = new WebClient();
    coo += "act=1375466977443%2F3;_e_0p4M_2=%5B%220p4M%22%2C1375466960620%2C%22act%22%2C1375466960619%2C2%2C%22captcha_response%22%2C%22click%22%2C%22click%22%2C%22-%22%2C%22r%22%2C%22%2Frecover%2Finitiate%22%2C%7B%22ft%22%3A%7B%7D%2C%22gt%22%3A%7B%7D%7D%2C0%2C0%2C0%2C1423%2C16%5D;wd=1920x796;_e_0p4M_3=%5B%220p4M%22%2C1375466977445%2C%22act%22%2C1375466977443%2C3%2C%22captcha_submit%22%2C%22click%22%2C%22click%22%2C%22-%22%2C%22r%22%2C%22%2Frecover%2Finitiate%22%2C%7B%22ft%22%3A%7B%7D%2C%22gt%22%3A%7B%7D%7D%2C0%2C0%2C0%2C1423%2C16%5D";

    client.Headers[HttpRequestHeader.Host] = "www.facebook.com";
    client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0";
    client.Headers[HttpRequestHeader.Accept] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    client.Headers[HttpRequestHeader.AcceptLanguage] = "en-US,en;q=0.5";
    //client.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
    client.Headers[HttpRequestHeader.Referer]="https://www.facebook.com/recover/initiate";
    client.Headers[HttpRequestHeader.Cookie] = coo;
    //client.Headers[HttpRequestHeader.Connection] = "keep-alive";
    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    //client.Headers[HttpRequestHeader.ContentLength] = "1235";

  image1.Source = new BitmapImage(new Uri(uri));
    MessageBox.Show("Alert");
    streamReader = new StreamReader("D:\\abc.txt");
    string newStr = streamReader.ReadLine();
    streamReader.Close();

    nameValuePairs = new NameValueCollection();
    nameValuePairs.Add("lsd", lsd);

    nameValuePairs.Add("captcha_persist_data", captcha_persist_data);

    nameValuePairs.Add("captcha_response", newStr);

    nameValuePairs.Add("captcha_submit", "Submit");

    response = client.UploadValues("https://www.facebook.com/recover/initiate", nameValuePairs);
    chars = new char[response.Length];
    for (int i = 0; i < response.Length; i++)
    {
        chars[i] = Convert.ToChar(response[i]);
    }
    s = new string(chars);


Anyone can help me with this?