KISS

Keep It Simple Stupid

Stop soiling my flash drive

| comments

On windows it’s popular for different malware to create autorun.inf file on all available drives to exploit the Autorun feature. I’ve heard modern versions of Windows restrict the behavior or even disable it by default, but I don’t know for sure. Anyway, it’s better to create an empty autorun.inf directory in the flash drive filesystem’s root. (I believe) most of malware will not remove it and create their file, but just silently fail.

On OS X it’s very annoying that the system creates a couple of directories for its own use, such as .Spotlight and .fseventsd. So, touch these regular files: .Trashes and .metadata_never_index. Also, creating a file no_log in .fseventsd directory prevents the system from writing filesystem logs to the device.

I’ve also created a simple script that does the steps described above and removes unnecessary files and directories:

Script to remove auxiliary files created by OS X and windows (stop_annoying_flash_drive.sh) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

echo "Warning! Some files may be deleted from your flash drive! Make sure you have a backup!"

DST_DIR=${1:?"Please specify the target directory of flash drive"}

[[ -w "${DST_DIR}" ]] || { echo "${DST_DIR} is not writable!"; exit 1; }

# NB! Always use quotes when specifying paths for rm command!

RM_OPTS="-rfv"
MKDIR_OPTS="-v"

### for OS X ###

# create .metadata_never_index file
rm ${RM_OPTS} "${DST_DIR}/.metadata_never_index"
touch "${DST_DIR}/.metadata_never_index"

# create .Trashes file
rm ${RM_OPTS} "${DST_DIR}/.Trashes"
touch "${DST_DIR}/.Trashes"

# create .fseventsd/no_log file
rm ${RM_OPTS} "${DST_DIR}/.fseventsd"
mkdir ${MKDIR_OPTS} "${DST_DIR}/.fseventsd"
touch "${DST_DIR}/.fseventsd/no_log"

# remove remnants
rm ${RM_OPTS} "${DST_DIR}/.Spotlight"
rm ${RM_OPTS} "${DST_DIR}/.TemporaryItems"
rm ${RM_OPTS} "${DST_DIR}/._.TemporaryItems"


### for windows ###

# create autorun.inf directory
rm ${RM_OPTS} "${DST_DIR}/autorun.inf"
mkdir ${MKDIR_OPTS} "${DST_DIR}/autorun.inf"

NB! I’m not responsible if the script deletes some necessary files. Use it on your own risk! Always make backups of your data! Use it like this:

1
$ ./stop_annoying_flash_drive.sh /Volumes/flash_drive

A source: http://hostilefork.com/2009/12/02/trashes-fseventsd-and-spotlight-v100/

Comments