PDA

View Full Version : Archived: PHP captcha cracker


Clover
03-24-2009, 03:01 PM
I just posted this in NS&H, but it's a proof of concept that it doesn't take much to create your own captcha cracker, for use in bots and whatnot. The captcha that's in it (slpctrl.freehostia.com/captcha.php) I'm not sure if I had completely secured that captcha or not, but I'm thinking the latter is correct. I don't feel like testing it right now, but here is the code:


<?php
/*
not the best way to do it but a very straightforward PoC.
even for this approach of 'ocr' there are still many optimizations
that could be done.. like skipping whiteblocks or doing some
preprocessing to see which rows have the most pixels and test
rows adjacent to that first...etc
*/

//note: you must have fopen wrappers w/ url support enabled for the following func to work
$captcha = imagecreatefrompng("http://slpctrl.freehostia.com/captcha.php");
imagepng($captcha, ".\\tmp.png");

//load all possible text combos
$kewlImages = array();

//different letters can compare equally.. most 'full' letters go first
$possibilities = "08bf74de123569ac";

//compares to bl's of images.. each letter - no matter the size - takes a fixed amount of iterations.
function block_compare($image, $startx, $starty, $compare) {
$maxx = imagesx($image);
$maxy = imagesy($image);
$black = imagecolorallocate($image,0,0,0);
for($y = $starty; ($y < $starty + 15 && $y < $maxy); $y++) {
for($x = $startx; ($x < $startx + 10 && $x < $maxx); $x++) {
$i = imagecolorat($image, $x, $y);
$c = imagecolorat($compare, ($x-$startx), ($y-$starty));
if($c == $black && $i != $black) return FALSE;
}
}
if($y == $maxy || $x == $maxx) return FALSE;
return TRUE;
}

//largest font to smallest
for($x = 5; $x >= 1; $x--) {
for($y = 0; $y < strlen($possibilities); $y++) {
$capture = imagecreatetruecolor(10, 15);
imagefill($capture, 0, 0, imagecolorallocate($capture, 255, 255, 255));
$black = imagecolorallocate($capture,0,0,0);
/*cheap hack fix.. small fonts are better at being big fonts than
big fonts.. need to shift index one pixel for smaller fonts*/
if($x < 4)
imagestring($capture, $x, 0, 0, $possibilities[$y], $black);
else
imagestring($capture, $x, 1, 0, $possibilities[$y], $black);
array_push($kewlImages, $capture);
}
}

$maxx = imagesx($captcha);
$maxy = imagesy($captcha);
$maxz = count($kewlImages);

$output = "";
$starty = 0;
$startz = 0;
$charfound = false;
$len = 0;

//we iterate through every (x,y) pixel coordinate and through each letter in our database
//and compare the image blocks to see if they are a match.. largest font sizes compared first
for($x = 0; $x < $maxx; $x++) {
for($y = $starty; $y < $maxy; $y++) {
$charfound = false;
for($z = $startz; $z < $maxz; $z++) {
if(block_compare($captcha, $x, $y, $kewlImages[$z])) {
$output .= ($possibilities[$z%16]);
//update limits
$starty = $y;
$maxy = $y+1;
//update fonts
$startz = ($z-($z%16));
$maxz = $startz + 16;
$len += 1;
$charfound = true;
}
if($charfound) break;
}
if($charfound) break;
if($len == 5) break;
}
if($len == 5) break;
}
echo $output . "<br>";

?>

Axiom
03-28-2009, 12:24 PM
Now, port it to 3D.. :)

http://news.cnet.com/8301-17938_105-10204300-1.html

Craigslist.org
03-28-2009, 01:23 PM
Is reCaptcha any good or just a gimmick? :confused:

Clover
03-31-2009, 03:01 PM
Now, port it to 3D.. :)

http://news.cnet.com/8301-17938_105-10204300-1.html

I think I will do this, but are the 3D captchas image based? I don't know if I could reliably do something like this, I'll have to do some research. This little script was basically created to demonstrate how easy it is to examine an image pixel by pixel, across one pixel slices going down and to take that information and compare it to other things (in this case, fonts). It can be ported to other good applications like barcode cracking etc. It was just a little demo.

Is reCaptcha any good or just a gimmick? :confused:

I have no experience with reCaptcha. I tend to code my own things, especially small things like this so that if anything goes awry, I'll have a good idea as to how to fix it. If you care to indulge a bit more I might be able to better tell you.

coolstorybro
07-02-2009, 06:59 PM
Is reCaptcha any good or just a gimmick? :confused:

Recaptcha works on OCR software being used to scan through books. When the OCR detects a word its not sure of, It is put together along with a word it does know to check for spam onto the reCaptcha. When you enter in the reCaptcha it first checks if you have the test word right and if so, lets you through, It then stores the other word in the database and if other users have put the same word in, the OCR takes that word and puts it into the digital book version

BastardLunatic
07-06-2009, 07:06 AM
I'm a retard when it comes to coding, but I could use reCAPTCHA cracker on user level.
Can someone simplify this in English?

Axiom
07-06-2009, 09:37 AM
I'm a retard when it comes to coding, but I could use reCAPTCHA cracker on user level.
Can someone simplify this in English?

it's not a reCAPTCHA cracker. reCAPTCHA hasn't been cracked yet afaik...

BastardLunatic
07-06-2009, 02:17 PM
:p Not that I can tell its any different.

TwinkleTits
08-03-2009, 03:59 PM
Excuse my ignorance but whats a captcha cracka?

Jaguarstrike
09-25-2009, 05:27 PM
Excuse my ignorance but whats a captcha cracka?

Its a computer program designed to crack captchas.

Captchas are the things at the end of a registration, where you have to read weird twisted letters and input them into a text box.

Captcha Crackers will take the test image, process it into text, thereby defeating the captcha and fooling the system into thinking that the form submission was done by a human.

Red Roundup
09-25-2009, 05:51 PM
Excuse my ignorance but whats a captcha cracka?

Ghetto slang for a white bounty hunter.

a334jv2df
10-25-2009, 02:42 AM
Works well on all the csrf I've done!