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

Skip to content

Commit 78d7b17

Browse files
committed
More replacements for refactoring.
Minor layout adjustments. Alignment of conffile/optiondict/cmdline parameters.
1 parent eb999de commit 78d7b17

10 files changed

Lines changed: 41 additions & 23 deletions

File tree

lib/controller/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ def checkNullConnection():
377377
infoMsg = "NULL connection is supported with HEAD header"
378378
logger.info(infoMsg)
379379
else:
380-
page, headers = Request.getPage(auxHeaders={"Range":"bytes=-1"})
380+
page, headers = Request.getPage(auxHeaders={NULLCONNECTION.RANGE: "bytes=-1"})
381381
if page and len(page) == 1 and 'Content-Range' in headers:
382382
kb.nullConnection = NULLCONNECTION.RANGE
383383

lib/controller/controller.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
from lib.core.common import getUnicode
2222
from lib.core.common import paramToDict
2323
from lib.core.common import parseTargetUrl
24-
from lib.core.common import popValue
25-
from lib.core.common import pushValue
2624
from lib.core.common import readInput
2725
from lib.core.data import conf
2826
from lib.core.data import kb
@@ -197,7 +195,7 @@ def start():
197195
setCookieAsInjectable = False
198196

199197
if setCookieAsInjectable:
200-
conf.httpHeaders.append(("Cookie", cookieStr))
198+
conf.httpHeaders.append((PLACE.COOKIE, cookieStr))
201199
conf.parameters[PLACE.COOKIE] = cookieStr
202200
__paramDict = paramToDict(PLACE.COOKIE, cookieStr)
203201

@@ -214,6 +212,7 @@ def start():
214212

215213
# Do a little prioritization reorder of a testable parameter list
216214
parameters = conf.parameters.keys()
215+
217216
for place in (PLACE.URI, PLACE.POST, PLACE.GET):
218217
if place in parameters:
219218
parameters.remove(place)

lib/core/common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1570,7 +1570,9 @@ def runningAsAdmin():
15701570

15711571
def logHTTPTraffic(requestLogMsg, responseLogMsg):
15721572
kb.locks.reqLock.acquire()
1573+
15731574
dataToTrafficFile("%s\n" % requestLogMsg)
15741575
dataToTrafficFile("%s\n" % responseLogMsg)
1575-
dataToTrafficFile("%s\n" % (160*'#'))
1576+
dataToTrafficFile("\n%s\n\n" % (76 * '#'))
1577+
15761578
kb.locks.reqLock.release()

lib/core/option.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from lib.core.data import queries
4444
from lib.core.datatype import advancedDict
4545
from lib.core.enums import HTTPMETHOD
46+
from lib.core.enums import PLACE
4647
from lib.core.enums import PRIORITY
4748
from lib.core.exception import sqlmapFilePathException
4849
from lib.core.exception import sqlmapGenericException
@@ -765,7 +766,7 @@ def __setHTTPAuthentication():
765766
errMsg += "must be in format key_file,cert_file"
766767
raise sqlmapSyntaxException, errMsg
767768

768-
#os.path.expanduser for support of paths with ~
769+
# os.path.expanduser for support of paths with ~
769770
key_file = os.path.expanduser(aCertRegExp.group(1))
770771
cert_file = os.path.expanduser(aCertRegExp.group(2))
771772

@@ -847,19 +848,19 @@ def __setHTTPUserAgent():
847848
debugMsg = "setting the HTTP User-Agent header"
848849
logger.debug(debugMsg)
849850

850-
conf.httpHeaders.append(("User-Agent", conf.agent))
851+
conf.httpHeaders.append((PLACE.UA, conf.agent))
851852
return
852853

853854
if not conf.userAgentsFile:
854855
addDefaultUserAgent = True
855856

856857
for header, _ in conf.httpHeaders:
857-
if header == "User-Agent":
858+
if header == PLACE.UA:
858859
addDefaultUserAgent = False
859860
break
860861

861862
if addDefaultUserAgent:
862-
conf.httpHeaders.append(("User-Agent", __defaultHTTPUserAgent()))
863+
conf.httpHeaders.append((PLACE.UA, __defaultHTTPUserAgent()))
863864

864865
return
865866

@@ -875,7 +876,7 @@ def __setHTTPUserAgent():
875876
warnMsg += "file '%s'" % conf.userAgentsFile
876877
logger.warn(warnMsg)
877878

878-
conf.httpHeaders.append(("User-Agent", __defaultHTTPUserAgent()))
879+
conf.httpHeaders.append((PLACE.UA, __defaultHTTPUserAgent()))
879880

880881
return
881882

@@ -887,7 +888,7 @@ def __setHTTPUserAgent():
887888
__userAgent = kb.userAgents[randomRange(stop=__count)]
888889

889890
__userAgent = sanitizeStr(__userAgent)
890-
conf.httpHeaders.append(("User-Agent", __userAgent))
891+
conf.httpHeaders.append((PLACE.UA, __userAgent))
891892

892893
logMsg = "fetched random HTTP User-Agent header from "
893894
logMsg += "file '%s': %s" % (conf.userAgentsFile, __userAgent)
@@ -914,7 +915,7 @@ def __setHTTPCookies():
914915
logger.debug(debugMsg)
915916

916917
conf.httpHeaders.append(("Connection", "Keep-Alive"))
917-
conf.httpHeaders.append(("Cookie", conf.cookie))
918+
conf.httpHeaders.append((PLACE.COOKIE, conf.cookie))
918919

