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

Skip to content

Commit 60a2364

Browse files
committed
now union technique parses headers too
1 parent 8ef4730 commit 60a2364

4 files changed

Lines changed: 22 additions & 11 deletions

File tree

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,6 @@
205205

206206
# Encoding used for Unicode data
207207
UNICODE_ENCODING = "utf8"
208+
209+
# Reference: http://www.w3.org/Protocols/HTTP/Object_Headers.html#uri
210+
URI_HTTP_HEADER = "URI"

lib/request/connect.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from lib.core.exception import sqlmapConnectionException
4141
from lib.core.exception import sqlmapSyntaxException
4242
from lib.core.settings import MIN_TIME_RESPONSES
43+
from lib.core.settings import URI_HTTP_HEADER
4344
from lib.core.threads import getCurrentThreadData
4445
from lib.request.basic import decodePage
4546
from lib.request.basic import forgeHeaders
@@ -257,6 +258,7 @@ def getPage(**kwargs):
257258
try:
258259
page = e.read()
259260
responseHeaders = e.info()
261+
responseHeaders[URI_HTTP_HEADER] = e.geturl()
260262
page = decodePage(page, responseHeaders.get("Content-Encoding"), responseHeaders.get("Content-Type"))
261263
except socket.timeout:
262264
warnMsg = "connection timed out while trying "

lib/techniques/inband/union/test.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
import time
1212

1313
from lib.core.agent import agent
14+
from lib.core.common import Backend
1415
from lib.core.common import clearConsoleLine
1516
from lib.core.common import dataToStdout
16-
from lib.core.common import Backend
1717
from lib.core.common import extractRegexResult
1818
from lib.core.common import getUnicode
19+
from lib.core.common import listToStrValue
1920
from lib.core.common import parseUnionPage
2021
from lib.core.common import randomStr
2122
from lib.core.data import conf
@@ -48,9 +49,10 @@ def __unionPosition(comment, place, parameter, value, prefix, suffix, count, whe
4849
payload = agent.payload(place=place, parameter=parameter, newValue=query, where=where)
4950

5051
# Perform the request
51-
resultPage, _ = Request.queryPage(payload, place=place, content=True, raise404=False)
52+
page, headers = Request.queryPage(payload, place=place, content=True, raise404=False)
53+
content = "%s%s" % (page or "", listToStrValue(headers.headers if headers else None) or "")
5254

53-
if resultPage and phrase in resultPage:
55+
if content and phrase in content:
5456
validPayload = payload
5557
vector = (position, count, comment, prefix, suffix, conf.uChar, where)
5658

@@ -66,9 +68,10 @@ def __unionPosition(comment, place, parameter, value, prefix, suffix, count, whe
6668
payload = agent.payload(place=place, parameter=parameter, newValue=query, where=2)
6769

6870
# Perform the request
69-
resultPage, _ = Request.queryPage(payload, place=place, content=True, raise404=False)
71+
page, headers = Request.queryPage(payload, place=place, content=True, raise404=False)
72+
content = "%s%s" % (page or "", listToStrValue(headers.headers if headers else None) or "")
7073

71-
if resultPage and ((phrase in resultPage and phrase2 not in resultPage) or (phrase not in resultPage and phrase2 in resultPage)):
74+
if content and ((phrase in content and phrase2 not in content) or (phrase not in content and phrase2 in content)):
7275
vector = (position, count, comment, prefix, suffix, conf.uChar, 2)
7376

7477
break

lib/techniques/inband/union/use.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
import time
1212

1313
from lib.core.agent import agent
14-
from lib.core.common import calculateDeltaSeconds
1514
from lib.core.common import Backend
15+
from lib.core.common import calculateDeltaSeconds
1616
from lib.core.common import getUnicode
1717
from lib.core.common import initTechnique
1818
from lib.core.common import isNumPosStrValue
19+
from lib.core.common import listToStrValue
1920
from lib.core.common import parseUnionPage
2021
from lib.core.data import conf
2122
from lib.core.data import kb
@@ -247,17 +248,19 @@ def unionUse(expression, direct=False, unescape=True, resetCounter=False, unpack
247248
payload = agent.payload(newValue=query)
248249

249250
# Perform the request
250-
resultPage, _ = Request.queryPage(payload, content=True)
251+
page, headers = Request.queryPage(payload, content=True, raise404=False)
252+
content = "%s%s" % (page or "", listToStrValue(headers.headers if headers else None) or "")
253+
251254
reqCount += 1
252255

253-
if kb.misc.start not in resultPage or kb.misc.stop not in resultPage:
256+
if kb.misc.start not in content or kb.misc.stop not in content:
254257
return
255258

256259
# Parse the returned page to get the exact inband
257260
# sql injection output
258-
startPosition = resultPage.index(kb.misc.start)
259-
endPosition = resultPage.rindex(kb.misc.stop) + len(kb.misc.stop)
260-
value = getUnicode(resultPage[startPosition:endPosition])
261+
startPosition = content.index(kb.misc.start)
262+
endPosition = content.rindex(kb.misc.stop) + len(kb.misc.stop)
263+
value = getUnicode(content[startPosition:endPosition])
261264

262265
duration = calculateDeltaSeconds(start)
263266

0 commit comments

Comments
 (0)