/
file.go
57 lines (44 loc) 路 1.28 KB
/
file.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
package protocol
import (
"bytes"
"crypto/sha1"
"encoding/hex"
"os"
"github.com/sensepost/godoh/lib"
)
// File represents a file to be send over DNS.
type File struct {
Size int64 `json:"size"`
Shasum string `json:"shasum"`
Name string `json:"name"`
Destination string `json:"destination"`
Data *[]byte `json:"data"`
Identifier string `json:"identifier"`
}
// Prepare configures the File struct with relevant data.
func (fc *File) Prepare(data *[]byte, fileInfo os.FileInfo) {
// prepare a shasum instance
h := sha1.New()
h.Write(*data)
fc.Size = fileInfo.Size()
fc.Shasum = hex.EncodeToString(h.Sum(nil))
fc.Name = fileInfo.Name()
fc.Data = data
fc.Identifier = lib.RandomString(5)
}
// GetARequests returns the hostnames to lookup as part of a file
// transfer operation via A records.
func (fc *File) GetARequests() ([]string, string) {
var b bytes.Buffer
lib.GobPress(fc, &b)
requests := ARequestify(b.Bytes(), FileProtocol)
return requests, SuccessDNSResponse
}
// GetTXTRequests returns the TXT record contents to return as
// part of a file transfer operation via TXT records
func (fc *File) GetTXTRequests() []string {
var b bytes.Buffer
lib.GobPress(fc, &b)
requests := TXTRequestify(b.Bytes(), FileProtocol)
return requests
}