0
0
mirror of https://git.sdf.org/deCloudflare/deCloudflare/ synced 2024-06-08 08:40:47 +00:00

Restyle main Javascript file

I tried to copy the indent style of files seen in Torbutton, with added
guidance from my instincts as a C programmer accustomed to KNF.  This
can now be edited without wrecking diffs, unless I change it again
because this will drive me crazy.

Closes issue #1.
This commit is contained in:
nullius 2017-12-12 04:31:18 +00:00
parent 5370bb3fe2
commit 9c4cd9c984
No known key found for this signature in database
GPG Key ID: C42793159F9EF949

View File

@ -1,33 +1,44 @@
/* /**
<<< Detect Cloudflare MiTM Attack >>> * <<< Detect Cloudflare MiTM Attack >>>
by Sw * by Sw
why? because... * why? because...
https://trac.torproject.org/projects/tor/ticket/24351 * https://trac.torproject.org/projects/tor/ticket/24351
http://www.crimeflare.com/ * http://www.crimeflare.com/
*/ */
//===============================================
function analyzemydata(res){ function analyzemydata(res) {
//console.log("mitmdetector: scanning: "+res.url); //console.log("mitmdetector: scanning: "+res.url);
var cflink=document.createElement('a');cflink.setAttribute('href',res.url); var cflink = document.createElement('a');
var cf_hostname=cflink.hostname; cflink.setAttribute('href',res.url);
var cf_protocol=cflink.protocol; var cf_hostname = cflink.hostname;
var cf_gothead=res.responseHeaders; var cf_protocol = cflink.protocol;
cflink=null; var cf_gothead = res.responseHeaders;
if ((cf_protocol=='http:'||cf_protocol=='https:') && cf_hostname.length>=4){ cflink = null;
//console.log("mitmdetector: testing...: "+res.url);
var is_cloudflare_infected=0;// 2 to confirm if ((cf_protocol == 'http:' || cf_protocol == 'https:') &&
for(var i=0;i<cf_gothead.length;i++){ cf_hostname.length >= 4) {
var cfv=cf_gothead[i]; //console.log("mitmdetector: testing...: "+res.url);
if (cfv['name']=='cf-ray' && cfv['value']!=undefined){is_cloudflare_infected+=1;} var is_cloudflare_infected=0; // 2 to confirm
if (cfv['name']=='server' && cfv['value'].includes("cloudflare")){is_cloudflare_infected+=1;}
if (is_cloudflare_infected==2){break;} for (var i=0; i < cf_gothead.length; i++) {
} var cfv=cf_gothead[i];
if (is_cloudflare_infected>=1){ if (cfv['name'] == 'cf-ray' && cfv['value'] != undefined) {
console.log('SECURITY_WARN: Cloudflare Detected: '+res.url); is_cloudflare_infected += 1;
return {redirectUrl: "https://0.0.0.0/"};// just drop the connection }
} if (cfv['name'] == 'server' && cfv['value'].includes("cloudflare")) {
} is_cloudflare_infected += 1;
return; }
if (is_cloudflare_infected == 2) {
break;
}
}
if (is_cloudflare_infected >= 1) {
console.log('SECURITY_WARN: Cloudflare Detected: '+res.url);
return {redirectUrl: "https://0.0.0.0/"}; // just drop the connection
}
}
return;
} }
browser.webRequest.onHeadersReceived.addListener(analyzemydata,{urls: ["<all_urls>"]},["blocking","responseHeaders"]); browser.webRequest.onHeadersReceived.addListener(analyzemydata,{urls: ["<all_urls>"]},["blocking","responseHeaders"]);
//