Browse Source

Deobfuscate Cloudflare-obfuscated emails

pull/61/merge
Ezerous 6 years ago
parent
commit
afd1c6fc79
No known key found for this signature in database GPG Key ID: 262B2954BBA319E3
  1. 2
      app/build.gradle
  2. 11
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  3. 44
      app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java

2
app/build.gradle

@ -64,7 +64,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-messaging:17.3.3'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'com.squareup.picasso:picasso:2.5.2'

11
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -38,8 +38,11 @@ import io.fabric.sdk.android.Fabric;
import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import timber.log.Timber;
import static gr.thmmy.mthmmy.utils.EmailDeobfuscator.deobfuscate;
public class BaseApplication extends Application {
private static BaseApplication baseApplication; //BaseApplication singleton
@ -100,8 +103,14 @@ public class BaseApplication extends Application {
request = request.newBuilder().url(newUrl).build();
}
}
return chain.proceed(request);
Response response = chain.proceed(request);
try {
response = deobfuscate(response);
} catch (Exception e) {
Timber.e(e, "Email deobfuscation error.");
}
return response;
})
.connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)

44
app/src/main/java/gr/thmmy/mthmmy/utils/EmailDeobfuscator.java

@ -0,0 +1,44 @@
package gr.thmmy.mthmmy.utils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.Response;
import okhttp3.ResponseBody;
//Deobfuscates Cloudflare-obfuscated emails
public class EmailDeobfuscator {
public static Response deobfuscate(Response response) throws IOException {
String responseBody = response.body().string();
Document document = Jsoup.parse(responseBody);
Elements obfuscatedEmails = document.select("span.__cf_email__");
for (Element obfuscatedEmail : obfuscatedEmails) {
String email = deobfuscateEmail(obfuscatedEmail.attr("data-cfemail"));
Element parent = obfuscatedEmail.parent();
if (parent.is("a")&&parent.attr("href").contains("email-protection"))
parent.attr("href", "mailto:"+email);
obfuscatedEmail.replaceWith(new TextNode(email, ""));
}
MediaType contentType = response.body().contentType();
ResponseBody body = ResponseBody.create(contentType, document.toString());
return response.newBuilder().body(body).build();
}
private static String deobfuscateEmail(final String encodedString) {
final StringBuilder email = new StringBuilder();
final int r = Integer.parseInt(encodedString.substring(0, 2), 16);
for (int n = 2; n < encodedString.length(); n += 2) {
final int i = Integer.parseInt(encodedString.substring(n, n+2), 16) ^ r;
email.append(Character.toString ((char) i));
}
return email.toString();
}
}
Loading…
Cancel
Save