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

Skip to content

Commit c29db43

Browse files
committed
Minor refactoring
1 parent e0eeed0 commit c29db43

5 files changed

Lines changed: 26 additions & 27 deletions

File tree

lib/core/agent.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,5 +1079,20 @@ def runAsDBMSUser(self, query):
10791079

10801080
return query
10811081

1082+
def whereQuery(self, query):
1083+
if conf.dumpWhere and query:
1084+
prefix, suffix = query.split(" ORDER BY ") if " ORDER BY " in query else (query, "")
1085+
1086+
if "%s)" % conf.tbl.upper() in prefix.upper():
1087+
prefix = re.sub(r"(?i)%s\)" % re.escape(conf.tbl), "%s WHERE %s)" % (conf.tbl, conf.dumpWhere), prefix)
1088+
elif re.search(r"(?i)\bWHERE\b", prefix):
1089+
prefix += " AND %s" % conf.dumpWhere
1090+
else:
1091+
prefix += " WHERE %s" % conf.dumpWhere
1092+
1093+
query = "%s ORDER BY %s" % (prefix, suffix) if suffix else prefix
1094+
1095+
return query
1096+
10821097
# SQL agent
10831098
agent = Agent()

lib/core/settings.py

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

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.1.1.1"
22+
VERSION = "1.1.1.2"
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)

lib/utils/pivotdumptable.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def pivotDumpTable(table, colList, count=None, blind=True):
4141

4242
if count is None:
4343
query = dumpNode.count % table
44-
query = whereQuery(query)
44+
query = agent.whereQuery(query)
4545
count = inject.getValue(query, union=False, error=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS) if blind else inject.getValue(query, blind=False, time=False, expected=EXPECTED.INT)
4646

4747
if isinstance(count, basestring) and count.isdigit():
@@ -91,7 +91,7 @@ def pivotDumpTable(table, colList, count=None, blind=True):
9191
logger.info(infoMsg)
9292

