@@ -1086,6 +1086,40 @@ def isBase64EncodedString(subject):
10861086def isHexEncodedString (subject ):
10871087 return re .match (r"\A[0-9a-fA-F]+\Z" , subject ) is not None
10881088
1089+ def profile (profileOutputFile = 'sqlmap.profile' , imageOutputFile = 'profile.png' ):
1090+ import cProfile
1091+ cProfile .run ("start()" , profileOutputFile )
1092+
1093+ graphScript = 'gprof2dot.py'
1094+ graphScriptRepositoryUrl = 'http://gprof2dot.jrfonseca.googlecode.com/hg/'
1095+ graphScriptPath = os .path .join (paths .SQLMAP_ROOT_PATH , graphScript )
1096+ if not os .path .exists (graphScriptPath ):
1097+ errMsg = "unable to find Jose Fonseca's '%s' graph " % graphScript
1098+ errMsg += "conversion script. please download it from "
1099+ errMsg += "official repository at '%s' " % graphScriptRepositoryUrl
1100+ errMsg += "and put it inside sqlmap's root directory ('%s')." % paths .SQLMAP_ROOT_PATH
1101+ logger .error (errMsg )
1102+ return
1103+
1104+ infoMsg = "converting profile data to an image."
1105+ logger .info (infoMsg )
1106+
1107+ if os .path .exists (imageOutputFile ):
1108+ os .remove (imageOutputFile )
1109+
1110+ msg = subprocess .Popen ('python %s -f pstats %s | dot -Tpng -o %s' % (graphScriptPath , profileOutputFile , imageOutputFile ), shell = True , stderr = subprocess .PIPE ).stderr .read ()
1111+
1112+ if msg :
1113+ errMsg = "there was an error while converting ('%s')." % msg .strip ()
1114+ logger .error (errMsg )
1115+ else :
1116+ if os .name == 'mac' :
1117+ subprocess .call (('open' , imageOutputFile ))
1118+ elif os .name == 'posix' :
1119+ subprocess .call (('xdg-open' , imageOutputFile ))
1120+ elif os .name == 'nt' :
1121+ subprocess .call (('start' , imageOutputFile ))
1122+
10891123def getConsoleWidth (default = 80 ):
10901124 width = None
10911125
@@ -1118,3 +1152,51 @@ def parseXmlFile(xmlFile, handler):
11181152
11191153def calculateDeltaSeconds (start , epsilon = 0.05 ):
11201154 return int (time .time () - start + epsilon )
1155+
1156+ def getCommonPredictionTables (value , originalTable ):
1157+ if not kb .commonTables :
1158+ kb .commonTables = {}
1159+ fileName = os .path .join (paths .SQLMAP_TXT_PATH , 'common-tables.txt' )
1160+ file = open (fileName , 'r' )
1161+ key = None
1162+ for line in file .xreadlines ():
1163+ line = line .strip ()
1164+ if len (line ) > 1 :
1165+ if line [0 ] == '[' and line [- 1 ] == ']' :
1166+ key = line [1 :- 1 ]
1167+ elif key :
1168+ if key not in kb .commonTables :
1169+ kb .commonTables [key ] = []
1170+ kb .commonTables [key ].append (line .strip ())
1171+
1172+ predictionSet = set ()
1173+ wildIndexes = []
1174+
1175+ kb .dbms = 'MySQL'
1176+
1177+ if value [- 1 ] != '.' :
1178+ value += '.'
1179+ charIndex = 0
1180+ findIndex = value .find ('.' , charIndex )
1181+ while findIndex != - 1 :
1182+ wildIndexes .append (findIndex )
1183+ charIndex += 1
1184+ findIndex = value .find ('.' , charIndex )
1185+ if kb .dbms in kb .commonTables :
1186+ for item in kb .commonTables [kb .dbms ]:
1187+ if re .search ('\A%s' % value , item ):
1188+ for index in wildIndexes :
1189+ char = item [index ]
1190+ if char not in predictionSet :
1191+ predictionSet .add (char )
1192+ predictionTable = []
1193+ otherTable = []
1194+ for ordChar in originalTable :
1195+ if chr (ordChar ) not in predictionSet :
1196+ otherTable .append (ordChar )
1197+ else :
1198+ predictionTable .append (ordChar )
1199+ predictionTable .sort ()
1200+ return predictionTable , otherTable
1201+ else :
1202+ return None , originalTable
0 commit comments