private

bypass easy captcha with PHP

[-]PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
// CAPTCHA Bypass Code (Works 99%)
// by Napalm
//
// 
//
 
function  imageconverttruecolor(&$image)
{
    $width = imagesx($image);
    $height = imagesy($image);   
    $final = imagecreatetruecolor($width, $height);
    imagecopy($final, $image, 0, 0, 0, 0, $width, $height);
    imagedestroy($image);   $image = $final;
}
 
// load images
 
$background = imagecreatefrompng("captcha.png");
$lettersimg = imagecreatefrompng("letters.png");
$captcha = imagecreatefrompng("http://www.xovie.us/captcha/captcha.php");
imageconverttruecolor($background);imageconverttruecolor($lettersimg);
imageconverttruecolor($captcha);
// first parse - difference test and pixel save
$pixels = array();
for($x = 0; $x < imagesx($captcha); $x++)
{   
    for($y = 0; $y < imagesy($captcha); $y++)
    {      
        $src = imagecolorat($background, $x, $y);      
        $dst = imagecolorat($captcha, $x, $y);     
        if(!($src == 0 && $dst == 0) && ($src == $dst))         
        $pixels[$x][$y] = 0xFFFFFF;       
        else $pixels[$x][$y] = 0x000000;      
    }
}
imagedestroy($background);
 
// second parse - filter out pixel noise
 
for($p = 0; $p < 3; $p++)
{
    // 3 noise parses
    for($x = 0; $x <  imagesx($captcha); $x++)
    {      
        for($y = 0; $y < imagesy($captcha); $y++)
        {          
            $filterpixel = true;           
            if(!$pixels[$x-1][$y-1] && !$pixels[$x+0][$y-1] && !$pixels[$x+1][$y-1])
            $filterpixel = false;
            // top          
            if(!$pixels[$x+1][$y-1] && !$pixels[$x+1][$y+0] && !$pixels[$x+1][$y+1])
            $filterpixel = false;
            // right        
            if(!$pixels[$x-1][$y+1] && !$pixels[$x+0][$y+1] && !$pixels[$x+1][$y+1])
            $filterpixel = false;
            // bottom           
            if(!$pixels[$x-1][$y-1] && !$pixels[$x-1][$y+0] && !$pixels[$x-1][$y+1])
            $filterpixel = false;
            // left         
            if($filterpixel) $pixels[$x][$y] = 0xFFFFFF;       
        }  
    }
}
for($x = 0; $x < imagesx($captcha); $x++)
{
    $pixels[$x][0] = 0xFFFFFF; 
    $pixels[$x][1] = 0xFFFFFF; 
    $pixels[$x][imagesy($captcha) - 1] = 0xFFFFFF; 
    $pixels[$x][imagesy($captcha) - 2] = 0xFFFFFF;
}
for($y = 0; $y < imagesy($captcha); $y++)
{   
    $pixels[0][$y] = 0xFFFFFF;  $pixels[1][$y] = 0xFFFFFF; 
    $pixels[imagesx($captcha) - 1][$y] = 0xFFFFFF; 
    $pixels[imagesx($captcha) - 2][$y] = 0xFFFFFF;
}
for($x = 50; $x < 54; $x++)
    for($y = 2; $y < 5; $y++)
    {      
        $pixels[$x][$y] = 0xFFFFFF;
    }
}
// third parse - rebuild image (just for show)
for($x = 0; $x < imagesx($captcha); $x++)
{  
    for($y = 0; $y < imagesy($captcha); $y++)
    {      
        imagesetpixel($captcha, $x, $y, 0xFFFFFF);     
        if(($x % 3) == 0 && ($y % 3) == 0 && $pixels[$x][$y] == 0)
        {        
            imagesetpixel($captcha, $x, $y, 0xFF0000);     
        }  
    }
}
// fourth parse - basic ocr (slow) :-(
$letters = 'ABCE';
$ocr = '';
for($x1 = 0; $x1 < imagesx($captcha) - 25; $x1++)
    for($y1 = 0; $y1 < imagesy($captcha) - 27; $y1++)
    {      
        $score = array();      
        for($letter = 0; $letter < 4; $letter++)
        {           
            for($x2 = 0; $x2 <  25; $x2++)
            {             
                for($y2 = 0; $y2 < 27; $y2++)
                {                  
                    $color = imagecolorat($lettersimg, ($letter * 25) + $x2, $y2);                 
                    if($pixels[$x1 + $x2][$y1 + $y2] == $color && $color == 0)
                    $score[$letter][0]++;                   
                    if($color == 0) $score[$letter][1]++;              
                }          
            }      
        }      
        $found = -1; $highest = 0;     
        for($letter = 0; $letter < 4; $letter++)
        {           
            $result = (($score[$letter][1] / 100) * 90);          
            if($score[$letter][0] >= $result)
            {              
                $result = ($score[$letter][0] - $result);              
                if($result > $highest)
                {                 
                    $highest = $result;                
                    $found = $letter;              
                }          
            }      
        }      
        if($found > -1)
        {        
            $ocr .= $letters[$found];          
            $x1  += 10;    
        }      
        unset($score); 
    }
}
imagedestroy($lettersimg);unset($pixels);
// last of all output
header('Content-Type: image/png');
imagestring($captcha, 2, 0, 0, $ocr, 0);
imagepng($captcha);
imagedestroy($captcha);
?>















,

알림

이 블로그는 구글에서 제공한 크롬에 최적화 되어있고, 네이버에서 제공한 나눔글꼴이 적용되어 있습니다.

카운터

Today :
Yesterday :
Total :

태그