Adding exit code (1) in case of sqlmap fail

This commit is contained in:
Miroslav Stampar 2019-04-19 14:36:23 +02:00
parent e7469ab570
commit 9b46540e00
3 changed files with 13 additions and 7 deletions

View File

@ -17,7 +17,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME
from lib.core.enums import OS from lib.core.enums import OS
# sqlmap version (<major>.<minor>.<month>.<monthly commit>) # sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.4.31" VERSION = "1.3.4.32"
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

View File

@ -10,7 +10,6 @@ import doctest
import os import os
import re import re
import shutil import shutil
import subprocess
import sys import sys
import tempfile import tempfile
import threading import threading
@ -54,7 +53,7 @@ def vulnTest():
""" """
retVal = True retVal = True
count, length = 0, 5 count, length = 0, 6
def _thread(): def _thread():
vulnserver.init(quiet=True) vulnserver.init(quiet=True)
@ -65,6 +64,7 @@ def vulnTest():
thread.start() thread.start()
for options, checks in ( for options, checks in (
("--version", ("1.", "#")),
("--flush-session", ("Type: boolean-based blind", "Type: time-based blind", "Type: UNION query", "back-end DBMS: SQLite", "3 columns")), ("--flush-session", ("Type: boolean-based blind", "Type: time-based blind", "Type: UNION query", "back-end DBMS: SQLite", "3 columns")),
("--banner --schema --dump -T users --binary-fields=surname --where 'id>3'", ("banner: '3", "INTEGER", "TEXT", "id", "name", "surname", "2 entries", "6E616D6569736E756C6C")), ("--banner --schema --dump -T users --binary-fields=surname --where 'id>3'", ("banner: '3", "INTEGER", "TEXT", "id", "name", "surname", "2 entries", "6E616D6569736E756C6C")),
("--all", ("5 entries", "luther", "blisset", "fluffy", "ming", "NULL", "nameisnull")), ("--all", ("5 entries", "luther", "blisset", "fluffy", "ming", "NULL", "nameisnull")),
@ -85,6 +85,8 @@ def vulnTest():
else: else:
logger.error("vuln test final result: FAILED") logger.error("vuln test final result: FAILED")
return retVal
def smokeTest(): def smokeTest():
""" """
Runs the basic smoke testing of a program Runs the basic smoke testing of a program

View File

@ -159,13 +159,13 @@ def main():
# Postponed imports (faster start) # Postponed imports (faster start)
if conf.smokeTest: if conf.smokeTest:
from lib.core.testing import smokeTest from lib.core.testing import smokeTest
smokeTest() os._exitcode = 1 - (smokeTest() or 0)
elif conf.vulnTest: elif conf.vulnTest:
from lib.core.testing import vulnTest from lib.core.testing import vulnTest
vulnTest() os._exitcode = 1 - (vulnTest() or 0)
elif conf.liveTest: elif conf.liveTest:
from lib.core.testing import liveTest from lib.core.testing import liveTest
liveTest() os._exitcode = 1 - (liveTest() or 0)
else: else:
from lib.controller.controller import start from lib.controller.controller import start
if conf.profile and PY2: if conf.profile and PY2:
@ -176,6 +176,8 @@ def main():
try: try:
start() start()
except Exception as ex: except Exception as ex:
os._exitcode = 1
if "can't start new thread" in getSafeExString(ex): if "can't start new thread" in getSafeExString(ex):
errMsg = "unable to start new threads. Please check OS (u)limits" errMsg = "unable to start new threads. Please check OS (u)limits"
logger.critical(errMsg) logger.critical(errMsg)
@ -409,7 +411,9 @@ if __name__ == "__main__":
finally: finally:
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program # Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
if threading.activeCount() > 1: if threading.activeCount() > 1:
os._exit(0) os._exit(getattr(os, "_exitcode", 0))
else:
sys.exit(getattr(os, "_exitcode", 0))
else: else:
# cancelling postponed imports (because of Travis CI checks) # cancelling postponed imports (because of Travis CI checks)
from lib.controller.controller import start from lib.controller.controller import start