From 22a52aff046b616e93f708e4abf58f7012e92017 Mon Sep 17 00:00:00 2001 From: DJ1975 <36563019+DJ1975-SE@users.noreply.github.com> Date: Wed, 1 Mar 2023 01:58:41 +0100 Subject: [PATCH] Feature - making X-Real-IP configurable (#70) --- README.md | 3 +++ internal/config/config.go | 1 + internal/config/defaults.go | 1 + internal/config/globals.go | 4 ++++ internal/http/router.go | 2 +- 5 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b5c76fd..3fda2af 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,9 @@ In the event of a missing configuration file, HellPot will attempt to place it's bind_addr = "127.0.0.1" bind_port = "8080" + # header name containing clients real IP, for reverse proxy deployments + real_ip_header = 'X-Real-IP' + # this contains a list of blacklisted useragent strings. (case sensitive) # clients with useragents containing any of these strings will receive "Not found" for any requests. uagent_string_blacklist = ["Cloudflare-Traffic-Manager", "curl"] diff --git a/internal/config/config.go b/internal/config/config.go index 82edfbd..fdf5ad7 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -129,6 +129,7 @@ func processOpts() { stringOpt := map[string]*string{ "http.bind_addr": &HTTPBind, "http.bind_port": &HTTPPort, + "http.real_ip_header": &HeaderName, "logger.directory": &logDir, "deception.server_name": &FakeServerName, } diff --git a/internal/config/defaults.go b/internal/config/defaults.go index ab18197..ce79f57 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -36,6 +36,7 @@ var defOpts = map[string]map[string]interface{}{ "unix_socket_permissions": "0666", "bind_addr": "127.0.0.1", "bind_port": "8080", + "real_ip_header": "X-Real-IP", "router": map[string]interface{}{ "catchall": false, diff --git a/internal/config/globals.go b/internal/config/globals.go index 8d06205..a5a25ff 100644 --- a/internal/config/globals.go +++ b/internal/config/globals.go @@ -42,6 +42,10 @@ var ( HTTPBind string // HTTPPort is defined via our toml configuration file. It is the port that HellPot listens on. HTTPPort string + // HeaderName is defined via our toml configuration file. It is the HTTP Header containing the original IP of the client, + // in traditional reverse Proxy deplyoments. + HeaderName string + // Paths are defined via our toml configuration file. These are the paths that HellPot will present for "robots.txt" // These are also the paths that HellPot will respond for. Other paths will throw a warning and will serve a 404. Paths []string diff --git a/internal/http/router.go b/internal/http/router.go index 339cf73..6669a8f 100644 --- a/internal/http/router.go +++ b/internal/http/router.go @@ -19,7 +19,7 @@ import ( var log *zerolog.Logger func getRealRemote(ctx *fasthttp.RequestCtx) string { - xrealip := string(ctx.Request.Header.Peek("X-Real-IP")) + xrealip := string(ctx.Request.Header.Peek(config.HeaderName)) if len(xrealip) > 0 { return xrealip }