mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-02-19 21:10:36 +03:00
Added resume functionality to -d and fixed logging with -d
This commit is contained in:
parent
e0d0913fc6
commit
eecee3b274
|
@ -27,7 +27,8 @@ try:
|
||||||
except:
|
except:
|
||||||
import md5
|
import md5
|
||||||
import sha
|
import sha
|
||||||
|
|
||||||
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
import struct
|
import struct
|
||||||
import urllib
|
import urllib
|
||||||
|
@ -38,7 +39,13 @@ def base64decode(string):
|
||||||
return string.decode("base64")
|
return string.decode("base64")
|
||||||
|
|
||||||
def base64encode(string):
|
def base64encode(string):
|
||||||
return string.encode("base64")[:-1]
|
return string.encode("base64")[:-1].replace("\n", "")
|
||||||
|
|
||||||
|
def base64pickle(string):
|
||||||
|
return base64encode(pickle.dumps(string))
|
||||||
|
|
||||||
|
def base64unpickle(string):
|
||||||
|
return pickle.loads(base64decode(string))
|
||||||
|
|
||||||
def hexdecode(string):
|
def hexdecode(string):
|
||||||
string = string.lower()
|
string = string.lower()
|
||||||
|
|
|
@ -123,14 +123,14 @@ def __setOutputResume():
|
||||||
if not conf.flushSession:
|
if not conf.flushSession:
|
||||||
readSessionFP = open(conf.sessionFile, "r")
|
readSessionFP = open(conf.sessionFile, "r")
|
||||||
lines = readSessionFP.readlines()
|
lines = readSessionFP.readlines()
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.count("][") == 4:
|
if line.count("][") == 4:
|
||||||
line = line.split("][")
|
line = line.split("][")
|
||||||
|
|
||||||
if len(line) != 5:
|
if len(line) != 5:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
url, _, _, expression, value = line
|
url, _, _, expression, value = line
|
||||||
|
|
||||||
if not value:
|
if not value:
|
||||||
|
@ -141,10 +141,10 @@ def __setOutputResume():
|
||||||
|
|
||||||
if value[-1] == "\n":
|
if value[-1] == "\n":
|
||||||
value = value[:-1]
|
value = value[:-1]
|
||||||
|
|
||||||
if url != conf.url:
|
if url not in ( conf.url, conf.hostname ):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if url not in kb.resumedQueries.keys():
|
if url not in kb.resumedQueries.keys():
|
||||||
kb.resumedQueries[url] = {}
|
kb.resumedQueries[url] = {}
|
||||||
kb.resumedQueries[url][expression] = value
|
kb.resumedQueries[url][expression] = value
|
||||||
|
|
|
@ -23,8 +23,12 @@ Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from lib.core.agent import agent
|
from lib.core.agent import agent
|
||||||
|
from lib.core.common import dataToSessionFile
|
||||||
|
from lib.core.convert import base64pickle
|
||||||
|
from lib.core.convert import base64unpickle
|
||||||
from lib.core.data import conf
|
from lib.core.data import conf
|
||||||
from lib.core.data import kb
|
from lib.core.data import kb
|
||||||
|
from lib.core.data import logger
|
||||||
from lib.core.settings import SQL_STATEMENTS
|
from lib.core.settings import SQL_STATEMENTS
|
||||||
from lib.utils.timeout import timeout
|
from lib.utils.timeout import timeout
|
||||||
|
|
||||||
|
@ -42,14 +46,25 @@ def direct(query, content=True):
|
||||||
select = True
|
select = True
|
||||||
break
|
break
|
||||||
|
|
||||||
if select:
|
logger.log(9, query)
|
||||||
output = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None)
|
|
||||||
else:
|
if not select:
|
||||||
output = timeout(func=conf.dbmsConnector.execute, args=(query,), duration=conf.timeout, default=None)
|
output = timeout(func=conf.dbmsConnector.execute, args=(query,), duration=conf.timeout, default=None)
|
||||||
|
elif conf.hostname in kb.resumedQueries and query in kb.resumedQueries[conf.hostname]:
|
||||||
|
output = base64unpickle(kb.resumedQueries[conf.hostname][query][:-1])
|
||||||
|
|
||||||
|
infoMsg = "resumed from file '%s': " % conf.sessionFile
|
||||||
|
infoMsg += "%s..." % str(output)[:20]
|
||||||
|
logger.info(infoMsg)
|
||||||
|
elif select:
|
||||||
|
output = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None)
|
||||||
|
|
||||||
if output is None or len(output) == 0:
|
if output is None or len(output) == 0:
|
||||||
return None
|
return None
|
||||||
elif content:
|
elif content:
|
||||||
|
if conf.hostname not in kb.resumedQueries or ( conf.hostname in kb.resumedQueries and query not in kb.resumedQueries[conf.hostname] ):
|
||||||
|
dataToSessionFile("[%s][%s][%s][%s][%s]\n" % (conf.hostname, kb.injPlace, conf.parameters[kb.injPlace], query, base64pickle(output)))
|
||||||
|
|
||||||
if len(output) == 1:
|
if len(output) == 1:
|
||||||
if len(output[0]) == 1:
|
if len(output[0]) == 1:
|
||||||
return str(list(output)[0][0])
|
return str(list(output)[0][0])
|
||||||
|
|
|
@ -67,8 +67,6 @@ class Connector(GenericConnector):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute(self, query):
|
def execute(self, query):
|
||||||
logger.debug(query)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
except (pyodbc.OperationalError, pyodbc.ProgrammingError), msg:
|
except (pyodbc.OperationalError, pyodbc.ProgrammingError), msg:
|
||||||
|
|
|
@ -66,8 +66,6 @@ class Connector(GenericConnector):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute(self, query):
|
def execute(self, query):
|
||||||
logger.debug(query)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
except kinterbasdb.OperationalError, msg:
|
except kinterbasdb.OperationalError, msg:
|
||||||
|
|
|
@ -70,8 +70,6 @@ class Connector(GenericConnector):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute(self, query):
|
def execute(self, query):
|
||||||
logger.debug(query)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
|
except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
|
||||||
|
|
|
@ -66,8 +66,6 @@ class Connector(GenericConnector):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute(self, query):
|
def execute(self, query):
|
||||||
logger.debug(query)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
except (MySQLdb.OperationalError, MySQLdb.ProgrammingError), msg:
|
except (MySQLdb.OperationalError, MySQLdb.ProgrammingError), msg:
|
||||||
|
|
|
@ -67,8 +67,6 @@ class Connector(GenericConnector):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute(self, query):
|
def execute(self, query):
|
||||||
logger.debug(query)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
except (cx_Oracle.DatabaseError), msg:
|
except (cx_Oracle.DatabaseError), msg:
|
||||||
|
|
|
@ -65,8 +65,6 @@ class Connector(GenericConnector):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute(self, query):
|
def execute(self, query):
|
||||||
logger.debug(query)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
except (psycopg2.OperationalError, psycopg2.ProgrammingError), msg:
|
except (psycopg2.OperationalError, psycopg2.ProgrammingError), msg:
|
||||||
|
|
|
@ -67,8 +67,6 @@ class Connector(GenericConnector):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def execute(self, query):
|
def execute(self, query):
|
||||||
logger.debug(query)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.cursor.execute(query)
|
self.cursor.execute(query)
|
||||||
except sqlite3.OperationalError, msg:
|
except sqlite3.OperationalError, msg:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user