BadUSB
On
accessories
that
turn
evil
Karsten
Nohl
<nohl@[Link]>
Sascha
Kriler
<sascha@[Link]>
Jakob
Lell
<jakob@[Link]>
SRLabs
Template
v12
Demo
1
USB
s&ck
takes
over
Windows
machine
Agenda
USB
background
Reprogramming
peripherals
BadUSB
aLack
scenarios
BadUSB
exposure
Defenses
and
next
steps
USB
devices
are
recognized
using
several
idenPers
USB
devices
Connectors
+
hubs
Host
Root
hub
Iden&er
Examples
USB
thumb
drive
Interface
class
8
Mass
Storage
a. 1
Audio
b. 14
Video
End
points
0
Control
1
Data
transfers
0
Control
1
Video
transfers
6
Audio
transfers
7
Video
interrupts
Serial
number
(opPonal)
AA627090820000000702
0258A350
Webcam
USB
devices
are
iniPalized
in
several
steps
USB
device
Devices
can
have
several
iden&&es
USB
plug-and-play
Register
Power-on
+
Firmware
init
Set
address
Send
descriptor
Set
conguraPon
Load
driver
Normal
operaPon
OpPonal:
deregister
Register
again
Load
another
driver
A
device
indicates
its
capabiliPes
through
a
descriptor
A
device
can
have
several
descriptors
if
it
supports
mulPple
device
classes;
like
webcam
+
microphone
Device
can
deregister
and
register
again
as
a
dierent
device
USB
devices
include
a
micro-controller,
hidden
from
the
user
USB
controller
8051
CPU
Bootloader
Flash
Controller
rmware
Mass
storage
The
only
part
visible
to
the
user
Agenda
USB
background
Reprogramming
peripherals
BadUSB
aLack
scenarios
BadUSB
exposure
Defenses
and
next
steps
Reversing
and
patching
USB
rmware
took
2
months
A
Document
rmware
update
process
Reverse-engineer
rmware
1. Find
leaked
rmware
and
ash
tool
on
the
net
1. Load
into
disassembler
(complicaPon:
MMU-like
memory
banking)
2. Sni
update
communicaPon
using
Wireshark
2. Apply
heurisPcs:
3. Replay
custom
SCSI
commands
used
for
updates
4. (Reset
bricked
devices
through
short-circuiPng
Flash
pins)
Patch
rmware
1. Add
hooks
to
rmware
to
add/change
funcPonality
2. Custom
linker
script
compiles
C
and
assembly
code
and
injects
it
into
unused
areas
of
Count
how
olen
funcPon
original
rmware
starts
match
up
with
funcPon
calls
for
dierent
Other
possible
targets
memory
locaPon
guesses;
the
most
matches
indicate
We
focused
on
USB
sPcks,
that
you
guessed
right
but
the
same
approach
should
work
for:
Find
known
USB
bit
elds
such
as
descriptors
External
HDDs
3. Apply
standard
solware
reversing
to
nd
hooking
points
Webcams,
keyboards
Probably
many
more
Agenda
USB
background
Reprogramming
peripherals
BadUSB
aKack
scenarios
BadUSB
exposure
Defenses
and
next
steps
Demo
2
Windows
infects
USB
s&ck
which
then
takes
over
Linux
machine
10
Keyboard
emulaPon
is
enough
for
infecPon
and
privilege
escalaPon
(w/o
need
for
solware
vulnerability)
Challenge
Linux
malware
runs
with
limited
user
privileges,
but
needs
root
privileges
to
infect
further
sPcks
Approach
Steal
sudo
password
in
screensaver
Restart
screensaver
(or
policykit)
with
password
stealer
added
via
an
LD_PRELOAD
library
User
enters
password
to
unlock
screen
Malware
intercepts
password
and
gains
root
privileges
using
sudo
11
Demo
3
Android
phone
changes
DNS
sePngs
in
Windows
12
Network
trac
can
also
be
diverted
by
DHCP
on
USB
DNS
assignment
in
DHCP
over
spoofed
USB-Ethernet
adapter
All
DNS
queries
go
to
aLackers
DNS
server
AKack
steps
Result
1. USB
sPck
spoofs
Ethernet
adapter
3. Internet
trac
is
sPll
routed
through
the
normal
Wi-Fi
connecPon
4. However,
DNS
queries
are
sent
to
the
USB-supplied
server,
enabling
redirecPon
aLacks
2. Replies
to
DHCP
query
with
DNS
server
on
the
Internet,
but
without
default
gateway
13
Can
I
charge
my
phone
on
your
laptop?
Android
phones
are
the
simplest
USB
aLack
plaworm
DHCP
overrides
default
gateway
over
USB-Ethernet
Computer
sends
all
Internet
trac
through
phone
Prepara&on
Android
comes
with
an
Ethernet-
over-USB
emulaPon
needing
liLle
conguraPon
AKack
Phone
supplies
default
route
over
USB,
eecPvely
intercepPng
all
Internet
trac
Proof-of-concept
released
at:
[Link]/badusb
Hacked
by
the
second
factor?
Using
keyboard
emulaPon,
a
virus-infected
smartphone
could
hack
into
the
USB-
connected
computer.
This
compromises
the
second
factor
security
model
of
online
banking.
14
Bonus:
Virtual
Machine
break-out
1. VM
tenant
reprograms
USB
device
(e.g.,
using
SCSI
commands)
Malicious
VM
2. USB
peripherals
spawns
a
second
device
that
gets
connected
to
the
VM
host
Host
3. USB
device
spoofs
key
strokes,
changes
DNS,
15
Boot-sector
virus,
USB
style
Fingerprint
OS/BIOS.
Patched
USB
sPck
rmware
can
disPnguish
Win,
Mac,
Linux,
and
the
BIOS
based
on
their
USB
behavior
Hide
rootkit
from
OS/AV.
When
an
OS
accesses
the
sPck,
only
the
USB
content
is
shown
USB
content,
for
example
Linux
install
image
Infect
machine
when
boo&ng.
When
the
BIOS
accesses
the
sPck,
a
secret
Linux
is
shown,
booPng
a
root
kit,
infecPng
the
machine,
and
then
booPng
from
hard
disk
Secret
Linux
image
16
Demo
4
USB
thumb
drive
emulates
keyboard
and
second
drive
to
infect
computer
during
boot
17
Family
of
possible
USB
aLacks
is
large
More
aKack
ideas
Eect
AKacks
shown
Hide
data
on
s&ck
or
HDD
Emulate
keyboard
Spoof
network
card
External
storage
can
choose
to
hide
les
instead
of
delePng
them
Rewrite
data
in-ight
Viruses
can
be
added
to
les
added
to
storage
First
access
by
virus
scanner
sees
original
le,
later
access
sees
virus
Update
PC
BIOS
Emulate
a
keyboard
during
boot
and
install
a
new
BIOS
from
a
le
in
a
secret
storage
area
on
a
USB
sPck
Spoof
display
Emulate
a
USB
display
to
access
security
informaPon
such
as
Captchas
and
randomly
arranged
PIN
pads
USB
boot-
sector
virus
18
Agenda
USB
background
Reprogramming
peripherals
BadUSB
aLack
scenarios
BadUSB
exposure
Defenses
and
next
steps
19
We
analyzed
the
possible
reach
of
BadUSB
from
two
perspecPves
Top-down
analysis
BoKom-up
analysis
Start
from
largest
USB
controller
vendors
Start
from
actual
hardware
Open
device
to
nd
which
chips
are
used
Determine
whether
bootloader
and
rmware
storage
(e.g.
SPI
ash)
are
available
Try
to
nd
rmware
update
tools
for
their
chips
Find
their
chip
families
for
popular
use
cases
Analyze
datasheets
and
web
sites
for
whether
chips
can
be
reprogrammed
5
device
classes:
Host,
Hub,
Charger,
Storage,
Peripheral
From
top
8
chip
vendors
Totaling
52
chip
families
(not
every
vendor
serves
each
class)
Analyzed
33
devices
from
six
device
classes:
Hub,
Input/HID,
Webcam,
SD
adapter,
SATA
adapter
Results
released
at
[Link]
20
Probably
vulnerable
Both
analyses
suggest
that
up
to
half
of
USB
chips
are
BadUSB-vulnerable
Top-down
analysis
Host
Hub
Charger
Storage
Peripheral
Top-down:
Perhaps
vulnerable,
depends
on
design
/
conguraPon;
BoLom-up:
more
research
needed
Unlikely
vulnerable
BoKom-up
analysis
1
4
2
8
3
5
Input
Webcam
SD
adapter
SATA
adapter
3
21
Small
hardware
design
dierences
can
determine
BadUSB-
vulnerability
These
USB
hubs
both
contain
the
same
controller
chip
Only
one
of
them
also
contains
an
SPI
ash
that
can
store
BadUSB
modicaPons
22
Recent
trends
suggest
that
BabUSB-exposure
is
further
growing
Insight
Trend
1
Newer
and
more
complex
devices
are
more
vulnerable
Some
device
types
appear
more
reprogrammable
/
BadUSB-vulnerable:
The
early
devices
of
a
new
standard
(e.g.
the
rst
available
USB
3
devices)
Peripherals
with
special
funcPonality
(e.g.
SATA
adapter
that
can
copy
disks)
High-end
peripherals
Trend
2
Chips
become
more
versa&le,
and
thereby
more
vulnerable
Custom-tailored
chips
in
high-volume
devices
were
tradiPonally
less
likely
to
be
reprogrammable;
probably
because
mask
ROMs
are
cheaper
than
Flash
Many
such
use
cases
are
increasingly
served
with
reprogrammable
mulP-
purpose
chips,
that
realize
economies
of
scale
by
combining
applicaPons
Trend
3
Most
controllers
that
can
be
programmed
are
vulnerable
USB
controllers
found
not
to
be
reprogrammable
were
missing
an
essenPal
component
for
upgrades,
such
as
bootloader
or
Flash
to
store
the
update
All
those
controllers
that
bring
the
essenPals
seem
to
be
upgradable
ProtecPon
from
malicious
updates
is
very
rare:
Only
one
(large)
chip
family
brings
fuse
bits;
none
implement
rmware
signing
23
Agenda
USB
background
Reprogramming
peripherals
BadUSB
aLack
scenarios
BadUSB
exposure
Defenses
and
next
steps
24
No
eecPve
defenses
from
USB
aLacks
exist
Protec&on
idea
Limita&on
Whitelist
USB
devices
USB
devices
do
not
always
have
a
unique
serial
number
OSs
dont
(yet)
have
whitelist
mechanisms
Block
cri&cal
device
classes,
block
USB
completely
Obvious
usability
impact
Very
basic
device
classes
can
be
used
for
abuse;
not
much
is
lel
of
USB
when
these
are
blocked
Scan
peripheral
rmware
for
malware
The
rmware
of
a
USB
device
can
typically
only
be
read
back
with
the
help
of
that
rmware
(if
at
all):
A
malicious
rmware
can
spoof
a
legiPmate
one
Use
code
signing
for
rmware
updates
ImplementaPon
errors
may
sPll
allow
installing
unauthorized
rmware
upgrades
Secure
cryptography
is
hard
to
implement
on
small
microcontrollers
Billions
of
exisPng
devices
stay
vulnerable
Disable
rmware
updates
in
hardware
Simple
and
eec&ve
(but
mostly
limited
to
new
devices)
25
Responsibility
for
BadUSB
miPgaPon
is
unclear
Fixes
are
not
yet
in
sight
No
response
from
chip
vendors
No
response
from
peripheral
vendors
No
OS
vendor
response
Phison,
the
mostly
discussed
vendor,
notes
that
they
are
already
oering
beLer
chips.
Their
customers
dont
seem
to
chose
them
olen
Other
aected
vendors
have
stayed
quiet
No
aected
vendor
oers
patches
or
a
threat
advisory
OS
implementers
do
not
appear
to
work
on
soluPon;
with
one
excepPon:
FreeBSD
adds
an
opPon
to
switch
o
USB
enumeraPon
vs.
BadUSB
malware
becomes
more
realis&c
Sample
exploit
code
for
Phison
USB
3
controllers
was
released
by
Adam
Caudill
and
Brandon
Wilson
at
Derbycon
in
September
Only
miPgaPon
aLempts
right
now
are
quick
xes
such
as
GDatas
Keyboard
Guard
26
USB
peripherals
can
also
be
re-programmed
for
construcPve
purposes
Idea
1
Speed
up
database
queries
Data
can
be
parsed
on
the
sPck
before
(or
instead
of)
sending
it
back
to
the
host
Our
original
moPvaPon
was
to
speed
up
of
A5/1
rainbow
table
lookups
Idea
2
Repurpose
cheap
controller
chips
Use
the
reprogrammable
chips
for
other
applicaPons
than
USB
storage
The
owswitch
/
phison
project,
for
example,
aims
for
a
low-cost
USB
3
interface
for
FPGAs
27
Take
aways
USB
peripherals
provide
for
a
versaPle
infec&on
path
Once
infected
through
USB
or
otherwise
malware
can
use
peripherals
as
a
hiding
place,
hindering
system
clean-up
As
long
as
USB
controllers
are
re-
programmable,
USB
peripherals
should
not
be
shared
with
others
QuesPons?
usb@[Link]
28
The
USB
microcontroller
market
is
split
among
many
vendors
Wired
USB
Market
Share
(2012
Cypress
Shareholders
MeePng)
Scope
of
top-down
analysis
Microchip
(SMSC)
10%
Cypress
8%
Others
26%
Alcor
7%
PLX
Via
Labs
1%
1%
Fresco
1%
Displaylink
2%
Exar
2%
Silicon
Labs
3%
Silicon
MoPon
3%
TI
JMicron
3%
3%
Source:
[Link]/NtN0cf
Renesas
6%
Genesys
5%
ASMedia
5%
ST-E
4%
FTDI
4%
Phison
5%
29