From e0ec2fcdbdee71fba665f8c1b5b78fe2c4bb5499 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Thu, 28 Sep 2023 20:34:52 +0200 Subject: [PATCH] Implements option --time-limit (#5502) --- lib/core/convert.py | 5 +++++ lib/core/option.py | 1 + lib/core/optiondict.py | 1 + lib/core/settings.py | 2 +- lib/parse/cmdline.py | 3 +++ sqlmap.conf | 7 +++++-- 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/core/convert.py b/lib/core/convert.py index c6f86aa1f..6478f98f2 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -16,6 +16,7 @@ import codecs import json import re import sys +import time from lib.core.bigarray import BigArray from lib.core.compat import xrange @@ -334,6 +335,10 @@ def getUnicode(value, encoding=None, noneToNull=False): True """ + # Best position for --time-limit mechanism + if conf.get("timeLimit") and kb.get("startTime") and (time.time() - kb.startTime > conf.timeLimit): + raise SystemExit + if noneToNull and value is None: return NULL diff --git a/lib/core/option.py b/lib/core/option.py index 951399fc0..897b6724a 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -2171,6 +2171,7 @@ def _setKnowledgeBaseAttributes(flushAll=True): kb.smokeMode = False kb.reduceTests = None kb.sslSuccess = False + kb.startTime = time.time() kb.stickyDBMS = False kb.suppressResumeInfo = False kb.tableFrom = None diff --git a/lib/core/optiondict.py b/lib/core/optiondict.py index d41e85b5e..b4dd0af75 100644 --- a/lib/core/optiondict.py +++ b/lib/core/optiondict.py @@ -239,6 +239,7 @@ optDict = { "skipWaf": "boolean", "testFilter": "string", "testSkip": "string", + "timeLimit": "float", "webRoot": "string", }, diff --git a/lib/core/settings.py b/lib/core/settings.py index 5370a2481..b60fa79a8 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -20,7 +20,7 @@ from thirdparty import six from thirdparty.six import unichr as _unichr # sqlmap version (...) -VERSION = "1.7.9.2" +VERSION = "1.7.9.3" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" 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) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 95493b9b9..b62a79037 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -736,6 +736,9 @@ def cmdLineParser(argv=None): general.add_argument("--test-skip", dest="testSkip", help="Skip tests by payloads and/or titles (e.g. BENCHMARK)") + general.add_argument("--time-limit", dest="timeLimit", type=float, + help="Run with a time limit in seconds (e.g. 3600)") + general.add_argument("--web-root", dest="webRoot", help="Web server document root directory (e.g. \"/var/www\")") diff --git a/sqlmap.conf b/sqlmap.conf index c74c20d34..114324e8d 100644 --- a/sqlmap.conf +++ b/sqlmap.conf @@ -820,12 +820,15 @@ skipWaf = False # Default: sqlmap tablePrefix = sqlmap -# Select tests by payloads and/or titles (e.g. ROW) +# Select tests by payloads and/or titles (e.g. ROW). testFilter = -# Skip tests by payloads and/or titles (e.g. BENCHMARK) +# Skip tests by payloads and/or titles (e.g. BENCHMARK). testSkip = +# Run with a time limit in seconds (e.g. 3600). +timeLimit = + # Web server document root directory (e.g. "/var/www"). webRoot =