2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2010-11-08 15:26:13 +03:00
|
|
|
|
|
|
|
"""
|
2018-01-02 02:48:10 +03:00
|
|
|
Copyright (c) 2006-2018 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2010-11-08 15:26:13 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
import urllib
|
|
|
|
import urllib2
|
|
|
|
|
2012-12-06 17:14:19 +04:00
|
|
|
from lib.core.exception import SqlmapConnectionException
|
2010-11-08 15:26:13 +03:00
|
|
|
|
|
|
|
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
|
2013-01-04 02:57:07 +04:00
|
|
|
begin with so all this class does is tell urllib2 that the
|
|
|
|
"206 Partial Content" response from the HTTP server is what we
|
2010-11-08 15:26:13 +03:00
|
|
|
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
|
2018-05-08 15:06:34 +03:00
|
|
|
req = urllib2.Request('https://www.python.org/')
|
2010-11-08 15:26:13 +03:00
|
|
|
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"
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapConnectionException(errMsg)
|