I'm currently dealing with a SQL injection problem that involves an input being taken and put through a function that replaces all '
with \'
and all \
with \\
. I've tried a lot of things but I don't seem to be able to escape from the string literal.
Database encoding: UTF-8 (not GBK or any other vulnerable encoding, so the "%BF
trick" won't work here)
Here's the sanitisation function and the SQL query:
function sillyEscape($s) {
# Replace \ with \\ then replace ' with \'
return str_replace('\'','\\\'', str_replace('\\','\\\\', $s));
}
$category = mysqli_query($conn, "SELECT * FROM categories WHERE name = '".sillyEscape($_GET['cat_name'])."';");
They always say "Don't make your own escaping function — you'll get it wrong." So my question is, did the person who created the sillyEscape
function go wrong? And if so, how did they go wrong and how do I exploit this?
Again, the database encoding is UTF-8, so I'm not aware of any multibyte characters that we can inject to get out of this one.