From 03f40faa01bc3725753b02c3ecd3b78419913f0c Mon Sep 17 00:00:00 2001 From: Colin Stubbs <3059577+colin-stubbs@users.noreply.github.com> Date: Fri, 9 Aug 2019 16:50:25 +1000 Subject: [PATCH] Use requests.Session() to obtain and use cookies Perform initial request using requests.Session() in order to obtain initial session cookie, subsequent API requests will use cookie and store response cookie which rolls with each request. --- analyzers/TalosReputation/TalosReputation.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/analyzers/TalosReputation/TalosReputation.py b/analyzers/TalosReputation/TalosReputation.py index d5f43e6a7..7c63a0f8a 100755 --- a/analyzers/TalosReputation/TalosReputation.py +++ b/analyzers/TalosReputation/TalosReputation.py @@ -31,14 +31,17 @@ def run(self): try: data = self.get_data() + s = requests.Session() + s.get('https://talosintelligence.com/reputation_center/lookup?search={}'.format(data)) + headers={ 'Host':'talosintelligence.com', 'Referer':'https://talosintelligence.com/reputation_center/lookup?search={}'.format(data), - 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0', - 'Accept':'*/*' + 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36', + 'Accept':'application/json' } - response_details = requests.get('https://talosintelligence.com/sb_api/query_lookup', + response_details = s.get('https://talosintelligence.com/sb_api/query_lookup', headers = headers, params = { 'query':'/api/v2/details/ip/', @@ -46,13 +49,13 @@ def run(self): } ) - response_location = requests.get('https://talosintelligence.com/sb_api/query_lookup', + response_location = s.get('https://talosintelligence.com/sb_api/query_lookup', headers = headers, params = { 'query':'/api/v2/location/ip/', 'query_entry':data } - ) + ) if response_details.status_code == 200 | 201: if response_location.status_code == 200 | 201: