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

Skip to content

Commit 1d5bde9

Browse files
committed
Implementing --live-cookies (Issue #4401)
1 parent 227a23f commit 1d5bde9

8 files changed

Lines changed: 39 additions & 10 deletions

File tree

lib/core/option.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
20632063
kb.lastParserStatus = None
20642064

20652065
kb.locks = AttribDict()
2066-
for _ in ("cache", "connError", "count", "handlers", "hint", "index", "io", "limit", "log", "socket", "redirect", "request", "value"):
2066+
for _ in ("cache", "connError", "count", "handlers", "hint", "index", "io", "limit", "liveCookies", "log", "socket", "redirect", "request", "value"):
20672067
kb.locks[_] = threading.Lock()
20682068

20692069
kb.matchRatio = None

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"paramDel": "string",
2828
"cookie": "string",
2929
"cookieDel": "string",
30+
"liveCookies": "string",
3031
"loadCookies": "string",
3132
"dropSetCookie": "boolean",
3233
"agent": "string",

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.4.10.27"
21+
VERSION = "1.4.10.28"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)
@@ -52,6 +52,9 @@
5252
# Timeout used in heuristic check for WAF/IPS protected targets
5353
IPS_WAF_CHECK_TIMEOUT = 10
5454

55+
# Timeout used in checking for existence of live-cookies file
56+
LIVE_COOKIES_TIMEOUT = 120
57+
5558
# Lower and upper values for match ratio in case of stable page
5659
LOWER_RATIO_BOUND = 0.02
5760
UPPER_RATIO_BOUND = 0.98

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ def cmdLineParser(argv=None):
168168
request.add_argument("--cookie-del", dest="cookieDel",
169169
help="Character used for splitting cookie values (e.g. ;)")
170170

171+
request.add_argument("--live-cookies", dest="liveCookies",
172+
help="Live cookies file used for loading up-to-date values")
173+
171174
request.add_argument("--load-cookies", dest="loadCookies",
172175
help="File containing cookies in Netscape/wget format")
173176

lib/request/connect.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import binascii
99
import logging
10+
import os
1011
import random
1112
import re
1213
import socket
@@ -25,6 +26,7 @@ class WebSocketException(Exception):
2526
from lib.core.agent import agent
2627
from lib.core.common import asciifyUrl
2728
from lib.core.common import calculateDeltaSeconds
29+
from lib.core.common import checkFile
2830
from lib.core.common import checkSameHost
2931
from lib.core.common import chunkSplitPostData
3032
from lib.core.common import clearConsoleLine
@@ -100,6 +102,7 @@ class WebSocketException(Exception):
100102
from lib.core.settings import IS_WIN
101103
from lib.core.settings import JAVASCRIPT_HREF_REGEX
102104
from lib.core.settings import LARGE_READ_TRIM_MARKER
105+
from lib.core.settings import LIVE_COOKIES_TIMEOUT
103106
from lib.core.settings import MAX_CONNECTION_READ_SIZE
104107
from lib.core.settings import MAX_CONNECTIONS_REGEX
105108
from lib.core.settings import MAX_CONNECTION_TOTAL_SIZE
@@ -292,6 +295,30 @@ def getPage(**kwargs):
292295

293296
return page, headers, code
294297

298+
if conf.liveCookies:
299+
with kb.locks.liveCookies:
300+
if not checkFile(conf.liveCookies, raiseOnError=False) or os.path.getsize(conf.liveCookies) == 0:
301+
warnMsg = "[%s] [WARNING] live cookies file '%s' is empty or non-existent. Waiting for timeout (%d seconds)" % (time.strftime("%X"), conf.liveCookies, LIVE_COOKIES_TIMEOUT)
302+
dataToStdout(warnMsg)
303+
304+
valid = False
305+
for _ in xrange(LIVE_COOKIES_TIMEOUT):
306+
if checkFile(conf.liveCookies, raiseOnError=False) and os.path.getsize(conf.liveCookies) > 0:
307+
valid = True
308+
break
309+
else:
310+
dataToStdout('.')
311+
time.sleep(1)
312+
313+
dataToStdout("\n")
314+
315+
if not valid:
316+
errMsg = "problem occurred while loading cookies from file '%s'" % conf.liveCookies
317+
raise SqlmapValueException(errMsg)
318+
319+
cookie = openFile(conf.liveCookies).read().strip()
320+
cookie = re.sub(r"(?i)\ACookie:\s*", "", cookie)
321+
295322
if multipart:
296323
post = multipart
297324
else:

lib/techniques/union/use.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
See the file 'LICENSE' for copying permission
66
"""
77

8-
import binascii
98
import json
109
import re
1110
import time
12-
import xml.etree.ElementTree
1311

1412
from lib.core.agent import agent
1513
from lib.core.bigarray import BigArray
@@ -33,14 +31,11 @@
3331
from lib.core.common import listToStrValue
3432
from lib.core.common import parseUnionPage
3533
from lib.core.common import removeReflectiveValues
36-
from lib.core.common import safeStringFormat
3734
from lib.core.common import singleTimeDebugMessage
3835
from lib.core.common import singleTimeWarnMessage
3936
from lib.core.common import unArrayizeValue
4037
from lib.core.common import wasLastResponseDBMSError
4138
from lib.core.compat import xrange
42-
from lib.core.convert import decodeBase64
43-
from lib.core.convert import getBytes
4439
from lib.core.convert import getUnicode
4540
from lib.core.convert import htmlUnescape
4641
from lib.core.data import conf

plugins/generic/databases.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from lib.core.agent import agent
1111
from lib.core.common import arrayizeValue
1212
from lib.core.common import Backend
13-
from lib.core.common import extractRegexResult
1413
from lib.core.common import filterNone
1514
from lib.core.common import filterPairValues
1615
from lib.core.common import flattenValue
@@ -23,7 +22,6 @@
2322
from lib.core.common import parseSqliteTableSchema
2423
from lib.core.common import popValue
2524
from lib.core.common import pushValue
26-
from lib.core.common import randomStr
2725
from lib.core.common import readInput
2826
from lib.core.common import safeSQLIdentificatorNaming
2927
from lib.core.common import safeStringFormat
@@ -54,7 +52,6 @@
5452
from lib.core.settings import UPPER_CASE_DBMSES
5553
from lib.core.settings import VERTICA_DEFAULT_SCHEMA
5654
from lib.request import inject
57-
from lib.techniques.union.use import unionUse
5855
from lib.utils.brute import columnExists
5956
from lib.utils.brute import tableExists
6057
from thirdparty import six

sqlmap.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ cookie =
5151
# Character used for splitting cookie values (e.g. ;).
5252
cookieDel =
5353

54+
# Live cookies file used for loading up-to-date values.
55+
liveCookies =
56+
5457
# File containing cookies in Netscape/wget format.
5558
loadCookies =
5659

0 commit comments

Comments
 (0)