Count down the CWE TOP 25 data from 2019 to 2023, and look at the protection of software defects

This article is shared from the HUAWEI CLOUD community " Looking at the Protection of Software Defects from CWE TOP 25 Data in the Past 5 Years ", author: Uncle_Tom.

 "Taking history as a mirror, we can know the ups and downs." CWE has released CWE TOP 25 for 5 consecutive years. We can look for the development trend of high-risk security vulnerabilities from the changing trend of CWE TOP 25 in the past 5 years, and provide guidance for security policies and investment decisions. The development of tools and programmers are of great significance.

1 Introduction

The most dangerous security flaws of CWE in 2023 have been published: "The 25 Most Threatening Security Vulnerabilities in 2023 (CWE TOP 25)" , which is very important for security personnel and developers of code inspection tools. Since 2019, CWE has released the CWE TOP 25 for five consecutive years. We can look for the development trend of high-risk security vulnerabilities from the change trend of CWE TOP 25 in the past five years, and provide guidance for security policies and investment decisions.

Everyone needs to pay attention to the statistical methods of the Top 25 data of the National Vulnerability Database (NVD) in the United States. New CWE entries, etc. Therefore, there is some bias in the reliability of the ranking due to data bias. For example, adding some CVEs to the data can drastically change the position of CWEs between rankings. This problem is also the problem we have been discussing in the previous discussion about the non-complete orthogonality of CWE definition classification. It is precisely because of this problem that CVE has ambiguity on the issue of CWE attribution, which may lead to the final data. deviation.

In addition, as a defender, you should not only focus on the TOP 25 issues, but need to focus on broader security issues, such as the top 40 or even the top 100 security issues. Because as a defender, the overall defense capability depends on the shortest board of defense. Just like the example I often give: the attacker takes a needle and pokes it in all aspects of your system. As long as there is a weak point, the system will be broken. As a defender, it is necessary to understand every weakness of the defense system of the entire system and take defensive measures. The cost of investment is much higher than that of the attacker.

2. CWE TOP 25 Data Analysis Strategies

In order to have a more comprehensive understanding of the changing trend of CWE TOP 25, we first obtain the data of CWE TOP 25 from 2019 to 2023; at the same time, we will expand the analysis data to TOP 40 to reduce the interference of data deviation brought by statistical data as much as possible. . This data can be obtained from CWE's web page: View historical rank data  .

2.1. 2019-2023 CWE TOP 25 data

CWE ID

CWE description

2019

2020

2021

2022

2023

slope

Trend

CWE-787

Out-of-bounds Write out-of-bounds write

12

2

1

1

1

-2.3

up

CWE-79

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') Improper escaping of input during Web page generation (cross-site scripting)

2

1

2

2

2

0.1

stable

CWE-89

Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')

6

6

6

3

3

-0.9

stable

CWE-416

Use After Free Use After Free

7

8

7

7

4

-0.7

stable

CWE-78

Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')

11

10

5

6

5

-1.6

up

CWE-20

Improper Input Validation Improper input validation

3

3

4

4

6

0.7

stable

CWE-125

Out-of-bounds Read out-of-bounds read

5

4

3

5

7

0.5

stable

CWE-22

Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')

10

12

8

8

8

-0.8

stable

CWE-352

Cross-Site Request Forgery (CSRF) Cross-Site Request Forgery (CSRF)

9

9

9

9

9

0

stable

CWE-434

Unrestricted Upload of File with Dangerous Type Unrestricted upload of dangerous type files

16

15

10

10

10

-1.7

up

CWE-862

Missing Authorization authorization mechanism is missing

36

25

18

16

11

-5.9

rapid_ascent

CWE-476

NULL Pointer Dereference Null pointer dereference

14

13

15

11

12

-0.6

stable

CWE-287

Improper Authentication authentication mechanism is not appropriate

13

14

14

14

13

0

stable

CWE-190

