-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
BadEnd
committed
Jan 19, 2024
0 parents
commit 906465e
Showing
6 changed files
with
263 additions
and
0 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,15 @@ | ||
# Ignore compiled binaries and executables | ||
*.exe | ||
VRConnectivity-Shield | ||
|
||
# Ignore go generated files | ||
*.pb.go | ||
*.log | ||
|
||
# Ignore the Go Modules cache | ||
/go.sum | ||
/go.mod | ||
|
||
# Ignore system and temporary files | ||
.DS_Store | ||
Thumbs.db |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Onyx Innovators | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,59 @@ | ||
# VRConnectivity Shield | ||
|
||
VRConnectivity Shield is a DNS blocking utility implemented in Go, designed to block specific hosts by responding to DNS requests with 0.0.0.0. This can be useful for preventing unwanted connections to analytics services, telemetry servers, etc. | ||
|
||
## Usage | ||
|
||
### Prerequisites | ||
|
||
- [Go](https://golang.org/doc/install) installed on your system. | ||
|
||
### Installation | ||
|
||
1. Clone the repository: | ||
|
||
```bash | ||
git clone https://github.com/Onyx-Innovators/VRConnectivity-Shield.git | ||
``` | ||
|
||
2. Change into the project directory: | ||
|
||
```bash | ||
cd VRConnectivity-Shield | ||
``` | ||
|
||
3. Build the project: | ||
|
||
```bash | ||
go build | ||
``` | ||
|
||
4. Run the program as root: | ||
- Double-click the executable file, or | ||
- Run the executable from the command line: | ||
|
||
```bash | ||
sudo ./VRConnectivity-Shield | ||
``` | ||
|
||
### Configuration | ||
|
||
The list of blocked hosts is sourced from [VRChat-Analytics-Blocker](https://github.com/DubyaDude/VRChat-Analytics-Blocker). The blocked hosts are defined in the utils/blockedHosts map in the utils package. You can modify this map to include or exclude specific hosts as needed. | ||
|
||
```go | ||
var blockedHosts = map[string]struct{}{ | ||
"api.amplitude.com": {}, | ||
"api2.amplitude.com": {}, | ||
// Add or remove hosts as necessary | ||
} | ||
``` | ||
|
||
## How it works | ||
|
||
The program sets up a DNS server listening on UDP port 53. When a DNS request is received, it checks if the requested host is in the list of blocked hosts. If it is, the request is blocked by responding with 0.0.0.0. Otherwise, the request is allowed to proceed. | ||
|
||
## License | ||
|
||
This project is licensed under the [MIT License](LICENSE). | ||
|
||
--- |
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,71 @@ | ||
package logger | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/fatih/color" | ||
) | ||
|
||
type LogLevel int | ||
|
||
const ( | ||
DebugLevel LogLevel = iota | ||
InfoLevel | ||
WarnLevel | ||
ErrorLevel | ||
FatalLevel | ||
SuccessLevel | ||
) | ||
|
||
type Logger struct { | ||
enableColors bool | ||
} | ||
|
||
// NewLogger creates a new logger instance. | ||
func NewLogger(enableColors bool) *Logger { | ||
return &Logger{enableColors: enableColors} | ||
} | ||
|
||
// GetLogger creates a new logger instance with colors enabled. | ||
func GetLogger() *Logger { | ||
return NewLogger(true) | ||
} | ||
|
||
func (l *Logger) log(level LogLevel, colorFunc func(a ...interface{}) string, message ...interface{}) { | ||
if l.enableColors { | ||
message = []interface{}{colorFunc(fmt.Sprint(message...))} | ||
} | ||
fmt.Printf("[%s] %s\n", time.Now().Format("15:04:05"), strings.TrimRight(fmt.Sprint(message...), "\n")) | ||
} | ||
|
||
func (l *Logger) Debug(message ...interface{}) { | ||
l.log(DebugLevel, color.New(color.FgWhite).SprintFunc(), message...) | ||
} | ||
|
||
func (l *Logger) Info(message ...interface{}) { | ||
l.log(InfoLevel, color.New(color.FgBlue).SprintFunc(), message...) | ||
} | ||
|
||
func (l *Logger) Warn(message ...interface{}) { | ||
l.log(WarnLevel, color.New(color.FgYellow).SprintFunc(), message...) | ||
} | ||
|
||
func (l *Logger) Error(message ...interface{}) { | ||
l.log(ErrorLevel, color.New(color.FgRed).SprintFunc(), message...) | ||
} | ||
|
||
func (l *Logger) Fatal(message ...interface{}) { | ||
l.log(FatalLevel, color.New(color.FgRed).SprintFunc(), message...) | ||
os.Exit(1) // Note: Fatal will exit the program | ||
} | ||
|
||
func (l *Logger) Success(message ...interface{}) { | ||
l.log(SuccessLevel, color.New(color.FgGreen).SprintFunc(), message...) | ||
} | ||
|
||
func (l *Logger) SetEnableColors(enableColors bool) { | ||
l.enableColors = enableColors | ||
} |
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,31 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/Onyx-Innovators/VRConnectivity-Shield/logger" | ||
"github.com/Onyx-Innovators/VRConnectivity-Shield/utils" | ||
"github.com/miekg/dns" | ||
) | ||
|
||
// main is the entry point of the program | ||
func main() { | ||
log := logger.GetLogger() // Get the logger | ||
|
||
port := "53" | ||
|
||
// Set up the DNS server | ||
dns.HandleFunc(".", utils.HandleDNSRequest) | ||
// Start the DNS server | ||
go func() { | ||
err := dns.ListenAndServe(":"+port, "udp", nil) // Listen on UDP port 53 | ||
if err != nil { | ||
log.Error("Failed to set udp listener: ", err) | ||
os.Exit(1) | ||
} | ||
}() | ||
|
||
log.Info("DNS blocker is running on port ", port) | ||
|
||
select {} // Block forever | ||
} |
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,66 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"strings" | ||
|
||
"github.com/Onyx-Innovators/VRConnectivity-Shield/logger" | ||
"github.com/miekg/dns" | ||
) | ||
|
||
// blockedHosts is a map of hosts that should be blocked | ||
var blockedHosts = map[string]struct{}{ | ||
"api.amplitude.com": {}, | ||
"api2.amplitude.com": {}, | ||
"api.lab.amplitude.com": {}, | ||
"api.eu.amplitude.com": {}, | ||
"regionconfig.amplitude.com": {}, | ||
"regionconfig.eu.amplitude.com": {}, | ||
"o1125869.ingest.sentry.io": {}, | ||
"api3.amplitude.com": {}, | ||
"cdn.amplitude.com": {}, | ||
"info.amplitude.com": {}, | ||
"static.amplitude.com": {}, | ||
"api.uca.cloud.unity3d.com": {}, | ||
"config.uca.cloud.unity3d.com": {}, | ||
"perf-events.cloud.unity3d.com": {}, | ||
"public.cloud.unity3d.com": {}, | ||
"cdp.cloud.unity3d.com": {}, | ||
"data-optout-service.uca.cloud.unity3d.com": {}, | ||
"ecommerce.iap.unity3d.com": {}, | ||
} | ||
|
||
// HandleDNSRequest handles DNS requests | ||
func HandleDNSRequest(w dns.ResponseWriter, r *dns.Msg) { | ||
log := logger.GetLogger() | ||
|
||
m := new(dns.Msg) | ||
m.SetReply(r) | ||
|
||
for _, q := range m.Question { | ||
host := strings.TrimSuffix(q.Name, ".") | ||
|
||
if _, blocked := blockedHosts[host]; blocked { | ||
// Block the request by responding with 0.0.0.0 | ||
rr, err := dns.NewRR(fmt.Sprintf("%s A 0.0.0.0", q.Name)) | ||
if err == nil { | ||
m.Answer = append(m.Answer, rr) | ||
} | ||
} else { | ||
// Allow the request to proceed | ||
addr, err := net.LookupHost(host) | ||
if err == nil { | ||
rr, err := dns.NewRR(fmt.Sprintf("%s A %s", q.Name, addr[0])) | ||
if err == nil { | ||
m.Answer = append(m.Answer, rr) | ||
} | ||
} | ||
} | ||
} | ||
|
||
err := w.WriteMsg(m) | ||
if err != nil { | ||
log.Error("Failed to write message: ", err) | ||
} | ||
} |