Skip to content

Instantly share code, notes, and snippets.

@adrianhorning08
Created January 10, 2024 22:21
Show Gist options
  • Save adrianhorning08/de8f2d02ed421c6d4c8557cf777774da to your computer and use it in GitHub Desktop.
Save adrianhorning08/de8f2d02ed421c6d4c8557cf777774da to your computer and use it in GitHub Desktop.
How to decrypt emails on cloudflare protected sites
import * as cheerio from "cheerio";
function getHexValue(str, index) {
var hex = str.substr(index, 2);
return parseInt(hex, 16);
}
function decryptEmail(encodedEmail, startIndex) {
var decryptedEmail = "",
key = getHexValue(encodedEmail, startIndex);
for (var i = startIndex + 2; i < encodedEmail.length; i += 2) {
var charCode = getHexValue(encodedEmail, i) ^ key;
decryptedEmail += String.fromCharCode(charCode);
}
try {
decryptedEmail = decodeURIComponent(escape(decryptedEmail));
} catch (error) {
console.log("error at decryptEmail", error.message);
}
if (decryptedEmail) {
return decryptedEmail;
}
}
const $ = cheerio.load(body);
const cfEmail = $(".__cf_email__");
if (cfEmail?.length) {
const emails = cfEmail?.map?.((index, element) => {
const data = $(element)?.attr?.("data-cfemail");
if (data) {
const email = decryptEmail(data, 0);
return email;
}
});
console.log('emails', emails)
return emails;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment