写在前面
这篇文章是关于作者学习2021版owasp top 10的笔记
原文(英文)的地址是:owasp-top-ten
在我个人看来,了解这份报告,一个目的是为了面试(笑),另一个目的是方便确定代码审计的切入点,关于这一点,我在文章最后进行了一个总结,这个总结可能不够全面,哪位朋友有意见或疑惑可以留言或联系h3llow0rld@foxmail.com
漏洞列表
顺序 | 漏洞 |
---|---|
1 | Broken Access Control |
2 | Cryptographic Failures |
3 | Injection |
4 | Insecure Design |
5 | Security Misconfiguration |
6 | Vulnerable and Outdated Components |
7 | Identification and Authentication Failures |
8 | Software and Data Integrity Failures |
9 | Security Loggin and Monitoring Failures |
10 | Server-Side Request Forgery |
漏洞详情
Broken Access Control
漏洞描述
- 违背最小权限原则或默认拒绝原则,本来只能允许特定capabilities,roles,user,但是所有人都能访问
- 通过修改url(参数伪造或强制浏览),内部应用状态,或者通过使用工具修改api请求来绕过访问控制检查
- 通过提交其他用户的独特标识参数来访问或编辑他人账户(IDOR)
- POST,PUT,DELETE方法的请求缺少访问控制
- 垂直越权。未登录使用登陆用户功能,普通用户登录使用管理员功能
- 元数据操纵,譬如重放或伪造JWT,或者操纵cookie或隐藏字段来进行提权或滥用JWT失效机制
- CORS错误配置导致允许来自未授权或不信任域的请求访问api
- 作为未认证用户浏览需要认证的页面,或则作为标准用户浏览特权用户的页面
表现形式
CWE-22 Improper Limitation of a Pathname to a Restricted Directory (‘Path Traversal’)
CWE-23 Relative Path Traversal
CWE-35 Path Traversal: ‘…/…//’
CWE-59 Improper Link Resolution Before File Access (‘Link Following’)
CWE-200 Exposure of Sensitive Information to an Unauthorized Actor
CWE-201 Exposure of Sensitive Information Through Sent Data
CWE-219 Storage of File with Sensitive Data Under Web Root
CWE-264 Permissions, Privileges, and Access Controls (should no longer be used)
CWE-275 Permission Issues
CWE-276 Incorrect Default Permissions
CWE-284 Improper Access Control
CWE-285 Improper Authorization
CWE-352 Cross-Site Request Forgery (CSRF)
CWE-359 Exposure of Private Personal Information to an Unauthorized Actor
CWE-377 Insecure Temporary File
CWE-402 Transmission of Private Resources into a New Sphere (‘Resource Leak’)
CWE-425 Direct Request (‘Forced Browsing’)
CWE-441 Unintended Proxy or Intermediary (‘Confused Deputy’)
CWE-497 Exposure of Sensitive System Information to an Unauthorized Control Sphere
CWE-538 Insertion of Sensitive Information into Externally-Accessible File or Directory
CWE-540 Inclusion of Sensitive Information in Source Code
CWE-548 Exposure of Information Through Directory Listing
CWE-552 Files or Directories Accessible to External Parties
CWE-566 Authorization Bypass Through User-Controlled SQL Primary Key
CWE-601 URL Redirection to Untrusted Site (‘Open Redirect’)
CWE-639 Authorization Bypass Through User-Controlled Key
CWE-651 Exposure of WSDL File Containing Sensitive Information
CWE-668 Exposure of Resource to Wrong Sphere
CWE-706 Use of Incorrectly-Resolved Name or Reference
[CWE-862 Missing Authorization](https://cwe.mitre.org/data/definitions/862.html
CWE-863 Incorrect Authorization
CWE-913 Improper Control of Dynamically-Managed Code Resources
CWE-922 Insecure Storage of Sensitive Information
CWE-1275 Sensitive Cookie with Improper SameSite Attribute
怎么防护
访问控制只能设置在可信任的服务端代码或server-less API
- 除了公共资源,其他资源都遵守默认拒绝原则
- 在整个应用程序中一次性实现访问控制机制并重复使用,包括尽量减少跨域资源共享(CORS)的使用
- 模型(指特定记录模型,例如数据库条目)访问控制应当强制执行记录所有权,而不是接受用户可以创建、读取、更新或删除任何记录
- 特定业务的业务限制要求应该由领域模型(domain model)强制执行
- 禁用web服务器目录列表,确保文件元数据或备份不在web根目录
- 记录登陆失败请求,满足监视条件则告警管理员
- 限制API速度和控制访问,最小化自动攻击工具带来的破坏
- 在服务器存储的状态session标识符应该在log out后销毁。无状态的JWT应该设置短的存活时间。对于存活时间较长的JWT,建议遵守OAuth标准撤销访问权限
Cryptographic Failures
漏洞描述
- 数据明文传输和存储
- 默认使用过时的或薄弱的加密算法
- 使用默认的加密密钥,生成的加密密钥太简单,或者重复使用加密密钥,缺少正确的加密密钥管理和轮换,将加密密钥在源代码中硬编码
- 未强制进行加密,缺少安全请求标头
- 未正确校验接收服务器证书和信任链
- 在没有密码基本密钥派生函数的情况下将密码作为加密密钥使用
- 忽略、重复使用或者使用不够安全的初始化向量。使用不安全的操作模式,例如ECB。在需要认证加密时使用了普通加密
- 使用废弃的哈希函数,如md5或sha1。在需要加密哈希函数的时候使用非加密哈希函数
- 使用废弃的加密填充方法,例如PKCS number 1 v1.5
- 密码错误信息或边信道信息被利用,例如Oracle填充攻击
表现形式
CWE-261 Weak Encoding for Password
CWE-296 Improper Following of a Certificate’s Chain of Trust
CWE-310 Cryptographic Issues
CWE-319 Cleartext Transmission of Sensitive Information
CWE-321 Use of Hard-coded Cryptographic Key
CWE-322 Key Exchange without Entity Authentication
CWE-323 Reusing a Nonce, Key Pair in Encryption
CWE-324 Use of a Key Past its Expiration Date
CWE-325 Missing Required Cryptographic Step
CWE-326 Inadequate Encryption Strength
CWE-327 Use of a Broken or Risky Cryptographic Algorithm
CWE-328 Reversible One-Way Hash
CWE-329 Not Using a Random IV with CBC Mode
CWE-330 Use of Insufficiently Random Values
CWE-331 Insufficient Entropy
CWE-335 Incorrect Usage of Seeds in Pseudo-Random Number Generator(PRNG)
CWE-336 Same Seed in Pseudo-Random Number Generator (PRNG)
CWE-337 Predictable Seed in Pseudo-Random Number Generator (PRNG)
CWE-338 Use of Cryptographically Weak Pseudo-Random Number Generator(PRNG)
CWE-340 Generation of Predictable Numbers or Identifiers
CWE-347 Improper Verification of Cryptographic Signature
CWE-523 Unprotected Transport of Credentials
CWE-720 OWASP Top Ten 2007 Category A9 - Insecure Communications
CWE-757 Selection of Less-Secure Algorithm During Negotiation(‘Algorithm Downgrade’)
CWE-759 Use of a One-Way Hash without a Salt
CWE-760 Use of a One-Way Hash with a Predictable Salt
CWE-780 Use of RSA Algorithm without OAEP
[CWE-818 Insufficient Transport Layer Protection](https://cwe.mitre.org/data/definitions/818.html
CWE-916 Use of Password Hash With Insufficient Computational Effort
如何防护
- 根据法律法规和业务需要确定哪些数据是敏感的
- 如非必要不存储敏感数据
- 确保对所有静态的敏感数据加密
- 使用strong的标准算法,协议和加密密钥,进行正确的密钥管理
- 使用安全协议传输数据,强制加密使用指令HSTS
- 禁止缓存包含敏感数据的响应
- 对每一种数据都实施安全控制
- 不要使用ftp或smtp这种旧协议传输敏感数据
- 使用强适应性和加盐的哈希函数存储密码,并设置工作因子(延迟因子),例如 Argon2、scrypt、bcrypt 或 PBKDF2。
- 根据操作模式正确的选择初始化向量。任何情况下,都不能对一个固定密钥使用两次相同的初始向量
- 使用认证加密而不是仅加密
- 密钥应该使用随机加密算法生成并且作为字节数组存储在内存。如果使用密码,则必须通过适当的基于密码的密钥派生函数将其转换为密钥
- 避免使用废弃的加密函数和填充协议,比如MD5, SHA1, PKCS number 1 v1.5 .
- 对配置和设置的有效性分别进行独立验证
Injection
漏洞描述
- 应用未对用户提供的数据进行验证,过滤或净化
- 动态查询或非参数化调用在没有上下文感知转义的情况下直接在解释器中使用。
- 恶意数据被用于对象关系映射(ORM)搜索参数中,以提取额外的敏感记录。
- 恶意数据被直接使用或连接。SQL 或命令在动态查询、系统命令或存储过程中包含结构和恶意数据。
表现形式
CWE-20 Improper Input Validation
CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component (‘Injection’)
CWE-75 Failure to Sanitize Special Elements into a Different Plane (Special Element Injection)
CWE-77 Improper Neutralization of Special Elements used in a Command (‘Command Injection’)
CWE-78 Improper Neutralization of Special Elements used in an OS Command (‘OS Command Injection’)
CWE-79 Improper Neutralization of Input During Web Page Generation (‘Cross-site Scripting’)
CWE-80 Improper Neutralization of Script-Related HTML Tags in a Web Page (Basic XSS)
CWE-83 Improper Neutralization of Script in Attributes in a Web Page
CWE-87 Improper Neutralization f Alternate XSS Syntax
CWE-88 Improper Neutralization of Argument Delimiters in a Command (‘Argument Injection’)
CWE-89 Improper Neutralization of Special Elements used in an SQL Command (‘SQL Injection’)
CWE-90 Improper Neutralization of Special Elements used in an LDAP Query (‘LDAP Injection’)
CWE-91 XML Injection (aka Blind XPath Injection)
CWE-93 Improper Neutralization of CRLF Sequences (‘CRLF Injection’)
CWE-94 Improper Control of Generation of Code (‘Code Injection’)
CWE-95 Improper Neutralization of Directives in Dynamically Evaluated Code (‘Eval Injection’)
CWE-96 Improper Neutralization of Directives in Statically Saved Code (‘Static Code Injection’)
CWE-97 Improper Neutralization of Server-Side Includes (SSI) Within a Web Page
CWE-98 Improper Control of Filename for Include/Require Statement in PHP Program (‘PHP Remote File Inclusion’)
CWE-99 Improper Control of Resource Identifiers (‘Resource Injection’)
CWE-100 Deprecated: Was catch-all for input validation issues
[CWE-113 Improper Neutralization of CRLF Sequences in HTTP Headers (‘HTTP Response Splitting’)](https://cwe.mitre.org/data/definitions/113.html
CWE-116 Improper Encoding or Escaping of Output
CWE-138 Improper Neutralizaton of Special Elements
CWE-184 Incomplete List of Disallowed Inputs
CWE-470 Use of Externally-Controlled Input to Select Classes or Code (‘Unsafe Reflection’)
CWE-471 Modification of Assumed-Immutable Data (MAID)
CWE-564 SQL Injection: Hibernate
CWE-610 Externally Controlled Reference to a Resource in Another Sphere
CWE-643 Improper Neutralization of Data within XPath Expressions (‘XPath Injection’)
CWE-644 Improper Neutralization of HTTP Headers for Scripting Syntax
CWE-652 Improper Neutralization of Data within XQuery Expressions (‘XQuery Injection’)
CWE-917 Improper Neutralization of Special Elements used in an Expression Language Statement (‘Expression Language Injection’)
如何防护
- 首选的做法是使用安全的API,这样可以完全避免使用解释器,提供参数化接口,或迁移到对象关系映射工具(ORM)
注意:即使使用了参数化存储过程,如果PL/SQL或T-SQL在查询和数据中进行连接或使用EXECUTE IMMEDIATE或exec()执行恶意数据,仍然可能引入SQL注入。 - 使用积极的服务端输入校验,但这不是一个彻底的防护,因为许多应用需要接受特殊字符,比如文本区域或移动端应用的APIs
- 对于任何的动态查询,请使用该解释器特定的转义语法对特殊字符进行转义。
注意:SQL结构(如表名、列名等)不能被转义,因此用户提供的结构名称是危险的。这在报表编写软件中是一个常见的问题。 - 在查询中使用limit或其他sql控制子句来预防sql注入导致记录批量泄漏
Insecure Design
漏洞描述
表现形式
如何防护
Security Misconfiguration
漏洞描述
- 应用堆栈的任意部分缺少恰当的安全加固,或者云服务权限配置不当
- 允许或安装了不必要的功能(譬如:不必要的端口,服务,页面,账户,权限
- 默认账户和密码任然保留且尚未修改
- 错误处理向用户泄漏堆栈追踪或其他包含过量信息的错误信息
- 对于更新后的系统,最新的安全功能被禁止了,或者没有安全地配置
- 在应用服务器,应用框架,库,数据库或其他组件中,安全设置项没有设置为安全的属性值
- 服务器没有发送安全标头或指令,或者这些属性没有设置为安全值
- 使用的软件过时了或者是有漏洞的
表现形式
CWE-11 ASP.NET Misconfiguration: Creating Debug Binary
CWE-13 ASP.NET Misconfiguration: Password in Configuration File
CWE-15 External Control of System or Configuration Setting
CWE-260 Password in Configuration File
CWE-315 Cleartext Storage of Sensitive Information in a Cookie
CWE-520 .NET Misconfiguration: Use of Impersonation
CWE-526 Exposure of Sensitive Information Through Environmental Variables
CWE-537 Java Runtime Error Message Containing Sensitive Information
CWE-541 Inclusion of Sensitive Information in an Include File
CWE-547 Use of Hard-coded, Security-relevant Constants
CWE-611 Improper Restriction of XML External Entity Reference
CWE-614 Sensitive Cookie in HTTPS Session Without ‘Secure’ Attribute
CWE-756 Missing Custom Error Page
CWE-776 Improper Restriction of Recursive Entity References in DTDs (‘XML Entity Expansion’)
CWE-942 Permissive Cross-domain Policy with Untrusted Domains
CWE-1004 Sensitive Cookie Without ‘HttpOnly’ Flag
CWE-1032 OWASP Top Ten 2017 Category A6 - Security Misconfiguration
CWE-1174 ASP.NET Misconfiguration: Improper Model Validation
如何防护
- 开发、质量保证(QA)和生产环境应配置相同,但每个环境使用不同的凭据
- 移除或别安装不使用的功能和框架
- 作为补丁管理流程的一部分,需要执行任务来审查和更新所有安全说明、更新和补丁相关的配置(参见A06:2021-易受攻击和过时的组件)。审查云存储权限(例如,S3桶权限)
- 分段的应用架构通过分段、容器化或云安全组(ACLs)在组件或用户之间提供有效且安全的隔离。
- 向客户端发送安全指令,譬如安全标头
- 实现用于校验所有环境配置和设置的有效性的自动化流程
Vulnerable and Outdated Components
漏洞描述
- 使用的软件是有漏洞的,不再支持的,或过期的
- 没有定期扫描漏洞和订阅你使用的组件的安全补丁
- 没有基于风险及时修复或升级底层平台、框架和依赖关系。这种情况通常发生在根据变更控制每月或每季度都要打补丁的环境中,这会让企业在数天或数月内不必要地暴露于已修复的漏洞。
- 没有测试更新,升级或补丁的兼容性
- 没有安全地配置组件
表现形式
如何防护
- 移除不使用的依赖,不必须的功能,组件,文件和文档
- 使用工具持续关注服务端和客户端使用的组件和它们的依赖的版本。持续关注漏洞平台关于自己所使用的组件的漏洞
- 只从官方安全渠道获取组件,推荐对包进行签名,减少包含修改过的,恶意组件的机会
- 监控那些未维护或不为旧版本创建安全补丁的库和组件。如果无法进行补丁修复,考虑部署虚拟补丁来监控、检测或防护已发现的问题。
Identification and Authentication Failures
漏洞描述
- 允许爆破
- 允许使用默认密码或弱口令
- 使用脆弱或无效的凭据恢复和忘记密码流程,比如基于预设置问题是不安全的
- 明文存储密码,或者使用脆弱的哈希函数处理密码
- 多重身份验证缺失或无效
- 在url暴露会话标识符
- 成功登录后重复使用会话标识符
- 无法正确使会话ID失效。用户会话或认证凭据(主要是单点登录凭据)在退出或一段时间不活跃后不能正确失效
表现形式
CWE-255 Credentials Management Errors
CWE-259 Use of Hard-coded Password
CWE-287 Improper Authentication
CWE-288 Authentication Bypass Using an Alternate Path or Channel
CWE-290 Authentication Bypass by Spoofing
CWE-294 Authentication Bypass by Capture-replay
CWE-295 Improper Certificate Validation
CWE-297 Improper Validation of Certificate with Host Mismatch
CWE-300 Channel Accessible by Non-Endpoint
CWE-302 Authentication Bypass by Assumed-Immutable Data
CWE-304 Missing Critical Step in Authentication
CWE-306 Missing Authentication for Critical Function
CWE-307 Improper Restriction of Excessive Authentication Attempts
CWE-346 Origin Validation Error
CWE-521 Weak Password Requirements
CWE-613 Insufficient Session Expiration
CWE-620 Unverified Password Change
CWE-640 Weak Password Recovery Mechanism for Forgotten Password
CWE-798 Use of Hard-coded Credentials
CWE-940 Improper Verification of Source of a Communication Channel
CWE-1216 Lockout Mechanism Errors
如何防护
- 推荐使用多重身份验证来避免爆破,窃取身份凭据重复使用的情景
- 不要在交付或部署中使用任何默认凭据
- 实现脆弱密码检查
- 使用安全指导标准来设置密码长度,复杂度和轮换策略
- 使用统一的错误回复消息避免泄露信息
- 在登陆失败后限制登陆或提高登陆的延迟。但是要注意避免dos场景。记录登陆失败尝试,检测到攻击时告警管理员
- 使用服务端,安全的,内置的session管理器生成随机的,不可伪造的session ID。会话标识符不能再url中包含。在退出,空闲或超时后正确的对会话ID进行失活处理
Software and Data Integrity Failures
漏洞描述
- 使用不可靠的软件源,仓库,或CDNs。
- 使用不安全的CI/CD pipline
- 软件的自动更新功能也可能导致(该功能是依赖于以前的校验结果,无法确保未来的结果
表现形式
CWE-345 Insufficient Verification of Data Authenticity
CWE-353 Missing Support for Integrity Check
CWE-494 Download of Code Without Integrity Check
CWE-502 Deserialization of Untrusted Data
CWE-565 Reliance on Cookies without Validation and Integrity Checking
CWE-784 Reliance on Cookies without Validation and Integrity Checking in a Security Decision
CWE-829 Inclusion of Functionality from Untrusted Control Sphere
CWE-830 Inclusion of Web Functionality from an Untrusted Source
CWE-915 Improperly Controlled Modification of Dynamically-Determined Object Attributes
如何防护
- 使用数字签名,或类似的机制去验证软件或数据是来自可靠的源头,并且没有被更改
- 确保库或依赖来自可靠的仓库。如果有更高的risk profile,考虑搭建一个经过审查的内部仓库
- 使用软件供应链安全工具来确保使用的组件没有包含一致的漏洞
- 对代码和配置的更改进行review
- 保证CI/CD环境正确的分段,配置和访问控制来保证代码流的完整性
- 确保未签名或未加密的序列化数据在没有进行完整性检查或数字签名之前不发送到不受信任的客户端来防护序列化数据的伪造和重放
Security Loggin and Monitoring Failures
漏洞描述
- 值得审计的事件,例如登陆,登陆失败和高额交易没有记录
- 警告和错误没有生成,或者生成不充分或不清晰的log信息
- APPs和APIs的日志没有监控可疑活动
- 日志只在本地存储
- 合适的告警阈值和响应升级流程未到位或无效
- 渗透测试和扫描工具的使用未触发警报
- 应用不能对活跃的攻击进行实时检测,响应升级或者告警
表现形式
CWE-117 Improper Output Neutralization for Logs
CWE-223 Omission of Security-relevant Information
CWE-532 Insertion of Sensitive Information into Log File
如何防护
- 确保所有登陆,访问控制和服务端输入校验失败都能生成日志并且保存用户文本用于识别可以或恶意账户,以及为之后的取证分析留下样本
- 确保日志是以某种统一格式生成的,这样日志管理更轻松
- 确保日志数据是正确编码的,防止对生成日志和监控系统的注入或攻击
- 确保对高额交易有完整性控制的审计追踪来防止伪造或删除,例如应用只追加数据库表或类似的方法
- 安全团队应该建立有效的监控和告警系统来检测可疑活动并且迅速响应
- 建立或应用突发事件响应和恢复计划,例如NIST800-61r2或之后的标准
Server-Side Request Forgery
漏洞描述
表现形式
如何防护
网络层
- 将远程资源访问功能划分到独立网络中,减少SSRF的影响(隔离
- 强制执行默认拒绝的防火墙策略或网络访问控制规则,以阻止除基本内部网流量外的所有流量
- 根据应用程序建立防火墙规则的所有权和生命周期
- 记录防火墙上所有被接受和被阻止的网络流量
应用层 - 净化和校验所有用户输入数据
- 使用白名单机制强制限定接受的url协议,端口和目的地
- 不要向客户端发送raw responses(避免被根据报错来修改攻击payload
- 禁止http重定向
- 识别url的一致性,避免如DNS重绑定和“time of check,time of use”(TOCTOU)条件竞争等攻击
总结
在学习了这一份报告后,我们在审计一个项目时,可以考虑从以下方面入手
- 系统的访问控制机制
- 系统提供的api是否能接受不同的http方法的请求?
- 系统的CORS配置是什么?有无漏洞?
- 能不能直接访问系统的后台界面?
- 系统的认证和授权框架
- 是自己实现的还是知名框架?
- 如果是自己实现的,仔细检查流程,很可能有错误
- 如果是知名框架,用的是哪个版本?是否有漏洞?
- 客户端是否能够进行爆破操作?
- 限制爆破使用的什么机制?验证码还是锁定账号?如果锁定账号又是什么机制?
- 怎么管理session的?session ID能否正确失活?
- 密码是否明文存储?
- 有无默认登陆凭证和弱口令?
- 系统有没有CSRF防护机制?CSRF机制完不完善?
- 系统使用的加密和哈希算法
- 使用的算法是否过时?
- 关键的seed或加密密钥是否硬编码?
- 系统的日志系统
- 是自己实现的?还是知名中间件?
- 如果是自己实现的
- 存不存在针对日志系统的注入攻击?
- 针对异常行为有无记录详细信息?
- 如果是知名中间件,用的是哪个版本?该版本有无漏洞?
- 系统数据的获取和持久化
- 有没有对输入的数据进行净化?
- 系统使用的组件和依赖
- 有没有使用有漏洞版本的组件或依赖
- 使用的组件有什么历史漏洞?这些历史漏洞的安全补丁是什么情况?系统正确的设置了对应的feature了吗
- 系统的响应报文
- 有没有设置安全标头或指令?
- 返回的错误信息有没有泄漏敏感信息
- 系统端的请求和跳转功能
- 有没有SSRF防护机制?防护机制玩不完善?
- 是否存在开放重定向漏洞?
最后我需要说的是上述罗列的方面肯定是不全面的,实际还要根据具体的业务场景具体分析,我列的这些仅供大家参考,希望大家有所收获