UDGuard is a base implementation of a zero-dependency DNS Proxy that enables authentication and packet processing. The data can be altered by adding custom code in the DNSLookupHandler
function.
To customize the DNS Proxy behavior, modify the following function in cmd/udguard/main.go
:
func DNSLookupHandler(msg []byte, addr *net.UDPAddr, s_conn *net.UDPConn) {
c_conn, err := internal.StartClient("1.1.1.1", "53")
if err != nil {
logger.Fatal(err)
panic(err)
}
defer c_conn.Close()
log.Println("Sending request to DNS server")
_, err = c_conn.Write(msg)
var buf [512]byte
_, _, err = c_conn.ReadFromUDP(buf[0:])
if err != nil {
logger.Fatal(err)
}
log.Println("Received response from DNS server")
log.Println(buf)
log.Println("Waiting for response from DNS server")
// ADD CODE HERE <------------
log.Println("Sending response to client")
_, err = s_conn.WriteToUDP(buf[:], addr)
if err != nil {
logger.Fatal(err)
}
}
There are two main programs in this repository located under the cmd/
folder:
udguard
: The main DNS Proxy server.stresser
: A tool for stress testing the proxy.
To build and compile the programs, follow these steps:
-
Clone the repository:
git clone https://github.com/joaoofreitas/udguard.git cd udguard
-
Build the main
udguard
program:cd cmd/udguard go build -o udguard
-
Build the
stresser
program:cd cmd/stresser go build -o stresser
To test the udguard
DNS Proxy, you can use the stresser
tool:
-
Start the
udguard
server:./udguard
-
In another terminal, run the
stresser
tool:./stresser
The stresser
tool will send multiple DNS requests to the udguard
server to test its performance and stability.
This code is provided as a base for implementing a DNS Proxy and is intended for educational and testing purposes only. It is not written with bad intentions, and I am not responsible for any misuse of this code, including its use as a basis for malware.