mirror of
https://github.com/r-smith/deceptifeed.git
synced 2025-11-02 13:13:37 +00:00
Add custom error page option for HTTP honeypots
- Added a new `<errorPagePath>` configuration option. This lets you specify a custom error page for HTTP and HTTPS honeypot servers. Only a single static HTML file may be specified. - Renamed `<htmlPath>` to `<homePagePath>` in the configuration. - Changed the default threat expiry hours from 168 (one week) to 336 (two weeks). - Changed minimum threat score from `1` to `0` for honeypot servers.
This commit is contained in:
@@ -30,7 +30,7 @@ func main() {
|
||||
flag.StringVar(&cfg.ThreatFeed.DatabasePath, "threat-database", config.DefaultThreatDatabasePath, "Path to threat feed database file")
|
||||
flag.IntVar(&cfg.ThreatFeed.ExpiryHours, "threat-expiry-hours", config.DefaultThreatExpiryHours, "Remove inactive IPs from threat feed after specified hours")
|
||||
flag.BoolVar(&cfg.ThreatFeed.IsPrivateIncluded, "threat-include-private", config.DefaultThreatIncludePrivate, "Include private IPs in threat feed")
|
||||
flag.StringVar(&http.HtmlPath, "html", config.DefaultHtmlPath, "Path to optional HTML file to serve")
|
||||
flag.StringVar(&http.HomePagePath, "html", config.DefaultHomePagePath, "Path to optional HTML file to serve")
|
||||
flag.StringVar(&http.Port, "port-http", config.DefaultPortHTTP, "Port number to listen on for HTTP server")
|
||||
flag.StringVar(&https.Port, "port-https", config.DefaultPortHTTPS, "Port number to listen on for HTTPS server")
|
||||
flag.StringVar(&ssh.Port, "port-ssh", config.DefaultPortSSH, "Port number to listen on for SSH server")
|
||||
@@ -53,7 +53,7 @@ func main() {
|
||||
cfg = *cfgFromFile
|
||||
} else {
|
||||
// No config file specified. Use command line args.
|
||||
https.HtmlPath = http.HtmlPath
|
||||
https.HomePagePath = http.HomePagePath
|
||||
cfg.Servers = append(cfg.Servers, http, https, ssh)
|
||||
// Set defaults.
|
||||
for i := range cfg.Servers {
|
||||
|
||||
@@ -20,11 +20,11 @@ const (
|
||||
DefaultPortHTTPS = "8443"
|
||||
DefaultPortSSH = "2022"
|
||||
DefaultPortThreatFeed = "8081"
|
||||
DefaultThreatExpiryHours = 168
|
||||
DefaultThreatExpiryHours = 336
|
||||
DefaultThreatDatabasePath = "deceptifeed-database.csv"
|
||||
DefaultThreatIncludePrivate = true
|
||||
DefaultLogPath = "deceptifeed-log.txt"
|
||||
DefaultHtmlPath = ""
|
||||
DefaultHomePagePath = ""
|
||||
DefaultCertPathHTTPS = "deceptifeed-https.crt"
|
||||
DefaultKeyPathHTTPS = "deceptifeed-https.key"
|
||||
DefaultKeyPathSSH = "deceptifeed-ssh.key"
|
||||
@@ -87,7 +87,8 @@ type Server struct {
|
||||
Port string `xml:"port"`
|
||||
CertPath string `xml:"certPath"`
|
||||
KeyPath string `xml:"keyPath"`
|
||||
HtmlPath string `xml:"htmlPath"`
|
||||
HomePagePath string `xml:"homePagePath"`
|
||||
ErrorPagePath string `xml:"errorPagePath"`
|
||||
Banner string `xml:"banner"`
|
||||
Headers []string `xml:"headers>header"`
|
||||
Prompts []Prompt `xml:"prompts>prompt"`
|
||||
@@ -157,9 +158,9 @@ func Load(filename string) (*Config, error) {
|
||||
}
|
||||
|
||||
for i := range config.Servers {
|
||||
// Ensure a minimum threat score of 1.
|
||||
if config.Servers[i].ThreatScore < 1 {
|
||||
config.Servers[i].ThreatScore = 1
|
||||
// Ensure a minimum threat score of 0.
|
||||
if config.Servers[i].ThreatScore < 0 {
|
||||
config.Servers[i].ThreatScore = 0
|
||||
}
|
||||
|
||||
// Validate regex rules.
|
||||
|
||||
@@ -167,24 +167,26 @@ func handleConnection(cfg *config.Server, customHeaders map[string]string) http.
|
||||
w.Header().Set(header, value)
|
||||
}
|
||||
|
||||
// Serve the web content to the client based on the requested URL. If
|
||||
// the root or /index.html is requested, serve the specified content.
|
||||
// For any other requests, return a '404 Not Found' response.
|
||||
// Serve a response based on the requested URL. If the root URL or
|
||||
// /index.html is requested, serve the homepage. For all other
|
||||
// requests, serve the error page with a 404 Not Found response.
|
||||
// Optionally, a single static HTML file may be specified for both the
|
||||
// homepage and the error page. If no custom files are provided,
|
||||
// default minimal responses will be served.
|
||||
if r.URL.Path == "/" || r.URL.Path == "/index.html" {
|
||||
// The request is for the root or /index.html.
|
||||
if len(cfg.HtmlPath) > 0 {
|
||||
// Serve the custom HTML file specified in the configuration.
|
||||
http.ServeFile(w, r, cfg.HtmlPath)
|
||||
// Serve the homepage response.
|
||||
if len(cfg.HomePagePath) > 0 {
|
||||
http.ServeFile(w, r, cfg.HomePagePath)
|
||||
} else {
|
||||
// Serve the default page that prompts the client for basic
|
||||
// authentication.
|
||||
w.Header()["WWW-Authenticate"] = []string{"Basic"}
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
}
|
||||
} else {
|
||||
// The request is outside the root or /index.html. Respond with a
|
||||
// 404 error.
|
||||
// Serve the error page response.
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
if len(cfg.ErrorPagePath) > 0 {
|
||||
http.ServeFile(w, r, cfg.ErrorPagePath)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user