š
Hardware Wallet Hack: Ledger Nano S - f00dbabe - YouTube
Channel: unknown
[0]
The Ledger Nano S is a Cryptocurrency hardware
wallet based on a secure element for storing
[5]
cryptocurrencies, embedding a screen to check
and secure digital payments.
[10]
And also they have these information sheets
where they proudly write: āDid you notice?
[14]
There is no anti-tampering sticker on this
box.
[18]
A cryptographic mechanism checks the integrity
of your Ledger deviceās internal software
[23]
each time it is powered on.ā...
[25]
Butā¦
ehmā¦
[26]
heyā¦
stopā¦
[27]
what are you doing?
[36]
The Ledger Nano S is a small portable gaming
system.
[39]
Currently there is only one game, SNAKE, but
we have also seen some promising tech demos.
[44]
Just kidding.
[46]
But just to answer your most pressing question
first I donāt want you to panic, if you
[50]
use a ledger and you are just a non-technical
person, itās not an attack where anybody
[54]
can directly read out your private key.
[57]
Maybe you shouldnāt plug in your Ledger
into an untrusted computer or leave it laying
[61]
around, but even then itās not like a full
critical private key compromise.
[66]
So donāt worry.
[67]
But reality is complex and there are situations
where your cryptocurrencies might be not perfectly
[73]
safe.
[74]
And what I will show you in this video, which
ledger says is not a vulnerability, might
[79]
have some impact for you, or not.
[81]
The real answer is of course a lot more complicatedā¦.
[85]
please define what a āvulnerabilityā is.
[87]
You will see there are different ways to look
at it.
[90]
But in my personal opinion, I think it is
very much a vulnerability.
[94]
There is certainly a lot to unpack, and in
this video I just want to explain on a higher
[98]
level how this ānonā-vulnerability works.
[101]
But I will make a series with more videos
where we discuss threat-models and go deep
[105]
into the hardware and I show you on a very
technical level how to analyse, research and
[109]
reverse-engineer the hardware and software
and how to setup a whole testing environment.
[115]
But before you think highly of me, I didnāt
do anything.
[118]
Donāt give me any credit.
[120]
These videos are based on research done by
my friend Thomas Roth who discovered this
[124]
in the first place.
[125]
He contacted me if I would be up for making
a video about it and then helped me a lot
[129]
by answering questions and helping me with
the setup.
[133]
So if you are interested in his research and
professional work, make sure to look him up.
[138]
And if you are interested in these upcoming
videos, make sure to follow this channel.
[142]
So the ānonā-vulnerability description
states: āIt was found that the Ledger Nano
[146]
S bootloader can be tricked into flashing
and executing untrusted firmware.
[151]
The bootloader is used to update the firmware
of the 'non-secure' processor in the Ledger
[155]
Nano S and has full control over the display,
USB and the buttons.ā
[160]
So when you put the device into the bootloader
mode, you can communicate with the ledger
[164]
from your computer using APDU commands.
[167]
This is a protocol typically used by smart
cards.
[170]
So nothing special.
[171]
But just as a little example, here you see
the Ledger Manager Software on my computer,
[175]
and with the Chrome developer tools we can
observe APDU commands being logged to the
[179]
console which is sent to the device and received
from the device.
[183]
Okay.
[184]
Writing software into the flash of a chip
typically involves using some special hardware
[188]
to put the chip into a special mode to write
the code into flash.
[190]
But that is not great when you want to be
able to update software later when the product
[194]
is already shipped to customers.
[197]
So typically software on a microcontroller
is split in two stages.
[201]
The bootloader and the main program or firmware.
[204]
And the bootloader is a small piece of code
that can help you with updates.
[207]
It might also help initializing or configuring
some features of the chip when the device
[211]
is powered on.
[212]
But in our case we are just interesting about
the update process.
[216]
If you just power on the device, the bootloader
will do some stuff and eventually jump to
[221]
the main firmware code.
[223]
But if you hold down the button when powering
it on, the bootloader will see the button
[228]
is pressed and instead stay in the bootloader
code.
[231]
And now the bootloader is executing a piece
of code where it can communicate with the
[235]
computer and receive APDU commands via USB.
[239]
Some of these commands can be used to update
the firmware, which basically means, writing
[243]
new code into flash memory.
[246]
And that process is pretty simple.
[248]
an updater program on your computer like the
ledger manager *cough* or a malware *cough
[253]
can use APDU commands first select a memory
segment on the chip then to send some data
[258]
and write that to the flash.
[260]
And so the bootloader has code to just simply
write new code into flash.
[265]
And when you are done, you just tell the bootloader
via an APDU command to please now boot that
[269]
code, which simply means, here please go execute
that.
[273]
And from here on out, the device runs the
new firmware.
[276]
Now you see, a person with physical access,
or a malware on your coputer, could write
[281]
malicious code and push that onto the device,
right?
[285]
Just put it into bootloader mode and send
the APDU commands to write the evil firmware.
[290]
BUT, not so fast.
[292]
Ledger tries to prevent that.
[294]
The bootloader implements a boot protection.
[297]
When powered on the bootloader will check
if the constant value 0xf00dbabe is stored
[302]
at the address 0x08003000.
[306]
Only if that value is present it will execute
your code.
[310]
If not, the bootloader simply doesnāt do
anything.
[313]
So in the bootloader code, where the APDU
commands for writing the new firmware is handled,
[318]
it will first erase the old 0xf00dbabe value.
[321]
If you would restart the device, the constant
would be missing and then doesnāt execute
[326]
it.
[327]
Now maybe you wonder why you canāt just
write f00dbabe to that address?
[331]
The bootloader code also has a check to make
sure that YOU donāt just send an APDU command
[337]
to write f00dbabe at this position.
[339]
In fact it protects the whole range from 0x08000000
to 0x08003000.
[346]
Which means you can also not overwrite the
bootloaderās own code which is stored in
[350]
that area.
[352]
So far so good.
[353]
You send the APDU commands to write your malicious
code, the f00dbabe value is removed and when
[358]
you try to restart the device, the bootloader
will refuse to jump to it.
[362]
Darn.
[363]
Now if you are ledger and you have a real
update firmware, then that firmware will come
[366]
with some kind of signature.
[367]
And when you are done writing your firmware
the bootloder can verify that your new firmware
[372]
is genuine firmware from ledger, and then
it will write the f00dbabe value at the magic
[377]
position, and the firmware is bootable again.
[381]
But we are not ledger⦠so what can we do?
[385]
Now we come to the awesome bug.
[388]
Have look at the memory map here in the official
STM32 manual.
[392]
From 0x08000000 0x08008000 the flash memory
is accessible.
[397]
Or mapped.
[398]
And in our case from 0x08000000 to 0x08003000
we have the bootloader area and at 0x08003000
[408]
we have the f00dbabe value.
[410]
And with APDU commands you cannot write to
this area.
[413]
BUT⦠look down here⦠depending on the
boot configuration you might have SRAM, System
[419]
Memory or FLASH mapped from 0x00000000 to
0x00008000.
[426]
And guess what the ledger has mapped down
here.
[430]
This means, in code, when you are writing
to address 0x00003456 it is exactly the same
[437]
as writing to 0x08003456.
[441]
Both these virtual memory areas map to the
same physical flash memory.
[447]
This means, we can bypass the check of not
being able to write to the bootloader area
[451]
and we can write the 0xf00dbabe value to 0x00003000.
[458]
This is then written to the real flash, and
when the bootloader checks if at address 0x08003000
[464]
is the magic 0xf00dbabe value it will find
it, and happily jump to the code.
[469]
BOOM!
[470]
You have your own code running.
[473]
What does this mean now⦠letās look at
a generic typical software wallet first.
[478]
if your computer had a malware it could compromise
your wallet to send bitcoins to an evil address.
[484]
But with a ledger it has to ask the ledger
to sign that transaction.
[489]
So even if malware could fake what is displayed
on the screen of your laptop and fool you
[495]
into thinking you send it to a trusted address,
with the ledger it would show you that you
[499]
are about to send bitcoins to an different
address.
[503]
But this display is controlled by the untrusted
chip, and we have just introduced an issue
[507]
that would allow a malware on your computer
to write malicious code onto the ledger.
[513]
So theoretically/maybe you might be able to
write code that also fakes the address that
[518]
is displayed on the ledger and trick you into
accepting it.
[522]
Oh or wait.
[523]
The buttons are also connected to the untrusted
chip, so maybe you can just accept that transaction
[528]
without the user even having to consent to
it.
[531]
Just do it without the requirement of the
button.
[533]
The untrusted chip does all that.
[536]
BUT.
[537]
I used the word āmaybeā because it might
not be that simple.
[541]
And maybe it might not be possible at all,
at least that is ledgerās position.
[546]
But Iām sceptical, it feels all like itās
standing on shaking ground and, maybe itās
[551]
not straight forward, but it feels iffy.
[554]
And I know I know.
[556]
PoC or GTFO.
[558]
And I donāt have a proof of concept.
[559]
Shame on me.
[562]
But letās go back to what Saleem Rashid
in March 2018 has criticised about the Dual-Chip
[566]
Design.
[567]
There he writes: āThe Nano S has a second,
non-secure microcontroller which acts as a
[572]
proxy for the Secure Element.
[574]
This processor drives the display, buttons,
and USB interface.
[578]
It interfaces with the Secure Element, which
stores the actual private keys.ā.
[583]
And he calls that inherently a architectural
vulnerability.
[587]
The base hardware design of the ledger is
already flawed.
[590]
So why is Saleem saying that, and why do I
believe he is right, and why do I think this
[594]
f00dbabe issue is a problem.
[596]
Letās start with the secure element.
[599]
In ledgerās own official development document
they write: āIt is incredibly unlikely for
[605]
the Device private key to become compromised,
because the Secure Element is designed
[610]
to be a stronghold against such physical attacks.
[613]
It is theoretically possible to extract the
private key, but only with great expense and
[618]
time, so only an organization such as the
NSA could do it.ā
[623]
Which is pretty honest.
[625]
Details about how the secure element protects
against advanced attacks are not known.
[629]
And hardware attacks can be crazy.
[631]
Like side channel attacks which we have shown
before on this channel, or using acid to open
[635]
up the package, probing it with microscopic
tiny wires or using equipment like electronic
[640]
micoscopes and focused ion beams to extract
single bits, is crazy.
[646]
Thatās why there is a layer of obscurity
and secrecy, not by ledger, but by STMicroelectronics
[653]
that sells this chip.
[655]
Without becoming a big customer and signing
non disclosure agreements you wont get any
[660]
details.
[661]
But thatās necessary because with enough
research, somebody like the NSA, or some other
[665]
lab might be able to extract the private key
after all.
[670]
But Iād say for most people, and count myself
to most people, the private key is really
[675]
secure in the secure element, *cough* if you
trust ledger to never make a backdoored firmware
[680]
for it *cough*.
[682]
But the main design issue that is criticized
here is, that the MCU, the non-secure chip
[688]
acts as a proxy.
[690]
This chip is essentially a man in the middle.
[692]
This chip has access to the Buttons, controls
the screen and communicates with your laptop
[697]
via USB.
[699]
And if you have control over USB, you could
make a BadUSB rubber ducky out of the Ledger,
[704]
for example when somebody plugs it in, it
will send keystrokes to the host computer
[708]
and do something bad.
[710]
You know, Iām not super excited about rubber
duckies, I donāt think thatās such a scary
[714]
attack, but if itās for you, well the ledger
could be turned into one.
[718]
The other thing about the non-trusted chip
acting as a proxy is something you know from
[724]
using the internet.
[726]
you know how dangerous man in the middle can
be.
[728]
You have no clue who sits between you and
google.
[731]
Thatās why we use crypto, like SSL, to create
a trusted end to end connection that even
[737]
if somebody sits in the middle, just eavesdropping
or capable of manipulating traffic, cannot
[741]
steal your secrets.
[743]
And this is actually what the Ledger does.
[745]
In the developer documents you can find a
big section about the Secure Channel, also
[749]
showing you in detail how the protocol works.
[752]
And on top of that the secure element apparently
uses various techniques trying to verify that
[757]
the untrusted chip is running genuine firmware
and otherwise refuses to work.
[763]
So the fact that we can run our own code on
here, might not mean you can actually do much
[767]
with it.
[768]
Like doing wifi man in the middle with everybody
just using a VPN or SSL.
[772]
And that is why ledger says, this is not a
vulnerability.
[775]
And I at least can understand why they are
saying that.
[778]
They clearly tried to design the protocol
in a way, that this chip doesn't have to be
[783]
trusted.
[784]
But the fact is, this is not a secure chip.
[788]
It proxies messages between the PC and the
secure element.
[791]
And yeah Iām pretty confident that that
channel is cryptographically secure and malicious
[794]
code maybe couldnāt really interfere with
it, BUT the chip is still responsible for
[799]
showing critical information about cryptographic
operations and asking via button presses for
[806]
consent from the user.
[809]
Which both malicious code can take over.
[812]
Itās not the secure element that displays
or responds to button clicks.
[816]
And even though the secure element tries to
verify the firmware running on the non-trusted
[820]
chip, it doesnāt magically make that chip
a secure chip.
[824]
The secure element still relies on information
provided by the untrusted chip.
[829]
And they are kind of relying on the fact that
the untrusted chip is limited in memory and
[833]
speed, so itās very difficult to write all
that code to spoof responses, basically emulating
[839]
a genuine firmware to fool the secure element.
[842]
But I think itās just very difficult and
not a perfect protection, and thus I am confident
[847]
that smarter people than me can come up with
a very creative way to pull it off.
[851]
But I admit, there are many challenges and
it requires a looot of more time reverse engineering
[857]
and researching.
[859]
So maybe the bar is high enough, to make this
not economically feasible for a criminal or
[864]
a researcher.
[865]
It certainly is high that I donāt think
I can do it.
[868]
But Iām also just a wannabe hacker.
[870]
BUT, thomas had a very clever idea and created
a proof of concept.
[875]
He created a firmware which is different from
the original one, as you can see and thus
[879]
clearly not trusted.
[881]
Yet this firmware will run once, and then
replaces itself with the genuine firmware,
[887]
so future checks if itās genuine will succeed.
[891]
So while itās not a full attack itās a
first proof of concept into the direction
[895]
of running some malicious code on there and
still have it succeed when tested the next
[899]
time for being genuine firmware.
[902]
I hope that was a good introduction and overview.
[905]
So⦠if you want to learn more about hardware
security and how to do research on the ledger,
[909]
or any kind of embedded hardware, then stay
tuned for more videos.
You can go back to the homepage right here: Homepage





