iMacros用于解决reCAPTCHA问题

时间:2015-08-10 12:25:12

标签: captcha recaptcha imacros

寻求使用iMacros解决reCAPTCHA的方法。 有没有办法解决这个验证码,有可能吗?

在这里您可以找到演示: google.com/recaptcha/api2/demo

它一定不是完美的,如果可以从30个验证码中解决2,那就太棒了。

非常感谢。

2 个答案:

答案 0 :(得分:0)

Tyr这段代码,但谷歌真的怀疑它是一个机器人:

VERSION BUILD=9052613
TAB T=1
TAB CLOSEALLOTHERS
' you need to insert get other url where ReCaptcha is located.
URL GOTO=http://tarex.ru/testdir/recaptcha/recaptcha.php 
SET !VAR1 EVAL("var randomNumber=Math.floor(Math.random()*5 + 1); randomNumber;")
WAIT SECONDS={{!VAR1}}
FRAME F=1 TAG POS=1 TYPE=SPAN ATTR=ID:recaptcha-anchor

答案 1 :(得分:0)

在javascript和jquery中使用imacros(firefox)进行recaptcha(api2演示)的示例:

文件:recaptcha_v2.js

//
// The script fill the captcha of recaptcha v2 demo.
//
// Note for users with firefox with the message "Firefox prevented this page from automatically reloading.":
// UNCHECK the option "warn me when pages try to redirect" in your browser
// You find the checkbox under Options > Advanced > General > Accessibility
//
// Please set your browser language to english! (EN)
//

// Loops
var max_loop = 1;

// Url
var myurl = "URL GOTO=https://www.google.com/recaptcha/api2/demo\n";
myurl += "";//extra lines

// Submit
mysubmit = "TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:NoFormName ATTR=*\n";
mysubmit += "";//extra lines

// Debug
var breakOnError = false;
var onBreakAlert = true;
var logFile = true;
var logFileName = 'iimLog.txt';
var max_loop_limit = 500;

//Main
var logFilePath = getiMacrosFolder('Logs')+'\\'+logFileName;

//Performance for recaptchav2
var start_frame_number = 0;
var max_frame_number = 40;

//JQuery
var url_jquery = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js";

// Step 1: Config for 9kw.eu for your apikey
var apikey = "";

//And priority (prio 1-20)
var prio = "1";

(function() {
	// Syntaxcheck: API Key, prio
	if(apikey.match(/^[a-zA-Z0-9]+$/) && apikey.length <= 50 && apikey.length >= 5){}else{alert_message("API Key \""+apikey+"\" is wrong.");return false;}
	var d = parseFloat(prio); if(d >= 0 && d <= 20){}else{alert_message("Prio \""+prio+"\" is not in the set range.");return false;}

	// only valid number
	if (/[^\d]/.test(max_loop)) {
		alert_message('Please enter a valid number for loop play');
		return false;
	}
	
	max_loop = parseInt(max_loop);
	if(max_loop > max_loop_limit){
		alert_message('Loop limit exceed (' + max_loop_limit + ') , edit the following variable to use your own limit.\n\nvar max_loop_limit = ' + max_loop_limit + ';');
		return false;
	}	
	
	for(var loop = 1; loop <= max_loop; loop++){
		var function_code = "";
		function_code = recaptchav2();
		if(function_code == false && breakOnError == true){
			return false;
		}
	}
})();
//End