Integer Overflow or Wraparound Integer Overflow or Wraparound

8

11

12

13

14

1.4

stable

CWE-502

Deserialization of Untrusted Data Deserialization of untrusted data

23

21

13

12

15

-2.5

up

CWE-77

Improper Neutralization of Special Elements used in a Command ('Command Injection')

30

31

25

17

16

-4.2

rapid_ascent

CWE-119

Improper Restriction of Operations within the Bounds of a Memory Buffer

1

5

17

19

17

4.6

rapid_decline

CWE-798

Use of Hard-coded Credentials use hard-coded credentials

19

20

16

15

18

-0.7

stable

CWE-918

Server-Side Request Forgery SSRF) Server-Side Request Forgery (SSRF)

32

27

24

21

19

-3.2

rapid_ascent

CWE-306

Missing Authentication for Critical Function The authentication mechanism for critical functions is missing

38

24

11

18

20

-4.2

rapid_ascent

CWE-362

Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition') Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')

31

34

33

22

21

-3.2

rapid_ascent

CWE-269

Improper Privilege Management

24

22

29

29

22

0.3

stable

CWE-94

Improper Control of Generation of Code ('Code Injection') Improper control of generated code (code injection)

18

17

28

25

23

1.8

stable

CWE-863

Incorrect Authorization Authorization mechanism is incorrect

35

29

38

28

24

-2.3

up

CWE-276

Incorrect Default Permissions The default permissions are incorrect

19

20

25

3

down

CWE-617

Reachable Assertion accessible assertion

26

CWE-427

Uncontrolled Search Path Element Uncontrolled Search Path Element

34

27

27

-3.5

rapid_ascent

CWE-611

Improper Restriction of XML External Entity Reference XML External Entity Reference Improper Restriction

17

19

23

24

28

2.7

down

CWE-770

Allocation of Resources Without Limits or Throttling 无限制或未控制地分配资源

39

40

29

-3.64

rapid_ascent

CWE-200

Exposure of Sensitive Information to an Unauthorized Actor 将敏感信息暴露给未经授权的参与者

4

7

20

33

30

7.8

rapid_decline

CWE-732

Incorrect Permission Assignment for Critical Resource 关键资源的权限分配不正确

15

16

22

30

31

4.6

rapid_decline

CWE-601

URL Redirection to Untrusted Site (‘Open Redirect’) URL 指向未可信站点的URL重定向(开放重定向)

34

35

37

35

32

-0.4

stable

CWE-1321

Improperly Controlled Modification of Object Prototype Attributes (‘Prototype Pollution’) 对象原型属性的不当控制修改(原型污染)

34

33

-1

stable

CWE-295

Improper Certificate Validation 证书验证不正确

25

28

26

26

34

1.6

stable

CWE-522

Insufficiently Protected Credentials 凭据保护不足

28

18

21

38

35

3.4

rapid_decline

CWE-401

Missing Release of Memory after Effective Lifetime 使用后内存未释放(内存泄露)

32

32

36

36

1.6

down

CWE-400

Uncontrolled Resource Consumption 不受控制的资源消耗

20

23

27

23

37

3.4

rapid_decline

CWE-639

Authorization Bypass Through User-Controlled Key 通过用户控制密钥绕过授权机制

38

CWE-59

Improper Link Resolution Before File Access (‘Link Following’) 在文件访问前对链接解析不恰当(链接跟随)

40

31

37

39

0.3

stable

CWE-668

Exposure of Resource to Wrong Sphere 将资源暴露在错误的领域

32

40

8

rapid_decline

我们将这些数据通过折线图表示,如下图:

cke_114.png

这个图看起来有些乱,不便于我们找到一些规律,于是我们采用下面的方法,对缺陷排名做个数据分析。

2.2. 斜率

将一个CWE的历年的排名作为纵坐标,将从2019到2023年做为横坐标,通过拟合横坐标和纵坐标形成的点图,可以通过线性拟合的方式得到一条斜线,这条拟合线可以用公式表示:

