diff --git a/blackhatgo/chapter4/fileServer.go b/blackhatgo/chapter4/fileServer.go new file mode 100644 index 0000000..39c4c98 --- /dev/null +++ b/blackhatgo/chapter4/fileServer.go @@ -0,0 +1,5 @@ +package main + +func main(){ + +} \ No newline at end of file diff --git a/blackhatgo/chapter5/dnsServer.go b/blackhatgo/chapter5/dnsServer.go new file mode 100644 index 0000000..61a0d9e --- /dev/null +++ b/blackhatgo/chapter5/dnsServer.go @@ -0,0 +1,70 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strings" + + "github.com/miekg/dns" +) + +var records map[string]string + +func parse(filename string) (map[string]string, error) { + records := make(map[string]string) + fh, err := os.Open(filename) + if err != nil { + return records, err + } + defer fh.Close() + scanner := bufio.NewScanner(fh) + for scanner.Scan() { + line := scanner.Text() + parts := strings.SplitN(line, ",", 2) + if len(parts) < 2 { + return records, fmt.Errorf("%s is not a valid line", line) + } + records[parts[0]] = parts[1] + } + return records, scanner.Err() + +} + +func dnsRequestHandler(w dns.ResponseWriter, req *dns.Msg) { + msg := dns.Msg{} + msg.SetReply(req) + if len(req.Question) < 1 { + dns.HandleFailed(w, req) + return + } + name := strings.TrimSuffix(req.Question[0].Name, ".") + parts := strings.Split(name, ".") + + if len(parts) > 1 { + name = strings.Join(parts[len(parts)-2:], ".") + } + match, ok := records[name] + fmt.Println(match) + if !ok { + dns.HandleFailed(w, req) + return + } + resp + if err != nil { + dns.HandleFailed(w, req) + return + } + if err := w.WriteMsg(resp); err != nil { + dns.HandleFailed(w, req) + return + } +} + +func main() { + records, _ = parse("proxy.config") + + dns.HandleFunc(".", dnsRequestHandler) + log.Fatal(dns.ListenAndServe(":53", "udp", nil)) +} diff --git a/blackhatgo/chapter5/go.mod b/blackhatgo/chapter5/go.mod new file mode 100644 index 0000000..5ff2a38 --- /dev/null +++ b/blackhatgo/chapter5/go.mod @@ -0,0 +1,9 @@ +module github.com/vanshaj/golang/blackhatgo/chapter5 + +go 1.17 + +require ( + github.com/miekg/dns v1.1.43 // indirect + golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect + golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 // indirect +) diff --git a/blackhatgo/chapter5/go.sum b/blackhatgo/chapter5/go.sum new file mode 100644 index 0000000..f289107 --- /dev/null +++ b/blackhatgo/chapter5/go.sum @@ -0,0 +1,11 @@ +github.com/miekg/dns v1.1.43 h1:JKfpVSCB84vrAmHzyrsxB5NAr5kLoMXZArPSw7Qlgyg= +github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04 h1:cEhElsAv9LUt9ZUUocxzWe05oFLVd+AA2nstydTeI8g= +golang.org/x/sys v0.0.0-20210303074136-134d130e1a04/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/blackhatgo/chapter5/proxy.config b/blackhatgo/chapter5/proxy.config new file mode 100644 index 0000000..3c173af --- /dev/null +++ b/blackhatgo/chapter5/proxy.config @@ -0,0 +1,2 @@ +attacker1.com,127.0.0.1:2021 +attacker2.com,127.0.0.1:2022 \ No newline at end of file diff --git a/blackhatgo/chapter5/wordlist b/blackhatgo/chapter5/wordlist new file mode 100644 index 0000000..41bff8e --- /dev/null +++ b/blackhatgo/chapter5/wordlist @@ -0,0 +1,11 @@ +qa1 +qa3 +qa7 +qa8 +qa9 +qa10 +abc +def +xyz +hhh +mnh