Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 577e346

Browse files
committed
Fixes #2144
1 parent 81c6aad commit 577e346

5 files changed

Lines changed: 39 additions & 46 deletions

File tree

lib/core/option.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
from lib.utils.search import search
156156
from lib.utils.purge import purge
157157
from thirdparty.keepalive import keepalive
158+
from thirdparty.multipart import multipartpost
158159
from thirdparty.oset.pyoset import oset
159160
from thirdparty.socks import socks
160161
from xml.etree.ElementTree import ElementTree
@@ -165,6 +166,7 @@
165166
proxyHandler = urllib2.ProxyHandler()
166167
redirectHandler = SmartRedirectHandler()
167168
rangeHandler = HTTPRangeHandler()
169+
multipartPostHandler = multipartpost.MultipartPostHandler()
168170

169171
def _feedTargetsDict(reqFile, addedTargetUrls):
170172
"""
@@ -1164,7 +1166,7 @@ def _setHTTPHandlers():
11641166
debugMsg = "creating HTTP requests opener object"
11651167
logger.debug(debugMsg)
11661168

1167-
handlers = filter(None, [proxyHandler if proxyHandler.proxies else None, authHandler, redirectHandler, rangeHandler, httpsHandler])
1169+
handlers = filter(None, [multipartPostHandler, proxyHandler if proxyHandler.proxies else None, authHandler, redirectHandler, rangeHandler, httpsHandler])
11681170

11691171
if not conf.dropSetCookie:
11701172
if not conf.loadCookies:

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.revision import getRevisionNumber
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.0.8.24"
22+
VERSION = "1.0.9.0"
2323
REVISION = getRevisionNumber()
2424
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2525
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}

lib/request/connect.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ class WebSocketException(Exception):
110110
from lib.request.direct import direct
111111
from lib.request.comparison import comparison
112112
from lib.request.methodrequest import MethodRequest
113-
from thirdparty.multipart import multipartpost
114113
from thirdparty.odict.odict import OrderedDict
115114
from thirdparty.socks.socks import ProxyError
116115

@@ -242,7 +241,7 @@ def getPage(**kwargs):
242241
referer = kwargs.get("referer", None) or conf.referer
243242
host = kwargs.get("host", None) or conf.host
244243
direct_ = kwargs.get("direct", False)
245-
multipart = kwargs.get("multipart", False)
244+
multipart = kwargs.get("multipart", None)
246245
silent = kwargs.get("silent", False)
247246
raise404 = kwargs.get("raise404", True)
248247
timeout = kwargs.get("timeout", None) or conf.timeout
@@ -254,6 +253,9 @@ def getPage(**kwargs):
254253
crawling = kwargs.get("crawling", False)
255254
skipRead = kwargs.get("skipRead", False)
256255

256+
if multipart:
257+
post = multipart
258+
257259
websocket_ = url.lower().startswith("ws")
258260

259261
if not urlparse.urlsplit(url).netloc:
@@ -298,20 +300,6 @@ def getPage(**kwargs):
298300
params = urlencode(params)
299301
url = "%s?%s" % (url, params)
300302

301-
elif multipart:
302-
# Needed in this form because of potential circle dependency
303-
# problem (option -> update -> connect -> option)
304-
from lib.core.option import proxyHandler
305-
306-
multipartOpener = urllib2.build_opener(proxyHandler, multipartpost.MultipartPostHandler)
307-
conn = multipartOpener.open(unicodeencode(url), multipart)
308-
page = Connect._connReadProxy(conn) if not skipRead else None
309-
responseHeaders = conn.info()
310-
responseHeaders[URI_HTTP_HEADER] = conn.geturl()
311-
page = decodePage(page, responseHeaders.get(HTTP_HEADER.CONTENT_ENCODING), responseHeaders.get(HTTP_HEADER.CONTENT_TYPE))
312-
313-
return page
314-
315303
elif any((refreshing, crawling)):
316304
pass
317305

@@ -364,7 +352,7 @@ def getPage(**kwargs):
364352
if not getHeader(headers, HTTP_HEADER.ACCEPT_ENCODING):
365353
headers[HTTP_HEADER.ACCEPT_ENCODING] = HTTP_ACCEPT_ENCODING_HEADER_VALUE if kb.pageCompress else "identity"
366354

367-
if post is not None and not getHeader(headers, HTTP_HEADER.CONTENT_TYPE):
355+
if post is not None and not multipart and not getHeader(headers, HTTP_HEADER.CONTENT_TYPE):
368356
headers[HTTP_HEADER.CONTENT_TYPE] = POST_HINT_CONTENT_TYPES.get(kb.postHint, DEFAULT_CONTENT_TYPE)
369357

370358
if headers.get(HTTP_HEADER.CONTENT_TYPE) == POST_HINT_CONTENT_TYPES[POST_HINT.MULTIPART]:
@@ -455,9 +443,10 @@ class _(dict):
455443

456444
requestMsg += "\n"
457445

458-
threadData.lastRequestMsg = requestMsg
446+
if not multipart:
447+
threadData.lastRequestMsg = requestMsg
459448

460-
logger.log(CUSTOM_LOGGING.TRAFFIC_OUT, requestMsg)
449+
logger.log(CUSTOM_LOGGING.TRAFFIC_OUT, requestMsg)
461450

462451
if conf.cj:
463452
for cookie in conf.cj:
@@ -578,7 +567,8 @@ class _(dict):
578567
elif conf.verbose > 5:
579568
responseMsg += "%s\n\n%s" % (logHeaders, (page or "")[:MAX_CONNECTION_CHUNK_SIZE])
580569

581-
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg)
570+
if not multipart:
571+
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg)
582572

583573
if ex.code == httplib.UNAUTHORIZED and not conf.ignore401:
584574
errMsg = "not authorized, try to provide right HTTP "
@@ -711,7 +701,8 @@ class _(dict):
711701
elif conf.verbose > 5:
712702
responseMsg += "%s\n\n%s" % (logHeaders, (page or "")[:MAX_CONNECTION_CHUNK_SIZE])
713703

714-
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg)
704+
if not multipart:
705+
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg)
715706

716707
return page, responseHeaders, code
717708

thirdparty/multipart/multipartpost.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ class MultipartPostHandler(urllib2.BaseHandler):
4747
def http_request(self, request):
4848
data = request.get_data()
4949

50-
if data is not None and type(data) != str:
50+
if isinstance(data, dict):
5151
v_files = []
5252
v_vars = []
5353

5454
try:
5555
for(key, value) in data.items():
56-
if isinstance(value, file) or hasattr(value, 'file') or isinstance(value, StringIO.StringIO):
56+
if isinstance(value, file) or hasattr(value, "file") or isinstance(value, StringIO.StringIO):
5757
v_files.append((key, value))
5858
else:
5959
v_vars.append((key, value))
@@ -65,10 +65,10 @@ def http_request(self, request):
6565
data = urllib.urlencode(v_vars, doseq)
6666
else:
6767
boundary, data = self.multipart_encode(v_vars, v_files)
68-
contenttype = 'multipart/form-data; boundary=%s' % boundary
69-
#if (request.has_header('Content-Type') and request.get_header('Content-Type').find('multipart/form-data') != 0):
70-
# print "Replacing %s with %s" % (request.get_header('content-type'), 'multipart/form-data')
71-
request.add_unredirected_header('Content-Type', contenttype)
68+
contenttype = "multipart/form-data; boundary=%s" % boundary
69+
#if (request.has_header("Content-Type") and request.get_header("Content-Type").find("multipart/form-data") != 0):
70+
# print "Replacing %s with %s" % (request.get_header("content-type"), "multipart/form-data")
71+
request.add_unredirected_header("Content-Type", contenttype)
7272

7373
request.add_data(data)
7474
return request
@@ -78,32 +78,32 @@ def multipart_encode(vars, files, boundary=None, buf=None):
7878
boundary = mimetools.choose_boundary()
7979

8080
if buf is None:
81-
buf = ''
81+
buf = ""
8282

8383
for (key, value) in vars:
8484
if key is not None and value is not None:
85-
buf += '--%s\r\n' % boundary
86-
buf += 'Content-Disposition: form-data; name="%s"' % key
87-
buf += '\r\n\r\n' + value + '\r\n'
85+
buf += "--%s\r\n" % boundary
86+
buf += "Content-Disposition: form-data; name=\"%s\"" % key
87+
buf += "\r\n\r\n" + value + "\r\n"
8888

8989
for (key, fd) in files:
9090
file_size = os.fstat(fd.fileno())[stat.ST_SIZE] if isinstance(fd, file) else fd.len
91-
filename = fd.name.split('/')[-1] if '/' in fd.name else fd.name.split('\\')[-1]
91+
filename = fd.name.split("/")[-1] if "/" in fd.name else fd.name.split("\\")[-1]
9292
try:
93-
contenttype = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
93+
contenttype = mimetypes.guess_type(filename)[0] or "application/octet-stream"
9494
except:
9595
# Reference: http://bugs.python.org/issue9291
96-
contenttype = 'application/octet-stream'
97-
buf += '--%s\r\n' % boundary
98-
buf += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename)
99-
buf += 'Content-Type: %s\r\n' % contenttype
100-
# buf += 'Content-Length: %s\r\n' % file_size
96+
contenttype = "application/octet-stream"
97+
buf += "--%s\r\n" % boundary
98+
buf += "Content-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n" % (key, filename)
99+
buf += "Content-Type: %s\r\n" % contenttype
100+
# buf += "Content-Length: %s\r\n" % file_size
101101
fd.seek(0)
102102

103103
buf = str(buf) if not isinstance(buf, unicode) else buf.encode("utf8")
104-
buf += '\r\n%s\r\n' % fd.read()
104+
buf += "\r\n%s\r\n" % fd.read()
105105

106-
buf += '--%s--\r\n\r\n' % boundary
106+
buf += "--%s--\r\n\r\n" % boundary
107107

108108
return boundary, buf
109109

txt/checksum.md5

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ e4aec2b11c1ad6039d0c3dbbfbc5eb1a lib/core/exception.py
3939
cc9c82cfffd8ee9b25ba3af6284f057e lib/core/__init__.py
4040
91c514013daa796e2cdd940389354eac lib/core/log.py
4141
b9779615206791e6ebbaa84947842b49 lib/core/optiondict.py
42-
85b144015724e1961e6c9ea1a42b329a lib/core/option.py
42+
57109386dcff87507201f14a5821fd41 lib/core/option.py
4343
1e8948dddbd12def5c2af52530738059 lib/core/profiling.py
4444
e60456db5380840a586654344003d4e6 lib/core/readlineng.py
4545
5ef56abb8671c2ca6ceecb208258e360 lib/core/replication.py
4646
99a2b496b9d5b546b335653ca801153f lib/core/revision.py
4747
7c15dd2777af4dac2c89cab6df17462e lib/core/session.py
48-
c523de8745fb88545bbbbd7cee1d0b2f lib/core/settings.py
48+
dd9d9aa60d7b2ba844189b90285c45cd lib/core/settings.py
4949
7af83e4f18cab6dff5e67840eb65be80 lib/core/shell.py
5050
23657cd7d924e3c6d225719865855827 lib/core/subprocessng.py
5151
0bc2fae1dec18cdd11954b22358293f2 lib/core/target.py
@@ -68,7 +68,7 @@ b40a4c5d91770d347df36d3065b63798 lib/parse/sitemap.py
6868
9299f21804033f099681525bb9bf51c0 lib/request/basicauthhandler.py
6969
a3e83cfe7e6825fb1b70951ad290d2ae lib/request/basic.py
7070
97fb6323bfb5f941b27cbdb00f9078e1 lib/request/comparison.py
71-
72a0e7bb1010bb39c6538dbc77eae180 lib/request/connect.py
71+
8bc040159a145a1dfdf8a3fe76a0adbc lib/request/connect.py
7272
49b4c583af68689de5f9acb162de2939 lib/request/direct.py
7373
1a46f7bb26b23ec0c0d9d9c95828241b lib/request/dns.py
7474
70ceefe39980611494d4f99afb96f652 lib/request/httpshandler.py
@@ -329,7 +329,7 @@ e0c6a936506bffeed53ce106ec15942d thirdparty/keepalive/keepalive.py
329329
d41d8cd98f00b204e9800998ecf8427e thirdparty/magic/__init__.py
330330
49f0d123e044dd32a452e2fe51f1a9c3 thirdparty/magic/magic.py
331331
d41d8cd98f00b204e9800998ecf8427e thirdparty/multipart/__init__.py
332-
fd52df5770ee286a7c186fdd2ccc4e0c thirdparty/multipart/multipartpost.py
332+
03c8abc17b228e59bcfda1f11a9137e0 thirdparty/multipart/multipartpost.py
333333
3e502b04f3849afbb7f0e13b5fd2b5c1 thirdparty/odict/__init__.py
334334
127fe54fdb9b13fdac93c8fc9c9cad5e thirdparty/odict/odict.py
335335
08801ea0ba9ae22885275ef65d3ee9dc thirdparty/oset/_abc.py

0 commit comments

Comments
 (0)