// functions
// recaptcha v2
function recaptchav2(){
	//header
	var imacros_header = "SET !EXTRACT_TEST_POPUP NO\n";
	imacros_header += "SET !ERRORIGNORE NO\n";
	imacros_header += "SET !TIMEOUT_PAGE 999\n";
	imacros_header += "SET !TIMEOUT_STEP 999\n";
	
	var imacros_first = "CODE:"+imacros_header+"TAB CLOSEALLOTHERS\n";
	imacros_first += "TAB T=1\n";
	imacros_first += myurl;
	iimPlay(imacros_first)
	
	// JQuery after url goto! (really important)
	loadScriptFromURL(url_jquery);
	$ = window.$,
	JQuery = window.JQuery;
	
	// start execution
	var start = new Date(), end; // for benchmarking
	
	// Step 2: Save the captcha picture to local disk
	// initial click macro
	
	$('iframe[src*="anchor"]').contents().find('.recaptcha-checkbox-checkmark').click();
	
	//Wait a random number of seconds
	wait(Math.floor(Math.random()*3 + 2));
	var checkOK;
	var more_correct_solutions;
	var captchaid;
	var numbers_rc2;

	for(var i3=1;i3<=5;i3++){
		captchaid = "";
		// macro for checking captcha checkbox
		if($('iframe').contents().find('html').find("#recaptcha-anchor").hasClass("recaptcha-checkbox-checked") == true){
			end =+ new Date();
			if(logFile){
				log_message('Captcha is solved\n\rTime spent: '+Math.floor((end-start)/1000));
			}
			//break;
		}else{
			if(i3 > 1){
				//more_correct_solutions = SearchOK("TAG POS=2 TYPE=DIV ATTR=TXT:Multiple<SP>correct<SP>solutions<SP>required<SP>-<SP>please*&&STYLE: CONTENT=EVENT:MOUSEOVER",0+other_frame_number);
				if(more_correct_solutions < 1){
					if($('iframe').contents().find('html').find("#recaptcha-anchor").hasClass("recaptcha-checkbox-checked") != true){
						iimPlay(imacros_first)
						wait(3)
						$('iframe[src*="anchor"]').contents().find('.recaptcha-checkbox-checkmark').click();
						loadScriptFromURL(url_jquery);
						$ = window.$,
						JQuery = window.JQuery;
					}
				}
			}

			numbers_rc2 = $('iframe').contents().find('html').find(".rc-image-tile-wrapper");
			if(numbers_rc2.length > 1){
				for(var i=0; i<numbers_rc2.length; i++){
					var i_high = i + 1;
					if(numbers_rc2.length > 10 && i < 9){
						$('iframe').contents().find('html').find(".rc-image-tile-wrapper").eq(i).append("<span style='position: absolute;width: 18px;left: 0px;top: 0px;border: 1px red black;color:rgb(0, 0, 0);background: rgba(255, 255, 255, 0.9);font: bold 18px Helvetica, Sans-Serif;padding: 0px 0px 0px 6px;'>0"+i_high+"</span>");
					}else{
						$('iframe').contents().find('html').find(".rc-image-tile-wrapper").eq(i).append("<span style='position: absolute;width: 18px;left: 0px;top: 0px;border: 1px red black;color:rgb(0, 0, 0);background: rgba(255, 255, 255, 0.9);font: bold 18px Helvetica, Sans-Serif;padding: 0px 0px 0px 6px;'>"+i_high+"</span>");
					}
				}
				var recaptcha_v2_error = false;
				
				var text_title;
				$('iframe').contents().find('html').find(".rc-imageselect-desc-no-canonical").html($('iframe').contents().find('html').find(".rc-imageselect-desc-no-canonical").html()+"<br><span style='border: 1px red solid;color: rgba(255, 255, 255, 0.9);background: rgba(0, 0, 0, 0.8);font: bold 18px Helvetica, Sans-Serif;padding: 0px 0px 0px 8px;'>Type the image numbers <br>&nbsp; without spaces, e.g: 358 </span>");
				$('iframe').contents().find('html').find(".rc-imageselect-desc").html($('iframe').contents().find('html').find(".rc-imageselect-desc").html()+"<br><span style='border: 1px red solid;color: rgba(255, 255, 255, 0.9);background: rgba(0, 0, 0, 0.8);font: bold 18px Helvetica, Sans-Serif;padding: 0px 0px 0px 8px;'>Type the image numbers <br>&nbsp; without spaces, e.g: 358 </span>");
			}

			var root = window.document.documentElement;
			var canvas = window.document.createElementNS('http://www.w3.org/1999/xhtml', 'html:canvas');
			var context = canvas.getContext('2d');
			
			var selection;
			if(numbers_rc2.length > 1){
				$('div:nth-of-type(2)').css({ transform: 'scale(.70)' });			
				selection = {
					top: $('div:nth-of-type(2)').offset().top,
					left: $('div:nth-of-type(2)').offset().left,
					width: $('div:nth-of-type(2)').width()*0.70,
					height: (($('div:nth-of-type(2)').height() - $('iframe').contents().find('html').find(".rc-footer").height())*0.70),
				};
			}else{
				selection = {
					top: $('div:nth-of-type(2)').offset().top,
					left: $('div:nth-of-type(2)').offset().left,
					width: $('div:nth-of-type(2)').width(),
					height: ($('div:nth-of-type(2)').height() - $('iframe').contents().find('html').find(".rc-footer").height()),
				};
			}
			
			canvas.height = selection.height;
			canvas.width = selection.width;
			
			context.drawWindow(
				window,
				selection.left,
				selection.top,
				selection.width,
				selection.height,
				'rgb(255, 255, 255)'
			);

			//Step 3: Open a new tab, and go to 9kw.eu, and submit the captcha picture
			var imacros_main2 = "CODE:"+imacros_header;
			imacros_main2 += "TAB OPEN\n";
			imacros_main2 += "TAB T=2\n";
			imacros_main2 += "URL GOTO=http://www.9kw.eu/grafik/form_base64.html\n";
			//The apikey is used to identify each of our customers, which you can get from the our page. It is assigned to the CONTENT.
			imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:apikey CONTENT="+apikey+"\n";
			//Priority in our system like min. 0 to max. 20 (cost +0-20)
			imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:prio CONTENT="+prio+"\n";
			//Options for the form. See more under http://www.9kw.eu/grafik/form.html and http://www.9kw.eu/api.html
			imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:selfsolve CONTENT=NO\n";
			imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:confirm CONTENT=NO\n";
			imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:case-sensitive CONTENT=NO\n";
			imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:nomd5 CONTENT=YES\n";
			//We need only numbers for this captcha
			if(numbers_rc2.length > 1){
				imacros_main2 += "TAG POS=1 TYPE=INPUT:CHECKBOX FORM=ACTION:/index.cgi ATTR=NAME:numeric CONTENT=YES\n";
			}
			imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:source CONTENT=imacros\n";
			// recaptcha v2 for non text captcha or recaptcha for text captcha
			if(numbers_rc2.length > 1){
				imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:oldsource CONTENT=recaptchav2\n";
			}else{
				imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:oldsource CONTENT=recaptcha\n";
			}
			//The path of the captcha picture saved is assigned to the CONTENT
			imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:file-upload-01 CONTENT="+canvas.toDataURL('image/png', '').split(',')[1]+"\n";
			//Submit the formdata to 9kw.eu
			imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=TYPE:submit\n";
			//Clean the !EXTRACT variable for the next task
			imacros_main2 += "SET !EXTRACT NULL\n";
			//Extract the characters that are recoginzed from the picture of captcha.
			imacros_main2 += "TAG POS=1 TYPE=INPUT ATTR=NAME:result EXTRACT=TXT\n";
			iimPlay(imacros_main2)
			var answer = iimGetLastExtract();
			//Step 4: Check the captcha answer (text or nothing like #EANF# = Extraction Anchor Not Found)
			if(answer == "#EANF#" || answer == "ERROR NO USER"){
				answer = "";
			}
			
			//Extract the captchaid from your captcha submit
			var imacros_main3 = "CODE:";
			imacros_main3 += "SET !EXTRACT NULL\n";
			imacros_main3 += "TAG POS=1 TYPE=INPUT ATTR=NAME:captchaid EXTRACT=TXT\n";
			imacros_main3 += "SET captchaid {{!EXTRACT}}\n";
			imacros_main3 += "TAB CLOSE\n";
			iimPlay(imacros_main3)
			captchaid = iimGetLastExtract();
			
			//Clean the !EXTRACT variable for the next task
			var imacros_main4 = "SET !EXTRACT NULL\n";
			iimPlay(imacros_main4)
			
			//Display extracted data (only for debug)
			//iimDisplay("captchaid: "+captchaid+"\nanswer: "+answer)
			
			//Step 5: Fill the recognized characters to the verification box (Click the pictures 1..16)
			if(numbers_rc2.length > 1){
				$('div:nth-of-type(2)').css({ transform: 'scale(1.0)' });
				
				var myarray = answer.split('');
				if(myarray.length < 2){
					alert_message("No answer found. Check the history on 9kw.eu!");
					if(breakOnError){
						return false;
					}else{
						break;
					}
				}else{
					for(var i = 0;i < myarray.length; i++){
						if(myarray[i].match(/^[0-9]+$/)){
							if(numbers_rc2.length > 10){
								var two_values;
								if(myarray[i+1].match(/^[0-9]+$/)){
									two_values = myarray[i]+myarray[i+1];
								}else{
									two_values = myarray[i];
								}
								i += 1;
								two_values = two_values.replace("0", "");
								two_values = parseFloat(two_values) - 1;
								if(two_values == ""){
									two_values = 0;
								}
								$('iframe').contents().find('html').find(".rc-image-tile-wrapper").eq(two_values).click();
							}else{
								myarray[i] = parseFloat(myarray[i]) - 1;
								if(myarray[i] == ""){
									myarray[i] = 0;
								}
								$('iframe').contents().find('html').find(".rc-image-tile-wrapper").eq(myarray[i]).click();
							}
						}
					}
				}
			}else{//text captcha
				SearchFrame("TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:default-response CONTENT="+answer,start_frame_number);
			}
				
			//Click the Verify button
			if(numbers_rc2.length > 1){
				SearchFrame("EVENT TYPE=CLICK SELECTOR=\"HTML>BODY>DIV>DIV>DIV:nth-of-type(3)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(2)>DIV\" BUTTON=0",start_frame_number);
			}else{
				SearchFrame("TAG POS=1 TYPE=DIV ATTR=ID:recaptcha-verify-button",start_frame_number);
			}
		}
		wait(1)
			
		// Submit
		var solved_OK;
		if($('iframe').contents().find('html').find("#recaptcha-anchor").hasClass("recaptcha-checkbox-checked") == true){
			if($('iframe').contents().find('html').find("#recaptcha-anchor").hasClass("recaptcha-checkbox-checked") == true){
				solved_OK = 1;
			}
			SearchFrame(mysubmit,start_frame_number);
			loadScriptFromURL(url_jquery);
			$ = window.$,
			JQuery = window.JQuery;
		}else{
			solved_OK = 0;
			if($('iframe').contents().find('html').find('.rc-imageselect-incorrect-response').css('display') == 'block'){
				more_correct_solutions = 1;
			}else{
				more_correct_solutions = "";
			}
		}
			
		//Step 6: Check and send the captcha feedback back to the captcha service (OK:1, NotOK:2, EN: Right/False, DE: Richtig/Falsch)
		var htmlcode = "";
		if(captchaid.length > 0){
			if($('iframe').contents().find('html').find("#recaptcha-anchor").hasClass("recaptcha-checkbox-checked") == true){
				var imacros_main4b = "CODE:TAG POS=1 TYPE=DIV ATTR=CLASS:recaptcha-success EXTRACT=TXT\n";
				iimPlay(imacros_main4b)
				htmlcode = iimGetLastExtract();
			}
		}
						
		var feedback;
		if(htmlcode.match(/Juhu/) || htmlcode.match(/Hooray/) || more_correct_solutions < 1 || solved_OK == 1){
			feedback = 1;
		}else{
			feedback = 2;
		}
			
		if(captchaid.length > 0){
			var imacros_main5 = "CODE:TAB OPEN\n";
			imacros_main5 += "TAB T=2\n";
			imacros_main5 += "URL GOTO=http://www.9kw.eu/index.cgi?source=imacros&action=usercaptchacorrectback&apikey="+apikey+"&correct="+feedback+"&id="+captchaid+"\n";
			imacros_main5 += "TAB CLOSE\n";
			iimPlay(imacros_main5)
		}

		if(feedback == "1"){
			break;
		}
	}
	return;
}

