When you Accidentally Compromise every CPU on Earth

Daniel Boctor
23 Mar 202415:59

Summary

TLDR这个视频脚本讲述了通过观察政府办公室的深夜披萨订单来预测军事行动的“披萨指数”现象,并深入探讨了计算机历史上最严重的漏洞之一——Spectre和Meltdown。这些漏洞影响了数十亿的计算机和智能手机,允许黑客窃取敏感信息。视频解释了这些漏洞是如何利用现代CPU技术的基本硬件特性来攻击的,以及它们如何通过侧信道攻击和缓存机制来泄露数据。

Takeaways

  • 📅 描述了1991年1月16日晚上的情景,海湾战争开始已经5个月又14天。
  • 🕒 通过比萨订单的增加,预测了即将进行的军事行动,这种现象被称为比萨指数。
  • 🔍 侧信道攻击是通过观察非预期的信息泄露来进行的,这些泄露可能由于协议或算法实现的基本方式造成。
  • 💥 描述了历史上最严重的计算机漏洞之一,影响了数十亿计算机和智能手机。
  • 🛑 漏洞Meltdown和Spectre被发现,它们允许黑客从几乎所有现代计算设备中窃取敏感信息。
  • 🚫 这些漏洞不依赖于任何代码中的基本弱点或缺陷,而是存在于现代CPU技术的核心。
  • 🔧 修复Spectre漏洞非常困难,因为它是一种硬件问题,存在于所有现代CPU中。
  • 📚 介绍了现代计算机的工作原理,特别是它们的记忆体结构。
  • 🔄 描述了投机执行和分支预测的概念,这是现代CPU快速执行指令的原因之一。
  • 🕳️ Spectre利用了CPU在错误猜测分支预测后不撤销缓存状态的缺陷。
  • 🕒 通过时间攻击,Spectre可以从CPU缓存中提取未经授权的记忆体数据。

Q & A

  • 什么是侧信道攻击?

    -侧信道攻击是一种利用计算系统中非预期的信息泄露来获取敏感数据的攻击方式。这种攻击不直接针对软件的漏洞,而是通过观察系统在执行过程中的无意信息泄露,如功耗分析、声音分析等,来提取敏感信息。

  • 在视频中提到的'披萨指数'是什么?

    -'披萨指数'是一个非传统的信息泄露渠道,通过观察政府办公室在大型军事行动前夕的披萨订单数量来预测军事行动的时间。例如,如果白宫和五角大楼在晚上的披萨订单数量激增,这可能意味着即将有重大行动发生。

  • 什么是熔断(Meltdown)和幽灵(Spectre)漏洞?

    -熔断和幽灵是两种影响现代计算机处理器的安全漏洞。熔断漏洞主要影响1995年后制造的英特尔CPU,允许恶意程序绕过安全隔离机制,访问其他应用程序和操作系统内核的记忆体。幽灵漏洞则是一系列攻击,利用现代CPU的推测执行和分支预测特性,几乎影响所有现代处理器。

  • 推测执行在CPU中的作用是什么?

    -推测执行是现代CPU中的一种优化技术,它允许CPU在等待内存数据响应的同时,预先执行可能需要的指令。这样可以减少CPU空闲时间,提高处理速度。但如果推测执行的方向错误,虽然会撤销错误的执行结果,CPU缓存的状态却可能不会完全恢复,这就是幽灵漏洞利用的关键点。

  • 如何利用幽灵漏洞从缓存中提取信息?

    -幽灵漏洞通过诱导CPU进行错误的推测执行,使得非法访问的数据被加载到缓存中。然后通过时间攻击,即测量从缓存和主内存中检索数据所需的时间差异,来间接推断出缓存中的数据内容。

  • 为什么说幽灵漏洞难以修复?

    -幽灵漏洞难以修复的原因在于它不是软件代码中的缺陷,而是现代CPU硬件架构中的基本特性问题。由于它涉及到所有现代CPU制造商和几乎所有设备,因此需要对硬件进行更换才能彻底消除漏洞。

  • 如何防止侧信道攻击?

    -防止侧信道攻击需要从多个层面进行,包括但不限于加强软件的安全性,例如及时更新和修补已知漏洞;使用硬件隔离技术,如安全启动和内存保护扩展;以及提高系统监控和异常检测能力。

  • 视频中提到的Codec Crafters是什么?

    -Codec Crafters是一个在线学习平台,专注于通过实际项目来教授编程和软件工程概念。用户可以通过构建真实的技术版本,如BitTorrent、Docker或Redux等,来学习和提高编程技能。

  • 如何理解CPU缓存的作用?

    -CPU缓存是一种高速存储器,用于临时存储从主内存中频繁访问的数据。当CPU需要读取或写入数据时,首先会检查缓存中是否有相应的数据副本。如果有,CPU可以直接从缓存中读取,这样可以显著提高数据处理速度。

  • 为什么说现代CPU的设计使得侧信道攻击成为可能?

    -现代CPU的设计强调性能优化,其中推测执行和分支预测是提高处理速度的关键技术。然而,这些技术在提高效率的同时也引入了安全风险,因为它们可能导致非法访问的数据被加载到缓存中,从而被侧信道攻击利用来泄露敏感信息。

  • 如何检测和防御针对CPU缓存的侧信道攻击?

    -检测和防御针对CPU缓存的侧信道攻击通常需要专业的工具和技术。例如,可以使用性能分析工具来监测CPU缓存的访问模式和时间,以及使用安全软件来监控和控制对内存的访问权限。此外,操作系统和硬件制造商也需要不断更新和改进安全措施,以减少此类攻击的风险。

