first commit
This commit is contained in:
+143
@@ -0,0 +1,143 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Config contains runtime configuration for the honeypot
|
||||
type Config struct {
|
||||
LogMode string `json:"log_mode"` // "file" | "stdout" | "sqlite"
|
||||
LogPath string `json:"log_path"`
|
||||
|
||||
Web struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Bind string `json:"bind"`
|
||||
Port int `json:"port"`
|
||||
} `json:"web"`
|
||||
|
||||
Services struct {
|
||||
HTTP bool `json:"http"`
|
||||
SSH bool `json:"ssh"`
|
||||
FTP bool `json:"ftp"`
|
||||
SMTP bool `json:"smtp"`
|
||||
POP3 bool `json:"pop3"`
|
||||
IMAP bool `json:"imap"`
|
||||
Telnet bool `json:"telnet"`
|
||||
MySQL bool `json:"mysql"`
|
||||
PostgreSQL bool `json:"postgresql"`
|
||||
Redis bool `json:"redis"`
|
||||
MongoDB bool `json:"mongodb"`
|
||||
RDP bool `json:"rdp"`
|
||||
SMB bool `json:"smb"`
|
||||
SIP bool `json:"sip"`
|
||||
VNC bool `json:"vnc"`
|
||||
DNS bool `json:"dns"`
|
||||
SNMP bool `json:"snmp"`
|
||||
LDAP bool `json:"ldap"`
|
||||
Generic []int `json:"generic"`
|
||||
} `json:"services"`
|
||||
|
||||
Ports struct {
|
||||
HTTP int `json:"http"`
|
||||
SSH int `json:"ssh"`
|
||||
FTP int `json:"ftp"`
|
||||
SMTP int `json:"smtp"`
|
||||
POP3 int `json:"pop3"`
|
||||
IMAP int `json:"imap"`
|
||||
Telnet int `json:"telnet"`
|
||||
MySQL int `json:"mysql"`
|
||||
PostgreSQL int `json:"postgresql"`
|
||||
Redis int `json:"redis"`
|
||||
MongoDB int `json:"mongodb"`
|
||||
RDP int `json:"rdp"`
|
||||
SMB int `json:"smb"`
|
||||
SIP int `json:"sip"`
|
||||
VNC int `json:"vnc"`
|
||||
DNS int `json:"dns"`
|
||||
SNMP int `json:"snmp"`
|
||||
LDAP int `json:"ldap"`
|
||||
} `json:"ports"`
|
||||
}
|
||||
|
||||
// EnsureConfig writes a default config file if the given path doesn't exist
|
||||
func EnsureConfig(path string) error {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
|
||||
return fmt.Errorf("create config dir: %w", err)
|
||||
}
|
||||
def := defaultConfig()
|
||||
b, _ := json.MarshalIndent(def, "", " ")
|
||||
if err := os.WriteFile(path, b, 0644); err != nil {
|
||||
return fmt.Errorf("write default config: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// LoadConfig loads JSON config from path
|
||||
func LoadConfig(path string) (Config, error) {
|
||||
var cfg Config
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
if err := json.Unmarshal(b, &cfg); err != nil {
|
||||
return cfg, err
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func defaultConfig() Config {
|
||||
var c Config
|
||||
c.LogMode = "file"
|
||||
c.LogPath = "honeypot.log"
|
||||
c.Web.Enabled = true
|
||||
c.Web.Bind = "127.0.0.1"
|
||||
c.Web.Port = 6333
|
||||
|
||||
// Enable common services by default
|
||||
c.Services.HTTP = true
|
||||
c.Services.SSH = true
|
||||
c.Services.FTP = true
|
||||
c.Services.SMTP = true
|
||||
c.Services.Telnet = true
|
||||
c.Services.MySQL = false
|
||||
c.Services.PostgreSQL = false
|
||||
c.Services.Redis = false
|
||||
c.Services.MongoDB = false
|
||||
c.Services.POP3 = false
|
||||
c.Services.IMAP = false
|
||||
c.Services.RDP = false
|
||||
c.Services.SMB = false
|
||||
c.Services.SIP = false
|
||||
c.Services.VNC = false
|
||||
c.Services.DNS = false
|
||||
c.Services.SNMP = false
|
||||
c.Services.LDAP = false
|
||||
c.Services.Generic = []int{}
|
||||
|
||||
// Standard ports
|
||||
c.Ports.HTTP = 8080
|
||||
c.Ports.SSH = 2222
|
||||
c.Ports.FTP = 2121
|
||||
c.Ports.SMTP = 2525
|
||||
c.Ports.POP3 = 1110
|
||||
c.Ports.IMAP = 1143
|
||||
c.Ports.Telnet = 2323
|
||||
c.Ports.MySQL = 3306
|
||||
c.Ports.PostgreSQL = 5432
|
||||
c.Ports.Redis = 6379
|
||||
c.Ports.MongoDB = 27017
|
||||
c.Ports.RDP = 3389
|
||||
c.Ports.SMB = 4450
|
||||
c.Ports.SIP = 5060
|
||||
c.Ports.VNC = 5900
|
||||
c.Ports.DNS = 5353
|
||||
c.Ports.SNMP = 1161
|
||||
c.Ports.LDAP = 3890
|
||||
|
||||
return c
|
||||
}
|
||||
Reference in New Issue
Block a user