So after researching how to solve captcha, thanks to the programmers who don't want to disclose their better methods and my low amount of time to find a better method, the only thing that came up was finding the darkest pixel, which does actually work pretty well. So heres some javascript code that does just that:
function rgbToHsl(r, g, b) { r /= 255, g /= 255, b /= 255; var max = Math.max(r, g, b), min = Math.min(r, g, b); var h, s, l = (max + min) / 2; if (max == min) { h = s = 0; // achromatic } else { var d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); switch (max) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; } h /= 6; } return ({ h: h, s: s, l: l, }); } function solve_captcha(url, callback) { var captcha = new Image(); captcha.src = url; //alert(url); captcha.onload = function(){ var canvas = document.createElement('canvas'); canvas.width = 200; canvas.height = 200; var context = canvas.getContext("2d"); context.drawImage(captcha, 0, 0); var imgData = context.getImageData(0, 0, 200, 200); var pixel = 0; var darkest_pixel_lightness = 100; var darkest_pixel_location = 0; for (var i = 0; i < imgData.data.length; i += 4) { red = imgData.data[i + 0]; green = imgData.data[i + 1]; blue = imgData.data[i + 2]; alpha = imgData.data[i + 3]; // skip transparent/semiTransparent pixels if (alpha < 230) { continue; } var hsl = rgbToHsl(red, green, blue); var lightness = hsl.l; if (lightness < darkest_pixel_lightness) { darkest_pixel_lightness = lightness; darkest_pixel_location = pixel; } pixel++; } var y = Math.floor(darkest_pixel_location/200); var x = darkest_pixel_location-(y*200); callback(x,y); } }
to use this call a function like this:
captcha_url = 'http://www.neopets.com/captcha_show.phtml?_x_pwned=6f3b55f8983a417085e91ee632b8219b'; // feed live chaptcha link in here solve_captcha(captcha_url, function(x, y) { alert('x: '+x+' & y: '+y); // alerts x and y coordinate of where it will click }
To break it down, you can get the url from the buy page of the captcha, and when inputted into this function along with a callback function, it will do the following:
1. Create a new image
2. Set the src of the image to the url of the captcha
3. When the image has loaded, create a new canvas
4. Set height and width of canvas
5. get canvas context.
6. Draw image to canvas context from the image we created in step 1 and 2
6. Get image data from the context (pixel by pixel RGB colors + alpha)
7. Loop through each pixel, converting each pixel to hsl, which gives us the light/dark percentage we need.
8. If we find a pixel darker then any other pixel so far, we save that pixel in the darkest_pixel_variable. If it finds an even darker pixel, that old value will be overridden.
9. Based on the darkest pixel, calculate the x and y coordinate of that pixel
10. Return the x and y to your callback function
And your done. I hope this can be helpful to someone trying to learn how to solve captchas