Outlines

00:00

🔍 侧信道攻击的启示

1991年1月16日,距离海湾战争开始已经5个月14天。视频通过一个关于美国军方筹划对伊拉克进行空袭行动的例子引入侧信道攻击概念,揭示了一个非传统的信息泄露渠道:比萨指数。这个指数通过监测政府办公室的比萨订单数量的异常增加来预测军事行动。这种方法展示了即使程序代码完全安全,执行过程中仍可能因为处理器在运行时无意中泄露信息。侧信道攻击能够通过分析电力消耗、触摸屏操作的声音等多种方式来获取敏感信息。接下来介绍了2018年早期发现的两个严重的CPU漏洞:Meltdown和Spectre,这两个漏洞允许任何进程访问未授权的内存数据,包括加密密钥、照片和银行信息等,展现了侧信道攻击在现代计算设备中的严重性和普遍性。

05:01

🖥️ CPU缓存与预测执行

为了解释为什么现代CPU存在这么严重的安全漏洞,视频进一步深入讨论了计算机的工作原理,特别是CPU如何通过缓存和预测执行来加速数据处理。由于主存的响应速度较慢,CPU使用更快的缓存来存储曾经访问过的数据。这一机制虽然提高了效率,但也引入了潜在的安全风险,因为缓存的内容可以通过时间分析(一个侧信道攻击的形式)被推断出来。视频通过实例说明了CPU预测执行的过程和它是如何导致Spectre漏洞的。通过训练CPU的分支预测器使其错误地执行代码,攻击者可以利用这一机制来非法访问内存数据,尽管这些操作最终会被撤销。

10:01

🕵️‍♂️ Spectre漏洞深度分析

继续深入讨论Spectre漏洞,视频展示了如何利用CPU的分支预测和规范执行特性来绕过操作系统的内存保护机制。通过“训练”CPU分支预测器,使之错误预测内存访问的边界,攻击者可以在预测执行过程中读取其他进程的内存数据。尽管CPU最终会撤销这些非法的内存访问,但通过巧妙地使用缓存,攻击者能够保留并推断出被非法访问的数据。这一过程不仅揭示了现代计算机体系结构的基本漏洞,也展示了攻击者如何利用这些漏洞来获取敏感信息。

15:02

🛡️ Spectre攻击的实现与防护

