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

Skip to content

Commit 35f3560

Browse files
committed
changes regarding Feature #160
1 parent 99d9f9e commit 35f3560

7 files changed

Lines changed: 100 additions & 27 deletions

File tree

lib/controller/action.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from lib.controller.handler import setHandler
2626
from lib.core.common import getHtmlErrorFp
27+
from lib.core.common import dataToStdout
2728
from lib.core.data import conf
2829
from lib.core.data import kb
2930
from lib.core.exception import sqlmapUnsupportedDBMSException
@@ -64,7 +65,7 @@ def action():
6465

6566
raise sqlmapUnsupportedDBMSException, errMsg
6667

67-
print "%s\n" % conf.dbmsHandler.getFingerprint()
68+
dataToStdout("%s\n" % conf.dbmsHandler.getFingerprint())
6869

6970
# Techniques options
7071
if conf.stackedTest:

lib/controller/controller.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242
from lib.core.session import setInjection
4343
from lib.core.target import initTargetEnv
4444
from lib.core.target import setupTargetEnv
45-
from lib.core.testing import smokeTest
46-
from lib.core.testing import liveTest
4745
from lib.utils.parenthesis import checkForParenthesis
4846

4947
def __selectInjection(injData):
@@ -99,16 +97,6 @@ def start():
9997
if conf.optimize:
10098
conf.useCommonPrediction = conf.useNullConnection = conf.keepAlive = True
10199

102-
103-
if conf.smokeTest:
104-
smokeTest()
105-
106-
if conf.liveTest:
107-
liveTest()
108-
109-
if conf.smokeTest or conf.liveTest:
110-
return
111-
112100
if conf.direct:
113101
initTargetEnv()
114102
setupTargetEnv()
@@ -173,7 +161,7 @@ def start():
173161
if conf.useNullConnection:
174162
checkNullConnection()
175163

176-
if not conf.dropSetCookie:
164+
if not conf.dropSetCookie and conf.cj:
177165
for _, cookie in enumerate(conf.cj):
178166
cookie = getUnicode(cookie)
179167
index = cookie.index(" for ")

lib/core/common.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,12 @@ def filePathToString(filePath):
412412
return strRepl
413413

414414
def dataToStdout(data):
415-
try:
416-
sys.stdout.write(data)
417-
sys.stdout.flush()
418-
except UnicodeEncodeError:
419-
print data.encode(conf.dataEncoding)
415+
if conf.verbose > 0:
416+
try:
417+
sys.stdout.write(data)
418+
sys.stdout.flush()
419+
except UnicodeEncodeError:
420+
print data.encode(conf.dataEncoding)
420421

421422
def dataToSessionFile(data):
422423
if not conf.sessionFile:
@@ -659,6 +660,7 @@ def setPaths():
659660
paths.FUZZ_VECTORS = os.path.join(paths.SQLMAP_TXT_PATH, "fuzz_vectors.txt")
660661
paths.DETECTION_RULES_XML = os.path.join(paths.SQLMAP_XML_PATH, "detection.xml")
661662
paths.ERRORS_XML = os.path.join(paths.SQLMAP_XML_PATH, "errors.xml")
663+
paths.LIVE_TESTS_XML = os.path.join(paths.SQLMAP_XML_PATH, "livetests.xml")
662664
paths.QUERIES_XML = os.path.join(paths.SQLMAP_XML_PATH, "queries.xml")
663665
paths.GENERIC_XML = os.path.join(paths.SQLMAP_XML_BANNER_PATH, "generic.xml")
664666
paths.MSSQL_XML = os.path.join(paths.SQLMAP_XML_BANNER_PATH, "mssql.xml")

lib/core/option.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,9 @@ def __setVerbosity():
10981098

10991099
conf.verbose = int(conf.verbose)
11001100

1101-
if conf.verbose == 1:
1101+
if conf.verbose == 0:
1102+
logger.setLevel(logging.CRITICAL)
1103+
elif conf.verbose == 1:
11021104
logger.setLevel(logging.INFO)
11031105
elif conf.verbose > 2 and conf.eta:
11041106
conf.verbose = 2
@@ -1173,7 +1175,7 @@ def init(inputOptions=advancedDict()):
11731175
parseTargetUrl()
11741176
parseTargetDirect()
11751177

1176-
if conf.url or conf.list or conf.requestFile or conf.googleDork:
1178+
if conf.url or conf.list or conf.requestFile or conf.googleDork or conf.liveTest:
11771179
__setHTTPTimeout()
11781180
__setHTTPExtraHeaders()
11791181
__setHTTPCookies()

