コード例 #1
0
ファイル: CaptchaBypass.cs プロジェクト: ooojustin/HF-Sharp
        /// <summary>
        /// Automatically bypasses HackForums captcha/cloudflare system.
        /// This should called immediately after initializing, if your program is running on a server.
        /// </summary>
        public static bool BypassCaptchaSystem(this HttpClient client, string _2captchApiKey)
        {
            // send a request to the API
            string response = client.ApiGet("?version");

            // check if we actually *need* to bypass the captcha
            if (!response.Contains("HackForums.net wants to verify that you're a human."))
            {
                return(true);
            }

            // get the url we'll be submitting our bypass to
            string submitURL = GetActionURL(response);

            if (string.IsNullOrEmpty(submitURL))
            {
                return(false);
            }

            // get the value of 's'
            string s = GetValueS(response);

            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }

            // get script data (data-raw and data-sitekey)
            Tuple <string, string> scriptData = GetScriptData(response);

            if (scriptData == null)
            {
                return(false);
            }

            string ray     = scriptData.Item1;
            string siteKey = scriptData.Item2;

            // use the _2Captcha class to get a valid token to bypass the captcha
            _2Captcha captcha = new _2Captcha(HACKFORUMS, siteKey, _2captchApiKey);
            string    token   = captcha.GetToken();

            if (token == null)
            {
                return(false);
            }

            NameValueCollection queryString = HttpUtility.ParseQueryString(string.Empty);

            queryString["s"]  = s;
            queryString["id"] = ray;
            queryString["g-recaptcha-response"] = token;

            string requestString = submitURL + "?" + queryString.ToString();

            _ = client.GetAsync(requestString).Result;

            return(true);
        }