Execute code when usb driver is pluged in?

Hi! I’m trying to execute some python code automatically after I plug a usb driver in a computer but no luck yet. I tried creating a autorun.inf file but as I read it’s has been disabled bcz most of the time people use it to execute milicious code. I also read that there is another way to do that using USB RUBBER DUCKY, but I can’t afford right now.

So my question is what’s the current way to do this without USB RUBBER DUCKY?

There are a few different approaches you could take to automatically execute Python code when a USB drive is plugged in, without using a USB Rubber Ducky. Here are a few options:

  1. Write a script that runs in the background and detects when a USB drive is plugged in. You could use a library like PyUSB to interface with the USB drive and monitor for changes. Once the script detects that a new USB drive has been plugged in, it could launch your Python code.

  2. Use a third-party tool like USBDeview or USBLogView to monitor for USB device events, and then trigger your Python code from a batch script or similar. You could use the Windows Task Scheduler to run the batch script automatically when a USB device is detected.

  3. If you have access to the Windows registry, you could modify the autorun settings to execute your Python code. Navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AutoplayHandlers\EventHandlersDefaultSelection and add a new key for your Python script, with a value of PythonScriptName.exe. Then, when a USB drive is plugged in, Windows should execute your Python script.

Note that some of these options may require elevated privileges or configuration changes to work correctly. Additionally, it’s important to keep in mind the security implications of automatically executing code when a USB drive is plugged in, as this can be a potential vector for malware.

First thanks for taking the time to answer me! but what u said is not what I’m looking for, bcz with all respect if I’m able to download a tool or change autorun settings so there’s no need for all these troubles I could easily just run the code myself by clicking on the file. What I’m trying to do is learn how do hackers put their usb driver in someone’s laptop and take all their informations without even touching their laptops.

to perform such an attack, an attacker would typically create a custom USB device with a microcontroller or other embedded system that emulates a keyboard or other input device. They could then use a programming language like Python to write scripts that are automatically executed when the device is plugged in, either by using the autorun feature or by exploiting a vulnerability in the operating system or software. They could also use tools like Metasploit or Powershell to launch more advanced attacks.

1 Like