2025-01-11 15:17:24 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"math/rand"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
2025-01-11 16:23:23 +01:00
|
|
|
"strings"
|
2025-01-11 15:17:24 +01:00
|
|
|
|
|
|
|
"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)
|
|
|
|
|
2025-01-11 16:23:23 +01:00
|
|
|
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." {
|
2025-01-11 15:17:24 +01:00
|
|
|
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,
|
|
|
|
},
|
2025-01-11 16:23:23 +01:00
|
|
|
Target: "number-" + strconv.Itoa(theNumber) + ".imposter.cringe-studios.com.",
|
2025-01-11 15:17:24 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2025-01-11 16:23:23 +01:00
|
|
|
if question.Name == "amogus.imposter.cringe-studios.com." {
|
2025-01-11 15:17:24 +01:00
|
|
|
msg.Answer = append(msg.Answer, &dns.CNAME{
|
|
|
|
Hdr: dns.RR_Header{
|
|
|
|
Name: question.Name,
|
|
|
|
Rrtype: dns.TypeCNAME,
|
|
|
|
Class: dns.ClassINET,
|
|
|
|
Ttl: 30,
|
|
|
|
},
|
2025-01-11 16:23:23 +01:00
|
|
|
Target: "test(test.imposter.cringe-studios.com.",
|
2025-01-11 15:17:24 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2025-01-11 16:23:23 +01:00
|
|
|
// msg.Answer = append(msg.Answer, &dns.NXNAME{
|
|
|
|
// Hdr: dns.RR_Header{
|
|
|
|
// Name: question.Name,
|
|
|
|
// Rrtype: dns.TypeNXNAME,
|
|
|
|
// Class: dns.ClassINET,
|
|
|
|
// Ttl: 30,
|
|
|
|
// },
|
|
|
|
// })
|
2025-01-11 15:17:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
w.WriteMsg(msg)
|
|
|
|
}
|
|
|
|
|
|
|
|
func getPage(w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.Write([]byte("Hello World!"))
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
2025-01-12 00:11:39 +01:00
|
|
|
log.Println("Starting Server!");
|
|
|
|
|
2025-01-11 15:17:24 +01:00
|
|
|
handler := new(dnsHandler)
|
|
|
|
|
|
|
|
server := &dns.Server{
|
2025-01-11 16:23:23 +01:00
|
|
|
Addr: ":53",
|
2025-01-11 15:17:24 +01:00
|
|
|
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)
|
|
|
|
}
|