视频最后部分详细介绍了Spectre攻击的具体实现方法,包括如何通过时间差异来识别缓存中的数据。通过这种方式,攻击者可以推断出缓存中的数据,从而获取到其他进程的敏感信息。此外,也指出Spectre并非单一的漏洞,而是一类漏洞的总称,这些漏洞共享相同的基本原理。视频还强调了修补这类硬件级漏洞的难度,以及为保护个人信息而需要采取的措施,包括更新CPU硬件。

Mindmap

Keywords

💡海湾战争

海湾战争是1990年至1991年间发生的一场大规模军事冲突,以伊拉克入侵科威特为导火索,美国领导的联军对伊拉克发起军事行动。在视频中,提到海湾战争开始5个月又14天后的某个夜晚,暗示了故事背景和时间点。

💡网络攻击

网络攻击指的是通过互联网对计算机系统或网络进行的恶意行为,旨在破坏、窃取或篡改数据。在视频中,提到了传统的网络攻击手段未能成功入侵军事系统,显示了军事系统安全防护的严密性。

💡披萨指数

披萨指数是一种非传统的情报收集方法,通过观察政府办公室在夜间的披萨订单数量来预测军事行动。视频中通过披萨订单数量的激增来暗示即将发生的军事行动。

💡侧信道攻击

侧信道攻击是一种利用计算机硬件或软件在处理信息时的非预期输出来获取敏感信息的攻击手段。在视频中,通过分析披萨订单的模式来预测军事行动,实际上就是一种侧信道攻击的运用。

💡熔断(Meltdown)

熔断是一种影响现代计算机处理器的安全漏洞,它允许恶意程序绕过安全隔离机制,访问其他程序和操作系统内核的内存数据。视频中提到,熔断漏洞使得几乎每一个现代计算设备和智能手机的安全受到威胁。

💡幽灵(Spectre)

幽灵是一种更为普遍和根本的CPU漏洞,它利用处理器的推测执行和分支预测功能来潜在地窃取敏感信息。与熔断相比,幽灵更加难以修复,因为它存在于所有现代CPU的微架构中。

💡动态随机存取存储器(DRAM)

动态随机存取存储器(DRAM)是计算机中用于存储数据的主要系统内存形式。它具有较大的存储容量,但由于读写速度较慢,会影响CPU的效率。

💡缓存

缓存是CPU内部的一种高速存储机制,用于临时存储频繁访问的数据,以减少CPU访问主内存的次数和延迟。缓存的容量相对较小,但其访问速度远超主内存。

💡推测执行

推测执行是现代CPU中的一种优化技术,它允许CPU在等待内存数据到来的同时,预先执行可能需要的指令,从而提高处理效率。如果预测正确,这些指令可以被保留并继续执行;如果预测错误,则撤销所有推测执行的操作。

💡分支预测

分支预测是CPU中的一种功能,它根据历史执行模式预测程序中分支语句的走向,以优化指令的执行顺序。这一功能是幽灵漏洞攻击的关键,因为它可以被操纵来诱导CPU执行非法内存访问。

💡时间攻击

时间攻击是一种侧信道攻击手段,通过分析操作执行的时间来推断出潜在的敏感信息。在视频中,攻击者利用时间攻击来探测CPU缓存中的数据,从而间接获取未经授权的内存信息。

Highlights

1991年1月16日晚上,海湾战争已经进行了5个月又14天,美国武装部队计划对伊拉克进行空袭行动。

尝试通过传统网络攻击手段侵入军事系统以预知空袭行动的日期,但未能成功。

弗朗克·米克斯,华盛顿特区43家达美乐比萨店的老板,通过观察深夜比萨订单的激增,发现政府官员在大型军事行动前夜通常会熬夜策划并订购大量比萨。

白宫在行动前夜相对基线订购了55个比萨,而五角大楼则订购了101个比萨,这一现象被称为“比萨指数”,并成功预测了多次军事行动。

侧信道攻击是基于对信息无意泄露的观察,这些泄露可能由于协议或算法实现的基本方式造成,而非协议或算法设计本身的缺陷。

尽管程序代码可能完全安全无漏洞,但这并不意味着程序执行就一定安全,因为CPU在运行时可能会无意中泄露信息。

2018年初,发现了两种严重的CPU漏洞——熔断(Meltdown)和幽灵(Spectre),它们影响了数十亿计算机和智能手机。

这些漏洞可能导致黑客从几乎所有现代计算设备和智能手机中窃取敏感信息,被认为是历史上最严重的计算机漏洞。

任何在计算机上运行的进程,无需任何提升权限或恶意安装,都可以自由访问系统内存中的所有数据,包括来自其他应用程序、不同虚拟机甚至操作系统内核的数据。

熔断和幽灵漏洞之所以特别危险,是因为它们不像以前见过的任何软件缺陷,它们攻击的是现代CPU技术的内在本质。

熔断是针对Intel CPU的一种特定类型的攻击,仅影响1995年之后制造的CPU。

幽灵是一种更为阴险的攻击,它是一系列利用推测执行和分支预测的攻击,这些是所有现代CPU中存在的硬件级特性。

由于幽灵不是软件中的漏洞或缺陷,而是根本的硬件问题,因此非常难以正确修补。

美国计算机紧急准备团队建议更换CPU硬件以彻底消除漏洞。

理解现代计算机的工作原理,特别是它们的记忆机制,对于理解幽灵漏洞的机制至关重要。

现代计算机的主系统内存(DRAM)虽然容量较大,但从内存中读取和写入数据的速度非常慢。

缓存内存(Cache Memory)作为额外的内存层级,可以加快CPU访问数据的速度。

缓存内存的容量相对较小,但访问速度极快,然而它对程序来说是不可见的。

推测执行是现代CPU中的一种优化技术,可以提前执行可能需要的指令,以提高处理速度。

分支预测是CPU中用于智能猜测分支可能走向的逻辑,是现代CPU快速处理的关键之一。

幽灵漏洞利用了当分支预测器做出错误猜测并在回滚期间不改变CPU缓存状态的缺陷。

通过训练CPU的分支预测器,可以诱导它故意做出错误的判断,从而利用幽灵漏洞。

幽灵漏洞的攻击通过诱导非法内存访问并利用时间差攻击从CPU缓存中提取信息。

Transcripts

00:00

it's the night of January 16th 1991 it's

00:03

been exactly 5 months and 14 days since

00:05

the start of the Gulf War you suspect

00:07

that the United States armed forces is

00:09

planning an aerial bombing campaign

00:11

against Iraq however you don't know when

00:13

they're going to initiate the operation

00:15

how can you find out the exact date

00:17

you've already tried to hack into

00:18

military systems with every traditional

00:20

Cyber attack in the book but to no avail

00:22

it turns out that there's a method to

00:24

find out without directly breaching

00:26

military systems discovered by Frank

00:28

Meeks owner of 43 Domino's pizza outlets

00:31

in the Washington DC area he knows that

00:33

Operation Desert Storm is going to

00:35

commence tomorrow on January 17th due to

00:38

the spike in late night pizza orders

00:39

from government offices you see the

00:42

night before large military operations

00:44

government officials tend to stay up all

00:46

night planning ordering in copious

00:48

amounts of pizza with Meek stating I

00:50

don't think they're sitting around

00:51

watching Redskins reruns that night

00:54

after 10: p.m. the White House ordered

00:56

55 pizzas relative to their Baseline of

00:58

five over at the Pentagon this number

01:01

surged to 101 pizzas relative to their

01:03

Baseline of three this correlation of

01:05

government pizza orders and imminent

01:07

military action was coined the pizza

01:09

index which also successfully predicted

01:11

military action ahead of time in many

01:13

other cases this is a classic example of

01:16

a side Channel attack with the pizza

01:17

orders acting as the side Channel Side

01:20

Channel attacks are based on the

01:21

observation of unintended emissions of

01:24

information certain information may be

01:26

leaked due to the fundamental way a

01:27

protocol or algorithm is implemented

01:30

rather than flaws in the design of the

01:32

protocol or algorithm itself we're soon

01:34

going to learn that even though a

01:35

program's code may be entirely safe and

01:37

bug-free this doesn't necessarily mean

01:40

that the execution of these programs is

01:42

going to be safe as the CPU could

01:44

inadvertently end up leaking information

01:46

at runtime these side channels are

01:48

everywhere spanning from the analysis of

01:50

power consumption all the way to being

01:52

able to extract your own fingerprints

01:54

just by listening to the acoustic

01:55

signatures generated by swiping on your

01:57

phone's touchcreen in this video we're

01:59

going to be diving deep covering one of

02:01

the most severe exploits in the history

02:03

of

02:05

computation Tech firms are rushing to

02:07

patch a security hold that is affecting

02:09

billions of computers and smartphones

02:11

it's caused by two major flaws in

02:13

computer chips called meltdown and

02:16

Spectre the defect could enable hackers

02:18

to steal sensitive information from

02:19

nearly every modern Computing device and

02:22

smartphone they're the worst computer

02:24

bugs in history and they could be coming

02:26

for your personal information what if

02:28

there was a way for any process running

02:30

on your entire computer without

02:32

requiring any elevated permissions or

02:34

malicious installs to have free access

02:37

to all of your systems memory both from

02:39

other applications including different

02:41

virtual machines and even from the

02:43

operating system kernel itself this

02:45

means that even the benign client side

02:47

JavaScript running within a browser tab

02:49

could have full access to all of your

02:51

computer's memory being able to recover

02:53

encryption Keys photos banking

02:55

information or anything else present in

02:57

your systems Ram this was the reality in

03:00

early 2018 when two of the most

03:02

dangerous and widespread CPU

03:04

vulnerabilities meltdown and Spectre

03:06

were discovered by researchers at Google

03:08

project zero allowing any process on any

03:11

device unrestricted access to

03:13

unauthorized memory what makes these

03:15

bugs particularly dangerous is that they

03:16

don't behave like any software bug we've

03:18

seen before as they don't rely on

03:20

exploiting any fundamental weakness or

03:22

flaws in any code these vulnerabilities

03:25

are baked into the very essence of

03:27

modern CPU technology attacking

03:29

underlying CPU

03:31

microarchitectures meltdown is a more

03:33

specific type of attack only affecting

03:35

Intel CPUs manufactured after

03:37

1995 this made it somewhat easier to fix

03:40

involving increased separation between

03:42

different memory spaces Spectre on the

03:44

other hand is much more Sinister it is a

03:47

whole class of attacks that take

03:48

advantage of something called

03:49

speculative execution and Branch

03:51

prediction which are Hardware level

03:53

features present on all modern CPUs

03:56

pervasive across all CPU manufacturers

03:58

and architectur

04:00

present in virtually every desktop

04:02

laptop server and smartphone in the

04:04

world because this is not a bug or flaw

04:07

in any software but rather a fundamental

04:09

Hardware issue it's incredibly difficult

04:11

to properly patch it the United States

04:14

computer emergency Readiness team's

04:16

recommendation was to replace your CPU

04:18

stating fully removing the vulnerability

04:21

requires replacing vulnerable CPU

04:23

Hardware in order to understand the

04:25

mechanics at the heart of Spectre we're

04:27

first going to need a foundational

04:28

understanding of how computers work

04:30

specifically their memory what does

04:32

execution on a modern computer look like

04:34

you have the CPU which is responsible

04:36

for processing data and the memory which

04:38

stores data during regular execution the

04:40

CPU will constantly be reading and

04:42

writing data to and from memory it's

04:45

going to be helpful to visualize memory

04:47

as a long sequence of boxes where each

04:49

box contains one bite of information now

04:52

this type of memory is the main system

04:54

memory also known as dam short for

04:56

dynamic Random Access Memory while it is

04:58

relatively large capacity it is very

05:01

slow to read and write from let's say

05:03

your CPU wants to load some data in from

05:05

memory this retrieval process is

05:07

incredibly slow let's say in the order

05:09

of 200 NS every single time you need to

05:12

access something in memory your CPU is

05:14

going to need to wait for the incredibly

05:15

slow main memory to respond with the

05:17

data that it wants it turns out that

05:19

there's additional layers of memory

05:21

called cache memory to make this process

05:23

faster once a particular memory location

05:25

is accessed for the first time the CPU

05:28

is going to store a copy in its cap

05:30

accessing the CPU cache is blazingly

05:32

fast achieving sub Nan speeds however

05:35

its capacity is quite small relative to

05:37

Dam the next time the same memory

05:39

location is accessed the CPU can just

05:41

get the data directly out of its cache

05:44

without needing to wait for a call to

05:45

the main memory something interesting to

05:47

note about the cache is that it's not

05:49

directly readable essentially being

05:51

transparent to the program being ran

05:54

there's no direct way to know if the

05:55

specific bite of memory you're accessing

05:57

is in cash or if it's coming from m main

05:59

memory now the cachee only speeds things

06:02

up for data that has already been

06:04

accessed from the main memory at least

06:05

once before over the regular course of

06:08

execution you're inevitably going to run

06:10

into the fact that your program is going

06:12

to need to read some data from Main

06:13

memory bottlenecking the CPU let's

06:16

visualize this with an example let's say

06:18

we have some variable meem defined in

06:20

memory and only if meem is equal to True

06:23

do we want to execute a bunch of other

06:25

instructions if meem is not already in

06:27

Cache we'll need to load it in for main

06:28

memory taking upwards of 200 NS during

06:32

this memory retrieval process the CPU is

06:34

going to be forced to sit idly by as it

06:36

waits for this slow response from memory

06:38

which is an absurd way to have a CPU

06:40

operate only after the value of mem is

06:43

retrieved from memory can the CPU start

06:45

executing the rest of the instructions

06:47

needless to say it is very inefficient

06:49

to have our CPU idle during the long

06:51

memory lookup process What if after

06:54

starting the retrieval process we could

06:56

get a head start sprinting ahead in

06:58

executing our instruction

07:00

speculatively so that we're already done

07:02

by the time you receive the value of

07:04

meem this is called speculative

07:05

execution which is an optimization

07:07

technique present in virtually every CPU

07:10

since the 1990s and it's actually one of

07:12

the reasons why modern CPUs are so fast

07:15

any time we have a branch such as this

07:17

if statement the CPU has some logic that

07:19

makes an intelligent guess about which

07:21

way the branch might go this is called a

07:23

branch prediction if the CPU thinks that

07:25

it's likely for meem to be equal to true

07:28

it can Sprint ahead and spec

07:29

speculatively execute these instructions

07:31

even before it gets its response from

07:33

memory once the lookup is finally

07:35

complete if we guessed right in meem is

07:38

indeed equal to true we just saved a lot

07:40

of time as our instructions are already

07:42

executed we can keep everything we just

07:44

did which is called a commit and resume

07:47

execution from this point on this sounds

07:49

pretty cool however we obviously need to

07:51

handle the case where we get the guess

07:53

wrong meaning that everything done

07:54

spectively needs to be fully reversible

07:57

if we guessed wrong in M was not equal

07:59

to true we would need to roll back all

08:01

of the changes that were made including

08:03

reverting all of the register values

08:05

which is called a discard here's where

08:07

things start to get interesting let's

08:09

introduce the flaw that Spectre was

08:11

exploiting it turns out that when the

08:13

branch predictor makes an incorrect

08:15

guess and we roll back all of the

08:16

changes that were made during

08:18

speculative execution the state of the

08:20

CPU cache is actually not reverted let's

08:23

make this clear the code being

08:25

spectively executed might have triggered

08:27

some data to be loaded in from Main

08:29

memory resulting in it getting cashed if

08:32

it turns out that we made a bad call and

08:34

everything needs to be rolled back the

08:36

data is actually going to remain within

08:38

the CPU cache even after the roll back

08:41

this is quite serious keeping in mind

08:43

that from the software point of view

08:45

