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

Skip to content

Commit 092829c

Browse files
committed
implemented basic smoke testing mechanism
1 parent f033943 commit 092829c

5 files changed

Lines changed: 33 additions & 10 deletions

File tree

extra/cloak/cloak.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ def hideAscii(data):
3434
retVal += chr(ord(data[i]) ^ 127)
3535
else:
3636
retVal += data[i]
37-
37+
3838
return retVal
3939

4040
def cloak(inputFile):
4141
f = open(inputFile, 'rb')
4242
data = bz2.compress(f.read())
4343
f.close()
44-
44+
4545
return hideAscii(data)
46-
46+
4747
def decloak(inputFile):
4848
f = open(inputFile, 'rb')
4949
data = bz2.decompress(hideAscii(f.read()))
5050
f.close()
51-
51+
5252
return data
5353

5454
def main():
@@ -71,7 +71,7 @@ def main():
7171
if not os.path.isfile(args.inputFile):
7272
print 'ERROR: the provided input file \'%s\' is not a regular file' % args.inputFile
7373
sys.exit(1)
74-
74+
7575
if not args.decrypt:
7676
data = cloak(args.inputFile)
7777
else:
@@ -82,7 +82,7 @@ def main():
8282
args.outputFile = args.inputFile + '_'
8383
else:
8484
args.outputFile = args.inputFile[:-1]
85-
85+
8686
fpOut = open(args.outputFile, 'wb')
8787
sys.stdout = fpOut
8888
sys.stdout.write(data)

lib/controller/controller.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from lib.core.common import paramToDict
3434
from lib.core.common import parseTargetUrl
3535
from lib.core.common import readInput
36+
from lib.core.common import smokeTest
3637
from lib.core.data import conf
3738
from lib.core.data import kb
3839
from lib.core.data import logger
@@ -93,6 +94,9 @@ def start():
9394
if not conf.start:
9495
return
9596

97+
if conf.smokeTest:
98+
smokeTest()
99+
96100
if conf.direct:
97101
initTargetEnv()
98102
setupTargetEnv()

lib/core/common.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
from lib.core.data import temp
5858
from lib.core.convert import urlencode
5959
from lib.core.exception import sqlmapFilePathException
60+
from lib.core.exception import sqlmapGenericException
6061
from lib.core.exception import sqlmapNoneDataException
6162
from lib.core.exception import sqlmapMissingDependence
6263
from lib.core.exception import sqlmapSyntaxException
@@ -471,7 +472,7 @@ def readInput(message, default=None):
471472

472473
data = default
473474
else:
474-
data = raw_input(message.encode(conf.dataEncoding))
475+
data = raw_input(message.encode(sys.stdout.encoding))
475476

476477
if not data:
477478
data = default
@@ -1410,3 +1411,18 @@ def longestCommonPrefix(*sequences):
14101411

14111412
def commonFinderOnly(initial, sequence):
14121413
return longestCommonPrefix(*filter(lambda x: x.startswith(initial), sequence))
1414+
1415+
def smokeTest():
1416+
for root, _, files in os.walk(paths.SQLMAP_ROOT_PATH):
1417+
for file in files:
1418+
if os.path.splitext(file)[1].lower() == '.py' and file != '__init__.py':
1419+
path = os.path.join(root, os.path.splitext(file)[0])
1420+
path = path.replace(paths.SQLMAP_ROOT_PATH, '.')
1421+
path = path.replace(os.sep, '.').lstrip('.')
1422+
try:
1423+
module = __import__(path)
1424+
except Exception, msg:
1425+
raise sqlmapGenericException, "smoke test failed at importing module '%s' (%s):\n\n%s" % (path, os.path.join(paths.SQLMAP_ROOT_PATH, file), msg)
1426+
1427+
infoMsg = "smoke test passed"
1428+
logger.info(infoMsg)

lib/parse/cmdline.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def cmdLineParser():
108108
request.add_option("--auth-cred", dest="aCred",
109109
help="HTTP authentication credentials "
110110
"(name:password)")
111-
111+
112112
request.add_option("--auth-cert", dest="aCert",
113113
help="HTTP authentication certificate ("
114114
"key_file,cert_file)")
@@ -457,6 +457,9 @@ def cmdLineParser():
457457
parser.add_option("--common-prediction", dest="useCommonPrediction", action="store_true",
458458
help=SUPPRESS_HELP)
459459

460+
parser.add_option("--smoke-test", dest="smokeTest", action="store_true",
461+
help=SUPPRESS_HELP)
462+
460463
parser.add_option_group(target)
461464
parser.add_option_group(request)
462465
parser.add_option_group(injection)
@@ -471,7 +474,7 @@ def cmdLineParser():
471474

472475
(args, _) = parser.parse_args([utf8decode(arg) for arg in sys.argv])
473476

474-
if not args.direct and not args.url and not args.list and not args.googleDork and not args.configFile and not args.requestFile and not args.updateAll:
477+
if not args.direct and not args.url and not args.list and not args.googleDork and not args.configFile and not args.requestFile and not args.updateAll and not args.smokeTest:
475478
errMsg = "missing a mandatory parameter ('-d', '-u', '-l', '-r', '-g', '-c' or '--update'), "
476479
errMsg += "-h for help"
477480
parser.error(errMsg)

sqlmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"""
2424

2525
import codecs
26-
import locale
2726
import os
2827
import sys
2928
import time
@@ -33,6 +32,7 @@
3332
warnings.filterwarnings(action="ignore", message=".*was already imported", category=UserWarning)
3433

3534
# NOTE: This breaks SQL shell and OS shell history and TAB functionalities
35+
#import locale
3636
#sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
3737

3838
try:

0 commit comments

Comments
 (0)