Fix reCaptcha

This commit is contained in:
Omar Roth 2020-05-28 11:47:48 -05:00
parent 80941eacbd
commit 6435c7b921
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2

View file

@ -241,7 +241,8 @@ def bypass_captcha(captcha_key, logger)
if response.body.includes?("To continue with your YouTube experience, please fill out the form below.") if response.body.includes?("To continue with your YouTube experience, please fill out the form below.")
html = XML.parse_html(response.body) html = XML.parse_html(response.body)
form = html.xpath_node(%(//form[@action="/das_captcha"])).not_nil! form = html.xpath_node(%(//form[@action="/das_captcha"])).not_nil!
site_key = form.xpath_node(%(.//div[@class="g-recaptcha"])).try &.["data-sitekey"] site_key = form.xpath_node(%(.//div[@id="recaptcha"])).try &.["data-sitekey"]
s_value = form.xpath_node(%(.//div[@id="recaptcha"])).try &.["data-s"]
inputs = {} of String => String inputs = {} of String => String
form.xpath_nodes(%(.//input[@name])).map do |node| form.xpath_nodes(%(.//input[@name])).map do |node|
@ -254,8 +255,9 @@ def bypass_captcha(captcha_key, logger)
"clientKey" => CONFIG.captcha_key, "clientKey" => CONFIG.captcha_key,
"task" => { "task" => {
"type" => "NoCaptchaTaskProxyless", "type" => "NoCaptchaTaskProxyless",
"websiteURL" => "https://www.youtube.com/watch?v=CvFH_6DNRCY&gl=US&hl=en&disable_polymer=1&has_verified=1&bpctr=9999999999", "websiteURL" => "https://www.youtube.com#{path}",
"websiteKey" => site_key, "websiteKey" => site_key,
"recaptchaDataSValue" => s_value,
}, },
}.to_json).body) }.to_json).body)
@ -278,6 +280,7 @@ def bypass_captcha(captcha_key, logger)
end end
inputs["g-recaptcha-response"] = response["solution"]["gRecaptchaResponse"].as_s inputs["g-recaptcha-response"] = response["solution"]["gRecaptchaResponse"].as_s
headers["Cookies"] = response["solution"]["cookies"].as_h.map { |k, v| "#{k}=#{v}" }.join("; ")
response = YT_POOL.client &.post("/das_captcha", headers, form: inputs) response = YT_POOL.client &.post("/das_captcha", headers, form: inputs)
yield response.cookies.select { |cookie| cookie.name != "PREF" } yield response.cookies.select { |cookie| cookie.name != "PREF" }
@ -288,7 +291,8 @@ def bypass_captcha(captcha_key, logger)
html = XML.parse_html(response.body) html = XML.parse_html(response.body)
form = html.xpath_node(%(//form[@action="index"])).not_nil! form = html.xpath_node(%(//form[@action="index"])).not_nil!
site_key = form.xpath_node(%(.//div[@class="g-recaptcha"])).try &.["data-sitekey"] site_key = form.xpath_node(%(.//div[@id="recaptcha"])).try &.["data-sitekey"]
s_value = form.xpath_node(%(.//div[@id="recaptcha"])).try &.["data-s"]
inputs = {} of String => String inputs = {} of String => String
form.xpath_nodes(%(.//input[@name])).map do |node| form.xpath_nodes(%(.//input[@name])).map do |node|
@ -303,6 +307,7 @@ def bypass_captcha(captcha_key, logger)
"type" => "NoCaptchaTaskProxyless", "type" => "NoCaptchaTaskProxyless",
"websiteURL" => location.to_s, "websiteURL" => location.to_s,
"websiteKey" => site_key, "websiteKey" => site_key,
"recaptchaDataSValue" => s_value,
}, },
}.to_json).body) }.to_json).body)
@ -325,10 +330,7 @@ def bypass_captcha(captcha_key, logger)
end end
inputs["g-recaptcha-response"] = response["solution"]["gRecaptchaResponse"].as_s inputs["g-recaptcha-response"] = response["solution"]["gRecaptchaResponse"].as_s
headers["content-type"] = "application/x-www-form-urlencoded" headers["Cookies"] = response["solution"]["cookies"].as_h.map { |k, v| "#{k}=#{v}" }.join("; ")
headers["origin"] = "https://www.google.com"
headers["user-agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36"
response = YT_POOL.client &.post("/sorry/index", headers: headers, form: inputs) response = YT_POOL.client &.post("/sorry/index", headers: headers, form: inputs)
headers = HTTP::Headers{ headers = HTTP::Headers{
"Cookie" => URI.parse(response.headers["location"]).query_params["google_abuse"].split(";")[0], "Cookie" => URI.parse(response.headers["location"]).query_params["google_abuse"].split(";")[0],