this code was quite literally never

08:46

executed we're soon going to see that

08:48

Spectre can induce one of these roll

08:50

backs by training the cpu's branch

08:52

predictor or officially conditioning it

08:54

to make a bad call on purpose the tricky

08:57

part is going to be extracting this

08:58

information from from the cache as it

09:00

contents are not directly readable

09:02

essentially being transparent since we

09:04

know that the cach responds faster than

09:06

main memory the contents of the Cache

09:08

can be inadvertently leaked with a

09:09

timing attack measuring the amount of

09:11

time it takes to retrieve the data this

09:14

alone seems easy but to be able to do

09:16

this on unauthorized memory is going to

09:18

be quite tricky however we're soon going

09:20

to see an incredibly elegant solution to

09:22

bring data from unauthorized memory into

09:24

a part of the cpu's cache that we can

09:26

probe but I digress let's not get ahead

09:29

of ourselves

09:30

with this we now have all the

09:31

ingredients needed to understand

09:33

Spectre if you've made it this far and

09:36

you're interested in learning new skills

09:37

advancing your career in building a

09:39

comprehensive understanding of software

09:41

engineering Concepts look no further

09:43

than this video sponsor codec Crafters

09:46

with codec Crafters you learn by

09:47

building your own versions of real

09:49

Technologies such as bit torrent Docker

09:51

or even redus each project Dives deep

09:54

into a specific topic starting from

09:56

scratch to final specification in a

09:58

practical Hands-On environment the cool

10:01

thing is that all of these challenges

10:02

are available in a wide variety of

10:04

programming languages meaning that you

10:06

can learn language specific skills or

10:08

new languages entirely in a real world

10:10

environment regardless of what the

10:11

original tool is written in you can get

10:14

started with any setup as you progress

10:16

through the different stages you'll be

10:17

conveniently pushing your code for

10:19

automatic rating the whole time you'll

10:21

have access to hints code examples and

10:24

even screencasts from fellow community

10:25

members if you get stuck in addition to

10:28

this any knowledge apps will be filled

10:30

in along the way as interactive

10:31

tutorials are provided to teach you

10:33

fundamental concepts when needed you can

10:36

get started with code Crafters today by

10:37

clicking the link in the description

10:39

they're offering a free tier and a 40%

10:42

discount on their paid memberships to

10:43

viewers of this channel thanks again to

10:45

codec crafters for supporting the

10:47

channel now let's get back to

10:49

Spectre let's go ahead and set the scene

10:52

starting with our main memory the

10:54

operating system kernel is responsible

10:56

for allocating this memory to different

10:57

applications a simil thing also happens

11:00

in multi-tenanted Cloud environments as

11:02

well with the hypervisor allocating

11:04

memory to different virtual machines

11:06

instead in either case this means that

11:08

there could be adjacent parts of memory

11:10

allocated to a process that we control

11:12

and to a potential victim the operating

11:15

system is supposed to isolate the memory

11:16

spaces between different processes

11:19

ensuring that any given process

11:20

including the JavaScript running within

11:22

your browser can't access another

11:24

process's memory so how do Spectre

11:27

circumvent this enabling us to read data

11:29

from a victim process let's start by

11:32

initializing an array in the part of

11:33

memory that we control we know that we

11:35

can access the elements within our array

11:38

by indexing into whatever position that

11:39

we want to retrieve all this does under

11:41

the hood is some simple pointer

11:43

arithmetic adding together the memory

11:45

location of the start of the array and

11:47

the index in order to find the memory

11:49

location that we want let's suppose that

11:51

the part of victim memory that we're

11:53

trying to read from contains the number

11:54

six but of course our code doesn't know

11:57

this what if we try to index into into a

11:59

position so high that we went out of

12:01

bounds in read from victim memory let's

12:04

call this array of x if you tried to do

12:06

this the operating system is going to

12:08

notice that we're trying to access

12:09

unauthorized memory deeming this an

12:11

illegal operation triggering a fault

12:14

preventing us from accessing the data

12:16

now what if we Instead try to do this