y = bx + a

其中, b 为数据点的线性回归线的斜率,斜率为垂直距离除以线上任意两个点之间的水平距离,即回归线的变化率。斜率越大可以说明变动越大。

斜率可以通过下面的公式求得:

cke_115.png

这里我们可以利用excle 表格中的 SLOPE 函数求得。计算结果见上表的"斜率"一列。

  • 注意:
  • 斜率为正数:名次变大,表示下降;正的越多,表示下降的越快;
  • 斜率为负数: 名次变小,表示上升;负的越多,表示上升的越快;
  • 斜率为零:名次没有变化。

2.3. 变动趋势

为了衡量斜率波动的大小,我们通过标准差(σ)的范围来衡量波动的大小。标准差可以测量值在平均值(中值)附近分布的范围大小。计算公式如下:

cke_116.png

这个我们也可以借助excel 的 STDEV 函数求得标准差:

σ = 3.11917143

以及斜率的平均值:

avg = 0.064661654

然后我们再将斜率按间隔: 0.5, 统计各个值段的频次,再利用excle 的 NORMDIST 函数, 得到指定平均值和标准偏差的正态分布函数。

  • NORMDIST 函数定义为:NORMDIST(x,mean,standard_dev,cumulative)
  • NORMDIST 函数语法具有下列参数:
    • X, 必需。 需要计算其分布的数值;
    • Mean, 必需。 分布的算术平均值;
    • standard_dev, 必需。 分布的标准偏差;
    • cumulative, 必需。 决定函数形式的逻辑值。 如果 cumulative 为 TRUE,则 NORMDIST 返回累积分布函数;如果为 FALSE,则返回概率密度函数。这里 我们使用cumulative 为 FALSE。
  • 通过计算得到下图:

cke_117.png
  • 通过分析,我们发现:
  • σ = 3.11917143, CWE对应的斜率波动的范围在10名左右;
  • 0.5σ = 1.559585715,CWE对应的斜率波动的范围在5名左右。

由此我们给出了斜率波动幅度的衡量标准:

斜率波动幅度

斜率波动范围

解释

相对稳定(stable)

±0.5σ±0.5σ之间: -1.494924061 < 斜率 < 1.624247369

CWE变动(上升/下降)在5名以内,相对稳定(stable).

上升趋势(up)

-σ ~ -0.5σ:-3.054509776 < 斜率 ≤≤ -1.494924061

CWE上升5-10名,有上升趋势(up).

快速上升(rapid_ascent)

≤≤ -σ: 斜率 ≤≤-3.054509776

CWE上升10名以上,有快速上升趋势(rapid_ascent).

下降趋势(down)

0.5σ ~ σ:1.624247369 ≤≤ 斜率 < 3.183833084

CWE下降5-10名,有下降趋势(down).

快速下降(rapid_decline)

≥≥σ:斜率 ≥≥ 3.183833084

CWE下降10名以上,有快速下降趋势(rapid_decline).

基于这个波动幅度,我们可以得到下表:

斜率波动

CWE数量

CWE百分比

相对稳定(stable)

17

42.50%

快速上升(rapid_ascent)

7

17.50%

快速下降(rapid_decline)

6

15.00%

上升(up)

5

12.50%

下降(down)

3

7.50%

新进

2

5.00%

总计

40

100.00%

从这个统计表,我们可以看到:

  • 相对稳定17个,占比42%,也就是大部分缺陷没有实质性的改变;
  • 上升5个,快速上升7个,占比30%,在过去的5年未得到有效的控制,特别是快速上升的缺陷更需要引起防范的注意;
  • 下降3个,快速下降6个,占比22.5%,说明过去5年通过大家的防御能力的提升,这些问题得到一定程度的控制;
  • 有2个今年新进入TOP 40,分别为26名的CWE-617:可访问断言, 以及38名的CWE-639:通过用户控制密钥绕过授权机制。

