How can USB vendor ID and product ID values be spoofed on OSX? - security

We are considering using the vendor and product ID of a USB device (obtained via IOKit) to unlock certain features of an application. I'm aware that these values can be spoofed, but I'm not sure how easily it can be done on OSX. What is involved in spoofing the vendor and product ID? Is it something that a non-programmer can do fairly easily?

I suspect it would be fairly easy (for a programmer) to create a kext that creates a reasonably realistic IOUSBDevice object in kernel space. However, once done anyone would be able to load it.
It may also be possible to build a codeless kext using AppleUSBMergeNub to masquerade a device as another (though I haven't tested this, it looks like it might work, assuming you only try to match the IOUSBDevice without actually using it).
It would probably be easier to just hijack your API calls in userspace and give your software the answers it expects.

A non-programmer cannot do that. What you can do is writing a kernel extension (an IOKit driver) for the device, that has a matching dictionary matching the real vendor-/product-ID of the device, which causes the system to automatically load the kernel extension when this device is connected and pass a reference to the device object. The driver is now responsible for initializing the device and create all necessary user space information that is necessary for the IOKit framework (the user space library) to communicate with the device. Usually Apple has default IOKit drivers for most USB device classes (that's why you don't need an extra driver for every USB mouse or keyboard for example), but if there is a more specific driver found, then this driver will be used instead. And when creating the user space data, of course the driver may lie about the vendor-/product-ID, causing the user space program to see false values. Since IOKit is written in C++ and heavily depends upon objects and object inheritance, it is not even necessary to write the driver from scratch, but instead it can inherit from Apple's default driver and just override some methods and otherwise rely upon the super implementation. However, writing IOKit kernel drivers is not that easy and even people developing Mac software for years may have no idea how to do that and the IOKit documentation is one of the worst ones Apple is offering.
So to answer your question: Is it possible? Yes. Is it fairly easy? No. Can non-programmers do it? Certainly not, unless someone else has written a ready to use extension for them, that they only need to install.

It's actually rather EASY, and I'm definitely not a programmer!
Found the guide here
http://rolande.wordpress.com/2012/10/25/getting-the-aten-usb-serial-adapter-working-with-mac-osx-lion
Thanks, Rolande!
I was able to change the IDs of a USB Ethernet adaptor I bought on eBay to use another driver with Mac OS X 10.8.

Since nobody has answered so far, I've stumbled across a page which basically says that you can get an Arduino and program it to return any VID/PID/serial that you want. I still can't find any software-only way to do this.

I can create A OCX in Delphi code to do that
And supply infomation to send/receive data to the USB with other states like:- is it still connected.
Natraly I need a little more detail than that in case that same chip is connected from another product.
example frendly name, device desription.............

Related

In Vulkan how can you associate each individual video card with monitors they're directly connected to

I have two monitors, each connected to a different GPU. Both GPUs are in a single machine, and I want to run a single application. I have two independent views, and I would like to render each one using a GPU/Monitor set. I can create multiple surfaces and devices, but I want to ensure I associate each surface with the GPU its monitor is plugged into, otherwise I suspect I'll suffer performance issues as the frame buffers need to be copied back and forth between cards.
I'm using fullscreen surfaces, and I was thinking this was something vkGetPhysicalDeviceSurfaceSupportKHR would tell me. However, both VkSurfaceKHR appear to be valid targets for each VkPhysicalDevice so I guess this is something the OS and GPU Driver can handle, but is there any hint about which surface is optimal to associate with a device?
From what I can tell the extension VK_KHR_display is one way of doing this, but it's not available on my Windows 10 machine or Nvidia GPU. It seems to be intended for embedded platforms only. However it lets you list attached displays for each device which is pretty much what I'm looking for: https://vulkan.lunarg.com/doc/view/1.0.30.0/linux/vkspec.chunked/ch29s03.html
This quote from the docs makes me belive this may not be supported on Windows:
Issues
1) Does Win32 need a way to query for compatibility between a particular physical device and a specific screen? Compatibility between a physical device and a window generally only depends on what screen the window is on. However, there is not an obvious way to identify a screen without already having a window on the screen.
RESOLVED: No. While it may be useful, there is not a clear way to do this on Win32. However, a method was added to query support for presenting to the windows desktop as a whole.
However, I'm still interested in hearing if there's a work around to achieve a similar effect.
Finally figured out a work around for this:
Direct X actually supports this through use of the IDXGIAdapter::EnumOutputs function. This lets you list the monitors connected to each GPU. Then using these two extensions you can remap this information to Vulkan:
VK_KHR_external_memory_capabilities
VK_KHR_get_physical_device_properties2
You can use these to get the deviceLUID from VkPhysicalDeviceIDPropertiesKHR.
This can then be compared with the Luid from this structure in Direct X DXGI_ADAPTER_DESC
You can also use glfwGetWin32Window to get the HWND of the monitor. This lets you associate a vulkan surface with a direct x monitor.
You now have all the information you need to accociate vulkan surfaces with the devices they're actually connected to.
At least in my application, setting this up correctly results in a significant difference in performance.
This would all be way simpler (and cross platform) if Windows would just support the VK_KHR_display and VK_KHR_display_swapchain extensions as Linux does.
There are two extensions that are useful for such things: the one mentioned by You, VK_KHR_display and the second called VK_KHR_display_swapchain which allows You to create a swapchain directly on a device’s display without any underlying window system.
But these extensions are rarely supported on Windows. In core Vulkan API there is no way to achieve what You want. And I'm afraid You need to use OS-specific functions (You need to rely on the WinAPI functions in this situation).
[EDIT]
Did You saw this question? How can you get the display adapter used for a particular monitor in Windows? If not, maybe it will help You start with Your research.
As you already discovered, on Win32 you need to use the OS windowing system to pick the display you want to use, using the Window API. It can be straight forward.
BUT if you intend to make simple and agnostic OS code, check GLFW project. It has high level functions to handle windows on all major OSs.
Check :
GLFW monitor Guide
GLFW Vulkan integration
GLFW on its own words:
GLFW is a free, Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan application development. It provides a simple, platform-independent API for creating windows, contexts and surfaces, reading input, handling events, etc.

