2010-04-11 4 views
2

저는 프로그래머에게 captcha가 너무 약하다는 것을 보여주고 싶습니다. 이 같은 지금은있어 뭔가 :하나의 이미지를 생성하는 데 약간의 결과가 있습니다.

기능 :

<?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; 
} 
?> 

작업 :

<?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"); 
?> 

난 아직도 정규 표현식을 배운하지 않은 preg_match를 보지 마십시오.

그래서 링크가 동일하다는 것을 알 수 있습니다 : (captcha.php? 1270900968),하지만 그 결과는 아닙니다.

도움말 나, (나는이 포털 스팸에 그 일을하고 있지 않다)하시기 바랍니다

편집 :

Q - 어떻게 하나 개의 링크에서 하나 개의 이미지를 얻는 방법? 왜 imagecreatefromgif ($ 이미지); 정상 링크와 같은 이미지를 반환하지 않습니까? 같은 이미지를 얻는 방법?

+1

그래서, 문제는 다시 무엇인가? – deceze

+0

ㅎ. 하나의 링크에서 하나의 이미지를 얻는 방법? 왜 imagecreatefromgif ($ 이미지); 정상 링크와 동일한 이미지를 반환하지 않습니까? 같은 이미지를 얻는 방법? – Misiur

+0

misiur- 질문을 수정하지 않으시겠습니까? – Moshe

답변

-1

결과가 항상 일정하지 않은 것으로 생각할 수있는 유일한 이유는 모든 요청에 ​​대해 소스 이미지가 변경되기 때문입니다. 이 스크립트를 테스트하고 싶다면 한 이미지를 로컬 서버에 저장하고 올바르게 파싱해야합니다. 그것의 작동한다면, 당신은 생성 된 다른 이미지를 바꿀 수 있고 그들이 잘 작동하는지 확인하십시오.

나는() 거기에서 로컬 임시 파일이나 뭐, 작업에 이미지를 저장 file_get_contents을 사용 :

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

cbreak('temp.gif'); 
+0

이제 동일한 이미지가 생겼으니 지금은 cURL로 확인하겠습니다. – Misiur

관련 문제