本文整理汇总了Python中java.net.URL.getProtocol方法的典型用法代码示例。如果您正苦于以下问题:Python URL.getProtocol方法的具体用法?Python URL.getProtocol怎么用?Python URL.getProtocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.URL
的用法示例。
在下文中一共展示了URL.getProtocol方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: googleSiteIndex
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
def googleSiteIndex(self, url, mCallBacks, startIndex):
#print 'Starting Google Site: Index for URL: ' + str(url)
data = 'Starting Google Site: Index for URL: ' + str(url) + '\n'
self.parent.printLogTab(str(data))
googleRequest = self.buildGoogleRequest(url, startIndex)
googleResponse = mCallBacks.makeHttpRequest('www.google.com', int('80'), False, googleRequest)
googleStringResponse = googleResponse.tostring()
for urlInSearch in re.findall(r'''<a href="([^<]+)" class=l''', googleStringResponse):
uUrl = URL(urlInSearch)
port = 80
if str(uUrl.getProtocol()) == "https":
port = 443
if mCallBacks.isInScope(uUrl):
newRequest = self.buildGenericRequest(uUrl)
newResponse = mCallBacks.makeHttpRequest(str(uUrl.getHost()), port, (str(uUrl.getProtocol()) == "https"), newRequest)
newResponseString = newResponse.tostring()
firstWord, statusCode, restResponse = newResponseString.split(" ", 2)
requestResponse = HttpRequestResponse.HttpRequestResponse(None, uUrl.getHost(), port, uUrl.getProtocol(), newRequest, newResponse, int(statusCode), uUrl)
mCallBacks.addToSiteMap(requestResponse)
#print "Adding: " + urlInSearch
data = "Adding: " + urlInSearch + "\n"
self.parent.printLogTab(str(data))
else:
data = "\n" + urlInSearch + " was not in scope.\n\n"
self.parent.printLogTab(str(data))
data = "End of Google Site Indexing for URL " + str(url) + "\n"
self.parent.printLogTab(str(data))
示例2: isUrlAvailable
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
def isUrlAvailable(url, acceptedStatusCodeRange, timeout=10000):
'''
Checks whether url is available
str, list(str), int -> bool
'''
from com.hp.ucmdb.discovery.library.clients import SSLContextManager
from com.hp.ucmdb.discovery.library.clients.http import ApacheHttpClientWrapper as HttpClientWrapper
if not url or not acceptedStatusCodeRange:
return 0
with _create_http_client_wrapper() as client:
client.setSocketTimeout(timeout)
try:
jurl = URL(url)
if jurl.getProtocol() == 'https':
port = jurl.getPort() or HttpClientWrapper.DEFAULT_HTTPS_PORT
context = SSLContextManager.getAutoAcceptSSLContext()
client.registerProtocol(context, port)
except:
logger.warn('Failed parsing url % ' % url)
try:
httpResult = client.get(url)
return httpResult.statusCode in acceptedStatusCodeRange
except:
logger.warn('Get Failed: %s' % logger.prepareJavaStackTrace())
return 0
示例3: googleSiteIndex_run
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
def googleSiteIndex_run(querys, maxIndex):
for i in querys:
try:
maxIndex = int(maxIndex)
except:
self.appendToResults("Index Value was not a valid Integer\n")
return
# setup counts to stay within provided index range
resultsCount = 0
currentIndex = 0
previousIndex = -1
self.appendToResults("Starting Google Hack for " + i.strip() + "\n")
while (currentIndex < maxIndex) and (previousIndex != currentIndex):
previousIndex = currentIndex
googleRequest = self.buildGoogleRequest(i, currentIndex)
try:
googleResponse = self._callbacks.makeHttpRequest('www.google.com', int('80'), False, googleRequest).tostring()
except:
self.appendToResults("Call to google was not made: (Could not make a connection)\n")
return
if re.findall(r'<a href="([^<]+)" class=l', googleResponse) and resultsCount < maxIndex:
currentIndex += 100
for urlInSearch in re.findall(r'<a href="([^<]+)" class=l', googleResponse):
if resultsCount < maxIndex:
uUrl = URL(urlInSearch)
port = 80
if str(uUrl.getProtocol()) == "https":
port = 443
if self._callbacks.isInScope(uUrl):
newRequest = self.buildGenericRequest(uUrl)
try:
requestResponse = self._callbacks.makeHttpRequest(self._helpers.buildHttpService(str(uUrl.getHost()), port, str(uUrl.getProtocol()) == "https"), newRequest)
self._callbacks.addToSiteMap(requestResponse)
resultsCount += 1
self.appendToResults("Adding " + urlInSearch + " to Target:\n")
except:
self.appendToResults("Call to URL found was not made: (Could not make a connection)\n")
else:
self.appendToResults(urlInSearch + " was found but not in Scope (Not Adding to Target)\n")
else:
previousIndex = currentIndex
self.appendToResults("Reached end of query " + i.strip() + " with " + str(resultsCount) + " results found\n\n")
示例4: nmapParse_run
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
def nmapParse_run(nmapFile, portField, serviceField, checkbox, hostName):
try: # Attempt to open XML file
source = open(nmapFile)
except:
self.appendToResults("Nmap File not found (Check if Path and Filename is Correct)\n")
return
resultList = []
try: # Attempt to get list of ports to parse
portList = portField.split(",")
for i in portList:
i.strip()
i.lstrip()
except:
self.appendToResults("Error with Port List\n")
return
try: # Attempt to get list of service names to parse
serviceList = serviceField.split(",")
for i in serviceList:
i.strip()
i.lstrip()
except:
self.appendToResults("Error with Service List")
return
self.appendToResults("Attempting to Parse XML File\n")
try: # Attempt to parse XML
Handler = NMAPContentHandler()
if hostName.isSelected():
Handler._useHostname = True
xml.sax.parse(source, Handler)
source.close()
self.appendToResults("Finished Parsing File\n")
for result in Handler._list:
for portCheck in portList:
if portCheck == result[1]:
if [result[0], result[1], result[2]] not in resultList:
resultList.append([result[0], result[1], result[2]])
for serviceCheck in serviceList:
if serviceCheck in result[2]:
if [result[0], result[1], result[2]] not in resultList:
resultList.append([result[0], result[1], result[2]])
except:
self.appendToResults("Error Parsing Nmap File\n")
return
# Take parsed results and attempt to make request to host and port using HTTP/HTTPS, adding successful request/response to scope
for list in resultList:
uUrl = URL("http", list[0], int(list[1]), "/")
newRequest = self._helpers.buildHttpRequest(uUrl)
try:
requestResponse = self._callbacks.makeHttpRequest(
self._helpers.buildHttpService(
str(uUrl.getHost()), int(list[1]), str(uUrl.getProtocol()) == "https"
),
newRequest,
)
if not requestResponse.getResponse() == None:
if not self._callbacks.isInScope(uUrl):
self.appendToResults(
"Adding http://" + (str(uUrl.getHost())) + " port " + str(list[1]) + " to the sitemap\n"
)
self._callbacks.includeInScope(uUrl)
self._callbacks.addToSiteMap(requestResponse)
if checkbox.isSelected():
self.appendToResults(
"Spidering http://" + (str(uUrl.getHost())) + " Port " + str(list[1]) + "\n"
)
self._callbacks.sendToSpider(uUrl)
else:
uUrl = URL("https", list[0], int(list[1]), "/")
newRequest = self._helpers.buildHttpRequest(uUrl)
try:
requestResponse = self._callbacks.makeHttpRequest(
self._helpers.buildHttpService(
str(uUrl.getHost()), int(list[1]), str(uUrl.getProtocol()) == "https"
),
newRequest,
)
if not requestResponse.getResponse() == None:
if not self._callbacks.isInScope(uUrl):
self.appendToResults(
"Adding https://"
+ (str(uUrl.getHost()))
+ " port "
+ str(list[1])
+ " to the sitemap\n"
)
self._callbacks.includeInScope(uUrl)
self._callbacks.addToSiteMap(requestResponse)
if checkbox.isSelected():
self.appendToResults(
"Spidering https://" + (str(uUrl.getHost())) + " Port " + str(list[1]) + "\n"
)
self._callbacks.sendToSpider(uUrl)
else:
self.appendToResults(
"Host "
+ list[0]
+ " with Port "
#.........这里部分代码省略.........
示例5: importList
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
def importList(self):
if self.parsedList:
urlsAdded = 0
# Loop through each URL and check the response. If the response code is less than 404, add to site map
for item in self.parsedList:
# Pass exception if urlopen returns an http error if the URL is not reachable
try:
code = urlopen(item).code
if code < 404:
javaURL = URL(item)
newRequest = self._helpers.buildHttpRequest(javaURL)
stringNewRequest = self._helpers.bytesToString(newRequest).rstrip()
if self.cookie:
stringNewRequest += '\nCookie: ' + self.cookie.rstrip('; ') + '\r\n\r\n'
requestResponse = self._callbacks.makeHttpRequest(self._helpers.buildHttpService(str(javaURL.getHost()), int(javaURL.getPort()), javaURL.getProtocol() == "https"), stringNewRequest)
else:
requestResponse = self._callbacks.makeHttpRequest(self._helpers.buildHttpService(str(javaURL.getHost()), int(javaURL.getPort()), javaURL.getProtocol() == "https"), newRequest)
self._callbacks.addToSiteMap(requestResponse)
urlsAdded += 1
except Exception, e:
print e
pass
JOptionPane.showMessageDialog(None, str(urlsAdded) + " URL(s) added to Burp site map.")
开发者ID:LucaBongiorni,项目名称:Directory-File-Listing-Parser-Importer,代码行数:25,代码来源:Directory-File-Listing-Parser-Importer.py
示例6: fuzzUrls
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
def fuzzUrls(self):
print 'Fuzzing %s viable URLs with a wsdl extension\n' % len(self.detectedUrlList)
for detectedUrl in self.detectedUrlList:
wsdlSuffixUrl = detectedUrl + '?wsdl'
if wsdlSuffixUrl not in self.foundWsdlList:
try:
# Try to open created wsdl url and read the response
wsdlSuffixUrlResponse = urllib2.urlopen(wsdlSuffixUrl)
wsdlSuffixUrlResponseData = wsdlSuffixUrlResponse.read()
# Loop through the keywords and check if one of them are in the response (very good indicator of wsdl or similar file)
for wsdlKeyword in self.wsdlKeywordList:
if wsdlKeyword in wsdlSuffixUrlResponseData:
# wsdl file found from created URL, add to fuzzed list
self.fuzzedWsdlList.append(wsdlSuffixUrl)
# Build a request and response based on the found wsdl URL and add them to the Burp site map
wsdlJavaURL = URL(wsdlSuffixUrl)
newRequest = self._helpers.buildHttpRequest(wsdlJavaURL)
requestResponse = self._callbacks.makeHttpRequest(self._helpers.buildHttpService(str(wsdlJavaURL.getHost()), int(wsdlJavaURL.getPort()), wsdlJavaURL.getProtocol() == "https"), newRequest)
self._callbacks.addToSiteMap(requestResponse)
break
except:
# wsdl URL was not valid, skip it
pass
示例7: connect
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
def connect(self, url):
if re.findall('(?:\:\d{2,5})', url) and self.urlRegex.match(url):
try:
javaURL = URL(url)
newRequest = self._helpers.buildHttpRequest(javaURL)
requestResponse = self._callbacks.makeHttpRequest(self._helpers.buildHttpService(str(javaURL.getHost()), javaURL.getPort(), str(javaURL.getProtocol())), newRequest)
# Follow redirects if a 301 or 302 response is received. As of Oct 9 2014 the API is not capable of this: http://forum.portswigger.net/thread/1504/ask-burp-follow-redirections-extension
response = requestResponse.getResponse()
if response:
requestInfo = self._helpers.analyzeResponse(response)
responseHeader = requestInfo.getHeaders()
if ('301' in responseHeader[0] or '302' in responseHeader[0]) and self.redirectsCheckbox.isSelected():
self.redirectCounter += 1
for headerLine in responseHeader:
if 'Location: ' in headerLine or 'location: ' in headerLine:
url = self.locationHeaderConvert(str(headerLine.split(' ')[1]), str(javaURL.getPort()), str(javaURL.getHost()), '')
self.connect(url)
self.goodUrlList.append(url)
self._callbacks.addToSiteMap(requestResponse)
else:
self.badUrlList.append(url)
except:
self.badUrlList.append(url)
else:
if 'http://' in url:
fixedUrl = self.addPort(url, '80')
self.connect(fixedUrl)
elif 'https://' in url:
fixedUrl = self.addPort(url, '443')
self.connect(fixedUrl)
else:
self.badUrlList.append(url)
示例8: BurpExtender
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
class BurpExtender(IBurpExtender, IHttpListener, IScannerListener):
def registerExtenderCallbacks(self, callbacks):
self._callbacks = callbacks
self._callbacks.setExtensionName("Carbonator")
self._helpers = self._callbacks.getHelpers()
self.clivars = None
self.spider_results=[]
self.scanner_results=[]
self.packet_timeout=5
self.last_packet_seen= int(time.time()) #initialize the start of the spider/scan
if not self.processCLI():
return None
else:
self.clivars = True
print "Initiating Carbonator Against: ", str(self.url)
#add to scope if not already in there.
if self._callbacks.isInScope(self.url) == 0:
self._callbacks.includeInScope(self.url)
#added to ensure that the root directory is scanned
base_request = str.encode(str("GET "+self.path+" HTTP/1.1\nHost: "+self.fqdn+"\n\n"))
if(self.scheme == 'HTTPS'):
print self._callbacks.doActiveScan(self.fqdn,self.port,1,base_request)
else:
print self._callbacks.doActiveScan(self.fqdn,self.port,0,base_request)
self._callbacks.sendToSpider(self.url)
self._callbacks.registerHttpListener(self)
self._callbacks.registerScannerListener(self)
while int(time.time())-self.last_packet_seen <= self.packet_timeout:
time.sleep(1)
print "No packets seen in the last", self.packet_timeout, "seconds."
print "Removing Listeners"
self._callbacks.removeHttpListener(self)
self._callbacks.removeScannerListener(self)
self._callbacks.excludeFromScope(self.url)
print "Generating Report"
self.generateReport(self.rtype)
print "Report Generated"
print "Closing Burp in", self.packet_timeout, "seconds."
time.sleep(self.packet_timeout)
if self.clivars:
self._callbacks.exitSuite(False)
return
def processHttpMessage(self, tool_flag, isRequest, current):
self.last_packet_seen = int(time.time())
if tool_flag == self._callbacks.TOOL_SPIDER and isRequest: #if is a spider request then send to scanner
self.spider_results.append(current)
print "Sending new URL to Vulnerability Scanner: URL #",len(self.spider_results)
if self.scheme == 'https':
self._callbacks.doActiveScan(self.fqdn,self.port,1,current.getRequest()) #returns scan queue, push to array
else:
self._callbacks.doActiveScan(self.fqdn,self.port,0,current.getRequest()) #returns scan queue, push to array
return
def newScanIssue(self, issue):
self.scanner_results.append(issue)
print "New issue identified: Issue #",len(self.scanner_results);
return
def generateReport(self, format):
if format != 'XML':
format = 'HTML'
file_name = self.output
self._callbacks.generateScanReport(format,self.scanner_results,File(file_name))
time.sleep(5)
return
def processCLI(self):
cli = self._callbacks.getCommandLineArguments()
if len(cli) < 0:
print "Incomplete target information provided."
return False
elif not cli:
print "Integris Security Carbonator is now loaded."
print "If Carbonator was loaded through the BApp store then you can run in headless mode simply adding the `-Djava.awt.headless=true` flag from within your shell. Note: If burp doesn't close at the conclusion of a scan then disable Automatic Backup on Exit."
print "For questions or feature requests contact us at carbonator at integris security dot com."
print "Visit carbonator at https://www.integrissecurity.com/Carbonator"
return False
else:
self.url = URL(cli[0])
self.rtype = cli[1]
self.output = cli[2]
self.scheme = self.url.getProtocol()
self.fqdn = self.url.getHost()
self.port1 = self.url.getPort()
if self.port1 == -1 and self.scheme == 'http':
self.port = 80
#.........这里部分代码省略.........
示例9: testRequest
# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getProtocol [as 别名]
def testRequest(self, url, messageInfo):
########### CONFIGURATION START ###########
#Host name for which you want to perform CSRF check and other attacks
host_name = "localhost"
#File extensions that you don't want to test (lowercase only)
skip_extensions = ["jpg","jpeg","png","gif","svg","css","js"]
#Which HTTP methods should be tested? Example: ["GET", "POST", "PUT"]
allowed_http_methods = ["POST"]
#Do you want to test for CSRF? True/False
csrf_check = True
#Name of the Anti-CSRF parameter in your application
anti_csrf_param = '_wpnonce'
#Message shown when the CSRF parameter is not sent in the request
csrf_fail_message = 'Are you sure you want to do this'
#Do you want to print original request? True/False
print_original_request = True
#Do you want to print modified request? True/False
print_modified_request = True
#Do you want to print response for modified request? True/False
print_modified_request_response = False
#Write to HTML file configuration
save_to_html = True
save_filepath = "c:\\temp\\report_test.html"
########### CONFIGURATION END ###########
#Check if the host is in scope for testing
if host_name != URL(str(url)).getHost():
return
#Check if the HTTP method is allowed for testing
if ((self._helpers.analyzeRequest(messageInfo)).getMethod()).upper() not in allowed_http_methods:
return
#Check if the file name is in scope for testing
if not self.isAllowedFileName(str(url), skip_extensions):
return
#Get the url and data to create the new URL request
urlString = str(url)#cast to cast to stop the TYPEerror on URL()
#Java URL to be used with Burp API
url = URL(urlString)
#print "UrlString: "+urlString
#Build the new request
newRequest = None
requestInfo = self._helpers.analyzeRequest(messageInfo)
#Get current request
currentRequest = self._helpers.bytesToString(messageInfo.getRequest());
#Get the request body
messageBody = currentRequest[requestInfo.getBodyOffset():];
list_messageBody = messageBody.split('&')
final_messageBody = ""
final_list_messageBody = list_messageBody
#Get headers in original request
headers = requestInfo.getHeaders()
#Data variables
data_original_request = ""
data_modified_request = ""
data_modified_request_response = ""
########### [Start] ADD/REMOVE Content ###########
#Add new headers
#Syntax: headers = self.addHeader(headers, 'header_name', 'header_value')
#headers = self.addHeader(headers, 'newheader', 'newheaderval')
#Remove header from request
#Syntax: headers = self.removeHeader(headers, 'header_name')
headers = self.removeHeader(headers, 'Referer') # Do not remove. This is important for CSRF testing
#Add a parameter to message body
#Syntax: final_messageBody = self.addParameter(final_messageBody, 'new_param_name', 'new_param_value')
#final_messageBody = self.addParameter(final_messageBody, 'newparam', 'newparamvalue')
#Remove a parameter from message body
#Syntax: final_messageBody = self.removeParameter(final_messageBody, 'existing_param_name')
#list_messageBody = self.removeParameter(list_messageBody, 'asd')
########### [End] ADD/REMOVE Content ###########
#Check if CSRF check is to be performed or not
if csrf_check:
#Remove anti-csrf token from request
final_list_messageBody = filter(lambda x: not x.startswith(anti_csrf_param+'='), list_messageBody)
#Add all params to message body string
for param in final_list_messageBody:
final_messageBody = final_messageBody + param + '&'
#Remove trailing "&" from the POST message body
final_messageBody = final_messageBody[:-1] if final_messageBody.endswith('&') else final_messageBody
#Prepare the final POST request message body
final_messageBody = bytearray(final_messageBody.encode('ascii', 'ignore'))
#VERIFICATION: when port isn't define in the URL it is equals to -1, so we set it back to http
if url.getPort() <= 0:
if url.getProtocol() == "https":
port = 443
else:
port = 80
else:
#.........这里部分代码省略.........