Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #usbdiskshield v1.0 beta
- #programming in python 3.3.4
- #the uds is small removable drive security tool.
- #author:p4tcher at yandex dot ua
- #home:p4tcher.blogspot.com & twitter.com/_p4tcher
- #script is free and opensource however if you want sharing the source please show the reference.
- import shutil, os, sys
- import logging,time
- from colorama import Fore,Style,init
- import ctypes
- from string import ascii_uppercase
- import hashlib
- import configparser
- _letter = ascii_uppercase
- removable_disk_status = 0x2
- #Initialize colorama module for console attributes
- init()
- #initialize configparser module
- c = configparser.ConfigParser()
- def getsum(file_handle):
- try:
- fopen = open(file_handle,'rb')
- fread = fopen.read()
- hash_id = hashlib.sha1(fread).hexdigest()
- return (hash_id)
- except (FileNotFoundError):
- logging.warning(file_handle + "File not found")
- finally:
- fopen.close()
- def sizeof(file_handle):
- s = os.stat(file_handle)
- return ("sizeof ",s[6])
- def _void():
- while 1:
- time.sleep(2)
- for j in range(0, len(_letter)):
- if ctypes.windll.kernel32.GetDriveTypeW(_letter[j] + ":") == removable_disk_status:
- #sys.stdout.write('\a') #beep
- if os.path.exists(_letter[j] + ":/Autorun.inf"):
- time.sleep(2)
- sys.stdout.write(time.asctime() + '\x1b[1m\x1b[31m' + "\n[+] Autorun.inf is detected ->" + _letter[j] + Style.RESET_ALL + '\n')
- print("sizeof ",sizeof(_letter[j] + ":/Autorun.inf"))
- os.system("attrib " + _letter[j] + ":/Autorun.inf")
- print("inf file sum(sha1): ",'\x1b[1m\x1b[35m' + getsum(_letter[j] + ":/Autorun.inf") + Style.RESET_ALL)
- c.read(_letter[j] + ":/Autorun.inf")
- if "Autorun" in c.sections():
- logging.info("Autorun section OK")
- if 'shellexecute' in c['Autorun']:
- print("execute file sum(sha1): ",c['Autorun']['shellexecute'],'\x1b[1m\x1b[35m' + getsum(_letter[j] + ":/" + c['Autorun']['shellexecute']) + Style.RESET_ALL)
- shutil.copy(_letter[j] + ":/" + c['Autorun']['shellexecute'],time.asctime().replace(" ","_").replace(":","_"))
- else:
- if 'open' in c['Autorun']:
- print("execute file sum(sha1): ",c['Autorun']['run'],'\x1b[1m\x1b[35m' + getsum(_letter[j] + ":/" + c['Autorun']['shellexecute']) + Style.RESET+ALL)
- shutil.copy(_letter[j] + ":/" + c['Autorun']['run'],time.asctime().replace(" ","_").replace(":","_"))
- else:
- continue
- try:
- action = input('\a\n\nDo you want delete Autorun.inf file [Y & N]:')
- if action.lower() == 'y':
- os.remove(_letter[j] + ":/Autorun.inf")
- logging.warning("File is successfully removed")
- else:
- continue
- except FileNotFoundError:
- continue
- else:
- continue
- else:
- continue
- _void()
Advertisement
Add Comment
Please, Sign In to add comment