lib/core/testing.py

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,25 @@
2121
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222
"""
2323

24+
import codecs
25+
import logging
2426
import os
27+
import re
2528
import sys
29+
import tempfile
2630
import time
2731

32+
from xml.dom import minidom
33+
34+
from lib.controller.controller import start
2835
from lib.core.common import dataToStdout
36+
from lib.core.common import getCompiledRegex
2937
from lib.core.common import getConsoleWidth
3038
from lib.core.data import conf
3139
from lib.core.data import logger
3240
from lib.core.data import paths
41+
from lib.core.option import init
42+
from lib.parse.cmdline import cmdLineParser
3343

3444
def smokeTest():
3545
"""
@@ -80,4 +90,60 @@ def liveTest():
8090
"""
8191
This will run the test of a program against the live testing environment
8292
"""
83-
pass
93+
vars = {}
94+
xfile = codecs.open(paths.LIVE_TESTS_XML, 'r', conf.dataEncoding)
95+
livetests = minidom.parse(xfile).documentElement
96+
xfile.close()
97+
98+
global_ = livetests.getElementsByTagName("global")
99+
if global_:
100+
for item in global_:
101+
for child in item.childNodes:
102+
if child.nodeType == child.ELEMENT_NODE and child.hasAttribute("value"):
103+
vars[child.tagName] = child.getAttribute("value")
104+
105+
for case in livetests.getElementsByTagName("case"):
106+
log = []
107+
session = []
108+
switches = {}
109+
110+
if case.getElementsByTagName("switches"):
111+
for child in case.getElementsByTagName("switches")[0].childNodes:
112+
if child.nodeType == child.ELEMENT_NODE and child.hasAttribute("value"):
113+
switches[child.tagName] = replaceVars(child.getAttribute("value"), vars)
114+
115+
if case.getElementsByTagName("log"):
116+
for item in case.getElementsByTagName("log")[0].getElementsByTagName("item"):
117+
if item.hasAttribute("value"):
118+
log.append(replaceVars(item.getAttribute("value"), vars))
119+
120+
if case.getElementsByTagName("session"):
121+
for item in case.getElementsByTagName("session")[0].getElementsByTagName("item"):
122+
if item.hasAttribute("value"):
123+
session.append(replaceVars(item.getAttribute("value"), vars))
124+
125+
runCase(switches, log, session)
126+
127+
def initCase():
128+
paths.SQLMAP_OUTPUT_PATH = tempfile.mkdtemp()
129+
paths.SQLMAP_DUMP_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "dump")
130+
paths.SQLMAP_FILES_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "files")
131+
cmdLineOptions = cmdLineParser()
132+
cmdLineOptions.liveTest = cmdLineOptions.smokeTest = False
133+
init(cmdLineOptions)
134+
conf.suppressOutput = True
135+
logger.setLevel(logging.CRITICAL)
136+
137+
def runCase(switches, log=None, session=None):
138+
initCase()
139+
for key, value in switches.items():
140+
conf[key] = value
141+
start()
142+
143+
def replaceVars(item, vars):
144+
retVal = item
145+
if item and vars:
146+
for var in re.findall(getCompiledRegex("\$\{([^}]+)\}"), item):
147+
if var in vars:
148+
retVal = retVal.replace("${%s}" % var, vars[var])
149+
return retVal

sqlmap.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
from lib.core.exception import unhandledException
5555
from lib.core.option import init
5656
from lib.core.profiling import profile
57+
from lib.core.testing import smokeTest
58+
from lib.core.testing import liveTest
5759
from lib.core.xmldump import closeDumper
5860
from lib.parse.cmdline import cmdLineParser
5961

@@ -84,7 +86,11 @@ def main():
8486
try:
8587
init(cmdLineOptions)
8688
if conf.profile:
87-
profile()
89+
profile()
90+
elif conf.smokeTest:
91+
smokeTest()
92+
elif conf.liveTest:
93+
liveTest()
8894
else:
8995
start()
9096
except exceptionsTuple, e:
@@ -107,7 +113,7 @@ def main():
107113
except:
108114
print
109115
errMsg = unhandledException()
110-
logger.error(errMsg)
116+
logger.critical(errMsg)
111117
traceback.print_exc()
112118
closeDumper(False, errMsg)
113119

xml/livetests.xml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22

33
<root>
44
<global>
5-
<host value="172.16.104.130"/>
5+
<host value="192.168.228.130"/>
66
</global>
7-
<!-- Oracle -->
7+
<!-- MySQL -->
88
<case>
99
<switches>
10-
<url value="http://$host/sqlmap/oracle/get_int.php?id=1"/>
10+
<url value="http://${host}/sqlmap/mysql/get_int.php?id=1"/>
11+
<getBanner value="True"/>
12+
</switches>
13+
</case>
14+
<!-- Oracle
15+
<case>
16+
<switches>
17+
<url value="http://${host}/sqlmap/oracle/get_int.php?id=1"/>
1118
<extensiveFp value="True"/>
1219
<getUsers value="True"/>
1320
</switches>
@@ -20,4 +27,5 @@
2027
<item value="[DBMS][Oracle]"/>
2128
</session>
2229
</case>
30+
-->
2331
</root>

0 commit comments

Comments
 (0)