Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/plugins/dbms/presto/connector.py
2992 views
1
#!/usr/bin/env python
2
3
"""
4
Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)
5
See the file 'LICENSE' for copying permission
6
"""
7
8
try:
9
import prestodb
10
except:
11
pass
12
13
import logging
14
import struct
15
16
from lib.core.common import getSafeExString
17
from lib.core.data import conf
18
from lib.core.data import logger
19
from lib.core.exception import SqlmapConnectionException
20
from plugins.generic.connector import Connector as GenericConnector
21
22
class Connector(GenericConnector):
23
"""
24
Homepage: https://github.com/prestodb/presto-python-client
25
User guide: https://github.com/prestodb/presto-python-client/blob/master/README.md
26
API: https://www.python.org/dev/peps/pep-0249/
27
PyPI package: presto-python-client
28
License: Apache License 2.0
29
"""
30
31
def connect(self):
32
self.initConnection()
33
34
try:
35
self.connector = prestodb.dbapi.connect(host=self.hostname, user=self.user, catalog=self.db, port=self.port, request_timeout=conf.timeout)
36
except (prestodb.exceptions.OperationalError, prestodb.exceptions.InternalError, prestodb.exceptions.ProgrammingError, struct.error) as ex:
37
raise SqlmapConnectionException(getSafeExString(ex))
38
39
self.initCursor()
40
self.printConnected()
41
42
def fetchall(self):
43
try:
44
return self.cursor.fetchall()
45
except prestodb.exceptions.ProgrammingError as ex:
46
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
47
return None
48
49
def execute(self, query):
50
retVal = False
51
52
try:
53
self.cursor.execute(query)
54
retVal = True
55
except (prestodb.exceptions.OperationalError, prestodb.exceptions.ProgrammingError) as ex:
56
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
57
except prestodb.exceptions.InternalError as ex:
58
raise SqlmapConnectionException(getSafeExString(ex))
59
60
self.connector.commit()
61
62
return retVal
63
64
def select(self, query):
65
retVal = None
66
67
if self.execute(query):
68
retVal = self.fetchall()
69
70
return retVal
71
72