MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / _checkFileLength

Method _checkFileLength

plugins/generic/filesystem.py:50–102  ·  view source on GitHub ↗
(self, localFile, remoteFile, fileRead=False)

Source from the content-addressed store, hash-verified

48 self.tblField = "data"
49
50 def _checkFileLength(self, localFile, remoteFile, fileRead=False):
51 if Backend.isDbms(DBMS.MYSQL):
52 lengthQuery = "LENGTH(LOAD_FILE('%s'))" % remoteFile
53
54 elif Backend.isDbms(DBMS.PGSQL) and not fileRead:
55 lengthQuery = "SELECT SUM(LENGTH(data)) FROM pg_largeobject WHERE loid=%d" % self.oid
56
57 elif Backend.isDbms(DBMS.MSSQL):
58 self.createSupportTbl(self.fileTblName, self.tblField, "VARBINARY(MAX)")
59 inject.goStacked("INSERT INTO %s(%s) SELECT %s FROM OPENROWSET(BULK '%s', SINGLE_BLOB) AS %s(%s)" % (self.fileTblName, self.tblField, self.tblField, remoteFile, self.fileTblName, self.tblField))
60
61 lengthQuery = "SELECT DATALENGTH(%s) FROM %s" % (self.tblField, self.fileTblName)
62
63 try:
64 localFileSize = os.path.getsize(localFile)
65 except OSError:
66 warnMsg = "file '%s' is missing" % localFile
67 logger.warning(warnMsg)
68 localFileSize = 0
69
70 if fileRead and Backend.isDbms(DBMS.PGSQL):
71 logger.info("length of read file '%s' cannot be checked on PostgreSQL" % remoteFile)
72 sameFile = True
73 else:
74 logger.debug("checking the length of the remote file '%s'" % remoteFile)
75 remoteFileSize = inject.getValue(lengthQuery, resumeValue=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
76 sameFile = None
77
78 if isNumPosStrValue(remoteFileSize):
79 remoteFileSize = int(remoteFileSize)
80 localFile = getUnicode(localFile, encoding=sys.getfilesystemencoding() or UNICODE_ENCODING)
81 sameFile = False
82
83 if localFileSize == remoteFileSize:
84 sameFile = True
85 infoMsg = "the local file '%s' and the remote file " % localFile
86 infoMsg += "'%s' have the same size (%d B)" % (remoteFile, localFileSize)
87 elif remoteFileSize > localFileSize:
88 infoMsg = "the remote file '%s' is larger (%d B) than " % (remoteFile, remoteFileSize)
89 infoMsg += "the local file '%s' (%dB)" % (localFile, localFileSize)
90 else:
91 infoMsg = "the remote file '%s' is smaller (%d B) than " % (remoteFile, remoteFileSize)
92 infoMsg += "file '%s' (%d B)" % (localFile, localFileSize)
93
94 logger.info(infoMsg)
95 else:
96 sameFile = False
97 warnMsg = "it looks like the file has not been written (usually "
98 warnMsg += "occurs if the DBMS process user has no write "
99 warnMsg += "privileges in the destination path)"
100 logger.warning(warnMsg)
101
102 return sameFile
103
104 def fileToSqlQueries(self, fcEncodedList):
105 """

Callers 2

askCheckWrittenFileMethod · 0.95
askCheckReadFileMethod · 0.95

Calls 6

isNumPosStrValueFunction · 0.90
getUnicodeFunction · 0.90
isDbmsMethod · 0.80
createSupportTblMethod · 0.80
infoMethod · 0.80
debugMethod · 0.80

Tested by

no test coverage detected