水貨CTO入職不到半年犯下低級錯誤,將公司拖入無底深淵

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從大公司聘請來的 CTO 太水,犯了個低級錯誤,事後還故意刪除代碼隱藏證據。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上週末,黑客組織 DDoSecrets 利用 SQL 注入漏洞,入侵了極右翼社交媒體網站 Gab,並下載了 70 GB 的數據。在 Gab 的開源代碼中快速瀏覽一下就會發現,這個關鍵漏洞是由公司的首席技術官引入的。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"CTO 犯的低級錯誤,CEO 來買單"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"黑客利用 SQL 注入漏洞從 Gab 的後臺數據庫中竊取了大約 70GB 的平臺用戶數據,包含該網站的 4000 多萬條帖子,之後將所盜走的 70GB 數據交給了爆料網站 Distributed Denial of Secrets(DDoSecrets)。泄露的數據包含公開 \/ 私人貼文、哈希密碼與用戶私有訊息,涉及 1.5 萬名用戶,其中還包括前美國總統特朗普。DDoSecrets 已經將這些數據彙編成了一個名爲 GabLeaks 的東西,打算將其提供給特定的記者、社會科學家和研究人員進行進一步分析。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作爲一家初創公司,泄露 70G 數據無疑嚴重影響了用戶權益,這個亂攤子讓 Gab 的 CEO 疲於應付。2 月 26 日,最初,CEO 安德魯·托爾巴(Andrew Torba)在 Gab 網站聲明中否認了這一入侵行爲,但數據泄露之後他又不得不承認已經發生了入侵行爲,並且還稱攻擊者爲“惡魔黑客”。Torba 說,該公司已意識到“該領域存在漏洞,並於上週對其進行了修補。” 並且還將着手進行全面的安全審覈,在 2 月 28 日的一份聲明中,他表示:“整個公司將全力調查發生的事情,並努力追蹤和修補問題。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/ab\/abbec441d6055d3a3cadfb130172bd90.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"黑客發 Twitter 嘲笑 Gab CEO 被嚇壞了。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通過查看公司的 git commit 發現,導致關鍵漏洞的代碼變更,是在 2 月份的某個時候從 Fosco Marotto 的賬戶上進行的,他是一名前 Facebook 軟件工程師,11 月成爲 Gab 的 CTO。週一,Gab 將此 git commit 從網站上刪除,但網絡上已有圖片保存了關鍵代碼。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/97\/97c37ad30f8bdc32e9054777ef7a1ad2.jpeg","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這張圖片顯示的是 2 月份的軟件變更情況,圖片來自一家保存提交的快照的網站。提交的內容顯示,一名軟件開發人員使用 Fosco Marotto 的賬戶提交了代碼,代碼中明顯存在新手錯誤,這種錯誤可能會導致報道中的泄密事件。具體來說,第 23 行刪除了“reject”和“filter”的代碼,這兩個 API 函數實現了防止 SQL 注入攻擊的編程實踐。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這一習慣允許程序員以安全的方式編寫 SQL 查詢,以“清理”網站訪問者在搜索框和其他 Web 字段中輸入的內容,確保所有惡意命令在文本傳遞到後端服務器之前被清除。取而代之的是,開發人員向包含 find_by_sql 方法的 Rails 函數添加一個調用,該方法直接接受查詢字符串中未經清理的輸入。Rails 是一套廣泛使用的網站開發工具包。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"“如果你知道在 Web 應用中使用 SQL 數據庫,那麼你將聽說過 SQL 注入,而且不難發現 find_by_sql 方法不安全警告。Facebook 的前產品工程師 Dmitry Borodaenko 在一封電子郵件中提醒了我這個問題。“現在還不能 100% 肯定這就是 Gab 數據泄露事件中所使用的漏洞,但是絕對有可能是這樣的漏洞,在最近提交的 GitLab 倉庫中出現的代碼更改被恢復,然後他們就讓代碼離線了。”具有諷刺意味的是,早在 2012 年,Fosco 就曾警告程序員同行們,要使用參數化查詢來防止 SQL 注入漏洞。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"刪除不安全的代碼,隱藏證據"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Gab 開發的安全代碼流程遭到質疑,同時,這家社交媒體網站因從其網站中刪除提交而受到批評。批評者稱,此舉違反了 Affero 通用公共許可證的條款,該許可證控制 Gab 對 Mastodon 的重用(用於託管社交網絡平臺的開源軟件包)。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"譯註:Affero 通用公共許可證(Affero General Public License,Affero GPL 或 AGPL),是一個廣泛被使用的自由軟件特許條款,最初由 Affero, Inc 撰寫。此特許條款最新版本爲第 3 版(v3),2007 年 11 月發佈。Affero 通用公衆特許條款是改自 GNU 通用公衆特許條款,並加入額外條款,其目的是爲了 Copyleft 條款應用於在網絡上運行的應用程序(如 Web 應用),從而避免有人以應用服務提供商方式逃避 GNU 通用公衆特許條款。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"上述批評者稱,這一刪除行爲違反了一條規定,即要求復刻(fork)的源代碼直接從網站上鍊接。該要求的目的是提供透明度,讓其他開源開發者也能從 Gab 同行的工作中受益。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Gab 長期以來一直在 "},{"type":"link","attrs":{"href":"https:\/\/code.gab.com\/","title":"","type":null},"content":[{"type":"text","text":"https:\/\/code.gab.com\/"}]},{"type":"text","text":" 提供提交內容。然後,在週一,該網站突然刪除了所有的提交:包括那些創建並修復了關鍵 SQL 注入漏洞的提交。取而代之的是,Gab 提供了 Zip 存檔文件形式的源代碼,該文件由密碼“JesusChristIsKingTrumpWonTheElection”(不含雙引號)保護。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Mastodon 項目的代表沒有立即回覆詢問他們是否同意批評者的擔憂的電子郵件。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此外,Gab 的 Git 提交還顯示出,除了關於安全編碼和許可合規的問題外,公司開發者也在努力修復他們脆弱的代碼。下圖顯示了有人使用用戶名“developer”嘗試完全修復包含 SQL 注入漏洞的代碼,但沒有成功。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/70\/70ed0e78cb849dc48cda5d309bb1a882.jpeg","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"線程參與者對此的反應是諷刺地指出開發者似乎遇到的困難。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/b4\/b42f4d262d4d957eb3e479ebb0e630e8.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 Gab 的安全漏洞事件,前後的代碼處理爲開發者提供了一個案例研究,說明如何維護站點的安全性和代碼透明度。考慮到提交的文件使用了 Gab 的 CTO 的賬號,這個教訓就顯得更有分量了,因爲在所有的人當中,他知道的東西應該更多。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"原因是 CTO 太水?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這件事情也引起了開發者的廣泛關注,一位從事多年 Rails 開發的網友說:“這是不好的代碼,讓我感到驚訝的是這是由一位前 Facebook 工程師寫的(後來他成了 CTO)。粗略檢查就能看出一些錯誤,比如大型原始 SQL 查詢完全可以使用 AREL 或 ActiveRecord 這種更慣用的方式,沒有清理用戶輸入等等。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"去年 11 月,Gab 宣佈聘請 Fosco Marotto 作爲他們的新 CTO。Marotto 曾在 Facebook 工作七年,擔任軟件工程師,負責後端工具包 Parse 的開發,是 Parse 團隊的關鍵成員,目前該工具包已經開源。同時他還利用業餘時間幫助 Gab 開發了免費語音網絡瀏覽器 Dissenter。加入 Gab 後,公司在他們網站的聲明中說:“Marotto 有 23 年的行業經驗,在後端基礎架構上有深厚的知識和見解。這有助於 Gab 迅速發展爲新的媒體巨頭。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"防止 SQL 注入,在 Rails 文檔中有明確的示例說明("},{"type":"link","attrs":{"href":"https:\/\/guides.rubyonrails.org\/security.html#sql-injection%EF%BC%89%EF%BC%8C%E7%94%9A%E8%87%B3%E7%A4%BA%E4%BE%8B%E4%B8%8E%E8%AF%A5%E6%8F%90%E4%BA%A4%E4%B8%AD%E6%89%80%E8%AE%A8%E8%AE%BA%E7%9A%84%E4%BB%A3%E7%A0%81%E5%AE%8C%E5%85%A8%E4%B8%80%E6%A0%B7%EF%BC%8C%E6%89%80%E4%BB%A5%E8%BF%99%E4%B8%AA%E6%8A%80%E6%9C%AF%E5%9C%A8","title":"","type":null},"content":[{"type":"text","text":"https:\/\/guides.rubyonrails.org\/security.html#sql-injection),甚至示例與該提交中所討論的代碼完全一樣,所以這個技術在"}]},{"type":"text","text":" Rails 裏並不是什麼新鮮玩意兒。在 2021 年還能讓黑客利用到 SQL 注入漏洞,這很讓人不可置信,一位網友在 Reddit 上評論道,“代碼將要部署到生產環境中,在合併代碼之前難道沒有讓同行審查嗎?如果首席技術官審查了開發人員的代碼後還犯這種錯誤,那麼要麼 CTO 和工程師都是白癡,要麼工程師們在故意欺騙這位白癡。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"而且除了這是一種糟糕的實踐之外,現有的每一個代碼靜態分析工具都會告訴你,這樣編寫 SQL 是一個非常糟糕的做法。CI 管道甚至會直接拒絕代碼,拒絕合併代碼。也就是說,即使我們的某個開發人員試圖忽略了這個明顯的安全漏洞,系統本身也能阻止它。因此,Gab 要麼根本沒有任何 SAST 工具,要麼故意選擇忽略他們的反饋。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"也有人認爲 CTO 不會關注這種細節,CTO 應該專注於戰略思維,同時讓公司中的一到兩位開發人員負責日常工作,針對此類基本問題進行代碼審查。大部分企業中,CTO 的確屬於高級管理人員,善用高層次、有遠見的思維制定戰略,並擔任企業中非常有影響力的溝通者角色。但這種情況不適合 Gab,因爲 Gab 總共才只有 26 名員工,那麼 CTO 就應該是該領域內對技術最熟練的人,同時也應該爲項目的交付流程負責。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這件事情發生後,Marotto 不僅刪除了 Gab 的代碼庫,連帶刪除了他之前在 Facebook 裏負責的 Parse 工具的安全代碼。這個 SQL 注入是個新手級別的錯誤,Gab 團隊原來的代碼是正確的,反而是被 CTO 搞砸了,很明顯,Gab 沒有聘請到正確的人。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"延伸閱讀:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/arstechnica.com\/gadgets\/2021\/03\/rookie-coding-mistake-prior-to-gab-hack-came-from-sites-cto\/","title":"","type":null},"content":[{"type":"text","text":"https:\/\/arstechnica.com\/gadgets\/2021\/03\/rookie-coding-mistake-prior-to-gab-hack-came-from-sites-cto\/"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/news.ycombinator.com\/item?id=26319649","title":"","type":null},"content":[{"type":"text","text":"https:\/\/news.ycombinator.com\/item?id=26319649"}]}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章