When you Accidentally Compromise every CPU on Earth
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
🔍 侧信道攻击的启示
1991年1月16日,距离海湾战争开始已经5个月14天。视频通过一个关于美国军方筹划对伊拉克进行空袭行动的例子引入侧信道攻击概念,揭示了一个非传统的信息泄露渠道:比萨指数。这个指数通过监测政府办公室的比萨订单数量的异常增加来预测军事行动。这种方法展示了即使程序代码完全安全,执行过程中仍可能因为处理器在运行时无意中泄露信息。侧信道攻击能够通过分析电力消耗、触摸屏操作的声音等多种方式来获取敏感信息。接下来介绍了2018年早期发现的两个严重的CPU漏洞:Meltdown和Spectre,这两个漏洞允许任何进程访问未授权的内存数据,包括加密密钥、照片和银行信息等,展现了侧信道攻击在现代计算设备中的严重性和普遍性。
🖥️ CPU缓存与预测执行
为了解释为什么现代CPU存在这么严重的安全漏洞,视频进一步深入讨论了计算机的工作原理,特别是CPU如何通过缓存和预测执行来加速数据处理。由于主存的响应速度较慢,CPU使用更快的缓存来存储曾经访问过的数据。这一机制虽然提高了效率,但也引入了潜在的安全风险,因为缓存的内容可以通过时间分析(一个侧信道攻击的形式)被推断出来。视频通过实例说明了CPU预测执行的过程和它是如何导致Spectre漏洞的。通过训练CPU的分支预测器使其错误地执行代码,攻击者可以利用这一机制来非法访问内存数据,尽管这些操作最终会被撤销。
🕵️♂️ Spectre漏洞深度分析
继续深入讨论Spectre漏洞,视频展示了如何利用CPU的分支预测和规范执行特性来绕过操作系统的内存保护机制。通过“训练”CPU分支预测器,使之错误预测内存访问的边界,攻击者可以在预测执行过程中读取其他进程的内存数据。尽管CPU最终会撤销这些非法的内存访问,但通过巧妙地使用缓存,攻击者能够保留并推断出被非法访问的数据。这一过程不仅揭示了现代计算机体系结构的基本漏洞,也展示了攻击者如何利用这些漏洞来获取敏感信息。
🛡️ Spectre攻击的实现与防护
视频最后部分详细介绍了Spectre攻击的具体实现方法,包括如何通过时间差异来识别缓存中的数据。通过这种方式,攻击者可以推断出缓存中的数据,从而获取到其他进程的敏感信息。此外,也指出Spectre并非单一的漏洞,而是一类漏洞的总称,这些漏洞共享相同的基本原理。视频还强调了修补这类硬件级漏洞的难度,以及为保护个人信息而需要采取的措施,包括更新CPU硬件。
Mindmap
Keywords
💡海湾战争
💡网络攻击
💡披萨指数
💡侧信道攻击
💡熔断(Meltdown)
💡幽灵(Spectre)
💡动态随机存取存储器(DRAM)
💡缓存
💡推测执行
💡分支预测
💡时间攻击
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
it's the night of January 16th 1991 it's
been exactly 5 months and 14 days since
the start of the Gulf War you suspect
that the United States armed forces is
planning an aerial bombing campaign
against Iraq however you don't know when
they're going to initiate the operation
how can you find out the exact date
you've already tried to hack into
military systems with every traditional
Cyber attack in the book but to no avail
it turns out that there's a method to
find out without directly breaching
military systems discovered by Frank
Meeks owner of 43 Domino's pizza outlets
in the Washington DC area he knows that
Operation Desert Storm is going to
commence tomorrow on January 17th due to
the spike in late night pizza orders
from government offices you see the
night before large military operations
government officials tend to stay up all
night planning ordering in copious
amounts of pizza with Meek stating I
don't think they're sitting around
watching Redskins reruns that night
after 10: p.m. the White House ordered
55 pizzas relative to their Baseline of
five over at the Pentagon this number
surged to 101 pizzas relative to their
Baseline of three this correlation of
government pizza orders and imminent
military action was coined the pizza
index which also successfully predicted
military action ahead of time in many
other cases this is a classic example of
a side Channel attack with the pizza
orders acting as the side Channel Side
Channel attacks are based on the
observation of unintended emissions of
information certain information may be
leaked due to the fundamental way a
protocol or algorithm is implemented
rather than flaws in the design of the
protocol or algorithm itself we're soon
going to learn that even though a
program's code may be entirely safe and
bug-free this doesn't necessarily mean
that the execution of these programs is
going to be safe as the CPU could
inadvertently end up leaking information
at runtime these side channels are
everywhere spanning from the analysis of
power consumption all the way to being
able to extract your own fingerprints
just by listening to the acoustic
signatures generated by swiping on your
phone's touchcreen in this video we're
going to be diving deep covering one of
the most severe exploits in the history
of
computation Tech firms are rushing to
patch a security hold that is affecting
billions of computers and smartphones
it's caused by two major flaws in
computer chips called meltdown and
Spectre the defect could enable hackers
to steal sensitive information from
nearly every modern Computing device and
smartphone they're the worst computer
bugs in history and they could be coming
for your personal information what if
there was a way for any process running
on your entire computer without
requiring any elevated permissions or
malicious installs to have free access
to all of your systems memory both from
other applications including different
virtual machines and even from the
operating system kernel itself this
means that even the benign client side
JavaScript running within a browser tab
could have full access to all of your
computer's memory being able to recover
encryption Keys photos banking
information or anything else present in
your systems Ram this was the reality in
early 2018 when two of the most
dangerous and widespread CPU
vulnerabilities meltdown and Spectre
were discovered by researchers at Google
project zero allowing any process on any
device unrestricted access to
unauthorized memory what makes these
bugs particularly dangerous is that they
don't behave like any software bug we've
seen before as they don't rely on
exploiting any fundamental weakness or
flaws in any code these vulnerabilities
are baked into the very essence of
modern CPU technology attacking
underlying CPU
microarchitectures meltdown is a more
specific type of attack only affecting
Intel CPUs manufactured after
1995 this made it somewhat easier to fix
involving increased separation between
different memory spaces Spectre on the
other hand is much more Sinister it is a
whole class of attacks that take
advantage of something called
speculative execution and Branch
prediction which are Hardware level
features present on all modern CPUs
pervasive across all CPU manufacturers
and architectur
present in virtually every desktop
laptop server and smartphone in the
world because this is not a bug or flaw
in any software but rather a fundamental
Hardware issue it's incredibly difficult
to properly patch it the United States
computer emergency Readiness team's
recommendation was to replace your CPU
stating fully removing the vulnerability
requires replacing vulnerable CPU
Hardware in order to understand the
mechanics at the heart of Spectre we're
first going to need a foundational
understanding of how computers work
specifically their memory what does
execution on a modern computer look like
you have the CPU which is responsible
for processing data and the memory which
stores data during regular execution the
CPU will constantly be reading and
writing data to and from memory it's
going to be helpful to visualize memory
as a long sequence of boxes where each
box contains one bite of information now
this type of memory is the main system
memory also known as dam short for
dynamic Random Access Memory while it is
relatively large capacity it is very
slow to read and write from let's say
your CPU wants to load some data in from
memory this retrieval process is
incredibly slow let's say in the order
of 200 NS every single time you need to
access something in memory your CPU is
going to need to wait for the incredibly
slow main memory to respond with the
data that it wants it turns out that
there's additional layers of memory
called cache memory to make this process
faster once a particular memory location
is accessed for the first time the CPU
is going to store a copy in its cap
accessing the CPU cache is blazingly
fast achieving sub Nan speeds however
its capacity is quite small relative to
Dam the next time the same memory
location is accessed the CPU can just
get the data directly out of its cache
without needing to wait for a call to
the main memory something interesting to
note about the cache is that it's not
directly readable essentially being
transparent to the program being ran
there's no direct way to know if the
specific bite of memory you're accessing
is in cash or if it's coming from m main
memory now the cachee only speeds things
up for data that has already been
accessed from the main memory at least
once before over the regular course of
execution you're inevitably going to run
into the fact that your program is going
to need to read some data from Main
memory bottlenecking the CPU let's
visualize this with an example let's say
we have some variable meem defined in
memory and only if meem is equal to True
do we want to execute a bunch of other
instructions if meem is not already in
Cache we'll need to load it in for main
memory taking upwards of 200 NS during
this memory retrieval process the CPU is
going to be forced to sit idly by as it
waits for this slow response from memory
which is an absurd way to have a CPU
operate only after the value of mem is
retrieved from memory can the CPU start
executing the rest of the instructions
needless to say it is very inefficient
to have our CPU idle during the long
memory lookup process What if after
starting the retrieval process we could
get a head start sprinting ahead in
executing our instruction
speculatively so that we're already done
by the time you receive the value of
meem this is called speculative
execution which is an optimization
technique present in virtually every CPU
since the 1990s and it's actually one of
the reasons why modern CPUs are so fast
any time we have a branch such as this
if statement the CPU has some logic that
makes an intelligent guess about which
way the branch might go this is called a
branch prediction if the CPU thinks that
it's likely for meem to be equal to true
it can Sprint ahead and spec
speculatively execute these instructions
even before it gets its response from
memory once the lookup is finally
complete if we guessed right in meem is
indeed equal to true we just saved a lot
of time as our instructions are already
executed we can keep everything we just
did which is called a commit and resume
execution from this point on this sounds
pretty cool however we obviously need to
handle the case where we get the guess
wrong meaning that everything done
spectively needs to be fully reversible
if we guessed wrong in M was not equal
to true we would need to roll back all
of the changes that were made including
reverting all of the register values
which is called a discard here's where
things start to get interesting let's
introduce the flaw that Spectre was
exploiting it turns out that when the
branch predictor makes an incorrect
guess and we roll back all of the
changes that were made during
speculative execution the state of the
CPU cache is actually not reverted let's
make this clear the code being
spectively executed might have triggered
some data to be loaded in from Main
memory resulting in it getting cashed if
it turns out that we made a bad call and
everything needs to be rolled back the
data is actually going to remain within
the CPU cache even after the roll back
this is quite serious keeping in mind
that from the software point of view
this code was quite literally never
executed we're soon going to see that
Spectre can induce one of these roll
backs by training the cpu's branch
predictor or officially conditioning it
to make a bad call on purpose the tricky
part is going to be extracting this
information from from the cache as it
contents are not directly readable
essentially being transparent since we
know that the cach responds faster than
main memory the contents of the Cache
can be inadvertently leaked with a
timing attack measuring the amount of
time it takes to retrieve the data this
alone seems easy but to be able to do
this on unauthorized memory is going to
be quite tricky however we're soon going
to see an incredibly elegant solution to
bring data from unauthorized memory into
a part of the cpu's cache that we can
probe but I digress let's not get ahead
of ourselves
with this we now have all the
ingredients needed to understand
Spectre if you've made it this far and
you're interested in learning new skills
advancing your career in building a
comprehensive understanding of software
engineering Concepts look no further
than this video sponsor codec Crafters
with codec Crafters you learn by
building your own versions of real
Technologies such as bit torrent Docker
or even redus each project Dives deep
into a specific topic starting from
scratch to final specification in a
practical Hands-On environment the cool
thing is that all of these challenges
are available in a wide variety of
programming languages meaning that you
can learn language specific skills or
new languages entirely in a real world
environment regardless of what the
original tool is written in you can get
started with any setup as you progress
through the different stages you'll be
conveniently pushing your code for
automatic rating the whole time you'll
have access to hints code examples and
even screencasts from fellow community
members if you get stuck in addition to
this any knowledge apps will be filled
in along the way as interactive
tutorials are provided to teach you
fundamental concepts when needed you can
get started with code Crafters today by
clicking the link in the description
they're offering a free tier and a 40%
discount on their paid memberships to
viewers of this channel thanks again to
codec crafters for supporting the
channel now let's get back to
Spectre let's go ahead and set the scene
starting with our main memory the
operating system kernel is responsible
for allocating this memory to different
applications a simil thing also happens
in multi-tenanted Cloud environments as
well with the hypervisor allocating
memory to different virtual machines
instead in either case this means that
there could be adjacent parts of memory
allocated to a process that we control
and to a potential victim the operating
system is supposed to isolate the memory
spaces between different processes
ensuring that any given process
including the JavaScript running within
your browser can't access another
process's memory so how do Spectre
circumvent this enabling us to read data
from a victim process let's start by
initializing an array in the part of
memory that we control we know that we
can access the elements within our array
by indexing into whatever position that
we want to retrieve all this does under
the hood is some simple pointer
arithmetic adding together the memory
location of the start of the array and
the index in order to find the memory
location that we want let's suppose that
the part of victim memory that we're
trying to read from contains the number
six but of course our code doesn't know
this what if we try to index into into a
position so high that we went out of
bounds in read from victim memory let's
call this array of x if you tried to do
this the operating system is going to
notice that we're trying to access
unauthorized memory deeming this an
illegal operation triggering a fault
preventing us from accessing the data
now what if we Instead try to do this
operation speculatively this is going to
be interesting so we want to index into
our array at position X but how can we
force this operation to be done
spectively we're going to need to add
some sort of Branch beforehand let's go
ahead and add a simple bouns check
making sure that X is within the bounds
of the array before proceeding simple
what we're going to do now is we're
actually going to train the cpu's branch
predictor conditioning it to determine
that it is likely for X to be in bounds
we can do this by making repeated calls
to this function handing it values of X
that are always in bounds if it keeps on
saying that X tends to be in bounds it
is going to become conditioned to
speculatively execute the body of the if
statement since there's a very high
chance that the bounce check will pass
based off its previous interactions
there's malicious intent here as once
the CPU has been trained we can hand it
a value of x that is purposefully out of
bounds and our CPU will happily Speed
Ahead speculatively executing the
instruction so how is this handled the
CPU is going to index into array of X
however it won't know that it's out of
bounds yet if this were to actually be
ran the colonel would kill the process
but the specul cative execution engine
just looks ahead and reads the number
six from victim memory the operating
system won't actually check if it's
accessing an illegal memory location
until later this is a crucial Nuance to
understand as a result data from victim
memory was indeed accessed this is very
interesting but once the CPU realizes
that it's gone the wrong way it's going
to roll back all of the erroneous work
that it's done even though illegal
memory has been accessed its contents
will be forgotten we need to find a way
to retain it after the roll back if it
can't be retained then all of this was
for nothing bear with me on this we're
actually going to define a second larger
array to capture this information akin
to Casting a large net let's modify our
code slightly to index into capture of
array of X when array of X is evaluated
to the number six capture of six is now
going to be accessed this is the crucial
part of the attack because we just read
from the capture array at index X6 this
memory location is going to be put into
the cache after the roll back as we now
know the cach is going to remain intact
think about that we never directly stole
the data from victim memory we just
brought an element of our own array into
cache at the index number that
corresponded to the data that we wanted
to steal it's quite an elegant trick
don't forget that the cash itself is
still not accessible to us the last step
is going to be a timing attack which is
a specific type type of side Channel
attack that's going to try and deduce
the data contained within the cache by
taking advantage of the timing
differences between cash in main memory
we can go ahead and access each and
every element of our capture array
timing how long it takes to retrieve
each element we're going to get a
sequence of slow 200 nond cache misses
until finally we get a near instant
cache hit since we found our cache hit
on array element 6 we know that the data
contained within the victim memory was
the number six it's quite a beautiful
attack Spectre comes in many different
variations what I just outlined was a
highly simplified version of Spectre
variant 1 although they all rely on the
same idea getting the CPU to spectively
run some code that illegally accesses
memory and then exfiltrating said memory
using a timing side channel on the CPU
cache if you're interested in more
vulnerability breakdowns check out these
videos and subscribe to the channel for
more content thanks for watching
5.0 / 5 (0 votes)