Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explanation of particular sql injection

Tags:

security

sql

Browsing through the more dubious parts of the web, I happened to come across this particular SQL injection:

http://server/path/page.php?id=1+union+select+0,1,concat_ws(user(),0x3a,database(),0x3a,version()),3,4,5,6--

My knowledge of SQL - which I thought was half decent - seems very limiting as I read this.

Since I develop extensively for the web, I was curious to see what this code actually does and more importantly how it works.

like image 339
Russell Dias Avatar asked Oct 28 '10 12:10

Russell Dias


People also ask

What is SQL injection explain them in detail?

An SQL injection, sometimes abbreviated to SQLi, is a type of cyber attack in which a hacker uses a piece of SQL (structured query language) code to manipulate a database and gain access to potentially valuable information.

What are the examples of SQL injection attacks?

Some common SQL injection examples include: Retrieving hidden data, where you can modify an SQL query to return additional results. Subverting application logic, where you can change a query to interfere with the application's logic. UNION attacks, where you can retrieve data from different database tables.

What are the different types of injection attacks?

Injection is involved in four prevalent attack types: OGNL injection, Expression Language Injection, command injection, and SQL injection. During an injection attack, untrusted inputs or unauthorized code are “injected” into a program and interpreted as part of a query or command.


1 Answers

It replaces an improperly written parametrized query like this:

$sql = '
SELECT  *
FROM    products
WHERE   id = ' . $_GET['id'];

with this query:

SELECT  *
FROM    products
WHERE   id = 1
UNION ALL
select 0,1,concat_ws(user(),0x3A,database(),0x3A,version()),3,4,5,6

, which gives you information about the database name, version and username connected.

like image 52
Quassnoi Avatar answered Oct 01 '22 06:10

Quassnoi