12:18

operation speculatively this is going to

12:20

be interesting so we want to index into

12:23

our array at position X but how can we

12:25

force this operation to be done

12:27

spectively we're going to need to add

12:29

some sort of Branch beforehand let's go

12:31

ahead and add a simple bouns check

12:33

making sure that X is within the bounds

12:35

of the array before proceeding simple

12:38

what we're going to do now is we're

12:39

actually going to train the cpu's branch

12:41

predictor conditioning it to determine

12:43

that it is likely for X to be in bounds

12:46

we can do this by making repeated calls

12:48

to this function handing it values of X

12:50

that are always in bounds if it keeps on

12:53

saying that X tends to be in bounds it

12:55

is going to become conditioned to

12:57

speculatively execute the body of the if

12:59

statement since there's a very high

13:01

chance that the bounce check will pass

13:03

based off its previous interactions

13:05

there's malicious intent here as once

13:07

the CPU has been trained we can hand it

13:09

a value of x that is purposefully out of

13:11

bounds and our CPU will happily Speed

13:14

Ahead speculatively executing the

13:16

instruction so how is this handled the

13:19

CPU is going to index into array of X

13:22

however it won't know that it's out of

13:23

bounds yet if this were to actually be

13:26

ran the colonel would kill the process

13:28

but the specul cative execution engine

13:30

just looks ahead and reads the number

13:32

six from victim memory the operating

13:34

system won't actually check if it's

13:36

accessing an illegal memory location

13:38

until later this is a crucial Nuance to

13:41

understand as a result data from victim

13:44

memory was indeed accessed this is very

13:46

interesting but once the CPU realizes

13:49

that it's gone the wrong way it's going

13:51

to roll back all of the erroneous work

13:53

that it's done even though illegal

13:55

memory has been accessed its contents

13:57

will be forgotten we need to find a way

13:59

to retain it after the roll back if it

14:01

can't be retained then all of this was

14:03

for nothing bear with me on this we're

14:06

actually going to define a second larger

14:08

array to capture this information akin

14:10

to Casting a large net let's modify our

14:13

code slightly to index into capture of

14:15

array of X when array of X is evaluated

14:19

to the number six capture of six is now

14:22

going to be accessed this is the crucial

14:24

part of the attack because we just read

14:27

from the capture array at index X6 this

14:30

memory location is going to be put into

14:32

the cache after the roll back as we now

14:35

know the cach is going to remain intact

14:38

think about that we never directly stole

14:40

the data from victim memory we just

14:42

brought an element of our own array into

14:45

cache at the index number that

14:47

corresponded to the data that we wanted

14:49

to steal it's quite an elegant trick

14:51

don't forget that the cash itself is

14:53

still not accessible to us the last step

14:56

is going to be a timing attack which is

14:58

a specific type type of side Channel

14:59

attack that's going to try and deduce

15:02

the data contained within the cache by

15:03

taking advantage of the timing

15:05

differences between cash in main memory

15:08

we can go ahead and access each and

15:10

every element of our capture array

15:12

timing how long it takes to retrieve

15:14

each element we're going to get a

15:16

sequence of slow 200 nond cache misses

15:20

until finally we get a near instant

15:22

cache hit since we found our cache hit

15:25

on array element 6 we know that the data

15:28

contained within the victim memory was

15:29

the number six it's quite a beautiful

15:32

attack Spectre comes in many different

15:34

variations what I just outlined was a

15:37

highly simplified version of Spectre

15:39

variant 1 although they all rely on the

15:41

same idea getting the CPU to spectively

15:43

run some code that illegally accesses

15:46

memory and then exfiltrating said memory

15:48

using a timing side channel on the CPU

15:51

cache if you're interested in more

15:52

vulnerability breakdowns check out these

15:54

videos and subscribe to the channel for

15:56

more content thanks for watching

Rate This

5.0 / 5 (0 votes)

相关标签
计算机漏洞数据安全军事预测侧信道攻击软件工程技术漏洞信息泄露硬件缺陷网络安全编程教育