@@ -203,29 +203,25 @@ def __updateMSSQLXML():
203
203
204
204
def __createFile (pathname , data ):
205
205
mkpath (os .path .dirname (pathname ))
206
+
206
207
fileFP = open (pathname , "wb" )
207
208
fileFP .write (data )
208
209
fileFP .close ()
209
210
210
211
211
- def __extractZipFile (zipFile ):
212
+ def __extractZipFile (tempDir , zipFile , sqlmapNewestVersion ):
212
213
# Check if the saved binary file is really a ZIP file
213
214
if zipfile .is_zipfile (zipFile ):
214
215
sqlmapZipFile = zipfile .ZipFile (zipFile )
215
216
else :
216
- raise sqlmapFilePathException , "the downloaded file does not seem to be a zipfile"
217
-
218
- # Create a temporary directory
219
- tempDir = tempfile .mkdtemp ("" , "sqlmap_latest-" )
217
+ raise sqlmapFilePathException , "the downloaded file does not seem to be a ZIP file"
220
218
221
219
# Extract each file within the ZIP file in the temporary directory
222
220
for info in sqlmapZipFile .infolist ():
223
221
if info .filename [- 1 ] != '/' :
224
222
data = sqlmapZipFile .read (info .filename )
225
223
__createFile (os .path .join (tempDir , info .filename ), data )
226
224
227
- return tempDir
228
-
229
225
230
226
def __updateSqlmap ():
231
227
infoMsg = "updating sqlmap"
@@ -247,6 +243,7 @@ def __updateSqlmap():
247
243
return
248
244
249
245
sqlmapNewestVersion = str (sqlmapNewestVersion ).replace ("\n " , "" )
246
+ sqlmapNewestVersion = "0.6.1"
250
247
251
248
if not re .search ("^([\w\.\-]+)$" , sqlmapNewestVersion ):
252
249
errMsg = "sqlmap version is in a wrong syntax"
@@ -259,11 +256,19 @@ def __updateSqlmap():
259
256
logger .info (infoMsg )
260
257
261
258
return
262
- else :
259
+
260
+ elif sqlmapNewestVersion > VERSION :
263
261
infoMsg = "sqlmap latest stable version is %s. " % sqlmapNewestVersion
264
262
infoMsg += "Going to download it from the SourceForge File List page"
265
263
logger .info (infoMsg )
266
264
265
+ elif sqlmapNewestVersion < VERSION :
266
+ infoMsg = "if you are running a version of sqlmap more updated than "
267
+ infoMsg += "the latest stable version (%s)" % sqlmapNewestVersion
268
+ logger .info (infoMsg )
269
+
270
+ return
271
+
267
272
sqlmapBinaryStringUrl = SQLMAP_SOURCE_URL % sqlmapNewestVersion
268
273
269
274
try :
@@ -278,25 +283,28 @@ def __updateSqlmap():
278
283
279
284
return
280
285
281
- # Save the sqlmap compressed source to a ZIP file in a temporary
282
- # directory and extract it
283
- zipFile = os .path .join (tempfile .gettempdir (), "sqlmap-%s.zip" % sqlmapNewestVersion )
286
+ debugMsg = 'saving the sqlmap compressed source to a ZIP file into '
287
+ debugMsg += 'the temporary directory and extract it'
288
+ logger .debug (debugMsg )
289
+
290
+ tempDir = tempfile .gettempdir ()
291
+ zipFile = os .path .join (tempDir , "sqlmap-%s.zip" % sqlmapNewestVersion )
284
292
__createFile (zipFile , sqlmapBinaryString )
285
- tempDir = __extractZipFile (zipFile )
293
+ __extractZipFile (tempDir , zipFile , sqlmapNewestVersion )
286
294
287
295
# For each file and directory in the temporary directory copy it
288
296
# to the sqlmap root path and set right permission
289
297
# TODO: remove files not needed anymore and all pyc within the
290
298
# sqlmap root path in the end
291
- for root , dirs , files in os .walk (os .path .join (tempDir , "sqlmap" )):
299
+ for root , dirs , files in os .walk (os .path .join (tempDir , "sqlmap-%s" % sqlmapNewestVersion )):
292
300
# Just for development release
293
- if '.svn' in dirs :
294
- dirs . remove ( '.svn' )
301
+ if '.svn' in root :
302
+ continue
295
303
296
304
cleanRoot = root .replace (tempDir , "" )
297
- cleanRoot = cleanRoot .replace ("%ssqlmap" % os .sep , "" )
305
+ cleanRoot = cleanRoot .replace ("%ssqlmap-%s " % ( os .sep , sqlmapNewestVersion ) , "" )
298
306
299
- if cleanRoot .startswith ("/" ):
307
+ if cleanRoot .startswith (os . sep ):
300
308
cleanRoot = cleanRoot [1 :]
301
309
302
310
for f in files :
@@ -307,18 +315,18 @@ def __updateSqlmap():
307
315
srcFile = os .path .join (root , f )
308
316
dstFile = os .path .join (paths .SQLMAP_ROOT_PATH , os .path .join (cleanRoot , f ))
309
317
318
+ if f == "sqlmap.conf" and os .path .exists (dstFile ):
319
+ infoMsg = "backupping configuration file to '%s.bak'" % dstFile
320
+ logger .info (infoMsg )
321
+ shutil .move (dstFile , "%s.bak" % dstFile )
322
+
310
323
if os .path .exists (dstFile ):
311
324
debugMsg = "replacing file '%s'" % dstFile
312
325
else :
313
326
debugMsg = "creating new file '%s'" % dstFile
314
327
315
328
logger .debug (debugMsg )
316
329
317
- if f == "sqlmap.conf" and os .path .exists (dstFile ):
318
- infoMsg = "backupping configuration file to '%s.bak'" % dstFile
319
- logger .info (infoMsg )
320
- shutil .move (dstFile , "%s.bak" % dstFile )
321
-
322
330
mkpath (os .path .dirname (dstFile ))
323
331
shutil .copy (srcFile , dstFile )
324
332
0 commit comments