Skip to content

Commit

Permalink
extract original host ip if forwarded by one or more hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
TimBF committed May 7, 2024
1 parent 79d22ba commit 1a73128
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/c2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,14 @@ func newHTTPSessionID() string {
func getRemoteAddr(req *http.Request) string {
ipAddress := req.Header.Get("X-Real-Ip")
if ipAddress == "" {
ipAddress = req.Header.Get("X-Forwarded-For")
xForwardedFor := req.Header.Get("X-Forwarded-For")
if xForwardedFor != "" {
ips := strings.Split(xForwardedFor, ",")
if len(ips) > 0 {
// Extracts original client ip address
ipAddress = strings.TrimSpace(ips[0])
}
}
}
if ipAddress == "" {
return req.RemoteAddr
Expand Down

0 comments on commit 1a73128

Please sign in to comment.