3 Desktop_pet (Workspace)
7 The file un charge of checking if an injection is attempted with the open database
11from typing
import Union, List
13from display_tty
import Disp, TOML_CONF, SAVE_TO_FILE, FILE_NAME
17 """ Check if an sql injection is present """
19 def __init__(self, error: int = 84, success: int = 0, debug: bool =
False) ->
None:
30 logger=self.__class__.__name__
37 'SELECT',
'INSERT',
'UPDATE',
'DELETE',
38 'DROP',
'CREATE',
'ALTER',
'TABLE',
'UNION',
'JOIN',
'WHERE'
47 def _perror(self, string: str =
"") ->
None:
48 """ Print an error message """
49 self.
disp.disp_print_error(f
"(Injection) {string}")
52 """ Check if a string is base64 encoded """
54 base64.b64decode(string, validate=
True)
60 """ Check if symbols are the source of the injection """
61 if isinstance(string, List)
is True:
66 if isinstance(string, str)
is True:
67 if ";base64" in string:
72 f
"Failed for {string}, node {i} was found.",
73 "check_if_symbol_sql_injection"
77 msg =
"(check_if_symbol_sql_injection) string must be a string or a List of strings"
83 """ Check if sql keywords are present """
84 if self.
debug is True:
85 msg =
"(check_if_command_sql_injection) string = "
86 msg += f
"'{string}', type(string) = '{type(string)}'"
87 self.
disp.disp_print_debug(msg)
88 if isinstance(string, List)
is True:
93 if isinstance(string, str)
is True:
97 f
"Failed for {string}, node {i} was found.",
98 "check_if_command_sql_injection"
102 msg =
"(check_if_command_sql_injection) string must be a string or a List of strings"
108 """ Check if a logic gate is present """
109 if isinstance(string, List)
is True:
114 if isinstance(string, str)
is True:
118 f
"Failed for {string}, node {i} was found.",
119 "check_if_logic_gate_sql_injection"
123 msg =
"(check_if_logic_gate_sql_injection) string must be a string or a List of strings"
129 """ Check if symbols and commands are the source of the injection """
132 if is_symbol
is True or is_command
is True:
137 """ Check if symbols and logic gates are the source of the injection """
140 if is_symbol
is True or is_logic_gate
is True:
145 """ Check if command and logic gates are the source of the injection """
148 if is_command
is True or is_logic_gate
is True:
153 """ Check if there is an sql injection, uses all the parameters """
154 if isinstance(string, List)
is True:
159 if isinstance(string, str)
is True:
160 if ";base64" in string:
166 msg =
"(check_if_sql_injection) string must be a string or a List of strings"
172 """ Check if there is an injection in the provided array of strings """
173 if isinstance(array_of_strings, List)
is True:
174 for i
in array_of_strings:
175 if isinstance(i, List)
is True:
179 if isinstance(i, str)
is False:
180 err_message =
"(check_if_injections_in_strings) Expected a string but "
181 err_message += f
"got an {type(i)}"
187 if isinstance(array_of_strings, str)
is True:
191 err_message =
"(check_if_injections_in_strings) The provided item is neither a List a table or a string"
195 def run_test(self, title: str, array: List[str], function: object, expected_response: bool =
False, global_status: int = 0) -> int:
196 """ Run a test and return it's status"""
198 global_response = global_status
199 print(f
"{title}", end=
"")
202 response = function(i)
203 if response != expected_response:
205 global_response = err
207 return global_response
210 """ Test the injection class """
212 global_status = success
218 "SELECT * FROM table;",
221 title=
"Logic gate test:",
224 expected_response=
True,
225 global_status=global_status
228 title=
"Keyword check:",
231 expected_response=
True,
232 global_status=global_status
235 title=
"Symbol check:",
238 expected_response=
True,
239 global_status=global_status
242 title=
"All injections:",
245 expected_response=
True,
246 global_status=global_status
249 title=
"Array check:",
252 expected_response=
True,
253 global_status=global_status
256 title=
"Double array check:",
259 expected_response=
True,
260 global_status=global_status
263 title=
"SQL sentences:",
264 array=test_sentences,
266 expected_response=
True,
267 global_status=global_status
272if __name__ ==
"__main__":
274 res = II.test_injection_class()
275 print(f
"test status = {res}")
int run_test(self, str title, List[str] array, object function, bool expected_response=False, int global_status=0)
bool check_if_command_sql_injection(self, Union[str, List[str]] string)
int test_injection_class(self)
bool check_if_symbol_and_logic_gate_injection(self, Union[str, List[str]] string)
bool _is_base64(self, str string)
bool check_if_symbol_sql_injection(self, Union[str, List[str]] string)
None __init__(self, int error=84, int success=0, bool debug=False)
bool check_if_injections_in_strings(self, Union[str, List[str], List[List[str]]] array_of_strings)
bool check_if_logic_gate_sql_injection(self, Union[str, List[str]] string)
bool check_if_command_and_logic_gate_injection(self, Union[str, List[str]] string)
None _perror(self, str string="")
bool check_if_symbol_and_command_injection(self, Union[str, List[str]] string)
bool check_if_sql_injection(self, Union[str, List[str]] string)