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

Skip to content

Commit 9b46540

Browse files
committed
Adding exit code (1) in case of sqlmap fail
1 parent e7469ab commit 9b46540

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from lib.core.enums import OS
1818

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

lib/core/testing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import os
1111
import re
1212
import shutil
13-
import subprocess
1413
import sys
1514
import tempfile
1615
import threading
@@ -54,7 +53,7 @@ def vulnTest():
5453
"""
5554

5655
retVal = True
57-
count, length = 0, 5
56+
count, length = 0, 6
5857

5958
def _thread():
6059
vulnserver.init(quiet=True)
@@ -65,6 +64,7 @@ def _thread():
6564
thread.start()
6665

6766
for options, checks in (
67+
("--version", ("1.", "#")),
6868
("--flush-session", ("Type: boolean-based blind", "Type: time-based blind", "Type: UNION query", "back-end DBMS: SQLite", "3 columns")),
6969
("--banner --schema --dump -T users --binary-fields=surname --where 'id>3'", ("banner: '3", "INTEGER", "TEXT", "id", "name", "surname", "2 entries", "6E616D6569736E756C6C")),
7070
("--all", ("5 entries", "luther", "blisset", "fluffy", "ming", "NULL", "nameisnull")),
@@ -85,6 +85,8 @@ def _thread():
8585
else:
8686
logger.error("vuln test final result: FAILED")
8787

88+
return retVal
89+
8890
def smokeTest():
8991
"""
9092
Runs the basic smoke testing of a program

sqlmap.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ def main():
159159
# Postponed imports (faster start)
160160
if conf.smokeTest:
161161
from lib.core.testing import smokeTest
162-
smokeTest()
162+
os._exitcode = 1 - (smokeTest() or 0)
163163
elif conf.vulnTest:
164164
from lib.core.testing import vulnTest
165-
vulnTest()
165+
os._exitcode = 1 - (vulnTest() or 0)
166166
elif conf.liveTest:
167167
from lib.core.testing import liveTest
168-
liveTest()
168+
os._exitcode = 1 - (liveTest() or 0)
169169
else:
170170
from lib.controller.controller import start
171171
if conf.profile and PY2:
@@ -176,6 +176,8 @@ def main():
176176
try:
177177
start()
178178
except Exception as ex:
179+
os._exitcode = 1
180+
179181
if "can't start new thread" in getSafeExString(ex):
180182
errMsg = "unable to start new threads. Please check OS (u)limits"
181183
logger.critical(errMsg)
@@ -409,7 +411,9 @@ def main():
409411
finally:
410412
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
411413
if threading.activeCount() > 1:
412-
os._exit(0)
414+
os._exit(getattr(os, "_exitcode", 0))
415+
else:
416+
sys.exit(getattr(os, "_exitcode", 0))
413417
else:
414418
# cancelling postponed imports (because of Travis CI checks)
415419
from lib.controller.controller import start

0 commit comments

Comments
 (0)