/// <summary> /// Browser test recaptcha normal /// </summary> private static void browser_test_normal() { Console.WriteLine("[=] BROWSER TEST STARTED (NORMAL CAPTCHA) [=]"); var s = ChromeDriverService.CreateDefaultService(); s.HideCommandPromptWindow = true; ChromeDriver d = new ChromeDriver(s); try { d.Navigate().GoToUrl(TEST_PAGE_NORMAL); // go to normal test page // complete regular data d.FindElementByName("username").SendKeys("my-username"); d.FindElementByName("password").SendKeys("password-here"); Console.WriteLine("[+] Completed regular info"); // --------------------- // get sitekey string site_key = d.FindElementByClassName("g-recaptcha").GetAttribute("data-sitekey"); Console.WriteLine(string.Format("[+] Site key: {0}", site_key)); // complete captcha Console.WriteLine("[+] Waiting for recaptcha to be solved ..."); ImageTypersAPI i = new ImageTypersAPI(IMAGETYPERS_TOKEN); Dictionary <string, string> p = new Dictionary <string, string>(); p.Add("page_url", TEST_PAGE_NORMAL); p.Add("sitekey", site_key); string recaptcha_id = i.submit_recaptcha(p); // submit recaptcha info // while in progress, sleep for 10 seconds while (i.in_progress(recaptcha_id)) { Thread.Sleep(10000); } string g_response_code = i.retrieve_captcha(recaptcha_id); //Console.Write("CODE:"); Console.ReadLine(); string g_response_code = File.ReadAllText("g-response.txt"); // get manually Console.WriteLine(string.Format("[+] Got g-response-code: {0}", g_response_code)); // set g-response-code in page source (with javascript) IJavaScriptExecutor e = (IJavaScriptExecutor)d; string javascript_code = string.Format("document.getElementById('g-recaptcha-response').innerHTML = '{0}';", g_response_code); e.ExecuteScript(javascript_code); Console.WriteLine("[+] Code set in page"); // submit form d.FindElementByTagName("form").Submit(); Console.WriteLine("[+] Form submitted"); } finally { Thread.Sleep(5000); d.Quit(); // quit browser Console.WriteLine("[=] BROWSER TEST FINISHED [=]"); } }
/// <summary> /// Requests test recaptcha invisible /// </summary> private static void requests_test_invisible() { ////button[@class="g-recaptcha"] Console.WriteLine("[=] REQUESTS TEST STARTED (INVISIBLE RECAPTCHA) [=]"); try { Console.WriteLine("[+] Getting sitekey from test page..."); string resp = get(TEST_PAGE_INVISIBLE); // download page first (to get sitekey) HtmlDocument d = new HtmlDocument(); d.LoadHtml(resp); // get sitekey string site_key = d.DocumentNode.SelectSingleNode("//button").GetAttributeValue("data-sitekey", ""); Console.WriteLine(string.Format("[+] Site key: {0}", site_key)); // complete captcha Console.WriteLine("[+] Waiting for recaptcha to be solved ..."); ImageTypersAPI i = new ImageTypersAPI(IMAGETYPERS_TOKEN); Dictionary <string, string> p = new Dictionary <string, string>(); p.Add("page_url", TEST_PAGE_NORMAL); p.Add("sitekey", site_key); p.Add("type", "2"); string recaptcha_id = i.submit_recaptcha(p); // submit recaptcha info // while in progress, sleep for 10 seconds while (i.in_progress(recaptcha_id)) { Thread.Sleep(10000); } string g_response_code = i.retrieve_captcha(recaptcha_id); //Console.Write("CODE:"); Console.ReadLine(); string g_response_code = File.ReadAllText("g-response.txt"); // get manually Console.WriteLine(string.Format("[+] Got g-response-code: {0}", g_response_code)); // create post request data string data = string.Format( "username=my-username&" + "password=password-here&" + "g-recaptcha-response={0}", g_response_code); // submit string response = post(TEST_PAGE_REQUESTS_VERIFY, data); Console.WriteLine(string.Format("[+] Response: {0}", response)); } finally { Console.WriteLine("[=] REQUESTS TEST FINISHED [=]"); } }
/// <summary> /// Test API /// </summary> static void test_api() { // change to your own username & password // ----------------------------------------- string access_key = "access_token_here"; // init imagetypersAPI obj with username and password ImageTypersAPI i = new ImageTypersAPI(access_key); // old school / legacy way // i.set_user_and_password("your_username", "your_password"); // balance // ------------ string balance = i.account_balance(); Console.WriteLine(string.Format("Balance: {0}", balance)); // captcha image // ========================================================================================== // optional parameters dict Dictionary <string, string> image_params = new Dictionary <string, string>(); //image_params.Add("iscase", "true"); // case sensitive captcha //image_params.Add("isphrase", "true"); // text contains at least one space (phrase) //image_params.Add("ismath", "true"); // instructs worker that a math captcha has to be solved //image_params.Add("alphanumeric", "1"); // 1 - digits only, 2 - letters only //image_params.Add("minlength", "2"); // captcha text length (minimum) //image_params.Add("maxlength", "5"); // captcha text length (maximum) Console.WriteLine("Solving image captcha ..."); string captcha_image_text = i.solve_captcha("captcha.jpg", image_params); Console.WriteLine(string.Format("Captcha text: {0}", captcha_image_text)); // ========================================================================================== // recaptcha // ---------- // submit // ------- // check https://www.github.com/imagetyperz-api/imagetyperz-api-csharp for more details // about how to get the page_url and sitekey // create params dict Dictionary <string, string> d = new Dictionary <string, string>(); d.Add("page_url", "page_url_here"); // add --capy or --hcaptcha at the end, to submit capy or hCaptcha d.Add("sitekey", "sitekey_here"); //d.Add("type", "3"); // optional //d.Add("v3_min_score", "0.1"); // optional //d.Add("v3_action", "homepage"); // optional //d.Add("proxy", "126.45.34.53:123"); // or with auth 126.45.34.53:123:user:pass - optional //d.Add("user_agent", "Your user agent"); // optional string captcha_id = i.submit_recaptcha(d); Console.WriteLine("Waiting for recaptcha to be solved ..."); // retrieve // --------- while (i.in_progress(captcha_id)) { System.Threading.Thread.Sleep(10000); // sleep for 10 seconds and retry } string gresponse = i.retrieve_captcha(captcha_id); Console.WriteLine(string.Format("Recaptcha response: {0}", gresponse)); // Geetest // ---------- // create params dict //Dictionary<string, string> dg = new Dictionary<string, string>(); //dg.Add("domain", "geetest captcha domain"); //dg.Add("challenge", "geetest captcha challenge"); //dg.Add("gt", "geetest captcha gt"); ////dg.Add("proxy", "126.45.34.53:123"); // or with auth 126.45.34.53:123:user:pass - optional ////dg.Add("user_agent", "Your user agent"); // optional //string geetest_id = i.submit_geetest(dg); //Console.WriteLine(string.Format("Geetest captcha id: {0}", geetest_id)); //Console.WriteLine("Waiting for geetest captcha to be solved ..."); //// retrieve //// --------- //while (i.in_progress(geetest_id)) System.Threading.Thread.Sleep(10000); // sleep for 10 seconds and retry //// we got a response at this point //// --------------------------------- //Dictionary<string, string> geetest_response = i.retrieve_geetest(geetest_id); // get the response //Console.WriteLine(string.Format("Geetest response: {0} - {1} - {2}", geetest_response["challenge"], // geetest_response["validate"], geetest_response["seccode"])); // Other examples // ---------------- // ImagetypersAPI i = new ImagetypersAPI(username, password, 123); // init with refid // i.set_timeout(10); // set timeout to 10 seconds // Console.WriteLine(i.set_captcha_bad(captcha_id)); // set captcha bad // i.submit_recaptcha(page_url, sitekey, "127.0.0.1:1234"); // solve recaptcha with proxy // i.submit_recaptcha(page_url, sitekey, "127.0.0.1:1234:user:pass"); // solve recaptcha with proxy - auth // Console.WriteLine(i.was_proxy_used(captcha_id)); // get status of proxy (if submitted with recaptcha) // Console.WriteLine(i.captcha_id()); // last captcha solved id // Console.WriteLine(i.captcha_text()); // last captcha solved text // Console.WriteLine(i.recaptcha_id()); // last recaptcha solved id // Console.WriteLine(i.recaptcha_response()); // last recaptcha solved response // Console.WriteLine(i.error()); // last error }
private static void abreReceitaIE() { Console.WriteLine("[=] BROWSER TEST STARTED (NORMAL CAPTCHA) [=]"); //var s = ChromeDriverService.CreateDefaultService(); //s.HideCommandPromptWindow = true; var options = new InternetExplorerOptions(); var driverService = InternetExplorerDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; var d = new InternetExplorerDriver(driverService, new InternetExplorerOptions()); // ChromeDriver d = new ChromeDriver(s); try { d.Navigate().GoToUrl(TEST_PAGE_receita); // go to normal test page // complete regular data var xID = "ctl00_ContentPlaceHolder1_txtChaveAcessoCompleta"; d.FindElementById(xID).SendKeys("35190700214121000217570010005716071769317990"); //d.SwitchTo().Frame(0); //d.FindElementById("recaptcha-anchor").Click(); //d.FindElementByName("password").SendKeys("113001"); //Console.WriteLine("[+] Completed regular info"); // --------------------- // get sitekey string site_key = d.FindElementByClassName("g-recaptcha").GetAttribute("data-sitekey"); Console.WriteLine(string.Format("[+] Site key: {0}", site_key)); // complete captcha Console.WriteLine("[+] Waiting for recaptcha to be solved ..."); ImageTypersAPI i = new ImageTypersAPI(IMAGETYPERS_TOKEN); Dictionary <string, string> p = new Dictionary <string, string>(); p.Add("page_url", TEST_PAGE_receita); p.Add("sitekey", site_key); string recaptcha_id = i.submit_recaptcha(p); // submit recaptcha info // while in progress, sleep for 10 seconds while (i.in_progress(recaptcha_id)) { Thread.Sleep(10000); } string g_response_code = i.retrieve_captcha(recaptcha_id); //Console.Write("CODE:"); Console.ReadLine(); string g_response_code = File.ReadAllText("g-response.txt"); // get manually Console.WriteLine(string.Format("[+] Got g-response-code: {0}", g_response_code)); // set g-response-code in page source (with javascript) IJavaScriptExecutor e = (IJavaScriptExecutor)d; string javascript_code = string.Format("document.getElementById('g-recaptcha-response').innerHTML = '{0}';", g_response_code); e.ExecuteScript(javascript_code); Console.WriteLine("[+] Code set in page"); ////input[@id='ctl00_ContentPlaceHolder1_btnConsultar'] /// name = ctl00$ContentPlaceHolder1$btnConsultar /// id = ctl00_ContentPlaceHolder1_btnConsultar /// try { System.Threading.Thread.Sleep(7000); var button = d.FindElementByCssSelector("input[value='Continuar']"); button.Click(); button.Click(); d.ExecuteScript("javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('ctl00$ContentPlaceHolder1$btnConsultar', '', true, 'completa', '', false, false))"); Console.WriteLine("[+] btnConsulta submitted"); } catch { } // javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$ContentPlaceHolder1$btnConsultar", "", true, "completa", "", false, false)) // submit form // d.FindElementByTagName("form").Submit(); // Console.WriteLine("[+] Form submitted"); // botao download ctl00_ContentPlaceHolder1_btnDownload Console.WriteLine("[+] botao download"); System.Threading.Thread.Sleep(8000); //Download do documento var buttonDownload = d.FindElementByCssSelector("input[value='Download do documento']"); buttonDownload.Click(); //d.FindElementById("ctl00_ContentPlaceHolder1_btnDownload").Click(); } catch (Exception ex) { string erro = ex.Message; } finally { Thread.Sleep(5000); // d.Quit(); // quit browser Console.WriteLine("[=] BROWSER TEST FINISHED [=]"); } }