what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

mysql-truncate.txt

mysql-truncate.txt
Posted Sep 12, 2008
Site 80sec.com

Short write up discussing MySQL character set truncation vulnerabilities.

tags | paper, vulnerability
SHA-256 | 1553a1e8d1d0ff34395194b38aa66753f806fd86e6b26acf190557782c16897b

mysql-truncate.txt

Change Mirror Download
Mysql charset Truncation vulnerability

By http://www.80sec.com/

We found that there is a interesting feature in mysql database,when you are
using utf8,gbk or

other charsets.This feature may make your application unsecure.

Stefen Esser shows some attack manners of mysql in his paper[1], in which he
issues the SQL

Column Truncation vulnerability.

The application is a forum where new users can register
The administrator's name is known e.g. 'admin'
MySQL is used in the default mode
There is no application restriction on the length of new user names
The database column username is limited to 16 characters

Although the application restrict the length of the username, we can bypass
it in the following

example:

<?php

$user=$_REQUEST['user'];


mysql_connect("localhost", "root", "") or
die("Could not connect: " . mysql_error());
mysql_select_db("test");

mysql_query("SET names utf8");

$result = mysql_query("SELECT * from test_user where user='$user'");

if(trim($user)=='' or strlen($user)>20 ){
die("Input user Invalid");
}
if(@mysql_fetch_array($result, MYSQL_NUM)) {
die("already exist");
}
else {
$sql="insert test_user values ('$user')";
mysql_query($sql);
echo "$user register OK!";
}

mysql_free_result($result);
?>


Read the code here:

$result = mysql_query("SELECT * from test_user where user='$user'");

If the attacker input a username 'admin z', and the sql
will be like this:

SELECT * FROM user WHERE username='admin z'

And the application will check the length of username with the following
code:

if(trim($user)=='' or strlen($user)>20 ){
die("Input user Invalid");
}

The attack will failed because the length of the username
'admin z' is

greater then 20.

But it will not end here, attacker can input username 'admin0xc1zzz', and
the sql will be like

this:

SELECT * FROM user WHERE username='admin0xc1zzz'

This pass the application's logic,when the insert commond executes:

insert test_user values ('admin0xc1zzz')

because the table is created in charset utf8,the 0xc1 is not a valid utf8
character,it will be

striped,also all of the next characters will be striped too.Then the
attacker got a user

"admin";

As you see,when mysql works at utf8,the invalid data will be striped ,but
the webapplication

doesn't know this,it works at binaray.The difference between webapplication
and database make a

vulnerability.


Reference:

[1]
http://www.suspekt.org/2008/08/18/mysql-and-sql-column-truncation-vulnerabilities/
Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    28 Files
  • 7
    May 7th
    3 Files
  • 8
    May 8th
    4 Files
  • 9
    May 9th
    54 Files
  • 10
    May 10th
    12 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    17 Files
  • 14
    May 14th
    11 Files
  • 15
    May 15th
    17 Files
  • 16
    May 16th
    13 Files
  • 17
    May 17th
    22 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    17 Files
  • 21
    May 21st
    0 Files
  • 22
    May 22nd
    0 Files
  • 23
    May 23rd
    0 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close