Google

[PHP][Linux] PHP安全性加強 抵擋 駭客 存取 linux 下的 /etc/password

近日公司部份客戶發現有被hacker 嘗試的 存取 linux 下的 /etc/passowrd 檔,請參照下圖

attachments/200806/9567811677.jpg

很明顯的看到是在要取得 password 檔的內容,另外在從MySQL資料庫中也發現到

看到這幾筆資料 , 就覺得有問題了:

| 44 | `cat /etc/passwd`                                                                  | y     |
| 45 | cat /etc/passwd                                                                    | y     |
| 46 | ;cat /etc/passwd;                                                                  | y     |
| 47 | |cat /etc/passwd                                                                   | y     |
| 48 |  cat /etc/passwd                                                                   | y     |
| 49 | <cat /etc/passwd                                                                   | y    |
| 50 | ../../../../../../../../etc/passwd                                                 | y      |
| 51 | ../../../../../../../../etc/passwd                                                 | y      |
| 52 |  ../../../../../../../../etc/passwd                                                | y      |
| 53 | ../../../../../../../../etc/passwd .html                                           | y    |
| 54 | ../../../../../../../../etc/passwd .jpg                                            | y     |
| 55 | .\\./.\\./.\\./.\\./.\\./.\\./etc/passwd                                           | y      |
| 56 | /etc/passwd                                                                        | y      |
| 57 | /./././././././etc/passwd                                                          | y      |
| 58 | ..\..\..\..\..\..\..\..\etc/passwd                                                 | y      |
| 59 | ../..//../..//../..//../..//../..//../..//../..//../..//etc/passwd                 | y      |
| 60 | ../.../.././../.../.././../.../.././../.../.././../.../.././../.../.././etc/passwd | y      |
| 61 | <../../../../../../../../etc/passwd                                                | y     |
 

 
由於是前人遺留下來的程式....所以還是需要花點時間去處理。
處理的方式有很多種
 
1.在寫程式時針對一些欄位需要在html 端檢查機制,例如 email 手機等..
   以增強安全性
 
 
2.不過厲害一點的hacker 或 hacker 軟件還是知道怎麼避開html 端的檢查機制
    還是需要程式端進行處理,原則上 linux 下的 /etc 目錄 (/etc 下是存放 linux 的config 設定檔 ) 是不被 web owner access 的,利用這個特點去檢查
    下面代碼會檢查 是否有/etc 目錄 有的話會強制 將 值回傳 boolean false
 
 
3.另外如果 已知一些變數的 型態 為特定的 例如 int 、boolean 、string 的話
   請將這些值強制的型態強制轉換
    
  例如有一個url http://www.iware.com.tw/pro.php?cid=20   
    
  程式寫法為 (int)$_REQUEST[cid]
  或
  intval($_REQUEST[cid])
 
 
  (int)$_REQUEST[cid] 的值會變成0 這樣也可以抵擋攻擊
引用通告地址: 點擊獲取引用地址
標籤: PHP php實例 程式設計 linux
評論: 1 | 引用: 0 | 閱讀: 2093
加入書籤: HemiDemi MyShare Baidu Google Bookmarks Yahoo! My Web Del.icio.us Digg technorati furl 加入此網頁到:YouPush
發表評論
暱 稱(*): 密 碼:
網 址: E - mail:
驗證碼(*): 驗證碼圖片 選 項:
頭 像:
內 容(*):