Skip to content

Commit 560ff41

Browse files
committed
Fixes #3388 (and refactors #1578)
1 parent 1d0d5f1 commit 560ff41

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

lib/controller/controller.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def start():
313313
conf.cookie = targetCookie
314314
conf.httpHeaders = list(initialHeaders)
315315
conf.httpHeaders.extend(targetHeaders or [])
316+
conf.httpHeaders = [conf.httpHeaders[i] for i in xrange(len(conf.httpHeaders)) if conf.httpHeaders[i][0].upper() not in (__[0].upper() for __ in conf.httpHeaders[i + 1:])]
316317

317318
initTargetEnv()
318319
parseTargetUrl()

lib/core/option.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
from lib.core.settings import DEFAULT_PAGE_ENCODING
103103
from lib.core.settings import DEFAULT_TOR_HTTP_PORTS
104104
from lib.core.settings import DEFAULT_TOR_SOCKS_PORTS
105+
from lib.core.settings import DEFAULT_USER_AGENT
105106
from lib.core.settings import DUMMY_URL
106107
from lib.core.settings import IS_WIN
107108
from lib.core.settings import KB_CHARS_BOUNDARY_CHAR
@@ -112,7 +113,6 @@
112113
from lib.core.settings import NULL
113114
from lib.core.settings import PARAMETER_SPLITTING_REGEX
114115
from lib.core.settings import PRECONNECT_CANDIDATE_TIMEOUT
115-
from lib.core.settings import SITE
116116
from lib.core.settings import SOCKET_PRE_CONNECT_QUEUE_SIZE
117117
from lib.core.settings import SQLMAP_ENVIRONMENT_PREFIX
118118
from lib.core.settings import SUPPORTED_DBMS
@@ -122,7 +122,6 @@
122122
from lib.core.settings import UNION_CHAR_REGEX
123123
from lib.core.settings import UNKNOWN_DBMS_VERSION
124124
from lib.core.settings import URI_INJECTABLE_REGEX
125-
from lib.core.settings import VERSION_STRING
126125
from lib.core.threads import getCurrentThreadData
127126
from lib.core.threads import setDaemon
128127
from lib.core.update import update
@@ -1256,14 +1255,6 @@ def _setHTTPExtraHeaders():
12561255
# Reference: http://stackoverflow.com/a/1383359
12571256
conf.httpHeaders.append((HTTP_HEADER.CACHE_CONTROL, "no-cache"))
12581257

