package main import ( "fmt" "log" "math/rand" "net/http" "strconv" "strings" "github.com/miekg/dns" ) type dnsHandler struct{} func (h *dnsHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { msg := new(dns.Msg) msg.SetReply(r) msg.Authoritative = true for _, question := range r.Question { fmt.Printf("Received query: %s (%d)\n", question.Name, question.Qtype) if question.Qtype == dns.TypeCNAME || question.Qtype == dns.TypeA || question.Qtype == dns.TypeAAAA { if question.Name == "google.com." { msg.Answer = append(msg.Answer, &dns.CNAME{ Hdr: dns.RR_Header{ Name: question.Name, Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: 30, }, Target: "test0.imposter.cringe-studios.com.", }) continue } if strings.HasPrefix(question.Name, "test") && strings.HasSuffix(question.Name, ".imposter.cringe-studios.com.") { num := question.Name[4:strings.Index(question.Name, ".imposter.cringe-studios.com.")] number, err := strconv.ParseUint(num, 10, 64) number++ log.Println(num) if err != nil { log.Fatal("sus", err) } msg.Answer = append(msg.Answer, &dns.CNAME{ Hdr: dns.RR_Header{ Name: question.Name, Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: 30, }, Target: "test" + strconv.Itoa(int(number)) + ".imposter.cringe-studios.com.", }) continue } if question.Name == "random-number.imposter.cringe-studios.com." { theNumber := rand.Intn(10000) msg.Answer = append(msg.Answer, &dns.CNAME{ Hdr: dns.RR_Header{ Name: question.Name, Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: 30, }, Target: "number-" + strconv.Itoa(theNumber) + ".imposter.cringe-studios.com.", }) continue } if question.Name == "amogus.imposter.cringe-studios.com." { msg.Answer = append(msg.Answer, &dns.CNAME{ Hdr: dns.RR_Header{ Name: question.Name, Rrtype: dns.TypeCNAME, Class: dns.ClassINET, Ttl: 30, }, Target: "test(test.imposter.cringe-studios.com.", }) continue } // msg.Answer = append(msg.Answer, &dns.NXNAME{ // Hdr: dns.RR_Header{ // Name: question.Name, // Rrtype: dns.TypeNXNAME, // Class: dns.ClassINET, // Ttl: 30, // }, // }) } } w.WriteMsg(msg) } func getPage(w http.ResponseWriter, r *http.Request) { w.Write([]byte("Hello World!")) } func main() { handler := new(dnsHandler) server := &dns.Server{ Addr: ":53", Net: "udp", Handler: handler, UDPSize: 65535, ReusePort: true, } go func() { err := server.ListenAndServe() if err != nil { log.Fatalln("failed to listen", err) } }() http.HandleFunc("/", getPage) http.ListenAndServe(":6980", nil) }