Skip to content

Instantly share code, notes, and snippets.

@giammirove
Created January 27, 2019 23:31
Show Gist options
  • Save giammirove/f3ea6147dc3663e8a91336f291ece196 to your computer and use it in GitHub Desktop.
Save giammirove/f3ea6147dc3663e8a91336f291ece196 to your computer and use it in GitHub Desktop.
bypass cloudflare using fetch nodejs
/*
Rovelli Gianmaria @2019
This script only show the cookie to bypass
Good job :P
*/
const fetch = require("node-fetch");
var url = "https://ilgeniodellostreaming.app/";
var _cfduid;
var cf_clearance;
returnCookie().then(function(done) {
console.log(done);
});
function returnCookie(){
var promise = new Promise(function(resolve, reject){
getCookie();
var show = setInterval(() =>{
if(cf_clearance != undefined) {
clearInterval(show);
//console.log(_cfduid + ";" + cf_clearance);
resolve (_cfduid + ";" + cf_clearance);
}
},10);
});
return promise;
}
async function getCookie() {
const cookie = await (await (fetch(url)
.then(data => {
data.headers.forEach(function(val, key) {
if(key == "set-cookie")
_cfduid = val;
});
try{
_cfduid = _cfduid.substr(0, _cfduid.indexOf(';'));
}catch(e){
console.log(e + " -> " + data.headers);
}
//console.log(_cfduid);
return data.text();
})
.then((response) => {
setTimeout(async () => {
var link = solveChallenge(response, url);
//console.log(link);
const cookie2 = await (await (fetch(link, {
method : 'GET',
redirect: 'manual',
headers : {
'cookie' : _cfduid
}
}).then((data2) => {
//console.log(data2.headers);
data2.headers.forEach(function(val, key) {
if(key == "set-cookie")
cf_clearance = val;
});
try{
cf_clearance = cf_clearance.substr(0, cf_clearance.indexOf(';'));
}catch(e){
console.log(e + " -> " + data2.headers);
}
//console.log(cf_clearance);
//console.log(_cfduid + ";" + cf_clearance);
return (_cfduid + ";" + cf_clearance);
})
));
}, 6000);
})
));
}
function solveChallenge(body, url) {
var host = url;
var r = host.match(/https?:\/\//)[0];
host = host.substr(r.length);
host = host.substr(0,host.length-1);
var challenge = body.match(/name="jschl_vc" value="(\w+)"/);
var jsChlVc;
var answerUrl;
jsChlVc = challenge[1];
challenge = body.match(/getElementById\('cf-content'\)[\s\S]+?setTimeout.+?\r?\n([\s\S]+?a\.value =.+?)\r?\n/i);
challenge_pass = body.match(/name="pass" value="(.+?)"/)[1];
challenge = challenge[1];
challenge = challenge.replace(/a\.value =(.+?) \+ .+?;/i, '$1');
challenge = challenge.replace(/\s{3,}[a-z](?: = |\.).+/g, '');
challenge = challenge.replace(/'; \d+'/g, '');
var answer = (eval(challenge) + host.length);
answerUrl = url + '/cdn-cgi/l/chk_jschl?jschl_vc=' + jsChlVc + '&pass=' + challenge_pass + '&jschl_answer=' + answer;
return answerUrl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment