|
|
@ -35,22 +35,39 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
public class DnsBlockList {
|
|
|
|
public class DnsBlockList {
|
|
|
|
private static final List<BlockList> BLOCKLISTS = Collections.unmodifiableList(Arrays.asList(
|
|
|
|
private static final List<BlockList> BLOCKLISTS = Collections.unmodifiableList(Arrays.asList(
|
|
|
|
new BlockList("Spamhaus/zen", "zen.spamhaus.org", new String[]{
|
|
|
|
// https://www.spamhaus.org/zen/
|
|
|
|
|
|
|
|
new BlockList(true, "Spamhaus/zen", "zen.spamhaus.org", true, new String[]{
|
|
|
|
// https://www.spamhaus.org/faq/section/DNSBL%20Usage#200
|
|
|
|
// https://www.spamhaus.org/faq/section/DNSBL%20Usage#200
|
|
|
|
"127.0.0.2", // SBL Spamhaus SBL Data
|
|
|
|
"127.0.0.2", // SBL Spamhaus SBL Data
|
|
|
|
"127.0.0.3", // SBL Spamhaus SBL CSS Data
|
|
|
|
"127.0.0.3", // SBL Spamhaus SBL CSS Data
|
|
|
|
"127.0.0.4", // XBL CBL Data
|
|
|
|
"127.0.0.4", // XBL CBL Data
|
|
|
|
"127.0.0.9" // SBL Spamhaus DROP/EDROP Data
|
|
|
|
"127.0.0.9", // SBL Spamhaus DROP/EDROP Data
|
|
|
|
//127.0.0.10 PBL ISP Maintained
|
|
|
|
//127.0.0.10 PBL ISP Maintained
|
|
|
|
//127.0.0.11 PBL Spamhaus Maintained
|
|
|
|
//127.0.0.11 PBL Spamhaus Maintained
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
new BlockList("Spamcop", "bl.spamcop.net", new String[]{
|
|
|
|
|
|
|
|
|
|
|
|
// https://www.spamhaus.org/dbl/
|
|
|
|
|
|
|
|
new BlockList(true, "Spamhaus/DBL", "dbl.spamhaus.org", false, new String[]{
|
|
|
|
|
|
|
|
// https://www.spamhaus.org/faq/section/Spamhaus%20DBL#291
|
|
|
|
|
|
|
|
"127.0.1.2", // spam domain
|
|
|
|
|
|
|
|
"127.0.1.4", // phish domain
|
|
|
|
|
|
|
|
"127.0.1.5", // malware domain
|
|
|
|
|
|
|
|
"127.0.1.6", // botnet C&C domain
|
|
|
|
|
|
|
|
"127.0.1.102", // abused legit spam
|
|
|
|
|
|
|
|
"127.0.1.103", // abused spammed redirector domain
|
|
|
|
|
|
|
|
"127.0.1.104", // abused legit phish
|
|
|
|
|
|
|
|
"127.0.1.105", // abused legit malware
|
|
|
|
|
|
|
|
"127.0.1.106", // abused legit botnet C&C
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new BlockList(true, "Spamcop", "bl.spamcop.net", true, new String[]{
|
|
|
|
// https://www.spamcop.net/fom-serve/cache/291.html
|
|
|
|
// https://www.spamcop.net/fom-serve/cache/291.html
|
|
|
|
"127.0.0.2"
|
|
|
|
"127.0.0.2",
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
new BlockList(false, "Barracuda", "b.barracudacentral.org", true, new String[]{
|
|
|
|
|
|
|
|
// https://www.barracudacentral.org/rbl/how-to-use
|
|
|
|
})
|
|
|
|
})
|
|
|
|
//new BlockList("b.barracudacentral.org", new String[]{
|
|
|
|
|
|
|
|
// // https://www.barracudacentral.org/rbl/how-to-use
|
|
|
|
|
|
|
|
//})
|
|
|
|
|
|
|
|
));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
private static final long CACHE_EXPIRY_AFTER = 3600 * 1000L; // milliseconds
|
|
|
|
private static final long CACHE_EXPIRY_AFTER = 3600 * 1000L; // milliseconds
|
|
|
@ -59,6 +76,7 @@ public class DnsBlockList {
|
|
|
|
static List<String> getNames() {
|
|
|
|
static List<String> getNames() {
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
List<String> names = new ArrayList<>();
|
|
|
|
for (BlockList blocklist : BLOCKLISTS)
|
|
|
|
for (BlockList blocklist : BLOCKLISTS)
|
|
|
|
|
|
|
|
if (blocklist.enabled)
|
|
|
|
names.add(blocklist.name);
|
|
|
|
names.add(blocklist.name);
|
|
|
|
return names;
|
|
|
|
return names;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -83,7 +101,7 @@ public class DnsBlockList {
|
|
|
|
|
|
|
|
|
|
|
|
boolean blocked = false;
|
|
|
|
boolean blocked = false;
|
|
|
|
for (BlockList blocklist : blocklists)
|
|
|
|
for (BlockList blocklist : blocklists)
|
|
|
|
if (isJunk(domain, blocklist)) {
|
|
|
|
if (blocklist.enabled && isJunk(domain, blocklist)) {
|
|
|
|
blocked = true;
|
|
|
|
blocked = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -97,6 +115,7 @@ public class DnsBlockList {
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean isJunk(String domain, BlockList blocklist) {
|
|
|
|
private static boolean isJunk(String domain, BlockList blocklist) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (blocklist.numeric) {
|
|
|
|
long start = new Date().getTime();
|
|
|
|
long start = new Date().getTime();
|
|
|
|
InetAddress[] addresses = InetAddress.getAllByName(domain);
|
|
|
|
InetAddress[] addresses = InetAddress.getAllByName(domain);
|
|
|
|
long elapsed = new Date().getTime() - start;
|
|
|
|
long elapsed = new Date().getTime() - start;
|
|
|
@ -119,27 +138,47 @@ public class DnsBlockList {
|
|
|
|
|
|
|
|
|
|
|
|
lookup.append(blocklist.address);
|
|
|
|
lookup.append(blocklist.address);
|
|
|
|
|
|
|
|
|
|
|
|
start = new Date().getTime();
|
|
|
|
if (isJunk(lookup.toString(), blocklist.responses))
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
long start = new Date().getTime();
|
|
|
|
|
|
|
|
String lookup = domain + "." + blocklist.address;
|
|
|
|
|
|
|
|
boolean junk = isJunk(lookup, blocklist.responses);
|
|
|
|
|
|
|
|
long elapsed = new Date().getTime() - start;
|
|
|
|
|
|
|
|
Log.i("isJunk" + " " + lookup + "=" + junk + " elapsed=" + elapsed);
|
|
|
|
|
|
|
|
return junk;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean isJunk(String lookup, InetAddress[] responses) {
|
|
|
|
|
|
|
|
long start = new Date().getTime();
|
|
|
|
InetAddress result;
|
|
|
|
InetAddress result;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Possibly blocked
|
|
|
|
// Possibly blocked
|
|
|
|
result = InetAddress.getByName(lookup.toString());
|
|
|
|
result = InetAddress.getByName(lookup);
|
|
|
|
} catch (UnknownHostException ignored) {
|
|
|
|
} catch (UnknownHostException ignored) {
|
|
|
|
// Not blocked
|
|
|
|
// Not blocked
|
|
|
|
result = null;
|
|
|
|
result = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elapsed = new Date().getTime() - start;
|
|
|
|
long elapsed = new Date().getTime() - start;
|
|
|
|
|
|
|
|
|
|
|
|
if (result != null && blocklist.responses.length > 0) {
|
|
|
|
if (result != null && responses.length > 0) {
|
|
|
|
boolean blocked = false;
|
|
|
|
boolean blocked = false;
|
|
|
|
for (InetAddress response : blocklist.responses)
|
|
|
|
for (InetAddress response : responses)
|
|
|
|
if (response.equals(result)) {
|
|
|
|
if (response.equals(result)) {
|
|
|
|
blocked = true;
|
|
|
|
blocked = true;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!blocked) {
|
|
|
|
if (!blocked) {
|
|
|
|
Log.w("isJunk" +
|
|
|
|
Log.w("isJunk" +
|
|
|
|
" addr=" + addr +
|
|
|
|
|
|
|
|
" lookup=" + lookup +
|
|
|
|
" lookup=" + lookup +
|
|
|
|
" result=" + result +
|
|
|
|
" result=" + result +
|
|
|
|
" elapsed=" + elapsed);
|
|
|
|
" elapsed=" + elapsed);
|
|
|
@ -147,20 +186,11 @@ public class DnsBlockList {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("isJunk " + addr +
|
|
|
|
Log.i("isJunk" +
|
|
|
|
" " + lookup + "=" + (result == null ? "false" : result) +
|
|
|
|
" " + lookup + "=" + (result == null ? "false" : result) +
|
|
|
|
" elapsed=" + elapsed);
|
|
|
|
" elapsed=" + elapsed);
|
|
|
|
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
return (result != null);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
Log.w(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class CacheEntry {
|
|
|
|
private static class CacheEntry {
|
|
|
@ -182,13 +212,17 @@ public class DnsBlockList {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static class BlockList {
|
|
|
|
static class BlockList {
|
|
|
|
|
|
|
|
boolean enabled;
|
|
|
|
String name;
|
|
|
|
String name;
|
|
|
|
String address;
|
|
|
|
String address;
|
|
|
|
|
|
|
|
boolean numeric;
|
|
|
|
InetAddress[] responses;
|
|
|
|
InetAddress[] responses;
|
|
|
|
|
|
|
|
|
|
|
|
BlockList(String name, String address, String[] responses) {
|
|
|
|
BlockList(boolean enabled, String name, String address, boolean numeric, String[] responses) {
|
|
|
|
|
|
|
|
this.enabled = enabled;
|
|
|
|
this.name = name;
|
|
|
|
this.name = name;
|
|
|
|
this.address = address;
|
|
|
|
this.address = address;
|
|
|
|
|
|
|
|
this.numeric = numeric;
|
|
|
|
List<InetAddress> r = new ArrayList<>();
|
|
|
|
List<InetAddress> r = new ArrayList<>();
|
|
|
|
for (String response : responses)
|
|
|
|
for (String response : responses)
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|