:::info 資料整理來源: * [112年教育體系資安教育訓練課程 (講師:翁御舜(敦陽科技資安部門技術處長))](https://tp2rc.tanet.edu.tw/node/652) * 109年度教育體系資安與個資教育訓練 (講師:王耀華、巫嘉勳(資策會資安科技研究所)) [CSSLP證照](https://www.uuu.com.tw/Course/Show/48/CSSLP%E8%B3%87%E5%AE%89%E8%BB%9F%E9%AB%94%E9%96%8B%E7%99%BC%E5%B0%88%E5%AE%B6%E8%AA%8D%E8%AD%89%E8%AA%B2%E7%A8%8B):針對參與軟體開發生命週期(SDLC)所有人員量身訂作的資安證照 ::: :::danger * [Web應用程式安全參考指引](https://download.nics.nat.gov.tw/UploadFile/attachfilecomm/106%E5%B9%B4Web%E6%87%89%E7%94%A8%E7%A8%8B%E5%BC%8F%E5%AE%89%E5%85%A8%E5%8F%83%E8%80%83%E6%8C%87%E5%BC%95(%E4%BF%AE%E8%A8%82)v2.1_1101231.rar) * [資通系統防護基準驗證實務](https://download.nics.nat.gov.tw/UploadFile/attachfilecomm/%e8%b3%87%e9%80%9a%e7%b3%bb%e7%b5%b1%e9%98%b2%e8%ad%b7%e5%9f%ba%e6%ba%96%e9%a9%97%e8%ad%89%e5%af%a6%e5%8b%99(V1.1)_1110928.rar) * [OWASP Top 10 Proactive Controls](https://top10proactive.owasp.org/) * 為了讓開發人員在專案之初始階段便具備完整之資安防護概念與實作概念,OWASP Top 10 Proactive Controls 提供針對開發人員了解於每個軟體開發項目均應包含之安全技術 ::: [toc] # 背景 * 弱點來源 * 網路層:佔7成,有2%是高風險弱點 * 應用層:佔3成,有20%是高風險弱點 * 軟體開發的困境 * 功能需求第一 * 專案時程趕工 * 基於以上,安全性需求往往會被犧牲(無視) * 軟體開發基礎 * 版本控管 * 組態管理 * 資產管理:SBOM表(軟體物料清單) * [企業導入SBOM軟體物料清單有六大常見迷思的考驗](https://www.ithome.com.tw/news/164109) * [dependency track](https://dependencytrack.org/) * 變更管理 # SSDLC方法論 * [Microsoft SDL](https://learn.microsoft.com/zh-tw/windows/security/threat-protection/msft-security-dev-lifecycle) ![](https://hackmd.io/_uploads/r1qJeXTdh.png) * OWASP - Comprehensive, Lightweight Application Security Process(CLASP) * [Cigital's Security **Touchpoints**](http://www.swsec.com/resources/touchpoints/) ![](https://hackmd.io/_uploads/S1enyQpO2.png) * NIST SP 800-160 * [(Vol.1)Engineering Trustworthy Secure Systems](https://csrc.nist.gov/publications/detail/sp/800-160/vol-1-rev-1/final) * [(Vol.2)Developing Cyber-Resilient Systems: A Systems Security Engineering Approach](https://csrc.nist.gov/publications/detail/sp/800-160/vol-2-rev-1/final) * 行政院國家資通安全會報技術服務中心-資訊系統安全強化要點 ![](https://hackmd.io/_uploads/ByNgDBaO2.png) # 軟體安全成熟度 * 新思科技(Synopsys) - Building Security In Maturity Model(BSIMM) * OWASP - Security Assurance Maturity Model(SAMM) # (1)需求分析:發展及萃取安全需求 :::info 可直接套規範要求:附表十、資通系統防護基準(七大構面) ::: * 外部需求 * 法規遵循:國內外相關安全標準或法規 * [個資法](https://law.moj.gov.tw/LawClass/LawAll.aspx?PCode=I0050021) * [資安責任等級分級辦法](https://law.moj.gov.tw/LawClass/LawAll.aspx?pcode=A0030304),重點在附表十==防護基準== * ISO27001 ==新版要求A.8.28== * [PCIDSS](https://www.microfocus.com/media/report/2019-application-security-risk-report.pdf) * 業界標準:業界遵循之標準或Best Practice * OWASP * NIST * CWE * 內部需求 * 資安政策 * 業務需求 * 事件案例 * 營運衝擊分析(BIA):識別RTO/RPO。 * 一般性安全需求(==軟體安全特性==):機密性、完整性、可用性、身分認證(鑑別)、授權、稽核、會話管理、錯誤及例外處理、組態管理。 * 需求追蹤管理:需求追溯矩陣(Requirements Traceability Matrix, RTM) # (2)設計階段:設定安全控制項 (風險控管) * 資產盤點:了解你要保護什麼 (系統分級評估) * 風險分析及處理 * 整理Attack Surfaces * API介面安全 * 方法論:威脅模型(Threat Modeling)分析 ![](https://hackmd.io/_uploads/SyeeuvSpd3.png) * [STRIDE](https://zh.wikipedia.org/zh-tw/STRIDE) (威脅分類模型) > [[ITHome]別讓你的程式布滿弱點](https://www.ithome.com.tw/node/46781) ![](https://hackmd.io/_uploads/Bk90Prp_2.png) * [DREAD](https://en.wikipedia.org/wiki/DREAD_(risk_assessment_model)) (威脅排序) > ![](https://hackmd.io/_uploads/Hk74uHTun.png) * 工具:[Microsoft Threat Modeling Tool](https://learn.microsoft.com/zh-tw/azure/security/develop/threat-modeling-tool-getting-started) * 安全設計準則 * External Systems are Insecure (零信任,系統外部不安全) > 對於任何使用者的輸入都要先白名單過濾後,再過濾黑名單。 > 所以檢查都要在伺服器端做,JavaScript的過濾會被Bypass掉。 > ![](https://hackmd.io/_uploads/H1_lprTdh.png) * Minimize Attack Surface Area (縮小可攻擊的面) > * 增加暴力破解(字典檔攻擊)的難度 > * 帳號鎖定機制 > * 密碼強度檢查 > * 圖形驗證碼 > * 多因子認證 > * 密碼定期更換政策實作 > ![](https://hackmd.io/_uploads/SkhA_Sa_n.png) > * 密碼重設機制 > ![](https://hackmd.io/_uploads/Syy_9Sp_n.png) * Secure Defaults (初始狀態是安全的) > * 登出實作 > * 清除所有存放於後端的session 資料 > * 讓session token 失效 * Least Privilege (最小權限) * Separation of Duties (權限分離) > 將一件機敏的動作權限分散給多人 * Defense in Depth (縱深防禦) > 逐層防範 * Fail Securely (安全故障) > 使用Exception handling blocks (try-catch) > 只呈現簡易的錯誤資訊 > 詳細技術資訊寫入後端日誌 * Do not trust Security through Obscurity * Simplicity (程式碼簡單易懂) * [安全軟體設計參考指引](https://download.nics.nat.gov.tw/UploadFile/attachfilecomm/103%E5%B9%B4%E5%AE%89%E5%85%A8%E8%BB%9F%E9%AB%94%E8%A8%AD%E8%A8%88%E5%8F%83%E8%80%83%E6%8C%87%E5%BC%95v1.0_1031031.rar) # (3)實作階段:撰寫安全的原始碼、弱點檢核與消弭 * 開發者和攻擊者思維落差,開發者以為很安全,其實不是。 * 語言的選擇 * Type-safe languages會比較安全 * 防護建議 * 程式原始碼採用版本控制管理 * 權限控制失效(Broken Access Control) * 防止重要網頁被直接存取 * 限制存取身份和權限 * 限制存取的IP * 不安全的物件參考(Insecure Direct Object Reference, IDOR) ![](https://hackmd.io/_uploads/rJRb5waOh.png) * OWASP TOP 10 - 2010-A4-不安全的物件參考 - 2013-A4-不安全的物件參考 - 2017-A5-無效的存取控管 - 2021-A1-權限控制失效 * 不是技術性漏洞、是邏輯性漏洞,WAF無法有效防範 * 最佳解法:index value or a reference map * 確認輸的檔案路徑位在所允許的合理範圍內 * [Insecure Direct Object Reference Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Insecure_Direct_Object_Reference_Prevention_Cheat_Sheet.html) * 身份認證 * [Authentication Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html) * 密碼不要存明文到資料庫裡,要變形後再儲存,建議採用==雜湊(Hash)==的方式 * 雜湊的結果是固定長度的字串 * 單向(One-way)推導 * Collision-free:沒有人能找出hash collision的可能 * Hash演算法,請使用通過過際標準的演算法:Sha512、… * 為避免Rainbow Table Attack,建議加入亂數字串(Salt)再雜湊(Hashing) * 第三方軟體元件 * 儘量用最新的的,避免已知漏洞 * 常檢視相關最新資安訊息 * Exploit DB * CVE/NVD/SNYK... * 官方Release Note * 弱點掃描工具 * [OWASP Dependency-Check](https://owasp.org/www-project-dependency-check/) * [Retrie.js](https://retirejs.github.io/retire.js/) * [composer audit](https://php.watch/articles/composer-audit) :掃描PHP Composer套件中已知漏洞的工具 * pip-audit :掃描Python環境中已知漏洞的工具 * npm-audit :掃描Node環境中已知漏洞的工具 * govulncheck :掃描Go環境中已知漏洞的工具 * SQL Injection * [SQL Injection Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html) * 透過SQL Injection植入WebShell是可能的。 * 透過SQL Injection可進行掛馬攻擊。 * 防範措施 * 建議白名單(長度+合法字元) > 黑名單 > 資料消毒 (在後端PHP做,只作前端Javascript的驗證是有可能會被繞過的) * 改寫成Prepared Statement * 資料庫連線最小化權限原則 * XSS * [Cross Site Scripting Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html) * 可掛馬攻擊、釣魚等 * 輸出轉換:將特殊字元先編碼再輸出,讓瀏覽器以資料方式處理。(HTML Encoding、URL Encoding) * HTTP Response 表頭設定 * 輸出設定為純文字 * Secure Random Number Generation | Language | Unsafe Functions | Cryptographically Secure Functions | | -------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------- | | **JAVA** | `java.util.Random()` | [`java.security.SecureRandom`](https://docs.oracle.com/javase/8/docs/api/java/security/SecureRandom.html) | | **PHP** | `rand()`, `mt_rand()`, <br>`array_rand()`, `uniqid()` | [`random_bytes()`](https://www.php.net/manual/en/function.random-bytes.php), [`random_int()`](https://www.php.net/manual/en/function.random-int.php) in PHP 7 or <br>`openssl_random_pseudo_bytes()` in PHP 5 | | **.NET/C#** | `Random()` | [`RandomNumberGenerator`](https://cheatsheetseries.owasp.org/cheatsheets/Cryptographic_Storage_Cheat_Sheet.html) | |**Node.JS**| `Math.random()` | `crypto.randomBytes`, `crypto.randomInt`, `crypto.randomUUID` | |**Python**| `random()` | `secrets()` | * 軟體及資料完整性 * 供應鏈攻擊(Supply Chain Attack):js引用來源若透過cdn的方式,只要cdn的來源端有受攻擊或汙染,下游使用方也會被影響。 * 不安全的反序列化 (Insecure Deserialization) > [Deserialization Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html) * [Cross-Site Request Forgery Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html) * [Server-Side Request Forgery Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html) * 檔案上傳的資安風險 * 重點在如何避免被上傳web shell,進而造成RCE(Remote Code Execution) * [Why File Upload Forms are a Major Security Threat](https://www.acunetix.com/websitesecurity/upload-forms-threat/) * 上傳時,要進行後端輸入檢驗,採白名單檢查,儲存時更名。 * 連結時,用間接參考的方式去取得所上傳的檔案。 * 關閉存放目錄的執行權限。 * 源碼檢測工具 * 兩種方式:做完再測、整合IDE邊做邊測 * 誤報機率很大,需要專案解讀 # (4)測試階段:驗證安全性需求 * 環境 * 整合測試環境 * Staging環境 * 重點 * 自行開發:預留人力及時程 * 外包:建議於契約中要求 * 測試前最好先備份資料 * 方式 * 基本檢測 * 功能測試:透過「需求追溯矩陣(RTM)」去做情境案例測試 * 壓力測試(效能測試) * 自動化工具(弱點掃描) * 系統面:Nessus、OpenVas、Rapid7、… * 網站面:Acunetix、AppScan、WebInspect、OWASP ZAP、… * 綜合檢測(滲透測試) * 模擬駭客的人為攻擊 * 測試準則 * [CWE Top 25](https://cwe.mitre.org/top25/archive/2023/2023_top25_list.html) * [SANS SWAT Checklist](https://www.sans.org/cloud-security/securing-web-application-technologies/) * [OWASP Application Security Verification Standard (ASVS)](https://owasp.org/www-project-application-security-verification-standard/):為開發人員提供了安全開發的要求列表 * [OWASP Web Security Testing Guide (WSTG)](https://owasp.org/www-project-web-security-testing-guide/):提供給滲透測試人員測試框架 * ISO 29119:軟體測試標準 * [安全軟體測試參考指引](https://download.nics.nat.gov.tw/UploadFile/attachfilecomm/103%E5%B9%B4%E5%AE%89%E5%85%A8%E8%BB%9F%E9%AB%94%E6%B8%AC%E8%A9%A6%E5%8F%83%E8%80%83%E6%8C%87%E5%BC%95v1.0_1031231.rar) # (5)部署建置階段:主機環境強化、縱深防禦機制 ## 作業系統組態層次 * 作業系統層次設定 * 修改預設登入帳密 * 關閉不必要的網路服務(service ports) * 各主機時間確實同步(NTP啟用) * 資料庫組態 * 修改預設登入帳密 * 最小權限化 ## 伺服器環境組態層次 * Web伺服器設定調整 * [Apache限制POST/GET的方法](https://www.tenable.com/audits/items/CIS_Apache_HTTP_Server_2.2_Benchmark_v3.6.0_Level_1_Middleware.audit:f4ce14bc78d35c29156acb014d3a0530) * [關閉Directory Listing](https://www.simplified.guide/apache/disable-directory-listing) * SSL設定建議 > [Testing TLS/SSL encryption](https://testssl.sh/) > [密碼套件(Cipher suite)](https://zh.wikipedia.org/zh-tw/%E5%AF%86%E7%A0%81%E5%A5%97%E4%BB%B6) > [IIS Crypto 軟體說明](https://hackmd.io/@Not/rJ52Vrp_v) * 可以的話,請關閉Renegotiation * [F5 SSL Renegotiation](https://my.f5.com/manage/s/article/K15278) * [Apache SSLInsecureRenegotiation Directive](https://httpd.apache.org/docs/current/mod/mod_ssl.html#sslinsecurerenegotiation) * 使用TLS v1.2 * [如何在 Apache Server 下停用 SSL 2.0 、 SSL 3.0 、 TLS 1.0](https://lawrencechuang760223.medium.com/%E5%A6%82%E4%BD%95%E5%9C%A8apache-server%E4%B8%8B%E5%81%9C%E7%94%A8ssl2-0-ssl3-0-tls1-0-96120ebb333e) * [你的 HTTPS 連線安全嗎? - 設定篇](https://www.gss.com.tw/blog/set-https-connect-protocols-and-ciphers) * [強化SSL設定](https://github.com/ssllabs/research/wiki/SSL-and-TLS-Deployment-Best-Practices) * [OWASP Transport Layer Protection Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Protection_Cheat_Sheet.html) * 加密長度1024以上 * 記得關閉非SSL的存取管道 * [資安相關HTTP Headers](https://devco.re/blog/2014/03/10/security-issues-of-http-headers-1/) ## 程式語言層次 * OWASP Cheat Sheet * [Configuration Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/PHP_Configuration_Cheat_Sheet.html) * [Laravel Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Laravel_Cheat_Sheet.html) * 避免XXE弱點:Disable DTD * [OWASP XML External Entity Prevention Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html#php) # (6)維運階段:著重Detection & Correction * 組態管理 * GCB導入 * 變更管理 * 定期弱點修補管理 * 作業系統 * 伺服器 * 程式語言 * 第三方元件 * 日誌稽核管理 > [How OWASP AppSensor leads to improved Logging and Monitoring](https://medium.com/@javan.rasokat/how-owasp-appsensor-leads-to-improved-logging-and-monitoring-8db6ca3914f3) > [OWASP AppSensor Guide](https://owasp.org/www-project-appsensor/) # (7)系統下線:敏感資料要移除