Loading...

RPO(Relative Path Overwrite)相對路徑覆蓋攻擊

Temperature: 0 °C

Mark ChangMark Chang
author_tools

首先,先來用例子說明何謂「相對路徑」何謂「絕對路徑」。

例如你有一個網址為http://www.demo.com

而在程式碼中你想要呼叫一個在http://www.demo.com/css/style.css 檔案

一般相對路徑的寫法會是:

include('css/style.css')//表示在css子目錄下的style.css檔案
//另外相對路徑的表現方式還有用「.」代表目前所在目錄,用「..」代表上一層目錄。

而絕對路徑的寫法則會是:
include('/css/style.css')//表示在本機www底下的css子目錄下的style.css檔案

不知道絕對路徑?
php取得絕對路徑的作法可以使用:
dirname(__FILE__)
echo __FILE__ ; // 取得當前文件的絕對地址
echo dirname(__FILE__); // 取得當前文件所在的絕對目錄
echo dirname(dirname(__FILE__)); //取得當前文件的上一層目錄名

所以該怎麼寫才能防止RPO(Relative Path Overwrite)相對路徑覆蓋攻擊呢?

解決方式就是別再使用相對路徑了......。
以後呼叫js、css或插入連結圖片及檔案從此不要再使用相對路徑。

另外也順便將iframe設定成「header("X-Frame-Options: DENY")」。

順便也過濾一些危險符號,例如「%2F」轉換成「/」...等。

說真的我是第一次遇到這樣的資安疑慮。

以往為了專案系統能夠順利移機到客戶端主機,基本上都會使用相對路徑的方式撰寫。

不管要include css 或者js。

以往也不曾被弱點掃描掃到有資安疑慮,這樣的撰寫模式也就沿用至今,直到這次被掃到弱點.......。

RPO(Relative Path Overwrite)相對路徑覆蓋攻擊

https://innstory.com/story-RPO(Relative_Path_Overwrite)相對路徑覆蓋攻擊-2120
apache Linux PHP

Prev
 分享_成功人士剛起步時和一般人的差異並不大!現代網路之父安德森給

Next
在PHP強制顯示錯誤訊息的方法 

About the Author

Mark Chang

離不開電腦的宅男

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

使用.htaccess關閉特定文件的緩存

使用.htaccess關閉特...

以特定檔案為例 <Files page.php> FileETag None Header unse...

php使用PDO獲取結果的方法

php使用PDO獲取結果的方...

fetch() 式例如下: mixed PDOStatement::fetch([int fetch...

PHP–implode() 將陣列轉成字串

PHP–implode() ...

pexelsphoto 使用implode將陣列轉換成字串; $ar=array(&#;a&#;,&...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format