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

Skip to content

Commit 40623e7

Browse files
committed
Minor patch (--update to work with #pip)
1 parent 35862bf commit 40623e7

2 files changed

Lines changed: 32 additions & 2 deletions

File tree

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.4.11.14"
21+
VERSION = "1.4.11.15"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/core/update.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import zipfile
1515

1616
from lib.core.common import dataToStdout
17+
from lib.core.common import extractRegexResult
1718
from lib.core.common import getLatestRevision
1819
from lib.core.common import getSafeExString
1920
from lib.core.common import openFile
@@ -27,6 +28,7 @@
2728
from lib.core.settings import GIT_REPOSITORY
2829
from lib.core.settings import IS_WIN
2930
from lib.core.settings import VERSION
31+
from lib.core.settings import TYPE
3032
from lib.core.settings import ZIPBALL_PAGE
3133
from thirdparty.six.moves import urllib as _urllib
3234

@@ -36,7 +38,34 @@ def update():
3638

3739
success = False
3840

39-
if not os.path.exists(os.path.join(paths.SQLMAP_ROOT_PATH, ".git")):
41+
if TYPE == "pip":
42+
infoMsg = "updating sqlmap to the latest stable version from the "
43+
infoMsg += "PyPI repository"
44+
logger.info(infoMsg)
45+
46+
debugMsg = "sqlmap will try to update itself using 'pip' command"
47+
logger.debug(debugMsg)
48+
49+
dataToStdout("\r[%s] [INFO] update in progress" % time.strftime("%X"))
50+
51+
output = ""
52+
try:
53+
process = subprocess.Popen("pip install -U sqlmap", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=paths.SQLMAP_ROOT_PATH)
54+
pollProcess(process, True)
55+
output, _ = process.communicate()
56+
success = not process.returncode
57+
except Exception as ex:
58+
success = False
59+
output = getSafeExString(ex)
60+
finally:
61+
output = getText(output)
62+
63+
if success:
64+
logger.info("%s the latest revision '%s'" % ("already at" if "already up-to-date" in output else "updated to", extractRegexResult(r"\binstalled sqlmap-(?P<result>\d+\.\d+\.\d+)", output) or extractRegexResult(r"\((?P<result>\d+\.\d+\.\d+)\)", output)))
65+
else:
66+
logger.error("update could not be completed ('%s')" % re.sub(r"[^a-z0-9:/\\]+", " ", output).strip())
67+
68+
elif not os.path.exists(os.path.join(paths.SQLMAP_ROOT_PATH, ".git")):
4069
warnMsg = "not a git repository. It is recommended to clone the 'sqlmapproject/sqlmap' repository "
4170
warnMsg += "from GitHub (e.g. 'git clone --depth 1 %s sqlmap')" % GIT_REPOSITORY
4271
logger.warn(warnMsg)
@@ -95,6 +124,7 @@ def update():
95124
os.chmod(os.path.join(directory, "sqlmap.py"), attrs)
96125
except OSError:
97126
logger.warning("could not set the file attributes of '%s'" % os.path.join(directory, "sqlmap.py"))
127+
98128
else:
99129
infoMsg = "updating sqlmap to the latest development revision from the "
100130
infoMsg += "GitHub repository"

0 commit comments

Comments
 (0)