How to crack a captcha
Ingredients:
- a pligg captcha
- gocr
- ImageMagick
- PHP
You’ve probably already heard about pligg, it’s a digg clone which is pretty easy to install. That means a lot of people already have it running on their domain (free backlinks with different IPs and PageRank!).
Pligg demands you enter the right captcha answer at sign up. Once you’re signed up however, you no longer need to enter captcha’s. So if you’re like me, you sign up for the sites, keep the passwords and logins in a nice list, put a small bot together and throw a couple of links to the pligg sites.
If however, you want to sign up for a lot of pligg sites and don’t want to do it manually you’ll have to crack the captcha pligg provides. Lukily the captcha is pretty easy to crack since there is enough space between all the numbers.
So we start by downloading the captcha through PHP with wget, you can fetch the captcha’s URL with fsockopen/curl on the sign-up page:
-
exec("/usr/bin/wget -O /home/cracker/captcha.jpg http://www.pliggsite.com/ts_image.php?ts_random=[xxxx] . " > /dev/null"));
-

Okay so we downloaded the captcha and saved it. Now let’s perform some ImageMagick actions to clear the noise in the background. We’ll use a floodfill to find the background color and then remove it from the image.
-
//optimize
-
exec("/usr/local/bin/convert /home/cracker/captcha.jpg -fuzz 25000 -fill black -draw ‘color 5,5 floodfill’ -quality 100 /home/cracker/captcha_c.jpg");
-
//floodfill and fill bg in black
-
exec("/usr/local/bin/convert /home/cracker/captcha_c.jpg -negate -quality 100 /home/cracker/captcha_h.jpg");
-
//negate the picture
-
-
exec("/usr/local/bin/convert /home/cracker/captcha_h.jpg -shave 10×10 -quality 100 /home/cracker/captcha_cracked.jpg");
-
//remove the border
Now we have a nice image with no background noise:

Ok so that’s looking pretty good. However we need to optimize this image a bit. First of all, for gocr to work properly we’ll need to add more space in between the numbers. We also should make the numbers bolder so gocr will recognize it better/faster.
-
$im = imagecreatefromjpeg(‘captcha_cracked.jpg’);
-
-
$width = imagesx($im);
-
$height = imagesy($im);
-
-
$x = 0;
-
$y = 0;
-
-
$new = imagecreate($width+300, $height+200); //make space for the extra spacing
-
$white = imagecolorallocate($new, 255, 255, 255);
-
$black = imagecolorallocate($new, 0, 0, 0);
-
$start = false;
-
$hitfound = 0;
-
$newx = 0;
-
$newy = 0;
-
$lastx = 0;
-
while ($x < $width) {
-
$y = 0;
-
-
$foundblack = 0;
-
-
while ($y < $height) {
-
if ((16777215 - imagecolorat($im, $x, $y)) > 1211142 ) {
-
$newy = $y;
-
imagesetpixel($new, $newx, $newy, $black);
-
imagesetpixel($new, $newx+1, $newy, $black);
-
imagesetpixel($new, $newx-1, $newy, $black);
-
-
$foundblack++;
-
} else {
-
if ( (aboveme($im, $x, $y) && belowme($im, $x, $y)) ) {
-
imagesetpixel($new, $newx, $newy, $black);
-
$foundblack++;
-
} else {
-
imagesetpixel($new, $newx, $newy, $white);
-
}
-
}
-
$y++; $newy++;
-
}
-
if ( ($foundblack < 2) && ($start) && ($hitfound < 7) && ($x > $lastx+6) ) {
-
$newx += 50;
-
$lastx = $x;
-
$hitfound++;
-
}
-
if (($foundblack > 0) && (!$start)) $start = true;
-
$x++; $newx++;
-
}
-
imagejpeg($new, ‘old.jpg’, 100);
-
-
//round 2
-
-
$im = imagecreatefromjpeg(‘old.jpg’);
-
-
$width = imagesx($im);
-
$height = imagesy($im);
-
-
$x = 0;
-
$y = 0;
-
-
$new = imagecreate($width+200, $height+200);
-
$white = imagecolorallocate($new, 255, 255, 255);
-
$black = imagecolorallocate($new, 0, 0, 0);
-
$start = false;
-
$hitfound = 0;
-
$newx = 0;
-
$newy = 0;
-
-
while ($x < $width) {
-
$y = 0;
-
-
$foundblack = 0;
-
-
while ($y < $height) {
-
if ((16777215 - imagecolorat($im, $x, $y)) > 2211142 ) {
-
$newy = $y;
-
imagesetpixel($new, $newx, $newy, $black);
-
imagesetpixel($new, $newx+1, $newy, $black);
-
imagesetpixel($new, $newx-1, $newy, $black);
-
-
$foundblack++;
-
} else {
-
if ( (aboveme($im, $x, $y) && belowme($im, $x, $y)) || ( diagonal($im, $x, $y) ) ) {
-
imagesetpixel($new, $newx, $newy, $black);
-
$foundblack++;
-
} else {
-
imagesetpixel($new, $newx, $newy, $white);
-
}
-
}
-
$y++; $newy++;
-
}
-
if (($foundblack > 0) && (!$start)) $start = true;
-
if ( ($foundblack < 2) && ($start) && ($hitfound < 6) ) {
-
$hitfound++;
-
}
-
$x++; $newx++;
-
}
-
imagejpeg($new, ‘new.jpg’, 100);
-
}
-
function aboveme($im, $x, $y) {
-
return isBlack($im, $x, $y-1);
-
}
-
function diagonal($im, $x, $y) {
-
return (isBlack($im, $x+1, $y-1) && isBlack($im, $x-1, $y+1) && isBlack($im, $x+2, $y-2));
-
}
-
-
function belowme($im, $x, $y) {
-
return isBlack($im, $x, $y+1);
-
}
-
function doublebelowme($im, $x, $y) {
-
return isBlack($im, $x, $y+2);
-
}
-
function leftme($im, $x, $y) {
-
return isBlack($im, $x-1, $y);
-
}
-
function rightme($im, $x, $y) {
-
return isBlack($im, $x+1, $y);
-
}
-
function isBlack($im, $x, $y) {
-
return (16777215 - imagecolorat($im, $x, $y)) > 2211142;
-
}
This code is using php’s GD library to perform some operations. It will scan the image and if it finds a spot with less than 2 black pixels it means there’s a space between the 2 numbers. We put extra space between the numbers and make them bolder.

The final step is to fetch the result from gocr.
Ofcourse you first need to train gocr, you can do this by:
This will train gocr. If you feel gocr has learned enough, you can request the captcha result by doing:
$a will contain the answer, simply post that to the sign up page with fsockopen and you’re in! Massive accounts in no time.
Trackback by LEROY on Wednesday July 21st, 2010:
Buy:Zetia.Female Pink Viagra.Ventolin.Buspar.Lipothin.Wellbutrin SR.Zocor.Lipitor.Female Cialis.Cozaar.SleepWell.Lasix.Amoxicillin.Benicar.Seroquel.Advair.Nymphomax.Prozac.Acomplia.Aricept….