-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task/Issue URL: https://app.asana.com/0/1198194956794324/1208368538104397/f ### Description Add detection for when the DNS blocks requests to domains that serve malware. The library also calls back into JVM with the blocked domain, if the JVM callback is present ### Steps to test this PR _Test_ - [x] checkout this branch and `cd` into the `android` folder - [x] run `./gradlew assemble publishToMavenLocal` - [x] go to the Android app repo, `develop` branch and apply the following patch ```diff commit 40e3568897a31e8c603490f5f49a519773aff8c9 Author: Aitor Viana <aitorvs@gmail.com> Date: Sun Jun 4 20:49:52 2023 -0400 Maven local use diff --git a/build.gradle b/build.gradle index de22b7abb..aee98799a 100644 --- a/build.gradle +++ b/build.gradle @@ -42,6 +42,7 @@ allprojects { google() mavenCentral() maven { url 'https://jitpack.io' } + mavenLocal() } configurations.all { resolutionStrategy.force 'org.objenesis:objenesis:2.6' diff --git a/versions.properties b/versions.properties index d092a0163..5f58ba46a 100644 --- a/versions.properties +++ b/versions.properties @@ -77,7 +77,7 @@ version.com.airbnb.android..lottie=5.2.0 version.com.android.installreferrer..installreferrer=2.2 -version.com.duckduckgo.netguard..netguard-android=1.6.12 +version.com.duckduckgo.netguard..netguard-android=1.7.0-SNAPSHOT version.com.duckduckgo.synccrypto..sync-crypto-android=0.3.0 ``` - [x] build Android app, `./gradlew assembleID`, install and run the app - [x] enable the VPN - [x] filter the logcat with `MID_RECORD_MALWARE_BLOCK` and another logcat with `tag:WireGuard/GoBackend/Write` - [x] with VPN enabled, go to "vpn-malware.goduckgo.com" - [x] verify `DNS malware was blocked for domain: vpn-malware.goduckgo.com. due to 'blocked:m' TXT record` log appears - [x] verify `MID_RECORD_MALWARE_BLOCK method not found` error log appears - [x] smoke test VPN and browsing
- Loading branch information
Showing
5 changed files
with
182 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright (c) 2022 DuckDuckGo | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
// #include <android/log.h> | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/miekg/dns" | ||
) | ||
|
||
|
||
// parseDNSResponse parses the raw DNS response from a byte slice. | ||
func parseDNSResponse(data []byte) *dns.Msg { | ||
tag := cstring("WireGuard/GoBackend/parseDNSResponse") | ||
// Create a new DNS message structure | ||
dnsMsg := new(dns.Msg) | ||
|
||
// Unpack the DNS message from the raw data | ||
err := dnsMsg.Unpack(data) | ||
if err != nil { | ||
C.__android_log_write(C.ANDROID_LOG_DEBUG, tag, cstring(fmt.Sprintf("Failed to unpack DNS message: %v", err))) | ||
return nil | ||
} | ||
|
||
// Check if this is a DNS response (QR bit set) | ||
if dnsMsg.Response { | ||
return dnsMsg | ||
} | ||
|
||
// If not a response, return nil | ||
return nil | ||
} | ||
|
||
|
||
/* | ||
* WasDNSMalwareBlocked checks if the DNS packet contains a "blocked:m" TXT | ||
* record under the "explanation.invalid" domain. If such a record is found, | ||
* it returns true along with the domain being blocked. | ||
* That record is found when our the DDG (malware) DNS server blocks domains that | ||
* serve malware | ||
*/ | ||
func WasDNSMalwareBlocked(dnsData []byte) (bool, string) { | ||
dnsResponse := parseDNSResponse(dnsData) | ||
if dnsResponse == nil { | ||
return false, "" | ||
} | ||
|
||
// Look for "explanation.invalid" in the additional section | ||
for _, rr := range dnsResponse.Extra { | ||
if txtRecord, ok := rr.(*dns.TXT); ok { | ||
if txtRecord.Hdr.Name == "explanation.invalid." { | ||
for _, txt := range txtRecord.Txt { | ||
if txt == "blocked:m" { | ||
// If there is a matching TXT record, return the blocked domain | ||
if len(dnsResponse.Question) > 0 { | ||
blockedDomain := dnsResponse.Question[0].Name | ||
// remove the trailing dot (FQDN) if present | ||
blockedDomain = strings.TrimSuffix(blockedDomain, ".") | ||
return true, blockedDomain | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return false, "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters