ShmooCon2014-Controlling USB Flash Drive Controllers
ShmooCon2014-Controlling USB Flash Drive Controllers
### Overview
Phison based flash drives have various modes that dictate how they operate;
Assuming you're doing this under Linux, insert your flash drive and look at your
kernel messages. You're looking for the 'scsi generic' device:
```
Jun 07 21:48:32 darkstar kernel: usb 2-1.4: new high-speed USB device number 28
using ehci-pci
Jun 07 21:48:32 darkstar kernel: usb 2-1.4: New USB device found, idVendor=13fe,
idProduct=5500
Jun 07 21:48:32 darkstar kernel: usb 2-1.4: New USB device strings: Mfr=1,
Product=2, SerialNumber=3
Jun 07 21:48:32 darkstar kernel: usb 2-1.4: Product:
Jun 07 21:48:32 darkstar kernel: usb 2-1.4: Manufacturer:
Jun 07 21:48:32 darkstar kernel: usb 2-1.4: SerialNumber: 070A8433D0485364
Jun 07 21:48:32 darkstar kernel: usb-storage 2-1.4:1.0: USB Mass Storage device
detected
Jun 07 21:48:32 darkstar kernel: scsi host8: usb-storage 2-1.4:1.0
Jun 07 21:48:33 darkstar kernel: scsi 8:0:0:0: Direct-Access PMAP PQ: 0 ANSI: 6
Jun 07 21:48:33 darkstar kernel: sd 8:0:0:0: Attached scsi generic sg5 type 0
Jun 07 21:48:33 darkstar kernel: sd 8:0:0:0: [sdd] 15482880 512-byte logical
blocks: (7.93 GB/7.38 GiB)
Jun 07 21:48:33 darkstar kernel: sd 8:0:0:0: [sdd] Write Protect is off
Jun 07 21:48:33 darkstar kernel: sd 8:0:0:0: [sdd] Mode Sense: 23 00 00 00
Jun 07 21:48:33 darkstar kernel: sd 8:0:0:0: [sdd] No Caching mode page found
Jun 07 21:48:33 darkstar kernel: sd 8:0:0:0: [sdd] Assuming drive cache: write
through
Jun 07 21:48:33 darkstar kernel: sdd: sdd1
Jun 07 21:48:33 darkstar kernel: sd 8:0:0:0: [sdd] Attached SCSI removable disk
```
Run `sg_raw` from sg3_utils to dump the configuration. You're going to need to be
root to do this.
If you don't see something on the screen like the above, either you picked the
wrong scsi generic device, or your flash drive isn't based on a Phison USB flash
drive controller.
BTW: 0x17E-0x17F (0x2307) is the phison chip ID (this drive is a PS2307, aka
PS2251-07).
You may want to save this off to a file in case you need to restore it later (not
certain on how to do that just yet):
If you *do* see the above, we can proceed! Look at offset 0x200 -- you see 0x4946.
I don't really know what this configuration page is for (aside from what appears to
be the serial number and some other settings), but the 0x49 and 0x46 are necessary
for dumping the actual configuration of how the drive is configured. I mention 0x49
and 0x46 because those bytes are used in dumping the correct "page"(?) of the flash
drive's configuration, but .. when I fuzzed 0x00-0xFF for the places 0x49 and 0x46
go in the following command, I only had a few (less than 5) that returned different
data.
This should create `configuration.bin`, which will contain the binary seen in the
hex dump above. To make it easy to modify and be sent back to the drive, I like to
use `xxd` and `xxd -r`.
```
00000000: 1201 0002 0000 0040 fe13 0055 0001 0102 .......@...U....
00000010: 0301 0403 0904 0000 0000 0000 0000 0000 ................
00000020: 0000 0000 0000 0000 0000 0000 1203 2020 ..............
00000030: 2020 2020 2020 0000 0000 0000 0000 0000 ..........
00000040: 0000 0000 0000 2203 2020 2020 2020 2020 ......".
00000050: 2020 2020 2020 2020 0000 0000 0000 0000 ........
00000060: 2203 3035 3733 3036 4134 3830 3430 3330 ".057306A4804030
00000070: 3330 4430 3030 3430 3830 3030 3030 3030 30D0004080000000
00000080: 3030 3030 3030 3030 3030 3030 3030 3030 0000000000000000
00000090: 3030 3030 0000 0000 0000 0000 2020 2020 0000........
000000a0: 2020 2020 2020 2020 2020 2020 0300 000a ....
000000b0: 2020 2020 2020 2020 504d 4150 3100 0000 PMAP1...
000000c0: 0cff ffff 5068 4973 4f6e 0007 0000 0000 ....PhIsOn......
000000d0: 0000 0000 0000 0000 0000 000d 0b11 0503 ................
000000e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000f0: 0000 0000 0000 0000 0000 0000 003f 964b .............?.K
00000100: 6432 0fd0 0000 0000 0000 0002 a0a0 0000 d2..............
00000110: 0000 0000 0000 0000 00d3 ee64 00a5 0000 ...........d....
00000120: ec00 0000 0000 0000 0000 0000 0000 00ff ................
00000130: a0a0 0000 0000 0000 0000 0000 0000 0000 ................
00000140: 0000 0000 0000 0000 0000 c000 0005 110b ................
00000150: 0104 2300 0000 0000 aa00 0000 0000 0000 ..#.............
00000160: 0000 0000 1124 906d 0000 0000 0000 0000 .....$.m........
00000170: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000180: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000190: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001a0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001c0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001d0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000200: 4946 0000 0000 0000 0000 0000 0000 0000 IF..............
```
2. Go to offset 0x0AC, and change 0x03 above to 0x07 (or vice versa) to flip
between modes on the drive.
3. Remove the line for offset 0x200 entirely, if it exists. We're only going to
send 512 bytes to the drive.
4. Modify offset 0x1FC through 0x1FF. This value (in modes other than mode 3) is
the size of one of the volumes, in 512 byte sectors.
5. Write the configuration back to the drive with the following command:
# Your drive should now be operating with a new configuration! Happy hacking!
Set your drive into mode 0x07, set your split based on your ISO9660 image size, and
set the configuration (above xxd -r | sg_raw command). Unplug and reconnect your
flash drive. dd over your ISO9660 image to the second LUN. Now that your ISO image
has been dumped to the flash drive, reconfigure it to mode 21 (0x15). Unplug and
reconnect your drive. You should now see two devices, an emulated cdrom, and a
flash drive.
@warewolf
Its possible change "[5511.755408] sd 4:0:0:0: [sdc] Write Protect is on" to "Write
Protect is off" by this hacking or I must download Phison driver (on Windows).
Sorry my English.
@sunbqto
I don't know what turns on and off read-only mode on a Phison based USB flash
drive, sorry. You should try Phison utilities under Windows from sites like
usbdev.ru, flashboot.ru, and upan.cc.
@warewolf
```
knoppix@Microknoppix:~$ sg_raw -r 1k -v /dev/sg3 06 05 00 00 00 00 00 00 80 00 00
00
cdb to send: 06 05 00 00 00 00 00 00 80 00 00 00
SCSI Status: Good
```
knoppix@Microknoppix:~$ sg_raw -r 1k -v /dev/sg3 06 05 49 4e 46 4f 00 00 80 00 00
00
cdb to send: 06 05 49 4e 46 4f 00 00 80 00 00 00
SCSI Status: Good
```
00000000: 1201 0002 0000 0040 6715 0289 0001 0102 .......@g.......
00000010: 0301 0403 0904 0000 0000 0000 0000 0000 ................
00000020: 0000 0000 0000 0000 0000 0000 1203 4b69 ..............Ki
00000030: 6e67 7374 6f6e 0000 0000 0000 0000 0000 ngston..........
00000040: 0000 0000 0000 1403 4454 2031 3031 2047 ........DT 101 G
00000050: 3200 0000 0000 0000 0000 0000 0000 0000 2...............
00000060: 3203 4130 4230 4330 4430 4530 4630 3030 2.A0B0C0D0E0F000
00000070: 3030 3031 3045 3033 3032 0000 0000 0000 00010E0302......
00000080: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000090: 0000 3900 0000 0000 0000 0000 4454 2031 ..9.........DT 1
000000a0: 3031 2047 3220 2020 2020 2020 0300 0000 01 G2 ....
000000b0: 4b69 6e67 7374 6f6e 504d 4150 0000 0000 KingstonPMAP....
000000c0: 0cff ffff 5068 4973 4f6e 0007 0000 0000 ....PhIsOn......
000000d0: 0000 0000 0000 0000 0000 000f 1000 0101 ................
000000e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000000f0: 1800 0000 0000 0000 0000 0000 0000 3232 ..............22
00000100: 3232 0fd0 0001 0200 0091 8111 a1a2 cd00 22..............
00000110: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000120: 0000 0000 0000 0000 0000 0000 0000 00ff ................
00000130: a0a0 0000 0000 bdbc 00b8 d401 0000 0000 ................
00000140: 0000 0000 00c1 0000 0000 c000 5010 14ff ............P...
00000150: 0101 3000 0000 0000 0000 0000 0000 0000 ..0.............
00000160: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000170: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000180: 0000 0000 0000 0000 0000 0000 0000 0000 ................
00000190: 4100 7f07 5550 546f 6f6c 2032 3039 335f A...UPTool 2093_
000001a0: 3230 3135 3132 3134 2d30 3832 3535 3600 20151214-082556.
000001b0: 4953 5036 312e 6269 6e00 002c 5344 544e ISP61.bin..,SDTN
000001c0: 424e 3631 5631 3134 752d 392e 6269 6e00 BN61V114u-9.bin.
000001d0: 3232 3658 2d44 3246 572d 3135 3031 3038 226X-D2FW-150108
000001e0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
000001f0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
```
Currently, one of the intrusion analysts at SRA national sensitive response center.
I've been doing it for about 10 years.
I primarily do malware analysis, Perl scripting, and just all around SysAdmin-fu.
And if you want to get in touch with me, here's my twitter, my email address, and
my github account where I've got all kinds of crazy code.
But overall, generally, I'm a hacker. This is me working on an Arduino like insect,
a programmer that I got from China. It was like 4 bucks.
And I wouldn't be quite such awesome hacker if a word for these two organizations,
Nova Hackers, and Nova Labs, I'm actually on the board of both these organizations.
Now, if there's anybody from either of these organizations in the audience, please
stand up.
All right, thank you. So these organizations are awesome because they promote you
to be better at speaking, doing more awesome hacks and stuff. So most people then
ask them, how do I join? And they'll hope you join.
There's also a women focused group starting up at a Nova Labs and Nova Hackers. Led
by Stacey and Sarah.
But so if you're trying to get into it, or hacking your stuff in your kind of like,
free to, like go see them, and I hope you up.
So why are we here? We're here for hacking on USB thumb drives.
So to give you a point of reference in why I started, it's because I heard about
this virus going around on twitter and on, like, Google Plus. You know, something,
it was kind of crazy.
### Page 007: (pic)
I mean, it was like this 7 headed hydra virus that was being written by some dude
in his basement.
Or like these crazy computers. All right, so this is the audience participation
point.
So this was the really scary part. All right, so say it with me. You probably know
what I'm talking about now. On the count of 3. 1, 2, 3, BadBIOS. All right. Thank
you. Yes.
3. We heard it could infect the host firmware, you know, like the BIOS, the
keyboard controller, et cetera.
6. And it also somehow had IPv6 networking, like you would do that for a command
and control.
7. And then the coup de grace of all of this was it would do audio based
networking. Sure, like your laptops, microphone, speaker to bridge air gaps, you
know, in case you unplug everything.
Ok, maybe you could do it once, unlike one particular system that you're targeting.
And you would know the hardware in and out, more than the original developers did.
But I mean, to do that, where you can go between a whole bunch of different systems
that someone owns, time and time again, and keep your infection present -- I think
it's kind of difficult. So just forget all that. I don't care about BadBIOS, but I
also don't want to hear anything about it. I don't want to hear anything about
leaks that have come out recently. I hadn't read any of them.
* So I'm here to talk about USB flash drives and USB mass storage.
* So I'm going to go over parts of the hardware. I'm going to show you some nice
hardware part photos. I love taking hardware apart.
* And show you how to identify the flash controllers and what their features are.
* And then ultimately, how you can reprogram them to do cool things for yourself.
So mass storage.
So I've got a family of hard drives here, a mummy, a daddy, and little baby, two
3.5 inch hard drives, one 2.5 inch hard drive. And those are pretty standard. You
seen those all over.
And we've also got these regular thumb drives that are about the size of your
thumb.
And then we've got these things that are absolutely fricking tiny.
Okay. So the point I'm trying to make here is, USB mass storage has gone from being
absolutely massive to absolutely tiny, but conversely, the capacity of these
devices has gotten larger and larger and larger.
So here, for some nice photos. So this is a really old USB hard drive where you got
your IDE hard drive, you got your data ribbon, your power cable. When tucked down
either, all of that is your control board that does the USB protocol, or IDE
protocol.
It's the same basic idea for your SATA hard drive where you got your plastic
clamshell case, your hard drive, and then your control board that does your data
and power.
And then flash drives, I mean, they've got basically their memory chips for storing
the actual data, and then got the controller. This drive actually happens to be
USB3. You can kind of tell by there's extra pins on the USB connector instead of
just four.
* So here is your host interface, where your USB cable comes in.
* You've got your power for making the power nice to the hard drive, and the rest
of it.
* Then you've got your USB data pins, now USB pins. There are differential
signaling, so that's why there's two separate wires, so you can have better signal
fidelity.
* And then coming out of the bridge chip, you've got your SATA pins. Now, these are
also differential signaling. It's 2 pair of them.
* And then, ultimately, down to your host device, your hard drive, CD-ROM,
whatever.
Now, I said, bridging controllers here. The reason why is because there's a
difference between a hard drive USB enclosure controller, versus a flash drive
controller. Under the hood, they're actually kind of similar, but it's the firmware
that's running on them.
* On a USB hard drive controller, which got spinning media or a CD-ROM, it's
intentionally generic firmware. You're only going to see the hard drive or CD-ROM
drive that's actually physically connected to it.
* On a flash controller, all it's doing is logically mapping the sector that the
computer asked for to a region in the flash memory on the chip. The flash, oh, the
controller can be reprogrammed, and the host ultimately sees what the controller
wants (itself) to (be).
Now, some of you have probably taken a hardware out of an enclosure because it
wasn't working and troubleshoot it, shoot it by plugging into your computer
directly. And if you've ever done that, it works on a computer.
It's because your controller lost its freaking mind. All right, so.
All right, so. Onto flash heart, USB flash controller parts.
### Page 032: Basic Components of Flash drives
So here's a basic USB thumb drive. And just for size reference, here is actually
this drive I took a picture of.
* So the chip I have circled here is the flash controller. It's an ASIC. ASIC, in
case you're not familiar, stands for Application Specific, Integrated Circuit. It
does one thing very special and that one thing very well. It's not generic. It
can't do a whole bunch of things.
* And if we flip this guy around, we've got the actual flash memory.
* The speed on them is between 6 megahertz and 2.5 gigahertz. 2.5 gigahertz is the
USB3 SuperSpeed end of the line.
* And all the bridge or controller chip does. It translates the USB protocol, to
what your hard drive or CD-ROM or whatever happens you plugged in, speaks.
* And the reason why, is because there's no direct translation from the USB mass
storage protocol to what the hard drive talks. You have to have that guy in the
middle doing the translation for you.
* Now what you probably weren't aware of is USB mass storage is actually SCSI. You
know those, those old old old loud ten thousand rpm drives that you have on this
chain of drives.
* And it's not a full SCSI command set. It's a subset based on whatever you have: a
hard drive, CD-ROM drive, tape drive, et cetera plugged in.
* And these SCSI commands actually ride on top of the USB protocol. It's
encapsulated. And that can sometimes cause trouble. So if you ever used the smart
control, or smartmon, a hard drive monitoring software, through USB like THAT,
sometimes it doesn't work right.
* And with this, it's still SCSI, still one SCSI target. That means you've got one
device. But you can have more than one logical unit, and that's what's called a
logical unit number.
So I keep going in this specifics of the USB protocol, and here's actually what it
looks like with the two data lines. Where you've got 1 it's a high voltage. O is a
low voltage.
And the reason why, is because when you have those two voltages separate from each
other like that, the device on the other end can say, oh, that was a 1, or that was
a 0.
Meanwhile, if you get some interference like EMI interference or RFI interference,
whatever that affects both of the lines (the same on the other line) you see
nothing. Because it has subtracted that noise out.
So why am I going on all this detail for all this USB level protocol stuff? It's
because I found this utility that lets me mess with flash drives. This one would
actually lets you hide parts of your flash drive with a password, so that your
operating system can't see it. And it worked. It was awesome, but I had no idea how
it worked. So I said, I had to figure this out.
So I, I had to figure out what my options were. I could use a logic analyzer, I
could use a hardware MITM device, and there are some pros and cons of both.
* The logic analyzer generally has too much detail. I mean, it's got exactly what's
on the wire, errors included, and there's no protocol-in-protocol decoding. All
that extra effort -- that the USB mass storage protocol, and the SCSI commands, and
stuff have on top of USB -- is just bits and bytes to these logic analyzers.
* If you want to use a hardware MITM in the middle of device, go seek Dominic talk
tomorrow. He's got a BeagleBone Black board that he's converted into being a USB
MITM device.
* And so I'm sniffing a USB thumb drive that's USB2 as well. And if you're trying
to do something at 60 miles an hour, and then record exactly everything that's
going on at 60 miles an hour, or USB2 speeds, you're going to drop some data.
* So I actually had to slow down my USB flash drive by plugging it into the USB1
hub. So that way I had faster recording capabilities that my actual device is
producing data.
And then stripped off the shielding and put in my test taps.
So I had to switch to high-level sniffing USB. And there's pros and cons of this as
well.
* So you can install a driver in windows called USBPcap. It basically ties in the
Wireshark, and can make a network interface that you say, does this USB interface.
And because it's so high-level, it's basically tracing the execution of the
commands, in windows, against that USB device. And in windows, you just send your
commands, and at some point down the line, like it gets actually sent on the USB
connector. And it can be in the same order you executed the commands, or can be a
different order. There's kind of scheduling that goes on, so they can or will miss
data.
* Another option is you can use your virtualization environment: VMware, QEMU,
VirtualBox or whatever. Almost all of them support: in the hypervisor, dumping out
the virtual USB stack.
* In Linux, under qemu-kvm, has got its kernel module called USBmon, and that does
the same thing as USBPcap. But it's lower level, so it actually will get all of the
data from the OS.
So there's lots of tools to look at. The USBPcaps, the usbmon variants, most
importantly, Wireshark. Wireshark has the USB protocol decoding, USB mass storage
decoding.
And that's what it looks like. So at the bottom of the bytes display, now we see
the word 'password' that I had from the logic analyzer. And up above, I have the
SCSI command where its SCSI command '0e', logically unit number '1'. So now I have
a much better understanding, of exactly what the command and the payload in that
command was, to describe the unlock.
### Page 046: Re-implementing USB Flash Drive Security Features Under Linux
So I was able to successfully re-implement the USB flash drive security software
under Linux.
* So I've got these random bytes here -- '0E 00 01 55 AA', that will turn off the
protection.
### Page 047: Re-implementing USB Flash Drive Security Features Under Linux
And, here's actually how to change or set the password under Linux. So, this is
using a command called sg_raw. It just fires SCSI commands at a device. And this is
actually basically a 64 bytes packet that gets sent: the first 16 bytes are the old
password in case you're changing the password; the next one is the new password;
and the last one, the last 32 or a password hint.
So you basically do the same thing I did for any other implementation of this --
you sniff the traffic, figure out how it's working, and then re-implement it with
sg_raw or other application.
So that was a little bit of a teaser of the cool things that you can do, when you
get this sort of sniffing stuff set up. But how do you get there? How do you get
that up to that point?
Well, you rip apart a hardware, and you look at the flash controller. So, this is
the flash controller on this drive here. I actually darkened the photo a little
bit, so it makes it easier to read. That chip says UP21. So I went to Google and I
punched a 'UP21 flash'.
And suddenly, bang, all these websites pop up with information about this chip. A
lot of them in Chinese or Russian (or there was a couple of veteran English
language) but a lot of them go through Google translate very well. And it got to
the point -- in some of these Chinese websites where I was downloading stuff, I
actually knew what the 'download' characters looked like: oh, it's that one, not
this one, this actually says, 'download.com toolbar' thing.
So. So when you're researching these flash drives, you've probably heard of all of
these consumer vendors: SanDisk, Kingston Digital, et cetera. These are all the
brands that you've seen in your stores.
And what you've probably not seen is the chips that are on the inside of these. So
this is where you get all the OEM flash controller manufacturers that produce chips
that are on the inside of those drives. You're not supposed to know nor care about
what these chips are. It's supposed to be insignificant to you. The driver is
supposed to operate as a flash drive, and you're dumb with it.
But. Going on. So the question is: what manufacturer of the consumer drives uses
what chip.
So I've got the chip flash controller vendors on the outside, I've got the consumer
vendor on the inside, and little arrows that point to each one, and then a running
tally of how many times I've seen that flash controller vendor was used. So let's
get started.
* Lenovo Alcor.
So Kingston is a name that I associate with quality, but apparently they don't
care, they don't care what flash drive controller they're going to use.
So. So I went out to the store, and I bought a whole bunch of thumb drives with the
intention of tearing these bad boys apart and see what was on the inside. I tried
to get as many different ones as possible: different shapes, sizes, features, et
cetera.
So this is what they look like when they have their casing removed.
Now there's one in the middle. It's kind of hard to see in the screen, but it looks
like a little black stick that we kind of knew what it would look like, like that
from the previous pic. So because it's an absolutely tiny thing.
But the other ones are also black sticks you couldn't tell. So, I mean, it was
plastic housing around this tiny, little black stick. And I had no idea those other
two would look that way.
But one and one of them, these are the different vendors that are the flash
controllers on these drives. So we've got Innostor, SMI, Phison, Phison, Phison,
USBest, SMI, Phison and Phison. So I'm seeing a running pattern here.
Phison is apparently really popular. At these drives, at least the drives that I
got from Micro Center, there were four different kinds of drives from Phison.
And these all pretty much had the same feature set between the Phison chips and
then across different manufacturers, like in a store in Silicon Motion.
* So just to give you new idea of what these capabilities are, here's this 4 gig
thumb drive that I got at Micro Center for five bucks.
* So this is a Phison controller. It's the PS2251-61. This supports multiple LUNs
(the multiple virtual drives), hidden LUNs (so now you can hide data). And then it
also supports password protecting them.
Again, for five bucks. This is not something you're supposed to be aware of.
* This is a Centeon drive. This one happens to be about a dollar a gig again.
* This one uses a different chip. This one uses the SMI SM3257ENLT, and supports
the same features of the chip I saw before.
* And this is one of the drives that I intentionally found, something that was
supposed to be awesome. So this is the Centeon secure chip. So this is about 2
dollars a gig.
* But wait, this one uses the same controller as the 5 dollar ,flash driver I had
before.
* And what it does have is it actually has a logical unit -- another virtual hard
drive on there that's got crypto software for mac. And I'm a PC guy. So this drive
was twice as expensive and useless to me.
* Or would you spend twice as much money on a drive that has no hardware crypto
support -- that just has software on it?
Me, I would buy the cheaper one. But the problem is you don't know what you're
getting, until you take it apart, or until you look at it.
So, just to give you guys a better idea, what those tiny little black sticks were,
those are called monolithic USB drives.
So here's what they look like with part of their epoxy removed, and these photos
came from RecoverMyFlashDrive.com. But this is all in one -- one package, the
controller and the memory at the same time.
And this is what they look like when they're being fabricated. These photos came
from Bunnie. If you saw Bunnie & xobs talk @ 30C3, go watch it, it's awesome. So
this is actually the bottom of these being fabricated.
And this is the top. So it's 8 chips. You can barely see it on this slide, but the
flash controller and the flash memory all right next to each other.
And just to point out which is which. So here is the flash drive I had (up earlier)
pointing out the flash controller, and then here's the monolithic chip together. So
that's the flash controller.
Now, just to give you guys a better sense of scale, here's what the monolithic
drive looks like in comparison to a regular USB drive. So you guys know how big a
USB connector is. And that entire chassis is about the width of a USB connector.
It's tiny, and they seemed can get even skinnier to be absolutely like the size of
a dime.
* The consumer packaging never mentions what controllers on the inside, so it's
just a game of guesswork.
* The OEMs like Kingston can use anything that they want.
* I don't have nitric acid and a fume hood to remove the epoxy from the drives.
* Well, the operating system sees what the flash controller wants it(self) to be: a
hard drive, CD-ROM, whatever.
* But they're not. I've seen an entire line of different sizes of thumb drives that
had the same product ID and vendor ID. And, a company doesn't have to use a
different vendor ID or product ID for a different product, if it's the same basic
functionality they can bring in a new controller chip, whatever.
Well, I happen to find one written by some folks in China. It's an application
called ChipEasy, and this really is easy to identify your drives.
And because I know this is kind of hard to see, I'll give you a zoom in on it. So
it's got all the details you could ever need: it's got the drive letter, the
capacity, the product ID, vender ID, serial number, et cetera. And the nice thing
about it is it shows you where the controller manufacturer, that controller type
is. And then the coup de grace on this, as it tells you where to download software
and mess with these drives. Thank you. Thank you.
All right, so. I had a whole bunch of Phison drives, so I decided to pick on them.
* They make controllers for USB 1 through 3, SATA, IDE, eMMC, SD cards, et cetera.
* Basically they have one common core that they can just bootstrap another
interface on. All of these chips seem to be based on the Intel 8051. That is what's
called an 'IP' core. Or it's such an old microcontroller that you can basically
license the software schematic of this chip and then integrate it into a chip that
you're designing.
* Some of Phison's controllers support crypto, most of them support AES, I've seen
some that supports RSA.
* And in all these drives support different modes. Modes are how the drive actually
interacts with the operating system as being a hard drive, a hidden drive, CD-ROM,
etc.
2. The encryption key ***may*** be held within the ASIC, not on your flash memory.
And this is probably done during the initial configuration of your thumb drive.
3. And then you've got logical numbers -- logical unit numbers. That are logical
drives that can be hidden or lock with a password and optionally encrypted.
4. So. Another thing that's crazy is these flash drives have more space than you
know. If you listen to Bunnie's talk, every flash chip as manufactured ultimately
ends up in some consumer device, everything is used. You fabricate an 8 gig chip
and only 7 gig of it is used well. Ok, now that's a fogging chip. So they actually
clip down. The reasons of that: the flash memory that's actually still usable, just
to make it something that you're used to on the shelf of the store. You see quarter
gig, half gig, 1 gig, 2 gig, 4 gig, etc. Even units of powers of two of your hard
drives.
So these are the modes that set up the way the flash drive works. The ones which
are probably used are: the mode 3, that's your flash drive; mode 21 is basically
the USB drive would emulates the CD-ROM drive and a hard drive; and mode 7 and 8
are the cool ones where you've got hidden drives.
* So, mode 21 is U3 equivalent. So there aren't really U3 drives out on the market
anymore, but you probably have a drive that supports this. You just need to find
the software that does it.
* The U3 drives are basically dead thanks to Microsoft and SanDisk, because they
superseded it with an application called 'StartKey', which appears to be related to
the 'Windows 2 Go' software. So you can take your Windows installed on a thumb
drive and go anywhere and boot up your office's PC, doesn't matter what hardware
yours being plugged into.
So here is the PS 2251 block diagram: you've got the USB connection coming in from
the computer to your USB PHY; you've got USB controller; your flash data module;
some ROMs and RAM; and then the little orange block in the center, that's the micro
controller.
That's this guy, the Intel 8051. This chip came out when I was born in 1980. Like
pretty much every software out there that does reverse engineering of binary object
code supports this chip. All right.
### Page 091: Bunnie & xobs @ 30C3 'SD Card Hacking'
* They basically found out that SD cards have this MCU inside of it.
* And they completely got executable code running on that microcontroller. That
controller that actually operates and manages the flash memory and talks to the
computer.
* So most of their work will probably actually port over to USB drives. Fairly
standardly, up all they have to do is just figure out what pins go where, and they
can use the same thing.
* They actually wrote a debugger so they could figure out like what all the
different registers were in these microcontrollers.
* And the reason why is because this is an 'IP' core. You've got this schematic for
it, so you can, you can change it, you can make it from being a 8 bit controller to
a sort of 8 bit plus a couple of 32 bit operation chips.
So, once you've figured all this stuff out, and you can mess with flash drives,
what can you do with them?
Well, I decided to come up with some hypothetical drives, repurposing the Micron
Center 5 dollar, 4 gig drive that I found. It'll soon makes the moosedrives, and
these aren't for sale. Sorry, I don't have enough to give around.
* So the features are, I've got a USB product ID and vendor ID of leet:leet.
* And then somewhere between 1 and 3 gigs of space that has been recovered from
this chip.
* Because it has additional space that is hidden and locked with a password.
* The windows software says that you can try 6 guesses and on the 6th failed
attempt it will erase the drive.
* But I found out, through reversing the actual protocol that goes across
USB, that, no, it doesn't wipe the drive. Why implement something in silicon when
you can implement it in software? So I was actually like doing hundreds of
thousands of password (against) attempts against these drives on Linux, and it
still managed just fine. So, be careful, don't trust what all the software says
because in some cases it might actually work that way.
You could also have an entire portable operating system. So you guys have heard of
the USB drives or the U3 drives that have portable apps. Well, this is an entire
portable operating system.
* So I put Fedora LiveCD image on there. And it's got another 3 gigs of space based
on it.
* So now I've got a persistent overlay of changes that I've made at this drive.
* And push or to shove, I can erase that overlay and get back to a bare metal
scratch image.
And if you're a pen tester like some people in the audience, you can have a drive
that has your Kali Linux or BackTrack or whatever your favorite image on there, and
then additional one and a half gigs of storage.
* Now, because these are emulated CD-ROM drives on these drives, you can't write to
these CD-ROM. It's read only.
* But the remaining flash memory on it, you can wipe. So for example, if you had a
customer said that I don't want you bringing in your own hardware, but they'll let
you bring in flash drives, now you can bring in your entire toolkit. And if they're
really paranoid about you ex-filling data, which was kind of what they're paying
you to do, you can say, ok, format this drive and then I've got no data, done.
* You can, you can buy a ISOSTICK, which is a 100 dollar project that someone made.
It's based on an Atmel processor, which is sort of the same thing that Arduinos are
made with. And they wrote a custom program for it, and they wrote a bootloader
called 'isosel'. So that'll let you bring up a menu and select what ISO you want to
boot on a computer when you plug it in. Rob says sometimes he's had problems with
it.
* There's another project out there that's not quite finished yet, called CDEMU.
This one actually has a four line LCD that gives you a menu of what ISO you want to
boot. This one is basically in beta production status. They haven't actually
produced hardware that you can assemble yet.
* Or you can use a regular thumb drive that you happen to have laying around. Out
of pocket costs could be, could be between 0 dollars or like going to the store and
buying a couple, and the only real cost is a little bit of your time, plus varying
levels of fun as you accidentally break thumb drives.
So. Here's how you reprogram drives. So with Phison, they've got a couple of
different ways.
* There's an easy, foolproof way called **Mode Converter**.
* This is literally point, click, done. There's no, like firmware that's being
rewritten, no executable code that's being re-downloaded to the drive. You're just
reconfiguring its layout.
* The more advanced way is to use their **MPAll** app. MP stands for Mass Produce,
so this lets you mass produce pretty much all of their flash controllers and
reconfigure them.
* That one comes with the app called GetInfo. This will tell you all the details
about how the drive is set up, what the block size is on the flash memory, what
mode the drive is in (you know, that mode 3 for regular drives, mode 21 for U3 like
drives).
* And this is the application that lets you reconfigure everything on the drive:
up a new firmware; reconfigured that partitioning the way it's laid out; change the
USB product ID, vendor ID strings; et cetera. And if the chip supports that, you
can turn on crypto -- hardware crypto in the flash controller that will encrypt the
flash memory.
So here's Mode Converter. It's a really simple app. Like I said, it's literally
point, click, done. You give it the number of partitions you want, and if you want
to be hidden or not.
And here's the more complex MPAll app. So this lets you mass produce 16 drives at
once.
And I know this is kind of hard to read, but these are all the different options
you have. So this is actually the page where it sets up the partitioning of the
drive, or whether you're going to have a virtual CO-ROM, a hidden hard drive, a
removable hard drive. You can actually make these drives look like they're not
removable media, make them more look like their actual hard drives.
And here is GetInfo that shows you all the details of how it's set up, and here's
the leet:leet product ID and vendor ID.
So here are all the settings that can be set with that MPAll app. You can change
the size of the drive, change the way that the led is blinking. You can make the
logical unit numbers read only or not. And, You can recover data from the region of
the chip that have been clipped in software because it was just below the next size
up chip. All that stuff.
So ultimately, when you're using MPAll, you're going to run into problems, because
it's not something that you're supposed to be using. It's not documented. You don't
get like training on it.
* But, so, use ChipEasy and I'll have a link for that later in the slide deck. Use
that to identify what chip and what controller are in the flash drive.
* And a lot of times these flash drives, the controllers have firmware updates. And
the reason they have firmware updates because new memory comes out that these chips
don't quite support.
* And you might have more updates to the software like this IDBlock_Timing things,
so that associates the ship identification bytes to actually what the timing of the
flash memory is. You know, when you're tuning the memory under gaming PC and it has
11, 10 or whatever, same sort of thing, but for flash memory.
* And double and triple check that you've got all the flash ID and timing settings
correct.
* And they've got different tiers of software that's based on how many hard drives
you want to plug in into your box -- it's between 3 and 24 drives.
* Free is on the the 3 drives and below line, and the pro version where you have 24
drives is like 120 bucks.
* And they have a very interesting licensing method. They say, go find a flash
drive, plug it in and read off what this GUID is.
Well, the problem is this is GUID, which is supposed to be globally unique, is not
so globally unique here.
Here is an example GUID which they have on their website. And I can tell you that
that GUID was from an Alcor flash drive. Because their GUID is literally just the
USB vendor ID, product ID, and the serial number.
So, here's how to clone a USB license for UnRAID: download the USB software for
maintaining the thumb drives, set the USB vendor ID and product ID to match, set
the serial number to match and win. You now have cloned your license for UnRAID.
So, developers, please use a real hardware security token like an Aladdin HASP, but
not some random thumb drive laying around.
* The reason why I need something like this is because there's no documentation on
how to talk to these controllers.
* And like I've mentioned before, USBpcap under windows can kind of miss data.
* And under Linux, there's no software that supports any of this stuff. Like the
usb_modeswitch that you may have seen before when you're using your, like 3G USB
modems or a thing officially show up as a CD-ROM drive, yet that doesn't work on
these drives at all.
* Bunnie and xobs talk at 30C3 where they went over getting that direct code
execution on the controller in the SD card
* And a lot of the photos I had in the monolithic drives. That was also done by
Bonnie -- he went to an actual fab plant and saw where they were born.
* Wesley McGrew. He actually took some U3 drives and turn them into a incident
response -- oh no, sorry, that's next. He had a product on actually reconfiguring
them, to make them not have to use the software that came with it. But for some
reason it phoned home to their websites to download an ISO image that had the U3
Launch app.
* The password protection on some of these drives. You would expect it to actually
pass the password, or some encrypted version of that password down the wire to the
drive to authenticate it. Well, there were some researchers that found out that,
no, the software just sends an unlock command, regardless of the password. And all
they had to do was just repeat, sending the unlock command, and suddenly there's
all your data. Oops.
So this is the slide you want to take pictures of if you're interested in messing
with these drives. This is all the links to all the software you want.
* If you want to download ChipEasy, that is the app that will tell you what the
chip is for the controller and what flash memory is on your drive, and that will
link you to upan.cc, which is unfortunately in Chinese. You'll have to run that
through Google translate.
* So and again, my contact info: I'm xabean on Twitter, warewolf on GitHub and
there's my email address.
### Q&A
Got it. Okay, so the question was, have I seen anybody doing any research on adding
new modes for these drives? So, like there is mode 3 for the regular flash drive,
Have I seen different modes for replicating what's going on there?
I haven't. I just found this software out there to reconfigure it, and I've re-
implemented some of the features under Linux.
But that's an excellent idea, I mean for people about doing forensics, probably
going to have to figure out what mode is this drive in. So you can get a general
idea of is this drive. Does it have hidden partitions or not? And then you can go
from there on other things.
But yeah, I don't have, like access an Intel 8051, like assembly language done.