Exemple #1
0
        private void ParseLine()
        {
            string regex = @"\((?<value>[\[\]\+\!]+)\)";

            List <string> internalLines = RegexScraper.ScrapeFromString <string>(Line, regex);

            foreach (string iLine in internalLines)
            {
                CFLine challenge = new CFLine(iLine);

                InternalLines.Add(challenge);
            }

            //Patch to fix lines without ( or ).
            if (internalLines.Count == 0)
            {
                string[] parts = Line.Split(':');

                if (parts.Length == 2)
                {
                    InternalLines.Add(new CFLine(parts[1]));
                }
                else
                {
                    parts = Line.Split('=');

                    if (parts.Length == 2)
                    {
                        InternalLines.Add(new CFLine(parts[1]));
                    }
                }
            }
        }
Exemple #2
0
        public string DownloadString(Uri address)
        {
            try
            {
                //UserAgent must be the same throughout all requests
                BaseWebClient.Headers.Add(HttpRequestHeader.UserAgent, UserAgent);

                return(BaseWebClient.DownloadString(address));
            }
            catch (WebException ex)
            {
                if (ex.Status != WebExceptionStatus.ProtocolError)
                {
                    throw;
                }

                HttpWebResponse httpResponse = (HttpWebResponse)ex.Response;

                if (httpResponse.StatusCode != HttpStatusCode.ServiceUnavailable)
                {
                    throw;
                }

                using (StreamReader stream = new StreamReader(ex.Response.GetResponseStream()))
                {
                    string response = stream.ReadToEnd();

                    List <CFValues> inputs = RegexScraper.ScrapeFromString <CFValues>(response, @"name=""(?<Name>.*?)"" value=""(?<Value>.*?)""");
                    List <string>   script = RegexScraper.ScrapeFromString <string>(response, @"<script.*?>(?<val>.*?)</script>", options: RegexOptions.Singleline);

                    //Shouldn't be needed, but causes no harm
                    List <string> action = RegexScraper.ScrapeFromString <string>(response, @"action=""(?<val>.*?)""");

                    if (inputs.Count == 0 || script.Count == 0 || action.Count == 0)
                    {
                        //Site's different or page changed
                        throw;
                    }

                    BaseWebClient.Headers.Add(HttpRequestHeader.Referer, address.ToString());
                    BaseWebClient.Headers.Add(HttpRequestHeader.UserAgent, UserAgent);

                    string baseAddress           = address.GetLeftPart(UriPartial.Authority);
                    string solveChallengeAddress = baseAddress + action[0];

                    CFChallenge challenge = new CFChallenge(script[0], address);

                    BaseWebClient.QueryString.Add("jschl_answer", challenge.SolveChallenge().ToString());

                    foreach (CFValues value in inputs)
                    {
                        BaseWebClient.QueryString.Add(value.Name, WebUtility.UrlEncode(value.Value));
                    }

                    //5 seconds is too fast for some sites
                    Thread.Sleep(6000);

                    string siteResponse = BaseWebClient.DownloadString(solveChallengeAddress);

                    BaseWebClient.QueryString.Clear();

                    return(siteResponse);
                }
            }
        }