How to determine from which keyboard the input comes

Scenario:
I have an usb-RFID reader
attaching it to notebook it works as an newly attached USB keyboard, e.g. without needing to install any drivers
when touching the reader with RFID tag
it enters into my current window (for example terminal/shell) the RFID number (like 0009339384\n) - e.g. it even sends the \n.
so, it works exactly as if I had typed the numbers in my notebook's keyboard
The questions are:
is it possible read the RFID reader directly without some kernel-level drivers, e.g. something like cat /dev/keyboard1 ...
in other words, how can I determine from which "keyboard" the characters are coming?
using OS X, but would be nice to know the solution for Linux too.
Moreover, I want attach two readers - so I definitely need to clearly differentiate between the two readers. And I want use the rfid-reader in a bash (perl) script, so I'm definitely looking for a solution without compiling some "drivers"... It is possible?
The OS X identifies it as:
SYC ID&IC USB Reader:
Product ID: 0x0035
Vendor ID: 0xffff
Version: 1.00
Serial Number: 08FF20140315
Speed: Up to 1.5 Mb/sec
Manufacturer: Sycreader RFID Technology Co., Ltd
Location ID: 0x14100000 / 18
Current Available (mA): 500
Current Required (mA): 100
Extra Operating Current (mA): 0
EDIT Okay, looks like in Linux it can be done - just found
this https://unix.stackexchange.com/questions/72483/how-to-distinguish-input-from-different-keyboards
also Accessing multiple keyboards input by C++ (or python) in linux
For OS X - exact duplicate on unix: https://unix.stackexchange.com/questions/228413/route-keyboard-through-only-dev-ttys000-on-mac-os-x - unfortunately, closed without any answer :(
Ok, so - easily solvable in Linux. As in edits in the question - here are already many similar questions like this.
The solution is: reading the particular /dev/input/eventN device(s).
In my case, me using the Linux::Input perl module. Works perfectly.
It is pointless adding code here, the package comes with the evtest.pl - so anyone could easily check how it works.
Still need solve one issue - e.g. even when reading the device and nicely getting all events from the rfid reader (4 events for one number), the rfid-code still is inserted into the active window, like it coming from a keyboard. (This will be an another question).
For OS X i haven't an easy solution yet, but now focusing for the Linux variant. :)
There is one thing that might help you solve this problem without resorting to programming in C. It is called multiseat. I didn't do it myself I just know it exists. In general it is a way how multiple people can work on same computer at the same time just using multiple keyboards, mice and monitors. It is not exactly what you are looking for but there might be possible way.