// random between 1 and 9
function rand(){
	return Math.floor(Math.random()*9) + 1;
}

// wait function like wait(2) for two seconds
function wait(waittime){
	iimPlay("CODE: WAIT SECONDS="+waittime+"\n");
	return;
}

// wait function like wait(2) for two seconds
function getextract(shortcode){
	iimPlay("CODE: "+shortcode);
	return iimGetLastExtract();
}

// date functione
function tempfile_date() {
	now = new Date();
	year = "" + now.getFullYear();
	month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
	day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
	hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
	minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
	second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
	return year + month + day + "_" + hour + minute + second;
}

// find frame with true or false as return
function SearchOK(checkcode,firstframenumber,lastframenumber){
	var check = "CODE:";
	check += "SET !ERRORIGNORE YES" + "\n";
	check += "SET !TIMEOUT_STEP 0" + "\n"; 
	check += "FRAME F={{i}}" + "\n"; 
	check += "SET !ERRORIGNORE NO" + "\n";
			
	if (checkcode != ""){
		check += checkcode + "\n"; 
	}else{
		return 0;
	}
		
	if(/^\d+$/.test(firstframenumber)) {
		frame = firstframenumber;
	}else{
		frame = 1;
	}
	
	if(/^\d+$/.test(lastframenumber)) {
		frame2 = lastframenumber;
	}else{
		frame2 = total_frame_number;
	}

	for(var i=frame;i<=frame2;i++){
		iimSet("i",i)

		if(iimPlay(check) == true){
			return 1;
		}
	}
	return 0;
}

