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

Skip to content

Commit 1196a1b

Browse files
committed
Fixes #405
1 parent c2262ed commit 1196a1b

9 files changed

Lines changed: 94 additions & 90 deletions

File tree

lib/core/common.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
from lib.core.enums import HTTP_HEADER
7373
from lib.core.enums import HTTPMETHOD
7474
from lib.core.enums import MKSTEMP_PREFIX
75+
from lib.core.enums import OPTION_TYPE
7576
from lib.core.enums import OS
7677
from lib.core.enums import PLACE
7778
from lib.core.enums import PAYLOAD
@@ -112,6 +113,7 @@
112113
from lib.core.settings import GOOGLE_ANALYTICS_COOKIE_PREFIX
113114
from lib.core.settings import HASHDB_MILESTONE_VALUE
114115
from lib.core.settings import HOST_ALIASES
116+
from lib.core.settings import IGNORE_SAVE_OPTIONS
115117
from lib.core.settings import INFERENCE_UNKNOWN_CHAR
116118
from lib.core.settings import INVALID_UNICODE_CHAR_FORMAT
117119
from lib.core.settings import IP_ADDRESS_REGEX
@@ -1145,7 +1147,7 @@ def banner():
11451147
This function prints sqlmap banner with its version
11461148
"""
11471149

1148-
if not any(_ in sys.argv for _ in ("--version", "--pickled-options")):
1150+
if not any(_ in sys.argv for _ in ("--version", "--api")):
11491151
_ = BANNER
11501152

11511153
if not getattr(LOGGER_HANDLER, "is_tty", False) or "--disable-coloring" in sys.argv:
@@ -2928,6 +2930,58 @@ def setOptimize():
29282930
debugMsg = "turning off switch '--null-connection' used indirectly by switch '-o'"
29292931
logger.debug(debugMsg)
29302932

2933+
def saveConfig(conf, filename):
2934+
"""
2935+
Saves conf to configuration filename
2936+
"""
2937+
2938+
config = UnicodeRawConfigParser()
2939+
userOpts = {}
2940+
2941+
for family in optDict.keys():
2942+
userOpts[family] = []
2943+
2944+
for option, value in conf.items():
2945+
for family, optionData in optDict.items():
2946+
if option in optionData:
2947+
userOpts[family].append((option, value, optionData[option]))
2948+
2949+
for family, optionData in userOpts.items():
2950+
config.add_section(family)
2951+
2952+
optionData.sort()
2953+
2954+
for option, value, datatype in optionData:
2955+
if datatype and isListLike(datatype):
2956+
datatype = datatype[0]
2957+
2958+
if option in IGNORE_SAVE_OPTIONS:
2959+
continue
2960+
2961+
if value is None:
2962+
if datatype == OPTION_TYPE.BOOLEAN:
2963+
value = "False"
2964+
elif datatype in (OPTION_TYPE.INTEGER, OPTION_TYPE.FLOAT):
2965+
if option in defaults:
2966+
value = str(defaults[option])
2967+
else:
2968+
value = "0"
2969+
elif datatype == OPTION_TYPE.STRING:
2970+
value = ""
2971+
2972+
if isinstance(value, basestring):
2973+
value = value.replace("\n", "\n ")
2974+
2975+
config.set(family, option, value)
2976+
2977+
with openFile(filename, "wb") as f:
2978+
try:
2979+
config.write(f)
2980+
except IOError, ex:
2981+
errMsg = "something went wrong while trying "
2982+
errMsg += "to write to the configuration file '%s' ('%s')" % (filename, getSafeExString(ex))
2983+
raise SqlmapSystemException(errMsg)
2984+
29312985
def initTechnique(technique=None):
29322986
"""
29332987
Prepares data for technique specified

lib/core/dicts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@
274274
"--auth-private": "use '--auth-file' instead",
275275
"--check-payload": None,
276276
"--check-waf": None,
277+
"--pickled-options": "use '--api -c ...' instead",
277278
}
278279