Modifying Bluetooth Low Energy Beacon

I was wondering if it is possible to modify the contents of a BLE beacon to include extra information. If you insert an extra bit at the end you could potentially broadcast a boolean in one direction. Theoretically, if you modified your device to read the extra bit of information this would work. Given existing protocols though it sounds like this would be a lot of work. Is there something out there like this already?
For info, I'm working on the mbed platform where you can modify your own bluetooth beacon payload.
Yes, you can do this with the new AltBeacon specification. There is a one byte manufacturer reserved field which you can use for whatever you want (tied to your manufacturer ID).
There are reference implementations of the specification available for Linux to show you how it works, and there is no reason you cannot implement it on the mbed platform.

turning on GPIO wired LEDs in Linux

I'm hoping to find a generic mechanism in Linux to toggle LEDs that are wired up to a GPIO controller in an embedded application.
I'm able to use either JTAG or my bootloader (setting the registers directly). However it'd be awesome to toggle some lights from usermode
I'm not well versed in this on Linux, is there a standard kernel driver that I can call from my usermode application? or do I need to write a driver for my application?
I've done a websearch and found ideas ranging from writing my own driver, to libraries that feel adhoc. I'm hoping to find the most 'standard' way, thought the stackoverflow crowd would have a good opinion
any tips would be great
You want to use the sysfs interface to GPIOs
http://www.kernel.org/doc/Documentation/gpio.txt
In that link search for "Sysfs Interface for Userspace"
I have no idea what type of system you are on, or if support for this is already enabled in your kernel or not, but that is where you want to look.

New to Linux Kernel/Driver development

Recently, i began developing a driver of an embedded device running linux.
Until now i have only read about linux internals.
Having no prior experience in driver devlopment, i am finding it a tad difficult to land my first step.
I have downloaded the kernel source-code (v2.6.32).
I have read (skimped) Linux Device Drivers (3e)
I read a few related posts here on StackOverflow.
I understand that linux has a "monolithic" approach.
I have built kernel (included existing driver in menuconfig etc.)
I know the basics of kconfig and makefile files so that should not be a problem.
Can someone describe the structure (i.e. the inter-links)
of the various directories in the kernel-source code.
In other words, given a source-code file,
which other files would it refer to for related code
(The "#include"-s provide a partial idea)
Could someone please help me in getting a better idea?
Any help will be greatly appreciated
Thank You.
Given a C file, you have to look at the functions it calls and data structures it uses, rather than worrying about particular files.
There are two basic routes to developing your own device driver:
Take a driver that is similar to yours; strip out the code that isn't applicable to your device, and fill in new code for your device.
Start with the very basic pieces of a device driver, and add pieces a little at a time until your device begins to function.
The files that compose your driver will make more sense as you complete this process. Do consider what belongs in each file, but to some extent, dividing a driver among files is more an art than a science. Smaller drivers often fit into just one or two files.
A bit of design may also be good. Consider what you device does, and what your driver will need to do. Based on that, you should be able to map out what functions a device driver will need to have.
I also believe Linux Device Drivers, Third Edition may help you get on your way to driver development.
Linux files themselves include files based on what they do, what layer they are in, and what layer they access of the call stack. The Big Picture truly informs how each file is related to the next.
I had to fix a kernel driver once. My biggest tip (if you use vim) is to set it up with ctags so you can jump around the kernel source with ctrl-] every time you see a function you don't understand.

Resources