Skip to content

Commit 95e0d46

Browse files
committed
Fix for an Issue sqlmapproject#110
1 parent 5bf8600 commit 95e0d46

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

lib/core/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ def nullAndCastField(self, field):
313313

314314
rootQuery = queries[Backend.getIdentifiedDbms()]
315315

316-
if field.startswith("(CASE") or field.startswith("(IIF") or conf.noCast:
316+
if field.startswith("(CASE") or field.startswith("(IIF") or\
317+
conf.noCast or Backend.isDbms(DBMS.SQLITE) and not isDBMSVersionAtLeast('3'):
317318
nulledCastedField = field
318319
else:
319320
nulledCastedField = rootQuery.cast.query % field

plugins/dbms/sqlite/syntax.py

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
See the file 'doc/COPYING' for copying permission
66
"""
77

8+
import binascii
9+
import re
10+
811
from lib.core.common import isDBMSVersionAtLeast
912
from lib.core.exception import sqlmapSyntaxException
1013
from plugins.generic.syntax import Syntax as GenericSyntax
@@ -15,36 +18,16 @@ def __init__(self):
1518

1619
@staticmethod
1720
def unescape(expression, quote=True):
21+
unescaped = expression
22+
1823
if isDBMSVersionAtLeast('3'):
1924
if quote:
20-
expression = expression.replace("'", "''")
21-
while True:
22-
index = expression.find("''")
23-
if index == -1:
24-
break
25-
26-
firstIndex = index + 2
27-
index = expression[firstIndex:].find("''")
28-
29-
if index == -1:
30-
raise sqlmapSyntaxException, "Unenclosed ' in '%s'" % expression.replace("''", "'")
31-
32-
lastIndex = firstIndex + index
33-
old = "''%s''" % expression[firstIndex:lastIndex]
34-
unescaped = ""
35-
36-
for i in xrange(firstIndex, lastIndex):
37-
unescaped += "X'%x'" % ord(expression[i])
38-
if i < lastIndex - 1:
39-
unescaped += "||"
40-
41-
#unescaped += ")"
42-
expression = expression.replace(old, unescaped)
43-
expression = expression.replace("''", "'")
25+
for item in re.findall(r"'[^']+'", expression, re.S):
26+
unescaped = unescaped.replace(item, "X'%s'" % binascii.hexlify(item.strip("'")))
4427
else:
45-
expression = "||".join("X'%x" % ord(c) for c in expression)
28+
unescaped = "X'%s'" % binascii.hexlify(expression)
4629

47-
return expression
30+
return unescaped
4831

4932
@staticmethod
5033
def escape(expression):

xml/queries.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@
306306
<!-- SQLite -->
307307
<dbms value="SQLite">
308308
<cast query="CAST(%s AS VARCHAR(8000))" dbms_version="&gt;=3.0"/>
309+
<!-- NOTE: On SQLite version 2 everything is stored as a string (Reference: http://www.mono-project.com/SQLite) -->
309310
<length query="LENGTH(%s)"/>
310311
<isnull query="IFNULL(%s,' ')" dbms_version="&gt;=3.0"/>
311312
<delimiter query="||"/>

0 commit comments

Comments
 (0)