Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Injection by LIKE operator [duplicate]

I've below code in one of my php files to fetch data from DB:

$products = $this->db->get_rows('SELECT * from products WHERE shop_id='.$_SESSION['shop_id'].'AND tags,title,text LIKE \'%'.$_POST['search'].'%\'');

Is it problematic? I mean LIKE operator can be injected?

Edited

please provide examples of injecting in this way

like image 631
revo Avatar asked Dec 08 '22 16:12

revo


2 Answers

Any operator can be injected without binding.

$_POST['search'] = "1%'; DROP TABLE myTable LIKE '%";

Would make

.... AND tags,title,text LIKE '%1%'; DROP TABLE myTable LIKE '%%'

Read on how to bind parameters.

like image 163
Kermit Avatar answered Dec 11 '22 07:12

Kermit


Of course this can be injected, you need to sanitize your input. Right now you are taking raw post data and inserting it into your SQL statement.

You should run your POST data through some sort of data sanitization, something like mysql_real_escape_string or the like

Or at least prepared statements. let server side code do the work for you.

like image 44
75inchpianist Avatar answered Dec 11 '22 07:12

75inchpianist