As you are aware, currently one most common medium for virus spreading is USB flash drives. There is a feature in Windows which allows automatically executing a program when removable disc (either USB drive or CD drive) is inserted. (This post will use the terms USB drive, flash drive, USB flash drive interchangeably. All refer to the same term.)
This autorun feature is implemented using a file autorun.inf. Autorun.inf is not a virus. It is a file which defines the autorun task which executes when the removable media is inserted. This file was a method to create automatic installation CDs, such that the software installation will start immediately after the CD is inserted into the CD-rom. For window OS, there is no distinction between a CD drive & USB drive, as far as autorun feature is concerned.
Viruses use this file – autorun.inf – in order to spread via USB flash drives.
A typical autorun.inf file created by a virus may look like follows:
By default, when you attach the USB drive, windows will check for this file in the drive. If found, it will check whether there is an entry for “open=” part. If there is any entry, this file will get executed after you attach the USB drive. Hence as per above sample autorun.inf file, the program path-to-virus-file.exe will get executed when it is attached. This way, the virus executes after connecting the USB drive.
Similarly, if you right click on the drive in my computer, you will see options like open, explore etc in popup menu. The corresponding entries in autorun.inf are executed when the respective menu items are clicked. If the entry for some option is missing in autorun.inf, the default action (open / explore e.g.) is taken. Also, when you double click on the drive, the default action is open; thus the command corresponding to ‘open’ in autorun.inf executes.
Now, above paragraph was a bit confusing. In short I would say, whether you double click on the drive, or right click on drive & select open/explore, in any of these cases, the autorun entry in autorun.inf will get executed. If this entry points to a virus file, virus file will get executed. Hence, never double click on drive. Never right click on drive & select open / explore.
Having said all this, how do I access files in the drive, if I cannot open the drive? Well, there is a way for that.
Open windows explorer, (by pressing <Windows button + E> together). After that, in left side pane, you will see the drives & folders in tree like structure. Now click on the desired drive in that pane. This will open the drive in safe way – bypassing autorun.inf. There are even more methods to achieve this, but I found this as simplest & safest method.
So this was about bypassing autorun.inf, while opening the drive. But what about the original feature of autorun? – automatically opening the installation program when the drive was connected…
For this, there are several ways out...
Simplest one is by keep pressing shift key, while attaching the USB drive (or inserting CD), till the drive is fully detected. When new type flash drive is connected for the first time, windows will install specific device driver. (E.g. when connecting sandisk drive for the first time, windows will install sandisc flash drive driver.) You have to keep the shift key pressed till the driver installation is complete & you can see the drive in “my computer”. If connecting external hard disc, containing multiple partitions, keep the shift key pressed, till all the partitions are detected.
Hint: open windows explorer by pressing Win+E, BEFORE connecting the USB drive, so that you can identify the point, when the device is fully detected & thus, when you can safely release shift key.
This method of pressing shift key is simple, but not reliable, because it involves human factor. You might forget to press shift key. Or some friend may connect his USB drive, when he is using your pc, without pressing shift. You might release the shift key before the drive detection is complete, & so on.
Thus there is another way – automatic way – of skipping the autorun feature when the USB drive is connected. This involves disabling autorun by using registry.
For this, copy following text into a text file. Save that file as autorun.reg. Double click on that file & press OK when prompted.
With this, the autorun feature will be disabled, when you connect the drive. So, no need to keep pressing the shift key. However, when the system is freshly installed, in order to make this setting for the first time, I generally copy this .reg file using a USB drive. So for that first time, while connecting, I need to use shift-key-method.
Also note that, this method disables the autorun, only when connecting the USB drive. This registry method or the shift key method will not work, if you double click on the drive. To prevent autorun from that method as well, use the windows explorer -> selecting the drive from tree view method.
With these precautions, the autorun feature of the USB drive is bypassed. & the virus, if any, does not execute when connecting the flash drive. This way, there is no need to virus-scan the flash drive, when connected.
Now, how to remove the virus, if any, from the flash drive?
Open the autorun.inf file, if found. It may be marked as system &/or hidden file. Make sure that you keep the system & hidden files visible (use folder options from the tools menu of windows explorer).
Ideally, you should see the autorun.inf file, only if there is some software installation in the flash drive. In autorun.inf, find the “open=something.exe” entry. If that name looks like some virus name, delete it. & Finally, don't forget to delete the autorun.inf file itself.
This autorun feature is implemented using a file autorun.inf. Autorun.inf is not a virus. It is a file which defines the autorun task which executes when the removable media is inserted. This file was a method to create automatic installation CDs, such that the software installation will start immediately after the CD is inserted into the CD-rom. For window OS, there is no distinction between a CD drive & USB drive, as far as autorun feature is concerned.
Viruses use this file – autorun.inf – in order to spread via USB flash drives.
A typical autorun.inf file created by a virus may look like follows:
[autorun]
open=path-to-virus-file.exe
explore=path-to-virus-file.exe
open=path-to-virus-file.exe
explore=path-to-virus-file.exe
By default, when you attach the USB drive, windows will check for this file in the drive. If found, it will check whether there is an entry for “open=” part. If there is any entry, this file will get executed after you attach the USB drive. Hence as per above sample autorun.inf file, the program path-to-virus-file.exe will get executed when it is attached. This way, the virus executes after connecting the USB drive.
Similarly, if you right click on the drive in my computer, you will see options like open, explore etc in popup menu. The corresponding entries in autorun.inf are executed when the respective menu items are clicked. If the entry for some option is missing in autorun.inf, the default action (open / explore e.g.) is taken. Also, when you double click on the drive, the default action is open; thus the command corresponding to ‘open’ in autorun.inf executes.
Now, above paragraph was a bit confusing. In short I would say, whether you double click on the drive, or right click on drive & select open/explore, in any of these cases, the autorun entry in autorun.inf will get executed. If this entry points to a virus file, virus file will get executed. Hence, never double click on drive. Never right click on drive & select open / explore.
Having said all this, how do I access files in the drive, if I cannot open the drive? Well, there is a way for that.
Open windows explorer, (by pressing <Windows button + E> together). After that, in left side pane, you will see the drives & folders in tree like structure. Now click on the desired drive in that pane. This will open the drive in safe way – bypassing autorun.inf. There are even more methods to achieve this, but I found this as simplest & safest method.
So this was about bypassing autorun.inf, while opening the drive. But what about the original feature of autorun? – automatically opening the installation program when the drive was connected…
For this, there are several ways out...
Simplest one is by keep pressing shift key, while attaching the USB drive (or inserting CD), till the drive is fully detected. When new type flash drive is connected for the first time, windows will install specific device driver. (E.g. when connecting sandisk drive for the first time, windows will install sandisc flash drive driver.) You have to keep the shift key pressed till the driver installation is complete & you can see the drive in “my computer”. If connecting external hard disc, containing multiple partitions, keep the shift key pressed, till all the partitions are detected.
Hint: open windows explorer by pressing Win+E, BEFORE connecting the USB drive, so that you can identify the point, when the device is fully detected & thus, when you can safely release shift key.
This method of pressing shift key is simple, but not reliable, because it involves human factor. You might forget to press shift key. Or some friend may connect his USB drive, when he is using your pc, without pressing shift. You might release the shift key before the drive detection is complete, & so on.
Thus there is another way – automatic way – of skipping the autorun feature when the USB drive is connected. This involves disabling autorun by using registry.
For this, copy following text into a text file. Save that file as autorun.reg. Double click on that file & press OK when prompted.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDriveTypeAutoRun"=dword:000000FF
"NoDriveAutoRun"=dword: 03FFFFFF
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDriveTypeAutoRun"=dword:000000FF
"NoDriveAutoRun"=dword: 03FFFFFF
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDriveTypeAutoRun"=dword:000000FF
"NoDriveAutoRun"=dword: 03FFFFFF
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer]
"NoDriveTypeAutoRun"=dword:000000FF
"NoDriveAutoRun"=dword: 03FFFFFF
With this, the autorun feature will be disabled, when you connect the drive. So, no need to keep pressing the shift key. However, when the system is freshly installed, in order to make this setting for the first time, I generally copy this .reg file using a USB drive. So for that first time, while connecting, I need to use shift-key-method.
Also note that, this method disables the autorun, only when connecting the USB drive. This registry method or the shift key method will not work, if you double click on the drive. To prevent autorun from that method as well, use the windows explorer -> selecting the drive from tree view method.
With these precautions, the autorun feature of the USB drive is bypassed. & the virus, if any, does not execute when connecting the flash drive. This way, there is no need to virus-scan the flash drive, when connected.
Now, how to remove the virus, if any, from the flash drive?
Open the autorun.inf file, if found. It may be marked as system &/or hidden file. Make sure that you keep the system & hidden files visible (use folder options from the tools menu of windows explorer).
Ideally, you should see the autorun.inf file, only if there is some software installation in the flash drive. In autorun.inf, find the “open=something.exe” entry. If that name looks like some virus name, delete it. & Finally, don't forget to delete the autorun.inf file itself.