
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Pythonified linux asm-generic/ioctl.h
.
So you can replicate driver's code computing fcntl.ioctl
's opt
argument.
For example, starting from the following IOCTL declaration (taken from input.h
):
.. code:: C
#include <sys/ioctl.h> #define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */
you could write the following:
.. code:: python
from ioctl_opt import IOC, IOC_READ EVIOCGNAME = lambda length: IOC(IOC_READ, ord('E'), 0x06, length)
The differences are minimal, and all come from python language or coding style:
ioctl_opt
for not start with an underscoreIOC
's nr
argument has to be an integer, so C's single-quote char becomes an ord
calllen
functionThe length
argument is an object (typically serving as an I/O buffer with the fcntl.ioctl()
call), the size of which is incorporated in the generated ioctl opt
value. IOC()
will
calculate the size of the object. Supported object types are:
ctypes
type or instancememoryview
bytearray
struct.Struct
array.array
You may want to then write a pythonic function to conveniently access that ioctl:
.. code:: python
import ctypes import fcntl
def getDeviceName(fd, length=1024): name = (ctypes.c_char * length)() actual_length = fcntl.ioctl(fd, EVIOCGNAME(length), name, True) if actual_length < 0: raise OSError(-actual_length) if name[actual_length - 1] == b'\x00': actual_length -= 1 return name[:actual_length]
More advanced example defining hidraw ioctls, requiring structures (for more on how structures are defined, check python's ctype documentation for your python version):
.. code:: python
import ctypes from ioctl_opt import IOR, IOC, IOC_READ, IOC_WRITE
HID_MAX_DESCRIPTOR_SIZE = 4096
class hidraw_report_descriptor(ctypes.Structure): fields = [ ('size', ctypes.c_uint), ('value', ctypes.c_ubyte * HID_MAX_DESCRIPTOR_SIZE), ]
class hidraw_devinfo(ctypes.Structure): fields = [ ('bustype', ctypes.c_uint), ('vendor', ctypes.c_short), ('product', ctypes.c_short), ]
HIDIOCGRDESCSIZE = IOR(ord('H'), 0x01, ctypes.c_int) HIDIOCGRDESC = IOR(ord('H'), 0x02, hidraw_report_descriptor) HIDIOCGRAWINFO = IOR(ord('H'), 0x03, hidraw_devinfo) HIDIOCGRAWNAME = lambda length: IOC(IOC_READ, ord('H'), 0x04, length) HIDIOCGRAWPHYS = lambda length: IOC(IOC_READ, ord('H'), 0x05, length) HIDIOCSFEATURE = lambda length: IOC(IOC_WRITE|IOC_READ, ord('H'), 0x06, length) HIDIOCGFEATURE = lambda length: IOC(IOC_WRITE|IOC_READ, ord('H'), 0x07, length)
FAQs
Functions to compute fnctl.ioctl's opt argument
We found that ioctl-opt demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.