如何預防 XSS

XSS (Cross-site scripting)
是一種網站應用程式的安全漏洞攻擊,允許惡意使用者將程式碼注入到網頁上,其他使用者在觀看網頁時就會受到影響。這類攻擊通常包含了 HTML 以及使用者端的 Javascript。

以前盛行的 SQL Injection 到現在的 JavaScript Injection
這類的問題真是層出不窮阿…
SQL Injection 很容易被 Search Engine 給搜出來(只要人家多給你散撥一下)
如果程式設計不妥,很容易就會被"入侵"了(說入侵實在太貼金了)
就連銀行都出過這種包呢!

駭客新手法 資料隱碼入侵 威脅九成官商網站

 刑事局指出,「資料隱碼」攻擊手法,是於去年六月間,在國外網站悄悄流傳,美國駭客年會並於去年九月份廣泛討論,知悉這種攻擊方法的駭客人數正逐漸增加;警方研判,台灣已有網站遭到毒手。

 據了解,「資料隱碼」(SQL Injection)攻擊法,專門經由Apache、IIS、Domino、Netscape的網站系統,透過ASP、PHP、JSP程式碼,攻擊破壞MS-SQL、My SQL、Oracle、Sybase、DB2等各種SQL資料庫。

 刑事局資訊室主任兼偵九隊隊長李相臣分析,目前國內有九成以上的政府及電子商務網站,使用上述網站資料庫系統;警方初步調查,其中有七成以上,均可以「資料隱碼」輕易攻擊入侵,已面臨安全威脅。

雖然這是民國 91 年的新聞
不過現在的狀況可能也好不到哪去
Flash 都有 XSS 喔!

這邊就來介紹 PHPIDS - Web Application Security 2.0
可以用來偵測 $_GET$_POST 變數中是否含有 XSS 等含有威脅的資料
需求環境為 PHP5 & SimpleXML

PHPIDS 可以預防抵擋哪些攻擊呢?
Currently the PHPIDS detects all sorts of XSS, SQL Injection, header injection, directory traversal, RFE/LFI, DoS and LDAP attacks. Through special conversion algorithms the PHPIDS is even able to detect heavily obfuscated attacks - this covers several charsets, entities of all forms, comment obfuscation, obfuscation through concatenation, shell code and many other variants. Furthermore the PHPIDS is able to detect yet unknown attack patterns with the PHPIDS Centrifuge component.

要如何使用 PHPIDS 呢?
set_include_path(
get_include_path()
. PATH_SEPARATOR
. 'path/to/phpids/lib'
);

require_once 'IDS/Init.php';

$request = array_merge($_GET, $_POST);
$init = IDS_Init::init('IDS/Config/Config.ini');

$ids = new IDS_Monitor($request, $init);
$result = $ids->run();

if (!$result->isEmpty()) {
// Take a look at the result object
echo $result;
}

可以到官方網站demo 看看

Comments

Popular posts from this blog

CentOS7 如何新增/移除 Rich Rule for firewalld

mac 安裝 mtr

Howto use Postman test Cors