Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python requests send multiple cookies

How would you go about sending multiple cookies with python requests

the documentation only gives

url = 'http://httpbin.org/cookies'
cookies = dict(cookies_are='working')
r = requests.get(url, cookies=cookies)
r.text

Here is what i have tried currently

url = 'http://192.168.0.57/dvwa/vulnerabilities/fi/?page=include.php'
cookies = dict(cookies_are=options.cookie)
r = requests.get(url, cookies=cookies, headers=headers)

when i run my script with

--cookie="security=Low; PHPSESSID=4edca0525666fbbe319f50ce3630b4a9"

the security cookie is not recognised but the PHPSESID is

like image 429
Hack_Hut Avatar asked Nov 02 '25 10:11

Hack_Hut


1 Answers

The cookies parameter is a dict where the key is cookie name and the value is cookie value. So while your cookie-input is cookie string you have two ways to use it with requests:

1) parse cookie string and make the dict from it like the following:

import requests
from Cookie import SimpleCookie

cookie_string = options.cookie
cookie = SimpleCookie(cookie_string)
cookie_dict = {k: v.value for k, v in cookie.iteritems()}
requests.get(url, cookies=cookie_dict)

2) simply set it as Cookie header:

import requests
from Cookie import SimpleCookie

cookie_string = options.cookie
headers = {'Cookie': cookie_string}
requests.get(url, headers=headers)
like image 113
skavans Avatar answered Nov 04 '25 01:11

skavans