下面我们分别对这些区域进行分析,试图找到这些高位安全问题的变动趋势和根因。

3. 2019-2023 CWE TOP 25 相对稳定的缺陷

对于波动相对稳定的CWE,前40名里有17个CWE。为了使图能够看的更加清楚,图里只展示了CWE 在2023年CWE TOP 25 中的 13 个CWE。如下图:

cke_118.png

在上图中一共有13个CWE,其中有10个CWE常年都维持在15名以内,波动的幅度较小。按CWE-1400 软件安全保障综合分类视图的分类,给出分类一栏的类别。

分类

CWE

2023年排名

CWE-1409:注入问题

CWE-79:在Web页面生成时对输入的转义处理不恰当(跨站脚本)

2

CWE-89:SQL命令中使用的特殊元素转义处理不恰当(SQL注入)

3

CWE-94:对生成代码的控制不恰当(代码注入)

23

CWE-1399:内存安全

CWE-416:释放后使用

4

CWE-125:越界读取

7

CWE-1406:不正确的输入验证

CWE-20:不正确的输入验证

6

CWE-1404:文件处理

CWE-22:对路径名的限制不恰当(路径遍历)

8

CWE-59:在文件访问前对链接解析不恰当(链接跟随)

39

CWE-1411:数据真实性验证不足

CWE-352:跨站请求伪造(CSRF)

9

CWE-1412:不良编码实践

CWE-476:空指针解引用

12

CWE-1396:访问控制

CWE-287:认证机制不恰当

13

CWE-798:使用硬编码的凭证

18

CWE-269:特权管理不恰当

22

CWE-601:指向未可信站点的URL重定向(开放重定向)

32

CWE-295:证书验证不正确

34

CWE-1415:资源控制

CWE-1321 对象原型属性的不当控制修改(原型污染)

33

这些稳定的CWE 大致可以分为3大类:

  • 外部输入导致:这类主要包括:CWE-20:不正确的输入验证、CWE-1409:注入问题、CWE-1404:文件处理、以及CWE-1411:数据真实性验证不足。这些问题是能够通过输入校验有效的避免这些问题的发生,同时静态检查工具也能通过污点分析方式,提供有效的排查帮助。
    • CWE-94:对生成代码的控制不恰当(代码注入)。由于ChatGpt的成功,更多的程序员开始使用AI辅助编程,已及今后由于大模型引起的开发模式的转变,程序员会更多的利用AIGC自动生成代码,自动生成代码的比例也会越来越大。如何通过静态检查工具增加对生成代码安全性的检测力度,以及如何利用大模型辅助静态检查,都会成为未来的静态检查的新兴课题。
  • 来自内部编程导致:这类主要包括:CWE-1399:内存安全、CWE-1412:不良编码实践、以及CWE-1415:资源控制。
    • 内存安全:缓冲去溢出(越界读、越界写、边界操作不当)一直是C语言的灵活性带来的副作用。依据微软的统计,Windows问题中的70,都是由于内存安全问题造成的。缓冲区溢出也一直是静态检查多年来未能有效解决的问题。工具在检查过程中,一方面需要记录内存分配的大小,还需要在使用时,对是否越界做出明确的判断。目前的工具多通过抽象解析,给出值域的判断,这种方法很多时候过于依赖代码中检查条件的判断,所以存在误报高的现象。通过符号执行并辅助约束求解的技术,能够在一定程度上提高分析的精度,降低误报。但这两个技术的使用会大幅度的降低分析工具的执行速度,无法达到应用级别的使用,只能非常有限的在工具中使用。程序员可以在编码过程中增强边界的检查意识,或通过代码增加对不确定边界的检查,来减低此类问题的发生。由于C语言一直存在的内存安全问题,这也是为什么不少企业在探索使用约束更多的rust语言来替代C语言的主要原因。
    • 内存泄露和空指针问题:静态分析工具可以通过状态机的方式,基本已经能够很好的予以解决。再配合动态测试,能够得到有效的得到控制。
  • 访问控制:这个问题涉及到权限的设计、分配、认证等控制。从检查上来看,需要给检查工具提供更多的信息,才能做出有效的判断。目前这类问题的检查主要聚焦于:默认的初始化设置、关键的提权函数的使用,以及最容易被攻击者利用的密码、密钥硬编码上,由于缺少更多的上下文的辅助信息,检查结果误报偏高。

