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

Skip to content

Commit ae8b1fe

Browse files
committed
Implementation for an Issue #678
1 parent efa3c3e commit ae8b1fe

3 files changed

Lines changed: 45 additions & 3 deletions

File tree

lib/core/enums.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ class EXPECTED:
179179
BOOL = "bool"
180180
INT = "int"
181181

182+
class OPTION_TYPE:
183+
BOOLEAN = "boolean"
184+
INTEGER = "integer"
185+
FLOAT = "float"
186+
STRING = "string"
187+
182188
class HASHDB_KEYS:
183189
DBMS = "DBMS"
184190
CONF_TMP_PATH = "CONF_TMP_PATH"

lib/core/option.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
from lib.core.enums import HTTP_HEADER
7676
from lib.core.enums import HTTPMETHOD
7777
from lib.core.enums import MOBILES
78+
from lib.core.enums import OPTION_TYPE
7879
from lib.core.enums import PAYLOAD
7980
from lib.core.enums import PRIORITY
8081
from lib.core.enums import PROXY_TYPE
@@ -120,6 +121,7 @@
120121
from lib.core.settings import PROBLEMATIC_CUSTOM_INJECTION_PATTERNS
121122
from lib.core.settings import SITE
122123
from lib.core.settings import SQLITE_ALIASES
124+
from lib.core.settings import SQLMAP_ENVIRONMENT_PREFIX
123125
from lib.core.settings import SUPPORTED_DBMS
124126
from lib.core.settings import SUPPORTED_OS
125127
from lib.core.settings import SYBASE_ALIASES
@@ -1823,16 +1825,16 @@ def _saveCmdline():
18231825
datatype = datatype[0]
18241826

18251827
if value is None:
1826-
if datatype == "boolean":
1828+
if datatype == OPTION_TYPE.BOOLEAN:
18271829
value = "False"
1828-
elif datatype in ("integer", "float"):
1830+
elif datatype in (OPTION_TYPE.INTEGER, OPTION_TYPE.FLOAT):
18291831
if option in ("threads", "verbose"):
18301832
value = "1"
18311833
elif option == "timeout":
18321834
value = "10"
18331835
else:
18341836
value = "0"
1835-
elif datatype == "string":
1837+
elif datatype == OPTION_TYPE.STRING:
18361838
value = ""
18371839

18381840
if isinstance(value, basestring):
@@ -1903,6 +1905,37 @@ def _mergeOptions(inputOptions, overrideOptions):
19031905
if hasattr(conf, key) and conf[key] is None:
19041906
conf[key] = value
19051907

1908+
_ = {}
1909+
for key, value in os.environ.items():
1910+
if key.upper().startswith(SQLMAP_ENVIRONMENT_PREFIX):
1911+
_[key[len(SQLMAP_ENVIRONMENT_PREFIX):].upper()] = value
1912+
1913+
types_ = {}
1914+
for group in optDict.keys():
1915+
types_.update(optDict[group])
1916+
1917+
for key in conf:
1918+
if key.upper() in _:
1919+
value = _[key.upper()]
1920+
1921+
if types_[key] == OPTION_TYPE.BOOLEAN:
1922+
try:
1923+
value = bool(value)
1924+
except ValueError:
1925+
value = False
1926+
elif types_[key] == OPTION_TYPE.INTEGER:
1927+
try:
1928+
value = int(value)
1929+
except ValueError:
1930+
value = 0
1931+
elif types_[key] == OPTION_TYPE.FLOAT:
1932+
try:
1933+
value = float(value)
1934+
except ValueError:
1935+
value = 0.0
1936+
1937+
conf[key] = value
1938+
19061939
mergedOptions.update(conf)
19071940

19081941
def _setTrafficOutputFP():

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@
346346
# Prefix for Google analytics cookie names
347347
GOOGLE_ANALYTICS_COOKIE_PREFIX = "__UTM"
348348

349+
# Prefix for configuration overriding environment variables
350+
SQLMAP_ENVIRONMENT_PREFIX = "SQLMAP_"
351+
349352
# Turn off resume console info to avoid potential slowdowns
350353
TURN_OFF_RESUME_INFO_LIMIT = 20
351354

0 commit comments

Comments
 (0)