public bool TwoCaptchaReport(Captcha.CaptchaSolution solution, bool good) { Logger.Trace("TwoCaptcha/RuCaptcha reporting..."); var _reportResponse = TwoCaptcha("res.php", new Dictionary <string, object>() { { "key", solution.Config.RuCaptcha.ApiKey }, { "action", (good) ? "reportgood" : "reportbad" }, { "id", solution.Id }, { "json", "0" }, }); Logger.Trace($"TwoCaptcha/RuCaptcha reporting: {_reportResponse?.FirstOrDefault()?.ToUpper()}"); return(_reportResponse?.FirstOrDefault()?.ToUpper() == "OK_REPORT_RECORDED"); }
public bool CreateAccount(string email, Captcha.CaptchaSolution captcha, Action <string> updateStatus, ref bool stop) { if (!(captcha?.Solved ?? false)) { Logger.Warn("Captcha not solved. Cannot create account."); return(false); } Logger.Debug("Creating account..."); SetConfig(VerifyCaptchaUri, Method.POST); _request.AddParameter("captchagid", _captchaGid); _request.AddParameter("captcha_text", captcha.Solution); _request.AddParameter("email", email); _request.AddParameter("count", "1"); var response = _client.Execute(_request); _request.Parameters.Clear(); if (!response.IsSuccessful) { Logger.Warn($"Creating account error: {Error.HTTP_FAILED}"); updateStatus(Error.HTTP_FAILED); return(false); } var matches = BoolRegex.Matches(response.Content); var bCaptchaMatches = bool.Parse(matches[0].Value); var bEmailAvail = bool.Parse(matches[1].Value); if (!bCaptchaMatches) { Logger.Warn("Creating account error: Wrong captcha"); updateStatus(Error.WRONG_CAPTCHA); if (captcha.Config != null && captcha.Config.Service == Enums.CaptchaService.RuCaptcha && captcha.Config.RuCaptcha.ReportBad) { TwoCaptchaReport(captcha, false); } return(false); } if (!bEmailAvail) { //seems to always return true even if email is already in use Logger.Warn("Creating account error: Email probably in use"); updateStatus(Error.EMAIL_ERROR); stop = true; return(false); } //Send request again SetConfig(AjaxVerifyCaptchaUri, Method.POST); _request.AddParameter("captchagid", _captchaGid); _request.AddParameter("captcha_text", captcha.Solution); _request.AddParameter("email", email); response = _client.Execute(_request); _request.Parameters.Clear(); try { dynamic jsonResponse = JsonConvert.DeserializeObject(response.Content); if (jsonResponse.success != 1) { switch (jsonResponse.success) { case 62: Logger.Warn($"Creating account error: #{jsonResponse.success} / {Error.SIMILIAR_MAIL}"); updateStatus(Error.SIMILIAR_MAIL); break; case 13: Logger.Warn($"Creating account error: #{jsonResponse.success} / {Error.INVALID_MAIL}"); updateStatus(Error.INVALID_MAIL); break; case 17: Logger.Warn($"Creating account error: #{jsonResponse.success} / {Error.TRASH_MAIL}"); updateStatus(Error.TRASH_MAIL); break; default: Logger.Warn($"Creating account error: #{jsonResponse.success} / {Error.UNKNOWN}"); updateStatus(Error.UNKNOWN); stop = !FormMain.UpdateProxy(); break; } return(false); } Logger.Trace($"Creating account, SessionID: {_sessionId}"); _sessionId = jsonResponse.sessionid; Logger.Debug("Creating account: Waiting for email to be verified"); updateStatus("Waiting for email to be verified"); } catch { } return(true); }
public Captcha.CaptchaSolution SolveCaptcha(Action <string> updateStatus, Models.CaptchaSolvingConfig captchaConfig) { Logger.Debug("Getting captcha..."); updateStatus?.Invoke("Getting captcha..."); //Store captcha ID SetConfig(JoinUri, Method.GET); var response = _client.Execute(_request); try { _captchaGid = CaptchaRegex.Matches(response.Content)[0].Groups[1].Value; } catch (Exception e) { Logger.Error("Captcha error.", e); updateStatus($"Captcha error: {e.Message}"); return(new Captcha.CaptchaSolution(true, $"{e}\n\n{response.ResponseStatus}", captchaConfig)); } //download and return captcha image SetConfig($"{CaptchaUri}{_captchaGid}", Method.GET); var captchaPayload = string.Empty; for (int i = 0; i < 3; i++) { try { Logger.Debug($"Downloading captcha: Try {i + 1}/3"); updateStatus($"Downloading captcha: Try {i + 1}/3"); var _captchaResp = _client.DownloadData(_request); captchaPayload = GetBase64FromImage(_captchaResp); break; } catch (Exception ex) { Logger.Error("Downloading captcha error.", ex); captchaPayload = string.Empty; } } // recognize captcha Logger.Debug("Recognizing captcha..."); updateStatus("Recognizing captcha..."); switch (captchaConfig.Service) { case Enums.CaptchaService.Captchasolutions: { Logger.Debug("Recognizing captcha via Captchasolutions..."); var _resp = Captchasolutions("solve", new Dictionary <string, object>() { { "p", "base64" }, { "captcha", $"data:image/jpg;base64,{captchaPayload}" }, { "key", captchaConfig.CaptchaSolutions.ApiKey }, { "secret", captchaConfig.CaptchaSolutions.ApiSecret }, { "out", "txt" }, }); if (Regex.IsMatch(_resp, @"Error:\s(.+)", RegexOptions.IgnoreCase)) { Logger.Warn($"Captchasolutions error:\n{_resp}\n====== END ======"); return(new Captcha.CaptchaSolution(true, _resp, captchaConfig)); } var solution = Regex.Replace(_resp, @"\t|\n|\r", ""); Logger.Debug($"Captchasolutions: {solution}"); return(new Captcha.CaptchaSolution(solution, null, captchaConfig)); } case Enums.CaptchaService.RuCaptcha: { Logger.Debug("Recognizing captcha via TwoCaptcha/RuCaptcha"); var _captchaIdResponse = TwoCaptcha("in.php", new Dictionary <string, object>() { { "key", captchaConfig.RuCaptcha.ApiKey }, { "body", $"data:image/jpg;base64,{captchaPayload}" }, { "method", "base64" }, { "soft_id", "2370" }, { "json", "0" }, }); var _captchaStatus = _captchaIdResponse?.FirstOrDefault()?.ToUpper() ?? "UNKNOWN"; Logger.Debug($"TwoCaptcha/RuCaptcha image upload response: {_captchaStatus}"); switch (_captchaStatus) { case "OK": break; case "ERROR_NO_SLOT_AVAILABLE": Thread.Sleep(6000); return(new Captcha.CaptchaSolution(true, _captchaStatus, captchaConfig)); default: return(new Captcha.CaptchaSolution(false, _captchaStatus, captchaConfig)); } var _captchaId = _captchaIdResponse.ElementAt(1); Logger.Debug($"TwoCaptcha/RuCaptcha ID: {_captchaId}"); Thread.Sleep(TimeSpan.FromSeconds(20)); var solution = string.Empty; for (int i = 0; i < 3; i++) { Logger.Debug($"TwoCaptcha/RuCaptcha requesting solution... Try {i} of 3"); var _captchaResponse = TwoCaptcha("res.php", new Dictionary <string, object>() { { "key", captchaConfig.RuCaptcha.ApiKey }, { "action", "get" }, { "id", _captchaId }, { "json", "0" }, }); var _status = _captchaResponse?.FirstOrDefault()?.ToUpper() ?? "UNKNOWN"; Logger.Debug($"TwoCaptcha/RuCaptcha solving status: {_status}"); switch (_status) { case "OK": { var _solution = new Captcha.CaptchaSolution(_captchaResponse.ElementAt(1), _captchaId, captchaConfig); Logger.Debug($"TwoCaptcha/RuCaptcha solution: {_solution.Solution}"); return(_solution); } case "CAPCHA_NOT_READY": case "ERROR_NO_SLOT_AVAILABLE": Thread.Sleep(6000); continue; default: return(new Captcha.CaptchaSolution(true, _status, captchaConfig)); } } } Logger.Debug("TwoCaptcha/RuCaptcha somethig went wrong."); return(new Captcha.CaptchaSolution(true, "Something went wrong", captchaConfig)); default: { using (var dialog = new CaptchaDialog(this, updateStatus, captchaConfig)) { if (dialog.ShowDialog() == DialogResult.OK) { return(dialog.Solution); } } } return(new Captcha.CaptchaSolution(false, "Can't solve captcha!", captchaConfig)); } }