Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Added support for 'X-Forwarded-For' header #1259

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions lib/listeners/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,9 +939,16 @@ def check_ip():
"""
Before every request, check if the IP address is allowed.
"""
if not self.mainMenu.agents.is_ip_allowed(request.remote_addr):

if request.headers.getlist("X-Forwarded-For"):
clientIP = request.headers.getlist("X-Forwarded-For")[0]
else:
clientIP = request.remote_addr
clientIP = clientIP.encode('utf-8')

if not self.mainMenu.agents.is_ip_allowed(clientIP):
listenerName = self.options['Name']['Value']
message = "[!] {} on the blacklist/not on the whitelist requested resource".format(request.remote_addr)
message = "[!] {} on the blacklist/not on the whitelist requested resource".format(clientIP)
signal = json.dumps({
'print': True,
'message': message
Expand Down Expand Up @@ -996,7 +1003,11 @@ def handle_get(request_uri):
This is used during the first step of the staging process,
and when the agent requests taskings.
"""
clientIP = request.remote_addr
if request.headers.getlist("X-Forwarded-For"):
clientIP = request.headers.getlist("X-Forwarded-For")[0]
else:
clientIP = request.remote_addr
clientIP = clientIP.encode('utf-8')

listenerName = self.options['Name']['Value']
message = "[*] GET request for {}/{} from {}".format(request.host, request_uri, clientIP)
Expand Down Expand Up @@ -1100,7 +1111,11 @@ def handle_post(request_uri):
"""

stagingKey = listenerOptions['StagingKey']['Value']
clientIP = request.remote_addr
if request.headers.getlist("X-Forwarded-For"):
clientIP = request.headers.getlist("X-Forwarded-For")[0]
else:
clientIP = request.remote_addr
clientIP = clientIP.encode('utf-8')

requestData = request.get_data()

Expand Down