9393
query = dumpNode.count2 % (column, table)
94-
query = whereQuery(query)
94+
query = agent.whereQuery(query)
9595
value = inject.getValue(query, blind=blind, union=not blind, error=not blind, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
9696

9797
if isNumPosStrValue(value):
@@ -125,7 +125,7 @@ def _(column, pivotValue):
125125
else:
126126
query = dumpNode.query2.replace("'%s'", "%s") % (agent.preprocessField(table, column), table, agent.preprocessField(table, colList[0]), unescaper.escape(pivotValue, False))
127127

128-
query = whereQuery(query)
128+
query = agent.whereQuery(query)
129129
return unArrayizeValue(inject.getValue(query, blind=blind, time=blind, union=not blind, error=not blind))
130130

131131
try:
@@ -179,18 +179,3 @@ def _(column, pivotValue):
179179
logger.critical(errMsg)
180180

181181
return entries, lengths
182-
183-
def whereQuery(query):
184-
if conf.dumpWhere and query:
185-
prefix, suffix = query.split(" ORDER BY ") if " ORDER BY " in query else (query, "")
186-
187-
if "%s)" % conf.tbl.upper() in prefix.upper():
188-
prefix = re.sub(r"(?i)%s\)" % re.escape(conf.tbl), "%s WHERE %s)" % (conf.tbl, conf.dumpWhere), prefix)
189-
elif re.search(r"(?i)\bWHERE\b", prefix):
190-
prefix += " AND %s" % conf.dumpWhere
191-
else:
192-
prefix += " WHERE %s" % conf.dumpWhere
193-
194-
query = "%s ORDER BY %s" % (prefix, suffix) if suffix else prefix
195-
196-
return query

plugins/generic/entries.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from lib.request import inject
4444
from lib.utils.hash import attackDumpedTable
4545
from lib.utils.pivotdumptable import pivotDumpTable
46-
from lib.utils.pivotdumptable import whereQuery
4746

4847
class Entries:
4948
"""
@@ -190,7 +189,7 @@ def dumpTable(self, foundData=None):
190189
else:
191190
query = rootQuery.inband.query % (colString, conf.db, tbl)
192191

193-
query = whereQuery(query)
192+
query = agent.whereQuery(query)
194193

195194
if not entries and query:
196195
entries = inject.getValue(query, blind=False, time=False, dump=True)
@@ -244,7 +243,7 @@ def dumpTable(self, foundData=None):
244243
else:
245244
query = rootQuery.blind.count % (conf.db, tbl)
246245

247-
query = whereQuery(query)
246+
query = agent.whereQuery(query)
248247

249248
count = inject.getValue(query, union=False, error=False, expected=EXPECTED.INT, charsetType=CHARSET_TYPE.DIGITS)
250249

@@ -329,7 +328,7 @@ def dumpTable(self, foundData=None):
329328
elif Backend.isDbms(DBMS.INFORMIX):
330329
query = rootQuery.blind.query % (index, agent.preprocessField(tbl, column), conf.db, tbl, sorted(colList, key=len)[0])
331330

332-
query = whereQuery(query)
331+
query = agent.whereQuery(query)
333332

334333
value = NULL if column in emptyColumns else inject.getValue(query, union=False, error=False, dump=True)
335334
value = '' if value is None else value

txt/checksum.md5

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ c55b400b72acc43e0e59c87dd8bb8d75 extra/shellcodeexec/windows/shellcodeexec.x32.
2424
10edc8d1057e89c145218d4c5ccaaa31 lib/controller/controller.py
2525
b3eec7f44bcc5d784d171a187b7fe8cb lib/controller/handler.py
2626
310efc965c862cfbd7b0da5150a5ad36 lib/controller/__init__.py
27-
178066b5737f0e719cbf9271051559a2 lib/core/agent.py
27+
19905ecb4437b94512cf21d5f1720091 lib/core/agent.py
2828
6cc95a117fbd34ef31b9aa25520f0e31 lib/core/bigarray.py
2929
445bd2c2fe0dcca0dd3aab87eb3839d3 lib/core/common.py
3030
5065a4242a8cccf72f91e22e1007ae63 lib/core/convert.py
@@ -45,7 +45,7 @@ e544108e2238d756c94a240e8a1ce061 lib/core/optiondict.py
4545
d8e9250f3775119df07e9070eddccd16 lib/core/replication.py
4646
785f86e3f963fa3798f84286a4e83ff2 lib/core/revision.py
4747
40c80b28b3a5819b737a5a17d4565ae9 lib/core/session.py
48-
f2357b8338b164d624446ddd8d6f2cbd lib/core/settings.py
48+
779a77140ccd74d4cdad70f28a48130b lib/core/settings.py
4949
d91291997d2bd2f6028aaf371bf1d3b6 lib/core/shell.py
5050
2ad85c130cc5f2b3701ea85c2f6bbf20 lib/core/subprocessng.py
5151
afd0636d2e93c23f4f0a5c9b6023ea17 lib/core/target.py
@@ -107,7 +107,7 @@ ccfdad414ce2ec0c394c3deaa39a82bf lib/utils/hashdb.py
107107
aff7355d582fc6c00a675eeee2a5217a lib/utils/hash.py
108108
e76a08237ee6a4cd6855af79610ea8a5 lib/utils/htmlentities.py
109109
310efc965c862cfbd7b0da5150a5ad36 lib/utils/__init__.py
110-
8e4ecc5e5bd8a5c7e2ad0a940cb1a5b1 lib/utils/pivotdumptable.py
110+
9d8c858417d356e49e1959ba253aede4 lib/utils/pivotdumptable.py
111111
8520a745c9b4db3814fe46f4c34c6fbc lib/utils/progress.py
112112
2c3638d499f3c01c34187e531f77d004 lib/utils/purge.py
113113
2da1b35339667646e51101adaa1dfc32 lib/utils/search.py
@@ -203,7 +203,7 @@ a7f4d3a194f52fbb4fb4488be41273b1 plugins/dbms/sybase/enumeration.py
203203
1f46f2eac95cfdc3fa150ec5b0500eba plugins/generic/connector.py
204204
a8f9d0516509e9e4226516ab4f13036a plugins/generic/custom.py
205205
3b54fd65feb9f70c551d315e82653384 plugins/generic/databases.py
206-
085f839221138aa7931bd94c33a32768 plugins/generic/entries.py
206+
45c32855126546a0d9936ecdc943ab3f plugins/generic/entries.py
207207
55802d1d5d65938414c77ccc27731cab plugins/generic/enumeration.py
208208
b6666109aa6882ca9c526d615c1bcde3 plugins/generic/filesystem.py
209209
feca57a968c528a2fe3ccafbc83a17f8 plugins/generic/fingerprint.py

0 commit comments

Comments
 (0)