mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-02-02 20:54:13 +03:00
added Range handler (dealing with 206 HTTP messages)
This commit is contained in:
parent
875781bf97
commit
eb999de0f1
|
@ -64,6 +64,7 @@ from lib.core.update import update
|
|||
from lib.parse.configfile import configFileParser
|
||||
from lib.request.proxy import ProxyHTTPSHandler
|
||||
from lib.request.certhandler import HTTPSCertAuthHandler
|
||||
from lib.request.rangehandler import HTTPRangeHandler
|
||||
from lib.request.redirecthandler import SmartRedirectHandler
|
||||
from lib.utils.google import Google
|
||||
|
||||
|
@ -71,6 +72,7 @@ authHandler = urllib2.BaseHandler()
|
|||
keepAliveHandler = keepalive.HTTPHandler()
|
||||
proxyHandler = urllib2.BaseHandler()
|
||||
redirectHandler = SmartRedirectHandler()
|
||||
rangeHandler = HTTPRangeHandler()
|
||||
|
||||
def __urllib2Opener():
|
||||
"""
|
||||
|
@ -80,12 +82,13 @@ def __urllib2Opener():
|
|||
global authHandler
|
||||
global keepAliveHandler
|
||||
global proxyHandler
|
||||
global rangeHandler
|
||||
global redirectHandler
|
||||
|
||||
debugMsg = "creating HTTP requests opener object"
|
||||
logger.debug(debugMsg)
|
||||
|
||||
handlers = [proxyHandler, authHandler, redirectHandler]
|
||||
handlers = [proxyHandler, authHandler, redirectHandler, rangeHandler]
|
||||
|
||||
if not conf.dropSetCookie:
|
||||
conf.cj = cookielib.LWPCookieJar()
|
||||
|
|
52
lib/request/rangehandler.py
Normal file
52
lib/request/rangehandler.py
Normal file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
$Id$
|
||||
|
||||
Copyright (c) 2006-2010 sqlmap developers (http://sqlmap.sourceforge.net/)
|
||||
See the file 'doc/COPYING' for copying permission
|
||||
"""
|
||||
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
from lib.core.exception import sqlmapConnectionException
|
||||
|
||||
class HTTPRangeHandler(urllib2.BaseHandler):
|
||||
"""
|
||||
Handler that enables HTTP Range headers.
|
||||
|
||||
Reference: http://stackoverflow.com/questions/1971240/python-seek-on-remote-file
|
||||
|
||||
This was extremely simple. The Range header is a HTTP feature to
|
||||
begin with so all this class does is tell urllib2 that the
|
||||
"206 Partial Content" reponse from the HTTP server is what we
|
||||
expected.
|
||||
|
||||
Example:
|
||||
import urllib2
|
||||
import byterange
|
||||
|
||||
range_handler = range.HTTPRangeHandler()
|
||||
opener = urllib2.build_opener(range_handler)
|
||||
|
||||
# install it
|
||||
urllib2.install_opener(opener)
|
||||
|
||||
# create Request and set Range header
|
||||
req = urllib2.Request('http://www.python.org/')
|
||||
req.header['Range'] = 'bytes=30-50'
|
||||
f = urllib2.urlopen(req)
|
||||
"""
|
||||
|
||||
def http_error_206(self, req, fp, code, msg, hdrs):
|
||||
# 206 Partial Content Response
|
||||
r = urllib.addinfourl(fp, hdrs, req.get_full_url())
|
||||
r.code = code
|
||||
r.msg = msg
|
||||
return r
|
||||
|
||||
def http_error_416(self, req, fp, code, msg, hdrs):
|
||||
# HTTP's Range Not Satisfiable error
|
||||
errMsg = "Invalid range"
|
||||
raise sqlmapConnectionException, errMsg
|
Loading…
Reference in New Issue
Block a user