这里我们再看下再过去5年中始终在TOP 25 中的高危漏洞,如下图。

cke_119.png

和相对稳定的图相比,增加了5个CWE,这些变动主要是因为缺陷上升或下降的原因,变动的CWE 主要有:

  • CWE-787:越界写入。 从2019年的12名,2020年2的第二名,之后就一直居于第一名。
  • CWE-78:OS命令中使用的特殊元素转义处理不恰当(OS命令注入)。 从2019年,逐步上升到2023年的第5名。这也是一个常见的注入类问题。这个除了对输入做出校验以外,还应该更多的是在代码中减少系统命令的直接使用,而是通过系统函数的调用方式实现系统命令的功能,隔离对系统命令的直接使用。在检查工具上,已经能够比较充分的发现这类问题。相信通过静态分析工具的使用,这个缺陷会逐步减少。
  • CWE-434:危险类型文件的不加限制上传。 这个问题被划分在 CWE-1416:资源生命周期管理中。这个缺陷从2019年的第16名,到目前已经连续三年保持第10名。这个问题持续排在第十位,确实有些让人意外,从检查和防范上没有太大的难度,这只能说明开发人员缺乏一定的安全意识,未曾对此类问题做出防范。相信通过对开发人员代码安全的教育的普及,这类问题会快速下降。
  • CWE-502:不可信数据的反序列化。这个问题属于对CWE-1415:资源控制的问题。这些年数据处理变得越来越重要,这个也给攻击者提供了一种通过构反序列化造数据,来绕过对数据安全检查的攻击方式。持续发现的Appache Siro、weblogic、tomcat、Jackson,Fastjson等一系列漏洞也说明了这一问题的风险。从防范上还是要坚持对外部数据的合法、有效性检测。
  • CWE-119:内存缓冲区边界内操作的限制不恰当。从2019年的第一名,逐年降低到2023年的第17名。看来是可以通过重视和增加检查来有效的避免此类问题的发生。
  • 过去5年持续在CWE TOP 25 中的这16个高危安全问题,我们需要在编码、检查和防御过程中引起高度的重视,可以说是重中之重。

4. 2019-2023 CWE TOP 25 增长趋势的缺陷

cke_120.png

这些CWE的增长速度基本在 5 到 10 名之间。这些CWE 有:

  • CWE-787:越界写入。 从2019年的12名,2020年2的第二名,之后就一直居于第一名。
  • CWE-78:OS命令中使用的特殊元素转义处理不恰当(OS命令注入)。从2019年,逐步上升到2023年的第5名。
  • CWE-434:危险类型文件的不加限制上传。从2019年的第16名,到目前已经连续三年保持第10名。
  • CWE-502:不可信数据的反序列化。从2019年的23名,逐步上升到2022年的最高点12名,2023年回落到15名。
  • CWE-863:授权机制不正确。从2019年的35名,逐步上升到今年终于进入前25名的第24名。
  • 对于这五个处于上升阶段的CWE缺陷,已经在前面的"相对稳定"和"始终在前25"的讨论中涉及,就不再一一解读。

5. 2019-2023 CWE TOP 快速增长的缺陷

cke_121.png

