JS破解乌云验证码 (WOOYUN)

  • A+
所属分类:WooYun-Zone

p.zJS破解乌云验证码  (WOOYUN) (谈钞票伤感情 谈感情又伤钞票又伤感情) JS破解乌云验证码  (WOOYUN) | 2015-01-17 15:35

以后盲打乌云后台有验证码也不怕啦

(function(){
    function decaptcha(image){
        var canvas = document.createElement("canvas").getContext('2d');
        var result = '';
        var letter = [[],[],[],[]];
        var letterArea = {
            '0': {'x1':14, 'x2':21, 'y1': 4, 'y2': 13},
            '1': {'x1':23, 'x2':30, 'y1': 4, 'y2': 13},
            '2': {'x1':32, 'x2':39, 'y1': 4, 'y2': 13},
            '3': {'x1':41, 'x2':50, 'y1': 4, 'y2': 13},
        }
        var captchaData = {
            '2':[[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,0,1,0,0,1,1],[0,0,0,0,0,0,1,1],[0,0,0,0,0,1,1,0],[0,0,0,0,1,1,0,0],[0,1,0,1,1,0,0,0],[0,0,1,1,0,0,0,0],[0,1,1,0,0,0,0,0],[1,1,1,1,1,1,1,1]],
            '3':[[0,1,1,1,1,1,0,0],[1,1,0,0,0,1,1,0],[0,0,0,0,0,0,1,1],[0,0,0,0,0,1,1,0],[0,0,0,1,1,1,0,0],[0,0,0,0,0,1,1,0],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,1,1],[1,1,0,0,0,1,1,0],[0,1,1,1,1,1,0,0]],
            '4': [[0,0,0,0,0,1,1,0],[0,0,0,0,1,1,1,0],[0,0,0,1,1,1,1,0],[0,0,1,1,0,1,1,0],[0,1,1,0,0,1,1,0],[1,1,0,0,0,1,1,0],[1,1,1,1,1,1,1,1],[0,0,0,0,0,1,1,0],[0,0,0,0,0,1,1,0],[0,0,0,0,0,1,1,0]],
            '5': [[1,1,1,1,1,1,1,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,1],[1,1,1,1,1,1,0,0],[1,1,1,0,0,1,1,0],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0]],
            '6': [[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,0,0,0,0,1,0],[1,1,0,1,0,0,0,0],[1,1,0,1,1,1,0,0],[1,1,1,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0]],
            '7': [[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,1,1],[0,0,0,0,0,1,1,0],[0,0,0,0,1,1,0,0],[0,0,0,1,1,0,0,0],[0,0,1,1,0,0,0,0],[0,1,1,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0]],
            '8': [[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0]],
            '9': [[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,1,0,0,1,1],[0,1,1,0,0,1,1,1],[0,0,1,1,1,0,1,1],[0,0,0,0,0,0,1,1],[0,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0]],
            'a': [[0,0,0,1,1,0,0,0],[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,1,1,1,1,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1]],
            'b': [[1,1,1,1,1,1,0,0],[1,1,0,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,1,1,0],[1,1,1,1,1,1,0,0],[1,1,0,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,1,1,0],[1,1,1,1,1,1,0,0]],
            'c': [[0,0,1,1,1,1,1,0],[0,1,1,0,0,0,1,1],[1,1,1,0,0,0,0,1],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,1],[0,1,1,0,0,0,1,1],[0,0,1,1,1,1,1,0]],
            'd': [[1,1,1,1,1,1,0,0],[1,1,0,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,1,0,1,1],[1,1,0,0,0,1,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,1,1,0],[1,1,1,1,1,1,0,0]],
            'e': [[1,1,1,1,1,1,1,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,1,0],[1,1,0,0,0,0,0,0],[1,1,1,1,1,1,0,1],[1,1,0,1,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,1,1,1,1,1,0]],
            'f': [[1,1,1,1,1,1,1,1],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,1,1,1,1,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0]],
            'g': [[0,0,1,1,1,1,1,0],[0,1,1,0,0,1,1,1],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,1,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[0,1,1,0,0,0,1,1],[0,0,1,1,1,1,1,0]],
            'h': [[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,1,1,1,1,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1]],
            'j': [[0,0,0,1,1,1,1,0],[0,0,0,0,0,1,1,0],[0,0,0,0,1,1,1,0],[1,0,0,0,0,1,1,0],[0,0,0,0,0,1,1,0],[0,1,0,0,0,1,1,0],[0,0,0,0,0,1,1,0],[0,1,0,0,0,1,1,0],[0,1,1,0,1,1,0,0],[0,0,1,1,1,0,0,0]],
            'k': [[1,1,0,0,0,0,1,1],[1,1,0,0,0,1,1,0],[1,1,0,0,1,1,0,0],[1,1,0,1,1,0,0,0],[1,1,1,1,0,0,0,0],[1,1,1,1,0,0,0,0],[1,1,0,1,1,0,0,0],[1,1,0,0,1,1,0,0],[1,1,0,0,0,1,1,0],[1,1,0,0,0,0,1,1]],
            'l': [[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,1,1,1,1,1,0]],
            'm': [[1,1,0,0,0,0,1,1],[1,1,1,0,0,1,1,1],[1,1,1,1,1,1,1,1],[1,1,0,1,1,0,1,1],[1,1,0,1,1,0,1,1],[1,1,0,1,1,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1]],
            'n': [[1,1,0,0,0,0,1,1],[1,1,1,0,0,0,1,1],[1,1,1,1,0,0,1,1],[1,1,1,1,0,0,1,1],[1,1,0,1,1,0,1,1],[1,1,0,1,1,0,1,1],[1,1,0,0,1,1,1,1],[1,1,0,0,0,1,1,1],[1,1,0,0,0,1,1,1],[1,1,0,0,1,0,1,1]],
            'p': [[1,1,1,1,1,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,1,1,1,1,1,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0]],
            'q': [[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,0,1,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,1,1,0,1,1],[1,1,0,0,1,1,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,1]],
            'r': [[1,1,1,1,1,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,1,1,1,1,1,0],[1,1,1,1,1,0,0,0],[1,1,1,0,1,1,0,0],[1,1,0,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1]],
            's': [[0,1,1,1,1,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[0,1,1,1,1,1,1,0],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,1,1],[0,0,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[0,1,1,1,1,1,1,0]],
            't': [[1,1,1,1,1,1,1,1],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0]],
            'u': [[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0]],
            'v': [[1,1,0,0,0,0,1,1],[1,1,1,0,0,1,1,1],[1,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,1,1,0,0,1,1,0],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0],[0,0,1,1,1,1,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0]],
            'w': [[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[1,1,0,1,1,0,1,1],[1,1,0,1,1,0,1,1],[1,1,0,1,1,0,1,1],[1,1,1,1,1,1,1,1],[1,1,1,0,0,1,1,1],[1,1,0,0,0,0,1,1]],
            'x': [[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,1,1,1,1,0,0],[0,1,1,0,0,1,1,0],[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1]],
            'y': [[1,1,0,0,0,0,1,1],[1,1,0,0,0,0,1,1],[0,1,1,0,0,1,1,0],[0,0,1,1,1,1,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0],[0,0,0,1,1,0,0,0]],
            'z': [[1,1,1,1,1,1,1,0],[0,0,0,0,0,1,1,0],[0,0,0,0,0,1,1,0],[0,0,0,0,1,1,0,0],[0,0,0,1,1,0,0,0],[0,0,1,1,0,0,0,0],[0,1,1,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,0,0,0,0,0,0],[1,1,1,1,1,1,1,0]],
        }

        var imageWidth = image.width;
        var imageHeight = image.height;

        canvas.drawImage(image, 0, 0)
        var imageData = canvas.getImageData(0, 0, imageWidth, imageHeight);
        var pixels = imageData.data;

        var isLetter = function(pixeldata){
            var sum = pixeldata[0] + pixeldata[1] + pixeldata[2];
            if (sum<6*3 || sum>250*3){
                return 1;
            }else{
                return 0;
            }
        }

        for(var _h=0; _h<imageHeight; _h++){
            for(var _w=0; _w<imageWidth; _w++){
                var i = 4*(_w + _h*imageWidth);
                for(var _offset in letterArea){
                    var areaData = letterArea[_offset]
                    if((_w>=areaData['x1']&&_w<=areaData['x2']) && (_h>=areaData['y1']&&_h<=areaData['y2'])){
                        var _x = _w - areaData['x1'];
                        var _y = _h - areaData['y1'];  
                        if(letter[_offset][_y] == undefined){
                            letter[_offset][_y] = [];
                        }
                        letter[_offset][_y][_x] = isLetter([].slice.call(pixels, i,i+4));
                    }
                }
            }
        }
        for(var i=0;i<letter.length;i++){
            var maxError = 1000;
            var bestResult = ' ';
            for(var _letter in captchaData){
                var _error = 0;
                for(var _i=0; _i<letter[i].length; _i++){
                    for(var _j=0; _j<letter[i][_i].length; _j++){
                        if(letter[i][_i][_j] != captchaData[_letter][_i][_j]){
                            _error += 1;
                        }
                    }
                }
                if(_error < maxError){
                    maxError = _error;
                    bestResult = _letter;
                }
            }
            result += bestResult;
        }

        return result
    }

    function main(target){
        if(!self.$) return;
        target.forEach(function(item){
            var cpt = $(item['cpt']);
            var ipt = $(item['ipt']);
            if(cpt.length && ipt.length){
                ipt.val(decaptcha(cpt[0]));
            }
        })
    }

    var target = [
        //评论/提交
        {'cpt': 'img[id^=captcha]','ipt':'input#captcha'},
        //集市
        {'cpt': 'img#captchabuy_img','ipt':'input#captchabuy'},
        //控制面板/登陆
        {'cpt': 'img[src^=http://www.wooyun.org/captcha.php]','ipt':'input[name=captcha]'}
    ];
    main(target);
})();

分享到: