p4tcher

UsbDiskShield

Apr 22nd, 2014
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.75 KB | None | 0 0
  1. #usbdiskshield v1.0 beta
  2. #programming in python 3.3.4
  3.  
  4. #the uds is small removable drive security tool.
  5. #author:p4tcher at yandex dot ua
  6. #home:p4tcher.blogspot.com & twitter.com/_p4tcher
  7. #script is free and opensource however if you want sharing the source please show the reference.
  8.  
  9.  
  10. import shutil, os, sys
  11. import logging,time
  12. from colorama import Fore,Style,init
  13. import ctypes
  14. from string import ascii_uppercase
  15. import hashlib
  16. import configparser
  17.    
  18. _letter = ascii_uppercase
  19. removable_disk_status = 0x2
  20.  
  21. #Initialize colorama module  for console attributes
  22. init()
  23. #initialize configparser module
  24. c = configparser.ConfigParser()
  25.  
  26. def getsum(file_handle):
  27.     try:
  28.         fopen = open(file_handle,'rb')
  29.         fread = fopen.read()
  30.         hash_id = hashlib.sha1(fread).hexdigest()
  31.         return (hash_id)
  32.     except (FileNotFoundError):
  33.         logging.warning(file_handle + "File not found")
  34.     finally:
  35.         fopen.close()
  36.  
  37. def sizeof(file_handle):
  38.     s = os.stat(file_handle)
  39.     return ("sizeof ",s[6])
  40.    
  41.    
  42.  
  43. def _void():
  44.     while 1:
  45.         time.sleep(2)
  46.         for j in range(0, len(_letter)):
  47.             if ctypes.windll.kernel32.GetDriveTypeW(_letter[j] + ":") == removable_disk_status:
  48.                 #sys.stdout.write('\a') #beep
  49.                 if os.path.exists(_letter[j] + ":/Autorun.inf"):
  50.                     time.sleep(2)
  51.                     sys.stdout.write(time.asctime() + '\x1b[1m\x1b[31m' + "\n[+] Autorun.inf is detected ->" + _letter[j] + Style.RESET_ALL + '\n')
  52.                     print("sizeof ",sizeof(_letter[j] + ":/Autorun.inf"))
  53.                     os.system("attrib " + _letter[j] + ":/Autorun.inf")
  54.                     print("inf file sum(sha1): ",'\x1b[1m\x1b[35m' + getsum(_letter[j] + ":/Autorun.inf") + Style.RESET_ALL)
  55.                     c.read(_letter[j] + ":/Autorun.inf")
  56.                     if "Autorun" in c.sections():
  57.                         logging.info("Autorun section OK")
  58.                         if 'shellexecute' in c['Autorun']:
  59.                             print("execute file sum(sha1): ",c['Autorun']['shellexecute'],'\x1b[1m\x1b[35m' + getsum(_letter[j] + ":/" + c['Autorun']['shellexecute']) + Style.RESET_ALL)
  60.                             shutil.copy(_letter[j] + ":/" + c['Autorun']['shellexecute'],time.asctime().replace(" ","_").replace(":","_"))
  61.                         else:
  62.                                 if 'open' in c['Autorun']:
  63.                                     print("execute file sum(sha1): ",c['Autorun']['run'],'\x1b[1m\x1b[35m' + getsum(_letter[j] + ":/" + c['Autorun']['shellexecute']) + Style.RESET+ALL)
  64.                                     shutil.copy(_letter[j] + ":/" + c['Autorun']['run'],time.asctime().replace(" ","_").replace(":","_"))
  65.                     else:
  66.                         continue
  67.                     try:
  68.                         action = input('\a\n\nDo you want delete Autorun.inf file [Y & N]:')
  69.                         if action.lower() == 'y':
  70.                             os.remove(_letter[j] + ":/Autorun.inf")
  71.                             logging.warning("File is successfully removed")
  72.                         else:
  73.                             continue
  74.                     except FileNotFoundError:
  75.                         continue
  76.                 else:
  77.                         continue
  78.             else:
  79.                 continue
  80.                
  81.        
  82.  
  83. _void()
Advertisement
Add Comment
Please, Sign In to add comment