1259-
def _defaultHTTPUserAgent():
1260-
"""
1261-
@return: default sqlmap HTTP User-Agent header
1262-
@rtype: C{str}
1263-
"""
1264-
1265-
return "%s (%s)" % (VERSION_STRING, SITE)
1266-
12671258
def _setHTTPUserAgent():
12681259
"""
12691260
Set the HTTP User-Agent header.
@@ -1308,7 +1299,7 @@ def _setHTTPUserAgent():
13081299
break
13091300

13101301
if _:
1311-
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, _defaultHTTPUserAgent()))
1302+
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, DEFAULT_USER_AGENT))
13121303

13131304
else:
13141305
if not kb.userAgents:
@@ -1323,10 +1314,10 @@ def _setHTTPUserAgent():
13231314
warnMsg += "file '%s'" % paths.USER_AGENTS
13241315
logger.warn(warnMsg)
13251316

1326-
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, _defaultHTTPUserAgent()))
1317+
conf.httpHeaders.append((HTTP_HEADER.USER_AGENT, DEFAULT_USER_AGENT))
13271318
return
13281319

1329-
userAgent = random.sample(kb.userAgents or [_defaultHTTPUserAgent()], 1)[0]
1320+
userAgent = random.sample(kb.userAgents or [DEFAULT_USER_AGENT], 1)[0]
13301321

13311322
infoMsg = "fetched random HTTP User-Agent header value '%s' from " % userAgent
13321323
infoMsg += "file '%s'" % paths.USER_AGENTS

lib/core/settings.py

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

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.2.11.18"
22+
VERSION = "1.2.11.19"
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)
2626
DESCRIPTION = "automatic SQL injection and database takeover tool"
2727
SITE = "http://sqlmap.org"
28+
DEFAULT_USER_AGENT = "%s (%s)" % (VERSION_STRING, SITE)
2829
DEV_EMAIL_ADDRESS = "[email protected]"
2930
ISSUES_PAGE = "https://github.com/sqlmapproject/sqlmap/issues/new"
3031
GIT_REPOSITORY = "https://github.com/sqlmapproject/sqlmap.git"

lib/request/connect.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class WebSocketException(Exception):
8989
from lib.core.settings import DEFAULT_CONTENT_TYPE
9090
from lib.core.settings import DEFAULT_COOKIE_DELIMITER
9191
from lib.core.settings import DEFAULT_GET_POST_DELIMITER
92+
from lib.core.settings import DEFAULT_USER_AGENT
9293
from lib.core.settings import EVALCODE_KEYWORD_SUFFIX
9394
from lib.core.settings import HTTP_ACCEPT_HEADER_VALUE
9495
from lib.core.settings import HTTP_ACCEPT_ENCODING_HEADER_VALUE
@@ -361,14 +362,21 @@ def getPage(**kwargs):
361362
if kb.proxyAuthHeader:
362363
headers[HTTP_HEADER.PROXY_AUTHORIZATION] = kb.proxyAuthHeader
363364

364-
if not getHeader(headers, HTTP_HEADER.ACCEPT):
365-
headers[HTTP_HEADER.ACCEPT] = HTTP_ACCEPT_HEADER_VALUE
365+
if not conf.requestFile or not target:
366+
if not getHeader(headers, HTTP_HEADER.HOST):
367+
headers[HTTP_HEADER.HOST] = getHostHeader(url)
366368

367-
if not getHeader(headers, HTTP_HEADER.HOST) or not target:
368-
headers[HTTP_HEADER.HOST] = getHostHeader(url)
369+
if not getHeader(headers, HTTP_HEADER.ACCEPT):
370+
headers[HTTP_HEADER.ACCEPT] = HTTP_ACCEPT_HEADER_VALUE
369371

370-
if not getHeader(headers, HTTP_HEADER.ACCEPT_ENCODING):
371-
headers[HTTP_HEADER.ACCEPT_ENCODING] = HTTP_ACCEPT_ENCODING_HEADER_VALUE if kb.pageCompress else "identity"
372+
if not getHeader(headers, HTTP_HEADER.ACCEPT_ENCODING):
373+
headers[HTTP_HEADER.ACCEPT_ENCODING] = HTTP_ACCEPT_ENCODING_HEADER_VALUE if kb.pageCompress else "identity"
374+
375+
elif conf.requestFile and getHeader(headers, HTTP_HEADER.USER_AGENT) == DEFAULT_USER_AGENT:
376+
for header in headers:
377+
if header.upper() == HTTP_HEADER.USER_AGENT.upper():
378+
del headers[header]
379+
break
372380

373381
if post is not None and not multipart and not getHeader(headers, HTTP_HEADER.CONTENT_TYPE):
374382
headers[HTTP_HEADER.CONTENT_TYPE] = POST_HINT_CONTENT_TYPES.get(kb.postHint, DEFAULT_CONTENT_TYPE)
@@ -385,10 +393,6 @@ def getPage(**kwargs):
385393
if conf.keepAlive:
386394
headers[HTTP_HEADER.CONNECTION] = "keep-alive"
387395

388-
# Reset header values to original in case of provided request file
389-
if target and conf.requestFile:
390-
headers = forgeHeaders({HTTP_HEADER.COOKIE: cookie})
391-
392396
if auxHeaders:
393397
headers = forgeHeaders(auxHeaders, headers)
394398

txt/checksum.md5

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ b3e60ea4e18a65c48515d04aab28ff68 extra/sqlharvest/sqlharvest.py
2424
c1bccc94522d3425a372dcd57f78418e extra/wafdetectify/wafdetectify.py
2525
3459c562a6abb9b4bdcc36925f751f3e lib/controller/action.py
2626
71334197c7ed28167cd66c17b2c21844 lib/controller/checks.py
27-
dd42ef140ffc0bd517128e6df369ab01 lib/controller/controller.py
27+
95cde6dc7efe2581a5936f0d4635cb3b lib/controller/controller.py
2828
988b548f6578adf9cec17afdeee8291c lib/controller/handler.py
2929
1e5532ede194ac9c083891c2f02bca93 lib/controller/__init__.py
3030
cb865cf6eff60118bc97a0f106af5e4d lib/core/agent.py
@@ -42,14 +42,14 @@ cada93357a7321655927fc9625b3bfec lib/core/exception.py
4242
1e5532ede194ac9c083891c2f02bca93 lib/core/__init__.py
4343
458a194764805cd8312c14ecd4be4d1e lib/core/log.py
4444
7d6edc552e08c30f4f4d49fa93b746f1 lib/core/optiondict.py
45-
a24992df012aee6d5617808f1dbb70ec lib/core/option.py
45+
7dacc178910ab4d57de36c3602bde17d lib/core/option.py
4646
c8c386d644d57c659d74542f5f57f632 lib/core/patch.py
4747
6783160150b4711d02c56ee2beadffdb lib/core/profiling.py
4848
6f654e1715571eff68a0f8af3d62dcf8 lib/core/readlineng.py
4949
0c3eef46bdbf87e29a3f95f90240d192 lib/core/replication.py
5050
a7db43859b61569b601b97f187dd31c5 lib/core/revision.py
5151
fcb74fcc9577523524659ec49e2e964b lib/core/session.py
52-
c0d7976aabdffc78b22a9e63f3a51683 lib/core/settings.py
52+
9f209388d9fed41480e57c8574d0111a lib/core/settings.py
5353
a971ce157d04de96ba6e710d3d38a9a8 lib/core/shell.py
5454
a7edc9250d13af36ac0108f259859c19 lib/core/subprocessng.py
5555
52642badbbca4c31a2fcdd754d67a983 lib/core/target.py
@@ -71,7 +71,7 @@ f6b5957bf2103c3999891e4f45180bce lib/parse/payloads.py
7171
30eed3a92a04ed2c29770e1b10d39dc0 lib/request/basicauthhandler.py
7272
2b81435f5a7519298c15c724e3194a0d lib/request/basic.py
7373
859b6ad583e0ffba154f17ee179b5b89 lib/request/comparison.py
74-
0113525b321d0d35cf973a9cff34850a lib/request/connect.py
74+
77b24c30b1a2163add76652998e74127 lib/request/connect.py
7575
dd4598675027fae99f2e2475b05986da lib/request/direct.py
7676
2044fce3f4ffa268fcfaaf63241b1e64 lib/request/dns.py
7777
98535d0efca5551e712fcc4b34a3f772 lib/request/httpshandler.py

0 commit comments

Comments
 (0)