|
|
|
|
@ -9,6 +9,12 @@ declare(strict_types=1); |
|
|
|
|
|
|
|
|
|
namespace tts; |
|
|
|
|
|
|
|
|
|
enum SQL_SAFETY_FLAG { |
|
|
|
|
case good; // All Okey |
|
|
|
|
case filtered; // Found isseues but tried to filter them out |
|
|
|
|
case dangerious; // May still be bad |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class safer_sql { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -198,6 +204,7 @@ class safer_sql { |
|
|
|
|
if (preg_match("/case when/i", $string) === 1) return true; |
|
|
|
|
if (preg_match("/extractvalue/i", $string) === 1) return true; |
|
|
|
|
if (preg_match("/\/etc\/passwd/i", $string) === 1) return true; |
|
|
|
|
if (preg_match("/\/var\/log/i", $string) === 1) return true; |
|
|
|
|
if (preg_match("/binary_checksum\s*\(/i", $string) === 1) return true; // ID MSSQL DB Engine |
|
|
|
|
if (preg_match("/user\s*\(\)/i", $string) === 1) return true; // Get current user |
|
|
|
|
if (preg_match("/system_user[\s]+\(\)/i", $string) === 1) return true; // Get current user |
|
|
|
|
@ -235,7 +242,7 @@ class safer_sql { |
|
|
|
|
'not_in', 'not_like', 'not_regexp', 'or', 'regexp', 'sounds_like', |
|
|
|
|
'floor', 'md5', 'rand', 'rlike', 'row', 'xor', |
|
|
|
|
// https://dev.mysql.com/doc/refman/8.0/en/string-functions.html |
|
|
|
|
'bit_length', 'elt', 'export_set', 'from_base64', 'hex', 'load_file', |
|
|
|
|
'bit_length', 'let', 'export_set', 'from_base64', 'hex', 'load_file', |
|
|
|
|
'make_set', 'match', 'oct', 'octet_length', 'ord', 'quote', 'regexp', |
|
|
|
|
'regexp_instr', 'regexp_like', 'regexp_replace', 'regexp_substr', |
|
|
|
|
'select', 'soundex', 'to_base64', 'unhex', 'weight_string' |
|
|
|
|
@ -442,11 +449,11 @@ class safer_sql { |
|
|
|
|
$safer = preg_replace('/[^a-zA-Z0-9.\s]/', "", $cleaner); |
|
|
|
|
|
|
|
|
|
if (self::found_sql_keyword($safer)) { |
|
|
|
|
throw new \Exception("MySQL keyword found after injection, attempt!"); |
|
|
|
|
return ["text"=>$safer, "status"=>SQL_SAFETY_FLAG::dangerious]; |
|
|
|
|
} |
|
|
|
|
return ["text"=>$safer, "danger"=>true]; |
|
|
|
|
return ["text"=>$safer, "status"=>SQL_SAFETY_FLAG::filtered]; |
|
|
|
|
} |
|
|
|
|
return ["text"=>$string, "danger"=>false]; |
|
|
|
|
return ["text"=>$string, "status"=>SQL_SAFETY_FLAG::good]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |