Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is this SQL injection doing?

Long story short, through an old asp site I run someone found an unfiltered URL parameter and was able to run this query. I'm trying to figure out what it DOES though...

The query should read:

select * from reserve where id = 345

the one that was ran was:

select * from reserve where id = 345 and ascii(substring((select concat(user,0x3a,password,0x3a,host) from mysql.user limit 0,1),17,1))=53

I'm really not sure what this obtains. Any Input?

like image 508
Neil M. Avatar asked Dec 16 '11 19:12

Neil M.


People also ask

What does SQL injection do?

SQL injection, also known as SQLI, is a common attack vector that uses malicious SQL code for backend database manipulation to access information that was not intended to be displayed. This information may include any number of items, including sensitive company data, user lists or private customer details.

What is SQL injection and how does it happen?

SQL Injection (SQLi) is a type of an injection attack that makes it possible to execute malicious SQL statements. These statements control a database server behind a web application. Attackers can use SQL Injection vulnerabilities to bypass application security measures.

What is the cause of SQL injection?

The three root causes of SQL injection vulnerabilities are the combining of data and code in dynamic SQL statement, error revealation, and the insufficient input validation.

What is SQL injection How do you prevent it?

SQL Injection is a code-based vulnerability that allows an attacker to read and access sensitive data from the database. Attackers can bypass security measures of applications and use SQL queries to modify, add, update, or delete records in a database.


2 Answers

It might be probing whether or not the web application is accessing the database as root. Removing the ascii(substring()) portions returns the following when run as root:

mysql> select concat(user,0x3a,password,0x3a,host) from mysql.user limit 0,1;
+--------------------------------------+
| concat(user,0x3a,password,0x3a,host) |
+--------------------------------------+
| root:<rootpw-hash>:localhost         |
+--------------------------------------+

Following a successful probe, they may then attempt to retrieve the contents of mysql.user from which they can start cracking passwords against rainbow tables.

like image 71
Michael Berkowski Avatar answered Sep 19 '22 03:09

Michael Berkowski


The second part of where condition is really strange: it looks for a mysql credentials and process them as follows:

  • concat(user,0x3a,password,0x3a,host) will be something like 'someUser:hisPass:localhost'
  • the above string will be splitted in a smaller one
  • the above string is converted to ascii code (you might know it from legacy languages as ord())
  • the result of the conversion is compared to 53 integer

I suppose that the first part of WHERE statement (id = 345) will always return true while the second one is too specific, so the entire query will probably return an empty result all the time.

like image 36
Salaros Avatar answered Sep 22 '22 03:09

Salaros