One image url, multiple results

I am trying to show programmers that some captchas are too weak and I am breaking them. Now I have something like this:

Functions:

<?php

function cbreak($image)
{

$info = getimagesize($image);
$width = $info[0];
$height = $info[1];

$img = imagecreatefromgif($image);

$map = array();
for($y=0; $y<$height; $y++)
{
  for($x=0; $x<$width; $x++)
  {
    $color = imagecolorsforindex($img, imagecolorat($img, $x, $y));

    $map[$x][$y] = ($color['red'] + $color['blue'] + $color['green'] > 750) ? TRUE : FALSE;  
  }  
}
echo '<pre>';
for($y=0; $y<$height; $y++)
{
  for($x=0; $x<$width; $x++)
  {
    echo ($map[$x][$y] == TRUE) ? 'X' : '-';  
  }
  echo '<br>';  
}
echo '</pre>';

$sum = '';
for($x=0; $x<$width; $x++)
{
  $count = 0;
  for($y=0; $y<$height; $y++)
  {
    if($map[$x][$y] == TRUE) $count++;  
  } 

  $sum .= ($count == 0) ? 'X' : $count;
}

$sum = preg_replace('#X+#', 'X', $sum);
$sum = trim($sum, 'X');
$letters = explode('X', $sum);

$patterns = array(
/* Still not here */
);

$token = '';
for($i=0; $i<count($letters); $i++)
{
  $token .= $patterns[$letters[$i]]; 
}

echo $token; 
}
?>

      

Act:

<?php

$cl = curl_init("http://www.takeagift.pl/rejestracja");

curl_setopt($cl, CURLOPT_RETURNTRANSFER, 1);

$r = curl_exec($cl);


$pattern = "/src=[\"'].*[\"']?/i";
preg_match_all($pattern, $r, $images);

$c = array();
for($i=0; $i<sizeof($images[0]); $i++)
{
    if(strstr($images[0][$i], 'captcha') !== false)
    {
        $c = $images[0][$i]; 
    }
}
$s1 = substr($c, 0, -8);
echo $s1."<br />";
$s = substr($s1, 5, -1);
echo $s."<br />";
curl_close($cl);

?>

<img src="http://www.takeagift.pl/includes/modules/captcha.php?1270900968" /><br />
<img src="http://www.takeagift.pl/includes/modules/captcha.php?1270900968" /><br />
<img src="http://www.takeagift.pl/includes/modules/captcha.php?1270900968" /><br />
<img src="http://www.takeagift.pl/includes/modules/captcha.php?1270900968" /><br />
<img src="http://www.takeagift.pl/includes/modules/captcha.php?1270900968" /><br />
<?php include('cb.php'); 
cbreak("http://www.takeagift.pl/includes/modules/captcha.php?1270900968");
?>

      

Don't look at preg_match. I haven't learned regexp yet.

So you can see that the links are the same: (captcha.php? 1270900968), but the result is not.

Help me please (I do not do this to spam this portal)

Edit:

Q - How to get one image from one link? Why is imagecreatefromgif ($ image); doesn't return the same image as a normal link? How do I get the same image?

+2


source to share


1 answer


The only thing I can think of if your results are not persistent is that the original image changes for every request. If you want to test this script, I suppose you should try to save one image to your local server and make sure it is parsed correctly. If it works, you can swap the images with other generated ones and make sure they work too.

I would use file_get_contents () to save the image to a local temp file or whatever, and work from there:



$ImageData = file_get_contents('http://www.takeagift.pl/includes/modules/captcha.php?1270900968');
file_put_contents('temp.gif', $ImageData);

cbreak('temp.gif');

      

-1


source







All Articles