279280
DUMP_DATA_PREPROCESS = {

lib/core/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ class MKSTEMP_PREFIX:
364364
HASHES = "sqlmaphashes-"
365365
CRAWLER = "sqlmapcrawler-"
366366
IPC = "sqlmapipc-"
367+
CONFIG = "sqlmapconfig-"
367368
TESTING = "sqlmaptesting-"
368369
RESULTS = "sqlmapresults-"
369370
COOKIE_JAR = "sqlmapcookiejar-"

lib/core/option.py

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
from lib.core.common import getFileItems
4646
from lib.core.common import getFileType
4747
from lib.core.common import getUnicode
48-
from lib.core.common import isListLike
4948
from lib.core.common import normalizePath
5049
from lib.core.common import ntToPosixSlashes
5150
from lib.core.common import openFile
@@ -58,12 +57,11 @@
5857
from lib.core.common import resetCookieJar
5958
from lib.core.common import runningAsAdmin
6059
from lib.core.common import safeExpandUser
60+
from lib.core.common import saveConfig
6161
from lib.core.common import setOptimize
6262
from lib.core.common import setPaths
6363
from lib.core.common import singleTimeWarnMessage
64-
from lib.core.common import UnicodeRawConfigParser
6564
from lib.core.common import urldecode
66-
from lib.core.convert import base64unpickle
6765
from lib.core.data import conf
6866
from lib.core.data import kb
6967
from lib.core.data import logger
@@ -112,7 +110,6 @@
112110
from lib.core.settings import DEFAULT_TOR_HTTP_PORTS
113111
from lib.core.settings import DEFAULT_TOR_SOCKS_PORTS
114112
from lib.core.settings import DUMMY_URL
115-
from lib.core.settings import IGNORE_SAVE_OPTIONS
116113
from lib.core.settings import INJECT_HERE_MARK
117114
from lib.core.settings import IS_WIN
118115
from lib.core.settings import KB_CHARS_BOUNDARY_CHAR
@@ -2107,53 +2104,7 @@ def _saveConfig():
21072104
debugMsg = "saving command line options to a sqlmap configuration INI file"
21082105
logger.debug(debugMsg)
21092106

2110-
config = UnicodeRawConfigParser()
2111-
userOpts = {}
2112-
2113-
for family in optDict.keys():
2114-
userOpts[family] = []
2115-
2116-
for option, value in conf.items():
2117-
for family, optionData in optDict.items():
2118-
if option in optionData:
2119-
userOpts[family].append((option, value, optionData[option]))
2120-
2121-
for family, optionData in userOpts.items():
2122-
config.add_section(family)
2123-
2124-
optionData.sort()
2125-
2126-
for option, value, datatype in optionData:
2127-
if datatype and isListLike(datatype):
2128-
datatype = datatype[0]
2129-
2130-
if option in IGNORE_SAVE_OPTIONS:
2131-
continue
2132-
2133-
if value is None:
2134-
if datatype == OPTION_TYPE.BOOLEAN:
2135-
value = "False"
2136-
elif datatype in (OPTION_TYPE.INTEGER, OPTION_TYPE.FLOAT):
2137-
if option in defaults:
2138-
value = str(defaults[option])
2139-
else:
2140-
value = "0"
2141-
elif datatype == OPTION_TYPE.STRING:
2142-
value = ""
2143-
2144-
if isinstance(value, basestring):
2145-
value = value.replace("\n", "\n ")
2146-
2147-
config.set(family, option, value)
2148-
2149-
confFP = openFile(conf.saveConfig, "wb")
2150-
2151-
try:
2152-
config.write(confFP)
2153-
except IOError, ex:
2154-
errMsg = "something went wrong while trying "
2155-
errMsg += "to write to the configuration file '%s' ('%s')" % (conf.saveConfig, getSafeExString(ex))
2156-
raise SqlmapSystemException(errMsg)
2107+
saveConfig(conf, conf.saveConfig)
21572108

21582109
infoMsg = "saved command line options to the configuration file '%s'" % conf.saveConfig
21592110
logger.info(infoMsg)
@@ -2229,26 +2180,6 @@ def _mergeOptions(inputOptions, overrideOptions):
22292180
@type inputOptions: C{instance}
22302181
"""
22312182

2232-
if inputOptions.pickledOptions:
2233-
try:
2234-
unpickledOptions = base64unpickle(inputOptions.pickledOptions, unsafe=True)
2235-
2236-
if type(unpickledOptions) == dict:
2237-
unpickledOptions = AttribDict(unpickledOptions)
2238-
2239-
_normalizeOptions(unpickledOptions)
2240-
2241-
unpickledOptions["pickledOptions"] = None
2242-
for key in inputOptions:
2243-
if key not in unpickledOptions:
2244-
unpickledOptions[key] = inputOptions[key]
2245-
2246-
inputOptions = unpickledOptions
2247-
except Exception, ex:
2248-
errMsg = "provided invalid value '%s' for option '--pickled-options'" % inputOptions.pickledOptions
2249-
errMsg += " (%s)" % repr(ex)
2250-
raise SqlmapSyntaxException(errMsg)
2251-
22522183
if inputOptions.configFile:
22532184
configFileParser(inputOptions.configFile)
22542185

@@ -2456,6 +2387,10 @@ def _basicOptionValidation():
24562387
errMsg = "switch '--dump' is incompatible with switch '--search'"
24572388
raise SqlmapSyntaxException(errMsg)
24582389

2390+
if conf.api and not conf.configFile:
2391+
errMsg = "switch '--api' requires usage of option '-c'"
2392+
raise SqlmapSyntaxException(errMsg)
2393+
24592394
if conf.data and conf.nullConnection:
24602395
errMsg = "option '--data' is incompatible with switch '--null-connection'"
24612396
raise SqlmapSyntaxException(errMsg)

lib/core/optiondict.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,5 +243,10 @@
243243
"liveTest": "boolean",
244244
"stopFail": "boolean",
245245
"runCase": "string",
246+
},
247+
"API": {
248+
"api": "boolean",
249+
"taskid": "string",
250+
"database": "string",
246251
}
247252
}

lib/core/settings.py

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

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

lib/parse/cmdline.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,6 @@ def cmdLineParser(argv=None):
770770
parser.add_option("--murphy-rate", dest="murphyRate", type="int",
771771
help=SUPPRESS_HELP)
772772

773-
parser.add_option("--pickled-options", dest="pickledOptions",
774-
help=SUPPRESS_HELP)
775-
776773
parser.add_option("--disable-precon", dest="disablePrecon", action="store_true",
777774
help=SUPPRESS_HELP)
778775

@@ -799,6 +796,14 @@ def cmdLineParser(argv=None):
799796

800797
parser.add_option("--run-case", dest="runCase", help=SUPPRESS_HELP)
801798

799+
# API options
800+
parser.add_option("--api", dest="api", action="store_true",
801+
help=SUPPRESS_HELP)
802+
803+
parser.add_option("--taskid", dest="taskid", help=SUPPRESS_HELP)
804+
805+
parser.add_option("--database", dest="database", help=SUPPRESS_HELP)
806+
802807
parser.add_option_group(target)
803808
parser.add_option_group(request)
804809
parser.add_option_group(optimization)
@@ -963,7 +968,7 @@ def _(self, *args):
963968

964969
if not any((args.direct, args.url, args.logFile, args.bulkFile, args.googleDork, args.configFile, \
965970
args.requestFile, args.updateAll, args.smokeTest, args.liveTest, args.wizard, args.dependencies, \
966-
args.purgeOutput, args.pickledOptions, args.sitemapUrl)):
971+
args.purgeOutput, args.sitemapUrl)):
967972
errMsg = "missing a mandatory option (-d, -u, -l, -m, -r, -g, -c, -x, --wizard, --update, --purge-output or --dependencies), "
968973
errMsg += "use -h for basic or -hh for advanced help\n"
969974
parser.error(errMsg)

lib/utils/api.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020

2121
from lib.core.common import dataToStdout
2222
from lib.core.common import getSafeExString
23+
from lib.core.common import saveConfig
2324
from lib.core.common import unArrayizeValue
24-
from lib.core.convert import base64pickle
2525
from lib.core.convert import hexencode
2626
from lib.core.convert import dejsonize
2727
from lib.core.convert import jsonize
@@ -163,12 +163,15 @@ def reset_options(self):
163163
self.options = AttribDict(self._original_options)
164164

165165
def engine_start(self):
166+
configFile = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.CONFIG, text=True)[1]
167+
saveConfig(self.options, configFile)
168+
166169
if os.path.exists("sqlmap.py"):
167-
self.process = Popen(["python", "sqlmap.py", "--pickled-options", base64pickle(self.options)], shell=False, close_fds=not IS_WIN)
170+
self.process = Popen(["python", "sqlmap.py", "--api", "-c", configFile], shell=False, close_fds=not IS_WIN)
168171
elif os.path.exists(os.path.join(os.getcwd(), "sqlmap.py")):
169-
self.process = Popen(["python", "sqlmap.py", "--pickled-options", base64pickle(self.options)], shell=False, cwd=os.getcwd(), close_fds=not IS_WIN)
172+
self.process = Popen(["python", "sqlmap.py", "--api", "-c", configFile], shell=False, cwd=os.getcwd(), close_fds=not IS_WIN)
170173
else:
171-
self.process = Popen(["sqlmap", "--pickled-options", base64pickle(self.options)], shell=False, close_fds=not IS_WIN)
174+
self.process = Popen(["sqlmap", "--api", "-c", configFile], shell=False, close_fds=not IS_WIN)
172175

173176
def engine_stop(self):
174177
if self.process:
@@ -657,7 +660,7 @@ def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, adapter=REST
657660

658661
logger.info("Running REST-JSON API server at '%s:%d'.." % (host, port))
659662
logger.info("Admin ID: %s" % DataStore.admin_id)
660-
logger.debug("IPC database: %s" % Database.filepath)
663+
logger.debug("IPC database: '%s'" % Database.filepath)
661664

662665
# Initialize IPC database
663666
DataStore.current_db = Database()

txt/checksum.md5

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ d79481ab99acd739615e747d4a79d9d0 lib/controller/handler.py
2626
310efc965c862cfbd7b0da5150a5ad36 lib/controller/__init__.py
2727
19905ecb4437b94512cf21d5f1720091 lib/core/agent.py
2828
6cc95a117fbd34ef31b9aa25520f0e31 lib/core/bigarray.py
29-
145d131884dd5401d7a52effaea2ee9e lib/core/common.py
29+
652266ff49168dd88a9d5649003a3951 lib/core/common.py
3030
5065a4242a8cccf72f91e22e1007ae63 lib/core/convert.py
3131
a8143dab9d3a27490f7d49b6b29ea530 lib/core/data.py
3232
7936d78b1a7f1f008ff92bf2f88574ba lib/core/datatype.py
3333
36c85e9ef109c5b4af3ca9bb1065ef1f lib/core/decorators.py
3434
47eecd5499eaa15e931793e1d1ac3566 lib/core/defaults.py
35-
4029f6869b36eb5f796c2bcc948f4fae lib/core/dicts.py
35+
7309cf449b009723d1a4655fcf1a96d7 lib/core/dicts.py
3636
77edcfd3d7c5522bb64baf59ac23a047 lib/core/dump.py
37-
2acf5449c71bfae4feec8da538e70116 lib/core/enums.py
37+
b9ff4e622c416116bee6024c0f050349 lib/core/enums.py
3838
9381a0c7e8bc19986299e84f4edda1a0 lib/core/exception.py
3939
310efc965c862cfbd7b0da5150a5ad36 lib/core/__init__.py
4040
9ba39bf66e9ecd469446bdbbeda906c3 lib/core/log.py
41-
66c9795e2e7da32f46f04497ae910070 lib/core/optiondict.py
42-
0324fce84ef88ed0416123f73c54a6d7 lib/core/option.py
41+
ebb778c2d26eba8b34d7d8658e4105a6 lib/core/optiondict.py
42+
bffd3f1bffa71a3c0ffc14768631f8ed lib/core/option.py
4343
5f2f56e6c5f274408df61943f1e080c0 lib/core/profiling.py
4444
40be71cd774662a7b420caeb7051e7d5 lib/core/readlineng.py
4545
d8e9250f3775119df07e9070eddccd16 lib/core/replication.py
4646
785f86e3f963fa3798f84286a4e83ff2 lib/core/revision.py
4747
40c80b28b3a5819b737a5a17d4565ae9 lib/core/session.py
48-
627833276af914ba8fcca145c1a22269 lib/core/settings.py
48+
4c2f45cb5c80dba2370379d230d526f3 lib/core/settings.py
4949
d91291997d2bd2f6028aaf371bf1d3b6 lib/core/shell.py
5050
2ad85c130cc5f2b3701ea85c2f6bbf20 lib/core/subprocessng.py
5151
afd0636d2e93c23f4f0a5c9b6023ea17 lib/core/target.py
@@ -56,7 +56,7 @@ ad74fc58fc7214802fd27067bce18dd2 lib/core/unescaper.py
5656
4d13ed693401a498b6d073a2a494bd83 lib/core/wordlist.py
5757
310efc965c862cfbd7b0da5150a5ad36 lib/__init__.py
5858
8c4b04062db2245d9e190b413985202a lib/parse/banner.py
59-
54f06c50771ce894a3c6a418d545f4bf lib/parse/cmdline.py
59+
aa89ea0c7c44eb74eaaeeccaddc94d39 lib/parse/cmdline.py
6060
3a31657bc38f277d0016ff6d50bde61f lib/parse/configfile.py
6161
14539f1be714d4f1ed042067d63bc50a lib/parse/handler.py
6262
64e5bb3ecbdd75144500588b437ba8da lib/parse/headers.py
@@ -99,7 +99,7 @@ d3da4c7ceaf57c4687a052d58722f6bb lib/techniques/dns/use.py
9999
310efc965c862cfbd7b0da5150a5ad36 lib/techniques/union/__init__.py
100100
19fd73af7a278fd72b46a5a60f5bdd09 lib/techniques/union/test.py
101101
8cd5655c60a638caa30ca1220896aeda lib/techniques/union/use.py
102-
7b4c2347f207f61d74135a5520690336 lib/utils/api.py
102+
9fca8077f1ee6f701ce7b7972e05ee53 lib/utils/api.py
103103
29e32d59fcdd63c5a13498af1f367c8c lib/utils/crawler.py
104104
ba12c69a90061aa14d848b8396e79191 lib/utils/deps.py
105105
3b9fd519164e0bf275d5fd361c3f11ff lib/utils/getch.py

0 commit comments

Comments
 (0)