-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
lures.go
161 lines (154 loc) · 5.54 KB
/
lures.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
package main
import (
"crypto/rand"
"fmt"
"net"
"os/exec"
"strconv"
)
func manageLures(config *Config) {
for _, lure := range config.Lures {
var content string
var username string
switch lure.GenerativeType {
case "golang":
switch lure.Type {
case "credential_pair":
if len(config.General.Usernames) > 0 {
username = selectRandomOrHardcoded(config.General.Usernames, config.General.SelectionMethod)[0]
} else {
logToFile(config.General.LogFile, "Error: No usernames provided for credential_pair.")
continue
}
lengthVal, ok := lure.GenerationParams["length"]
if !ok {
logToFile(config.General.LogFile, "Error: 'length' parameter is required for credential_pair.")
continue
}
length, err := strconv.Atoi(fmt.Sprintf("%v", lengthVal))
if err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error: Invalid 'length' parameter: %v", err))
continue
}
password, err := generateRandomPassword(length, config)
if err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error generating password: %v", err))
continue
}
content = fmt.Sprintf("Username: %s\nPassword: %s", username, password)
case "ssh_key":
cmd := exec.Command("ssh-keygen", "-t", "rsa", "-b", "2048", "-f", lure.Location, "-N", "")
err := cmd.Run()
if err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error generating SSH key: %v", err))
continue
}
content = fmt.Sprintf("Generated SSH Key at %s", lure.Location)
case "website_url":
baseURL, ok := lure.GenerationParams["base_url"].(string)
if !ok {
logToFile(config.General.LogFile, "Error: 'base_url' parameter is required for website_url.")
continue
}
content = baseURL
case "registry_key":
registryKeyType, ok := lure.GenerationParams["registry_key_type"].(string)
if !ok {
logToFile(config.General.LogFile, "Error: 'registry_key_type' parameter is required for registry_key.")
continue
}
registryKeyValue, ok := lure.GenerationParams["registry_key_value"].(string)
if !ok {
logToFile(config.General.LogFile, "Error: 'registry_key_value' parameter is required for registry_key.")
continue
}
err := createRegistryKey(lure.Location, registryKeyType, registryKeyValue, config)
if err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error creating registry key: %v", err))
continue
}
content = fmt.Sprintf("Created registry key at %s with type %s and value %s", lure.Location, registryKeyType, registryKeyValue)
case "csv":
documentContent, ok := lure.GenerationParams["document_content"].(string)
if !ok {
logToFile(config.General.LogFile, "Error: 'document_content' parameter is required for csv.")
continue
}
content = documentContent
case "api_key":
apiKeyFormat, ok := lure.GenerationParams["api_key_format"].(string)
if !ok {
logToFile(config.General.LogFile, "Error: 'api_key_format' parameter is required for api_key.")
continue
}
if apiKeyFormat == "uuid" {
apiKey := make([]byte, 16)
_, err := rand.Read(apiKey)
if err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error generating API key: %v", err))
continue
}
content = fmt.Sprintf("Generated API Key: %x", apiKey)
} else {
logToFile(config.General.LogFile, "Unsupported API key format")
continue
}
case "lnk":
targetPath, ok := lure.GenerationParams["target_path"].(string)
if !ok {
logToFile(config.General.LogFile, "Error: 'target_path' parameter is required for lnk.")
continue
}
err := createLinkFile(lure.Location, targetPath, config)
if err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error creating link file at location: %s, error: %v", lure.Location, err))
continue
}
content = fmt.Sprintf("Created link file at %s pointing to %s", lure.Location, targetPath)
default:
logToFile(config.General.LogFile, "Unsupported lure type for Go random generation.")
continue
}
case "openai":
if config.General.OpenaiApiKey == "" {
logToFile(config.General.LogFile, "Error: OpenAI API key is required for OpenAI generation.")
continue
}
content = generateContentUsingGPT(config.General.OpenaiApiKey, lure.OpenaiPrompt, config)
default:
logToFile(config.General.LogFile, "Unsupported generative type.")
continue
}
if lure.Type != "lnk" && lure.Type != "ssh_key" && lure.Type != "registry_key" {
if err := createFileAtLocation(lure.Location, content, config); err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error creating file at location: %s, error: %v", lure.Location, err))
continue
}
}
sourceIP, err := getSourceIP()
if err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error getting source IP: %v", err))
continue
}
if err := sendMetadataToRedis(config, username, content, sourceIP); err != nil {
logToFile(config.General.LogFile, fmt.Sprintf("Error sending metadata to Redis: %v", err))
continue
}
logToFile(config.General.LogFile, fmt.Sprintf("Generated lure: %s", content))
logToFile(config.General.LogFile, fmt.Sprintf("Lure created and metadata processed successfully."))
}
}
func getSourceIP() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
return "", err
}
for _, addr := range addrs {
if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String(), nil
}
}
}
return "", fmt.Errorf("cannot find local IP address")
}