Skip to content

Commit

Permalink
Merge pull request #1675 from BishopFox/xforwardedfor_fix
Browse files Browse the repository at this point in the history
extract original host ip if forwarded by one or more hosts
  • Loading branch information
rkervella authored May 7, 2024
2 parents eff371f + a424412 commit c642bfc
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/c2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,16 @@ 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])
} else {
ipAddress = xForwardedFor
}
}
}
if ipAddress == "" {
return req.RemoteAddr
Expand Down

0 comments on commit c642bfc

Please sign in to comment.