919920
def __setHTTPTimeout():
920921
"""

lib/core/optiondict.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,17 @@
5959
"os": "string",
6060
"prefix": "string",
6161
"postfix": "string",
62+
"tamper": "string"
63+
},
64+
65+
"Detection": {
6266
"string": "string",
6367
"regexp": "string",
6468
"eString": "string",
6569
"eRegexp": "string",
6670
"thold": "float",
6771
"textOnly": "boolean",
68-
"longestCommon": "boolean",
69-
"tamper": "string"
72+
"longestCommon": "boolean"
7073
},
7174

7275
"Techniques": {
@@ -147,6 +150,7 @@
147150
"Miscellaneous": {
148151
"xmlFile": "string",
149152
"sessionFile": "string",
153+
"trafficFile": "string",
150154
"flushSession": "boolean",
151155
"forms": "boolean",
152156
"eta": "boolean",
@@ -155,6 +159,8 @@
155159
"batch": "boolean",
156160
"cleanup": "boolean",
157161
"replicate": "boolean",
162+
"checkPayload": "boolean",
163+
"beep": "boolean",
158164
"verbose": "integer"
159165
},
160166
}

lib/core/target.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@ def __setRequestParams():
9999
# Perform checks on User-Agent header value
100100
if conf.httpHeaders:
101101
for httpHeader, headerValue in conf.httpHeaders:
102-
if httpHeader == "User-Agent":
102+
if httpHeader == PLACE.UA:
103103
# No need for url encoding/decoding the user agent
104104
conf.parameters[PLACE.UA] = headerValue
105105

106106
condition = not conf.testParameter
107-
condition |= "User-Agent" in conf.testParameter
107+
condition |= PLACE.UA in conf.testParameter
108108
condition |= "user-agent" in conf.testParameter
109109
condition |= "useragent" in conf.testParameter
110110
condition |= "ua" in conf.testParameter

lib/parse/cmdline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ def cmdLineParser():
457457
"on a session file")
458458

459459
miscellaneous.add_option("-t", dest="trafficFile",
460-
help="Save all HTTP traffic data "
461-
"into a textual file")
460+
help="Log all HTTP traffic into a "
461+
"textual file")
462462

463463
miscellaneous.add_option("--flush-session", dest="flushSession",
464464
action="store_true", default=False,

lib/request/basic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from lib.core.data import conf
2222
from lib.core.data import kb
2323
from lib.core.data import logger
24+
from lib.core.enums import PLACE
2425
from lib.parse.headers import headersParser
2526
from lib.parse.html import htmlParser
2627

@@ -33,9 +34,9 @@ def forgeHeaders(cookie, ua):
3334
headers = {}
3435

3536
for header, value in conf.httpHeaders:
36-
if cookie and header == "Cookie":
37+
if cookie and header == PLACE.COOKIE:
3738
headers[header] = cookie
38-
elif ua and header == "User-Agent":
39+
elif ua and header == PLACE.UA:
3940
headers[header] = ua
4041
else:
4142
headers[header] = value

lib/request/connect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def getPage(**kwargs):
166166

167167
requestHeaders += "\n".join(["%s: %s" % (header, value) for header, value in req.header_items()])
168168

169-
if not req.has_header("Cookie") and cookieStr:
169+
if not req.has_header(PLACE.COOKIE) and cookieStr:
170170
requestHeaders += "\n%s" % cookieStr[:-2]
171171

172172
if not req.has_header("Connection"):
@@ -283,7 +283,7 @@ def getPage(**kwargs):
283283
page = sanitizeAsciiString(page)
284284
parseResponse(page, responseHeaders)
285285

286-
responseMsg += "[#%d] (%s - %d):\n" % (requestID, status, code)
286+
responseMsg += "[#%d] (%d %s):\n" % (requestID, code, status)
287287
logHeaders = "\n".join(["%s: %s" % (key.capitalize() if isinstance(key, basestring) else key, value) for (key, value) in responseHeaders.items()])
288288

289289
logHTTPTraffic(requestMsg, "%s%s\n\n%s" % (responseMsg, logHeaders, page))
@@ -370,7 +370,7 @@ def queryPage(value=None, place=None, content=False, getSeqMatcher=False, silent
370370
if not auxHeaders:
371371
auxHeaders = {}
372372

373-
auxHeaders["Range"] = "bytes=-1"
373+
auxHeaders[NULLCONNECTION.RANGE] = "bytes=-1"
374374

375375
_, headers = Connect.getPage(url=uri, get=get, post=post, cookie=cookie, ua=ua, silent=silent, method=method, auxHeaders=auxHeaders, raise404=raise404)
376376

sqlmap.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,9 @@ xmlFile =
499499
# Save and resume all data retrieved on a session file.
500500
sessionFile =
501501

502+
# Log all HTTP traffic into a textual file.
503+
trafficFile =
504+
502505
# Flush session file for current target.
503506
# Valid: True or False
504507
flushSession = False
@@ -533,6 +536,12 @@ cleanup = False
533536
# Valid: True or False
534537
replicate = False
535538

539+
# IDS detection testing of injection payload.
540+
checkPayload = False
541+
542+
# Alert with audio beep when sql injection found.
543+
beep = False
544+
536545
# Verbosity level.
537546
# Valid: integer between 0 and 6
538547
# 0: Show only critical messages

0 commit comments

Comments
 (0)