// find frame with the framenumber as return
function SearchFrame(checkcode,firstframenumber){
	var check = "CODE:";
	check += "SET !ERRORIGNORE YES" + "\n";
	check += "SET !TIMEOUT_STEP 0" + "\n"; 
	check += "FRAME F={{i}}" + "\n"; 
	check += "SET !ERRORIGNORE NO" + "\n";
			
	if (checkcode != ""){
		check += checkcode + "\n"; 
	}else{
		return 0;
	}
		
	if(/^\d+$/.test(firstframenumber)) {
		frame = firstframenumber;
	}else{
		frame = 1;
	}

	for(var i=frame;i<=max_frame_number;i++){
		iimSet("i",i)

		//if the result of the macro is true save frame number and break
		if(iimPlay(check) == true){
			frame = i;
			break;
		}
	}
	//return frame number
	return frame;
}

// Get the imacros folder
function getiMacrosFolder(folderName){
   var pname;
   switch (folderName){
      case "Macros" :
         pname = "defsavepath";
         break;
      case "DataSources" :
         pname = "defdatapath";
         break;
      case "Downloads" :
         pname = "defdownpath";
         break;
      case "Logs" :
         pname = "deflogpath";
         break;
      default :
         throw folderName + " is not a valid iMacros folder name";
         break;
   }
   return imns.Pref.getFilePref(pname).path;
}

// Logfunction
function log_message(msg) {
	var time = new Date().toString().replace(/\s+GMT.*/, '');
	msg = time + ' - ' + msg + '\n';
	var file_o = imns.FIO.openNode(logFilePath);
	imns.FIO.appendTextFile(file_o, msg);
}

// Logfunction
function alert_message(msg){
	if(logFile){
		log_message(msg);
	}

	iimDisplay(msg);

	if(onBreakAlert){
		alert(msg);
	}
}

// jquery
function loadScriptFromURL(url) {
	var request = Components.classes['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Components.interfaces.nsIXMLHttpRequest),
	async = false;
	request.open('GET', url, async);
	request.send();
	if(request.status !== 200){
		var message = 'an error occurred while loading script at url: ' + url + ', status: ' + request.status;
		iimDisplay(message);
		return false;
	}
	eval(request.response);
	return true;
}