Windows Remote Memory Access Though FireWire
Thomas Ptacek | February 9th, 2007 | Filed Under: Defenses, Development, Uncategorized
Maximillian Dornseif made a splash at CanSec in 2005 by hijacking Linux and OS X machines using a malicious iPod and the FireWire port. As it turns out, the “link layer” for FireWire —- OHCI, which is roughly to FireWire what Ethernet would be to 1000bTX if it included a standard programming interface —- supports direct DMA to host physical memory. You can plug a FireWire device in to a machine and read or write arbitrary physical memory locations.

Get a sense of what this looks like for an “attacker” from Maximillian’s own presentation. Then, note the table of systems “compatible” with the attack:
OS X (supports read/write)
FreeBSD (supports read/write)
Linux (supports write)
Windows 2000 (crashes)
Windows XP (no support)
The reason Maximillian’s attack doesn’t seem to work against Windows XP is that OHCI specifies “Asynchronous Filter” and “Physical Filter” CSRs (a CSR is a hardware ioctl, by the way); if these CSRs are set to zero, the FireWire chipset will reject requests to access host physical memory. According to the spec, they default to zero. Windows doesn’t set them. So, by default, Windows disallows FireWire DMA.
I think this is pretty well known, but the attack does work against Windows (at least, pre-Vista). For instance, Adam Boileau showed that you can fake up a config ROM for yourself that, when read by the Windows host, will open up the filter CSRs. His attack basically advertises his machine as requiring DMA access, and Windows complies.
An attractive thing about both Maximillian’s and Adam’s attacks are that they’re implemented in Python; both quickly wrap the Linux or OSX FireWire APIs with Python bindings and then speak FireWire to the target with Python scripts.
I’m not particularly interested in “owning” my Windows box with FireWire, because I own my Windows box already. But I am interested in surreptitiously debugging my kernel and user processes that are aggressively rigged for anti-debugging. So I bought a $20 FireWire PCI card, and got Nate Lawson to talk me through disabling the OHCI Physical Request filters.
CSRs for PCI devices are mapped into memory; the host will typically map a block of address space just for the CSRs, which Windows will tell you about if you click on “Driver Details”; you want the smaller, 2-4k address range.
Unix and Windows ioctls have indexes or codes. In mapped memory, CSRs have offsets. The offsets we care about are 0x100 and 0x108 (the high and low 32 bits of the 64 bit AsynchronousRequestFilter) and 0x110 and 0x108 (the 64 bit PhysicalRequestFilter). Windows says my OHCI CSRs live at 0xdfbf8800 (phy addresses, not kernel virts). So I want to write 0xdfbf8900, 0xdfbf8908, 0xdfbf8910, and 0xdfbf8918; I simply want them to be 0xFFFFFFFF.
You can do this from any ring 0 code, or you can just use kd:
!dc dfbf8900 # see if they're already set
!ed dfbf8910 ffffffff
!ed dfbf8918 ffffffff # set the physical request filters
g
… and now Maximillian’s code will work against Vista (you can then disable kd with kdbgctrl.exe if you need to).
Note that a FireWire bus reset will clear these registers; the Windows OHCI driver will set the AsyncRequestFilter, but not the PhysicalRequestFilter, so you’ll need to repeat this process —- in particular, and annoyingly, every time you close your FireWire IOKit object on OSX. I got around this problem by writing a quick proxy from TCP to FireWire, which holds the object open and (so far) prevents the bus reset from getting me.
Obligatory “what does this let me do” graf? Adam and Maximillian explain it better, but the answer is, uh, anything? The FireWire chipset autonomously DMA’s host memory; if the kernel can’t keep the chipset’s CSRs configured to reject physical DMA requests, it can’t do anything to stop me from rewriting bits of the kernel or stealing crypto secrets out of memory.


Nate
February 12th, 2007 2:59 pmI think the most useful purpose is that all DMA happens without the CPU being aware or even able to detect it if it wanted to. This means all anti-debugging measures just go away and with some simple tools to find PTEs and regen the virtual map, you have remote debugging with no OS assistance.
Ryan Russell
February 12th, 2007 5:27 pmNice, so a high-speed serial debugging interface, eh?
Thomas Ptacek
February 12th, 2007 5:49 pmCareful: there’s already a 1394 debugging interface in Vista, but it’s very detectable. This is, as Dornseif and Boileau both point out, something more insidious than a debugging interface.
On the other hand, if you can write into an instruction stream, you can set breakpoints, so consing up a debug stub from it CAN’T be THAT HARD.
Adam Boileau
February 13th, 2007 4:34 amHeh, glad someone actually read the pdf
I think one of the small-but-cool things that came out of my work on firewire memory access was the ability to recover plain text real-mode-disk-crypto passwords (like PGP Wholedisk or similar) from the real mode bios keyboard buffer. Of course, this is just one of the many treasures that lies around in memory, but it’s not the first thing you think of. You boot your laptop, enter your disk crypto (or bios disk locker, or whatever) password out in realmode, and it stays there, forever, because it’s never used again now you’re in protected mode.
I thought it was neat, anyway.
Jon Evans
February 24th, 2007 12:49 pmAs Adam points out, the possibilities of recovering crypto passwords from the realmode memory is cool. It works rather well
I’m sure I read an article by Simson Garfinkel where he has hinted that acquiring memory using DMA may also be possible using USB.
http://www.csoonline.com/read/050106/ipods.html
Matasano Chargen » Where-o-Where-o-Where-Is-Thomas-Ptacek?
April 18th, 2007 1:52 pm[…] That regardless of the ego-tripping that IDA Pro, BinNavi, and firewire/PCI kernel debugging promote (mea maxima culpa), web applications are the future of development and web app security is the future of security. […]
Simon Cross
March 14th, 2008 4:26 amThe first use that springs to mind is a virus / malware checker that inspects RAM via the Firewire interface.
DouglasWard.net » Blog Archive » Physically Hack Windows
March 15th, 2008 2:21 am[…] Firewire hacks have been demonstrated on Linux and OS X as […]
Leave a reply