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

Skip to content

Commit 10521b6

Browse files
committed
Major bug fix in multipartpost and minor adjustments elsewhere
1 parent 06af405 commit 10521b6

5 files changed

Lines changed: 30 additions & 23 deletions

File tree

lib/contrib/multipartpost.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,32 +74,34 @@ def http_request(self, request):
7474
request.add_data(data)
7575
return request
7676

77-
def multipart_encode(vars, files, boundary = None, buffer = None):
77+
def multipart_encode(vars, files, boundary = None, buf = None):
7878
if boundary is None:
7979
boundary = mimetools.choose_boundary()
8080

81-
if buffer is None:
82-
buffer = ''
81+
if buf is None:
82+
buf = ''
8383

84-
for(key, value) in vars:
85-
buffer += '--%s\r\n' % boundary
86-
buffer += 'Content-Disposition: form-data; name="%s"' % key
87-
buffer += '\r\n\r\n' + value + '\r\n'
84+
for (key, value) in vars:
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

89-
for(key, fd) in files:
89+
for (key, fd) in files:
9090
file_size = os.fstat(fd.fileno())[stat.ST_SIZE]
9191
filename = fd.name.split('/')[-1]
9292
contenttype = mimetypes.guess_type(filename)[0] or 'application/octet-stream'
93-
buffer += '--%s\r\n' % boundary
94-
buffer += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename)
95-
buffer += 'Content-Type: %s\r\n' % contenttype
96-
# buffer += 'Content-Length: %s\r\n' % file_size
93+
buf += '--%s\r\n' % boundary
94+
buf += 'Content-Disposition: form-data; name="%s"; filename="%s"\r\n' % (key, filename)
95+
buf += 'Content-Type: %s\r\n' % contenttype
96+
# buf += 'Content-Length: %s\r\n' % file_size
9797
fd.seek(0)
98-
buffer += '\r\n' + fd.read() + '\r\n'
9998

100-
buffer += '--%s--\r\n\r\n' % boundary
99+
buf = str(buf)
100+
buf += '\r\n%s\r\n' % fd.read()
101101

102-
return boundary, buffer
102+
buf += '--%s--\r\n\r\n' % boundary
103+
104+
return boundary, buf
103105

104106
multipart_encode = Callable(multipart_encode)
105107

lib/core/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,9 @@ def dataToOutFile(data):
377377
if not data:
378378
return "No data retrieved"
379379

380-
rFile = filePathToString(conf.rFile)
380+
rFile = filePathToString(conf.rFile)
381381
rFilePath = "%s%s%s" % (conf.filePath, os.sep, rFile)
382-
rFileFP = codecs.open(rFilePath, "wb", conf.dataEncoding)
382+
rFileFP = codecs.open(rFilePath, "wb", conf.dataEncoding)
383383

384384
rFileFP.write(data)
385385
rFileFP.flush()

lib/parse/configfile.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ def configFileParser(configFile):
7272
logger.debug(debugMsg)
7373

7474
checkFile(configFile)
75+
configFP = codecs.open(configFile, "rb", conf.dataEncoding)
7576
config = UnicodeRawConfigParser()
76-
config.readfp(codecs.open(configFile, "rb", conf.dataEncoding))
77+
config.readfp(configFP)
7778

7879
if not config.has_section("Target"):
7980
raise NoSectionError, "Target in the configuration file is mandatory"

lib/takeover/web.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
"""
2424

25+
import codecs
2526
import os
2627
import posixpath
2728
import re
@@ -82,13 +83,15 @@ def webBackdoorRunCmd(self, cmd):
8283
return output
8384

8485
def webFileUpload(self, fileToUpload, destFileName, directory):
85-
inputFile = open(fileToUpload, "r")
86-
retVal = self.__webFileStreamUpload(inputFile, destFileName, directory)
87-
inputFile.close()
86+
inputFP = codecs.open(fileToUpload, "rb")
87+
retVal = self.__webFileStreamUpload(inputFP, destFileName, directory)
88+
inputFP.close()
89+
8890
return retVal
8991

9092
def __webFileStreamUpload(self, stream, destFileName, directory):
91-
stream.seek(0) #rewind
93+
stream.seek(0) # Rewind
94+
9295
if self.webApi in ("php", "asp"):
9396
multipartParams = {
9497
"upload": "1",

sqlmap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232

3333
warnings.filterwarnings(action="ignore", message=".*was already imported", category=UserWarning)
3434

35-
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
35+
# NOTE: This breaks SQL shell and OS shell history and TAB functionalities
36+
#sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
3637

3738
try:
3839
import psyco

0 commit comments

Comments
 (0)