/// <inheritdoc /> public override void Process(BotData data) { if (!data.GlobalSettings.Captchas.BypassBalanceCheck) { base.Process(data); } data.Log(new LogEntry("WARNING! This block is obsolete and WILL BE REMOVED IN THE FUTURE! Use the SOLVECAPTCHA block!", Colors.Tomato)); data.Log(new LogEntry("Solving reCaptcha...", Colors.White)); string recapResponse = ""; try { recapResponse = Captchas.GetService(data.GlobalSettings.Captchas) .SolveRecaptchaV2Async(ReplaceValues(siteKey, data), ReplaceValues(url, data)).Result.Response; } catch { data.Log(recapResponse == string.Empty ? new LogEntry("Couldn't get a reCaptcha response from the service", Colors.Tomato) : new LogEntry("Succesfully got the response: " + recapResponse, Colors.GreenYellow)); } if (VariableName != string.Empty) { data.Log(new LogEntry("Response stored in variable: " + variableName, Colors.White)); data.Variables.Set(new CVar(variableName, recapResponse)); } }
/// <inheritdoc /> public override void Process(BotData data) { base.Process(data); string errorMessage; var service = Captchas.GetService(data.GlobalSettings.Captchas); try { try { var replacedId = ReplaceValues(CaptchaId, data); service.ReportSolution(long.Parse(replacedId), Type).Wait(); data.Log(new LogEntry($"Captcha reported successfully!", Colors.GreenYellow)); return; } catch (Exception ex) // This unwraps aggregate exceptions { if (ex is AggregateException) { throw ex.InnerException; } else { throw; } } } catch (TaskReportException ex) { errorMessage = $"The captcha report was not accepted! {ex.Message}"; } catch (NotSupportedException ex) { errorMessage = $"The currently selected service ({data.GlobalSettings.Captchas.CurrentService}) does not support reports! {ex.Message}"; } catch (Exception ex) { errorMessage = $"An error occurred! {ex.Message}"; } data.Log(new LogEntry(errorMessage, Colors.Tomato)); }
/// <inheritdoc /> public override void Process(BotData data) { base.Process(data); var service = Captchas.GetService(data.GlobalSettings.Captchas); string errorMessage; Proxy proxy = data.UseProxies && UseProxy ? proxy = new Proxy { Host = data.Proxy.Host, Port = int.Parse(data.Proxy.Port), Type = (ProxyType)Enum.Parse(typeof(ProxyType), data.Proxy.Type.ToString()), Username = data.Proxy.Username, Password = data.Proxy.Password, UserAgent = UserAgent, Cookies = data.Cookies.ToList().Concat(data.GlobalCookies.ToList()).Select(p => (p.Key, p.Value)).ToArray() }
/// <inheritdoc /> public override void Process(BotData data) { base.Process(data); // If bypass balance check, skip this method. if (data.GlobalSettings.Captchas.BypassBalanceCheck) { return; } // Get balance. If balance is under a certain threshold, don't ask for captcha solve Balance = 0; // Reset it or the block will save it for future calls data.Log(new LogEntry("Checking balance...", Colors.White)); Balance = Captchas.GetService(data.GlobalSettings.Captchas).GetBalanceAsync().Result; if (Balance <= 0) { throw new System.Exception($"[{data.GlobalSettings.Captchas.CurrentService}] Bad token/credentials or zero balance!"); } data.Log(new LogEntry($"[{data.GlobalSettings.Captchas.CurrentService}] Current Balance: ${Balance}", Colors.GreenYellow)); data.Balance = Balance; }
/// <inheritdoc /> public override void Process(BotData data) { base.Process(data); // If the clearance info is already set and we're not getting it fresh each time, skip if (data.UseProxies) { if (data.Proxy.Clearance != "" && !data.GlobalSettings.Proxies.AlwaysGetClearance) { data.Log(new LogEntry("Skipping CF Bypass because there is already a valid cookie", Colors.White)); data.Cookies["cf_clearance"] = data.Proxy.Clearance; data.Cookies["__cfduid"] = data.Proxy.Cfduid; return; } } var localUrl = ReplaceValues(url, data); var uri = new Uri(localUrl); // Initialize the captcha provider CaptchaService service = Captchas.GetService(data.GlobalSettings.Captchas); // Initialize the Cloudflare Solver CloudflareSolver cf = new CloudflareSolver(service, ReplaceValues(UserAgent, data)) { ClearanceDelay = 3000, MaxCaptchaTries = 1, MaxTries = 3 }; // Create the cookie container CookieContainer cookies = new CookieContainer(); foreach (var cookie in data.Cookies) { cookies.Add(new Cookie(cookie.Key, cookie.Value, "/", uri.Host)); } // Initialize the http handler HttpClientHandler handler = new HttpClientHandler { AllowAutoRedirect = AutoRedirect, CookieContainer = cookies, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate, SslProtocols = SecurityProtocol.ToSslProtocols() }; // Assign the proxy to the inner handler if necessary if (data.UseProxies) { if (data.Proxy.Type != Extreme.Net.ProxyType.Http) { throw new Exception($"The proxy type {data.Proxy.Type} is not supported by this block yet"); } handler.Proxy = new WebProxy(data.Proxy.Proxy, false); handler.UseProxy = true; if (!string.IsNullOrEmpty(data.Proxy.Username)) { handler.DefaultProxyCredentials = new NetworkCredential(data.Proxy.Username, data.Proxy.Password); } } // Initialize the http client HttpClient http = new HttpClient(handler); http.Timeout = TimeSpan.FromSeconds(data.GlobalSettings.General.RequestTimeout); http.DefaultRequestHeaders.Add("User-Agent", ReplaceValues(UserAgent, data)); SolveResult result = new SolveResult(); try { result = cf.Solve(http, handler, uri, ReplaceValues(UserAgent, data)).Result; } catch (AggregateException ex) { // Join all the aggregate exception inner exception messages var message = string.Join(Environment.NewLine, ex.InnerExceptions.Select(e => e.Message)); if (data.ConfigSettings.IgnoreResponseErrors) { data.Log(new LogEntry(message, Colors.Tomato)); data.ResponseCode = message; return; } throw new Exception(message); } catch (Exception ex) { if (data.ConfigSettings.IgnoreResponseErrors) { data.Log(new LogEntry(ex.Message, Colors.Tomato)); data.ResponseSource = ex.Message; return; } throw; } if (result.Success) { data.Log(new LogEntry($"[Success] Protection bypassed: {result.DetectResult.Protection}", Colors.GreenYellow)); } else if (result.DetectResult.Protection == CloudflareProtection.Unknown) { data.Log(new LogEntry($"Unknown protection, skipping the bypass!", Colors.Tomato)); } else { var message = $"CF Bypass Failed: {result.FailReason}"; if (data.ConfigSettings.IgnoreResponseErrors) { data.Log(new LogEntry(message, Colors.Tomato)); data.ResponseSource = message; return; } throw new Exception(message); } // Now that we got the cookies, proceed with the normal request HttpResponseMessage response = null; try { response = http.GetAsync(uri).Result; } catch (Exception ex) { if (data.ConfigSettings.IgnoreResponseErrors) { data.ResponseSource = ex.Message; return; } throw new Exception(ex.Message); } finally { handler.Dispose(); http.Dispose(); } var responseString = response.Content.ReadAsStringAsync().Result; // Save the cloudflare cookies var clearance = ""; var cfduid = ""; foreach (Cookie cookie in cookies.GetCookies(uri)) { switch (cookie.Name) { case "cf_clearance": clearance = cookie.Value; break; case "__cfduid": cfduid = cookie.Value; break; } } // Save the cookies in the proxy if (data.UseProxies) { data.Proxy.Clearance = clearance; data.Proxy.Cfduid = cfduid; } if (clearance != "") { data.Log(new LogEntry("Got Cloudflare clearance!", Colors.GreenYellow)); data.Log(new LogEntry(clearance + Environment.NewLine + cfduid + Environment.NewLine, Colors.White)); } // Get address data.Address = response.RequestMessage.RequestUri.AbsoluteUri; if (PrintResponseInfo) { data.Log(new LogEntry($"Address: {data.Address}", Colors.Cyan)); } // Get code data.ResponseCode = ((int)response.StatusCode).ToString(); if (PrintResponseInfo) { data.Log(new LogEntry($"Response code: {data.ResponseCode}", Colors.Cyan)); } // Get headers if (PrintResponseInfo) { data.Log(new LogEntry("Received headers:", Colors.DeepPink)); } data.ResponseHeaders.Clear(); foreach (var header in response.Headers) { var h = new KeyValuePair <string, string>(header.Key, header.Value.First()); data.ResponseHeaders.Add(h.Key, h.Value); if (PrintResponseInfo) { data.Log(new LogEntry($"{h.Key}: {h.Value}", Colors.LightPink)); } } // Add the Content-Length header if it was not sent by the server if (!data.ResponseHeaders.ContainsKey("Content-Length")) { if (data.ResponseHeaders.ContainsKey("Content-Encoding") && data.ResponseHeaders["Content-Encoding"].Contains("gzip")) { data.ResponseHeaders["Content-Length"] = GZip.Zip(responseString).Length.ToString(); } else { data.ResponseHeaders["Content-Length"] = responseString.Length.ToString(); } if (PrintResponseInfo) { data.Log(new LogEntry($"Content-Length: {data.ResponseHeaders["Content-Length"]}", Colors.LightPink)); } } // Get cookies if (PrintResponseInfo) { data.Log(new LogEntry("Received cookies:", Colors.Goldenrod)); } foreach (Cookie cookie in cookies.GetCookies(uri)) { data.Cookies[cookie.Name] = cookie.Value; if (PrintResponseInfo) { data.Log(new LogEntry($"{cookie.Name}: {cookie.Value}", Colors.LightGoldenrodYellow)); } } // Print source data.ResponseSource = responseString; if (PrintResponseInfo) { data.Log(new LogEntry("Response Source:", Colors.Green)); data.Log(new LogEntry(data.ResponseSource, Colors.GreenYellow)); } }
/// <inheritdoc /> public override void Process(BotData data) { if (!data.GlobalSettings.Captchas.BypassBalanceCheck) { base.Process(data); } var localUrl = ReplaceValues(url, data); data.Log(new LogEntry("WARNING! This block is obsolete and WILL BE REMOVED IN THE FUTURE! Use the SOLVECAPTCHA block!", Colors.Tomato)); data.Log(new LogEntry("Downloading image...", Colors.White)); // Download captcha var captchaFile = string.Format("Captchas/captcha{0}.jpg", data.BotNumber); if (base64) { var bytes = Convert.FromBase64String(localUrl); using (var imageFile = new FileStream(captchaFile, FileMode.Create)) { imageFile.Write(bytes, 0, bytes.Length); imageFile.Flush(); } } else if (sendScreenshot && data.Screenshots.Count > 0) { Bitmap image = new Bitmap(data.Screenshots.Last()); image.Save(captchaFile); } else { try { Download.RemoteFile(captchaFile, localUrl, data.UseProxies, data.Proxy, data.Cookies, out Dictionary <string, string> newCookies, data.GlobalSettings.General.RequestTimeout * 1000, ReplaceValues(UserAgent, data)); data.Cookies = newCookies; } catch (Exception ex) { data.Log(new LogEntry(ex.Message, Colors.Tomato)); throw; } } string response = ""; var bitmap = new Bitmap(captchaFile); try { var converter = new ImageConverter(); var bytes = (byte[])converter.ConvertTo(bitmap, typeof(byte[])); response = Captchas.GetService(data.GlobalSettings.Captchas) .SolveImageCaptchaAsync(Convert.ToBase64String(bytes)).Result.Response; } catch (Exception ex) { data.Log(new LogEntry(ex.Message, Colors.Tomato)); throw; } finally { bitmap.Dispose(); } data.Log(response == string.Empty ? new LogEntry("Couldn't get a response from the service", Colors.Tomato) : new LogEntry("Succesfully got the response: " + response, Colors.GreenYellow)); if (VariableName != string.Empty) { data.Log(new LogEntry("Response stored in variable: " + variableName, Colors.White)); data.Variables.Set(new CVar(variableName, response)); } }