这些CWE的排名在过去的5年中,基本上增长超过了10名。这些CWE有:

  • CWE-862:授权机制缺失。从2019年的36名,一路上升到2023年的11名,上升25名。
  • CWE-77:在命令中使用的特殊元素转义处理不恰当(命令注入)。从2019年的30名,上升到2023年的16名,上升14名。
  • CWE-918:服务端请求伪造(SSRF)。从2019年的32名,一路上升到2023年的19名,上升12名。
    • SSRF是一种由攻击者构造形成由服务端发起请求的一个安全漏洞,大都是由于服务端提供了从其他服务器应用获取数据的功能且没有对目标地址做过滤与限制。对于静态分析,能做的有限。
  • CWE-306:关键功能的认证机制缺失。从2019年的38名,快速上升到2021年的11名,这两年逐步回落到2023年的20名,上升18名。
  • CWE-362:使用共享资源的并发执行不恰当同步问题(竞争条件)。从2019年的31名到2021年的33名,这两年快速上升到21名,上升12名,进入到TOP 25。
    • 随着并发的普遍使用,竞争条件会成为静态检查除内存安全之外的另一个挑战。
  • CWE-427:不受控制的搜索路径元素。从2021年的34名,上升到2023年的27名。
  • CWE-770:无限制或未控制地分配资源。从2020年的39名到2022年跌出前40,2023年却突然上升到29名,上升10名。

6. 2019-2023 CWE TOP 下降趋势的缺陷

cke_122.png

这些CWE的下降的速度基本在 5 到 10 名之间。这些CWE 有:

  • CWE-276:默认权限不正确。从2021年的19名,降到2023年的25名。只要在安全意识上足够重视,这类安全问题会进一步下降。
  • CWE-611:XML 外部实体引用限制不当。从2019年的17名,降到2023年的28名,跌出了TOP 25。这可能是在解析xml时,做了默认设置和限制,同时这些年json的使用,也分流了一部分xml的使用。
  • CWE-401:使用后内存未释放(内存泄露)。从2021年的32名,降到了2023年的36名。工具检测技术的成熟,对这类问题的减少也起到了一定的作用。

7. 2019-2023 CWE TOP 快速下降的缺陷

cke_123.png

这些CWE的排名快速下降,下降的速度基本在 10 名以上。这些CWE 有:

  • CWE-119:内存缓冲区边界内操作的限制不恰当。从2019年的第一名,逐年降到2023年的第17名,下降了17名。
  • CWE-200:将敏感信息暴露给未经授权的参与者。从2019年的第4名,逐年降到2023年的30名,下降26名。各国隐私保护法的实施起到了很大的推动作用。
  • CWE-732:关键资源的权限分配不正确。从2019年的15名,逐步降到2023年的31名,下降16名。也是一个访问控制问题。
  • CWE-522:凭据保护不足。从2019年的28名,在2020年上升到18名后,逐步下降到2023年的35名。也是一个访问控制问题。
  • CWE-400:不受控制的资源消耗。从2019年的20名,降到2023年的37名,下降17名。属于CWE-1416:资源生命周期管理问题。
  • CWE-668:将资源暴露在错误的领域。从2022年的32名,降到2023年的40名。属于CWE-1403:资源泄露。

8. 总结

  • Analyzed the changes of CWE TOP 25 from 2019 to 2023;
  • External input verification, access control issues, injection issues, and memory security are the main security issues in the past five years, and will continue for a period of time in the future. Special attention should be paid to the 16 types of issues that have been in the TOP 25 for the past five years;
  • Special attention needs to be paid to rapidly growing security issues: CWE-918: Server-Side Request Forgery (SSRF), CWE-362: Improper synchronization of concurrent executions using shared resources (race conditions);
  • Due to the rapid application of code generation, it is important to focus on: CWE-94: Inappropriate controls over generated code (code injection);

9. Reference

Click to follow and learn about Huawei Cloud's fresh technologies for the first time~

Guess you like

Origin blog.csdn.net/devcloud/article/details/132696944