Windows Manage Driver Loader - Metasploit


This page contains detailed information about how to use the post/windows/manage/driver_loader metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Windows Manage Driver Loader
Module: post/windows/manage/driver_loader
Source code: modules/post/windows/manage/driver_loader.rb
Disclosure date: -
Last modification time: 2017-07-24 06:26:21 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module loads a KMD (Kernel Mode Driver) using the Windows Service API.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


There are two ways to execute this post module.

From the Meterpreter prompt

The first is by using the "run" command at the Meterpreter prompt. It allows you to run the post module against that specific session:

meterpreter > run post/windows/manage/driver_loader

From the msf prompt

The second is by using the "use" command at the msf prompt. You will have to figure out which session ID to set manually. To list all session IDs, you can use the "sessions" command.

msf > use post/windows/manage/driver_loader
msf post(driver_loader) > show options
    ... show and set options ...
msf post(driver_loader) > set SESSION session-id
msf post(driver_loader) > exploit

If you wish to run the post against all sessions from framework, here is how:

1 - Create the following resource script:


framework.sessions.each_pair do |sid, session|
  run_single("use post/windows/manage/driver_loader")
  run_single("set SESSION #{sid}")
  run_single("run")
end

2 - At the msf prompt, execute the above resource script:

msf > resource path-to-resource-script

Required Options


  • SESSION: The session to run this module on.

  • DRIVER_PATH: Driver path in %SYSTEMROOT%. Example: c:\windows\system32\msf.sys

Go back to menu.

Msfconsole Usage


Here is how the windows/manage/driver_loader post exploitation module looks in the msfconsole:

msf6 > use post/windows/manage/driver_loader

msf6 post(windows/manage/driver_loader) > show info

       Name: Windows Manage Driver Loader
     Module: post/windows/manage/driver_loader
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Borja Merino <[email protected]>

Compatible session types:
  Meterpreter

Basic options:
  Name          Current Setting  Required  Description
  ----          ---------------  --------  -----------
  DRIVER_NAME                    no        Driver Name.
  DRIVER_PATH                    yes       Driver path in %SYSTEMROOT%. Example: c:\windows\system32\msf.sys
  ERROR_TYPE    ignore           yes       Error type. (Accepted: ignore, normal, severe, critical)
  SERVICE_TYPE  kernel           yes       Service type. (Accepted: kernel, file_system, adapter, recognizer)
  SESSION                        yes       The session to run this module on.
  START_TYPE    auto             yes       Start type. (Accepted: boot, system, auto, demand, disabled)

Description:
  This module loads a KMD (Kernel Mode Driver) using the Windows 
  Service API.

Module Options


This is a complete list of options available in the windows/manage/driver_loader post exploitation module:

msf6 post(windows/manage/driver_loader) > show options

Module options (post/windows/manage/driver_loader):

   Name          Current Setting  Required  Description
   ----          ---------------  --------  -----------
   DRIVER_NAME                    no        Driver Name.
   DRIVER_PATH                    yes       Driver path in %SYSTEMROOT%. Example: c:\windows\system32\msf.sys
   ERROR_TYPE    ignore           yes       Error type. (Accepted: ignore, normal, severe, critical)
   SERVICE_TYPE  kernel           yes       Service type. (Accepted: kernel, file_system, adapter, recognizer)
   SESSION                        yes       The session to run this module on.
   START_TYPE    auto             yes       Start type. (Accepted: boot, system, auto, demand, disabled)

Advanced Options


Here is a complete list of advanced options supported by the windows/manage/driver_loader post exploitation module:

msf6 post(windows/manage/driver_loader) > show advanced

Module advanced options (post/windows/manage/driver_loader):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   VERBOSE    false            no        Enable detailed status messages
   WORKSPACE                   no        Specify the workspace for this module

Post Actions


This is a list of all post exploitation actions which the windows/manage/driver_loader module can do:

msf6 post(windows/manage/driver_loader) > show actions

Post actions:

   Name  Description
   ----  -----------

Evasion Options


Here is the full list of possible evasion options supported by the windows/manage/driver_loader post exploitation module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 post(windows/manage/driver_loader) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

SERVICE_ERROR_CRITICAL


Here is a relevant code snippet related to the "SERVICE_ERROR_CRITICAL" error message:

16:	    "disabled"  => "SERVICE_DISABLED",
17:	    "system"    => "SERVICE_SYSTEM_START"
18:	  }
19:	
20:	  ERROR_TYPE = {
21:	    "critical"  => "SERVICE_ERROR_CRITICAL",
22:	    "normal"    => "SERVICE_ERROR_NORMAL",
23:	    "severe"    => "SERVICE_ERROR_SEVERE",
24:	    "ignore"    => "SERVICE_ERROR_IGNORE"
25:	  }
26:	

SERVICE_ERROR_NORMAL


Here is a relevant code snippet related to the "SERVICE_ERROR_NORMAL" error message:

17:	    "system"    => "SERVICE_SYSTEM_START"
18:	  }
19:	
20:	  ERROR_TYPE = {
21:	    "critical"  => "SERVICE_ERROR_CRITICAL",
22:	    "normal"    => "SERVICE_ERROR_NORMAL",
23:	    "severe"    => "SERVICE_ERROR_SEVERE",
24:	    "ignore"    => "SERVICE_ERROR_IGNORE"
25:	  }
26:	
27:	  SERVICE_TYPE = {

SERVICE_ERROR_SEVERE


Here is a relevant code snippet related to the "SERVICE_ERROR_SEVERE" error message:

18:	  }
19:	
20:	  ERROR_TYPE = {
21:	    "critical"  => "SERVICE_ERROR_CRITICAL",
22:	    "normal"    => "SERVICE_ERROR_NORMAL",
23:	    "severe"    => "SERVICE_ERROR_SEVERE",
24:	    "ignore"    => "SERVICE_ERROR_IGNORE"
25:	  }
26:	
27:	  SERVICE_TYPE = {
28:	    "kernel"       => "SERVICE_KERNEL_DRIVER",

SERVICE_ERROR_IGNORE


Here is a relevant code snippet related to the "SERVICE_ERROR_IGNORE" error message:

19:	
20:	  ERROR_TYPE = {
21:	    "critical"  => "SERVICE_ERROR_CRITICAL",
22:	    "normal"    => "SERVICE_ERROR_NORMAL",
23:	    "severe"    => "SERVICE_ERROR_SEVERE",
24:	    "ignore"    => "SERVICE_ERROR_IGNORE"
25:	  }
26:	
27:	  SERVICE_TYPE = {
28:	    "kernel"       => "SERVICE_KERNEL_DRIVER",
29:	    "file_system"  => "SERVICE_FILE_SYSTEM_DRIVER",

Error type.


Here is a relevant code snippet related to the "Error type." error message:

47:	      [
48:	        OptString.new('DRIVER_PATH', [true,  'Driver path in %SYSTEMROOT%. Example: c:\\windows\\system32\\msf.sys']),
49:	        OptString.new('DRIVER_NAME', [false, 'Driver Name.']),
50:	        OptEnum.new('START_TYPE',    [true,  'Start type.', 'auto', [ 'boot', 'system', 'auto', 'demand','disabled']]),
51:	        OptEnum.new('SERVICE_TYPE',  [true,  'Service type.', 'kernel', [ 'kernel', 'file_system', 'adapter', 'recognizer']]),
52:	        OptEnum.new('ERROR_TYPE',    [true,  'Error type.', 'ignore', [ 'ignore', 'normal', 'severe', 'critical']])
53:	      ])
54:	  end
55:	
56:	  def run
57:	    driver = datastore['DRIVER_PATH']

ERROR_TYPE


Here is a relevant code snippet related to the "ERROR_TYPE" error message:

54:	  end
55:	
56:	  def run
57:	    driver = datastore['DRIVER_PATH']
58:	    start = START_TYPE[datastore['START_TYPE']]
59:	    error = ERROR_TYPE[datastore['ERROR_TYPE']]
60:	    service = SERVICE_TYPE[datastore['SERVICE_TYPE']]
61:	
62:	    name = datastore['DRIVER_NAME'].blank? ? Rex::Text.rand_text_alpha((rand(8)+6)) : datastore['DRIVER_NAME']
63:	
64:	    unless is_admin?

Administrator or better privileges needed. Try 'getsystem' first.


Here is a relevant code snippet related to the "Administrator or better privileges needed. Try 'getsystem' first." error message:

60:	    service = SERVICE_TYPE[datastore['SERVICE_TYPE']]
61:	
62:	    name = datastore['DRIVER_NAME'].blank? ? Rex::Text.rand_text_alpha((rand(8)+6)) : datastore['DRIVER_NAME']
63:	
64:	    unless is_admin?
65:	      print_error("Administrator or better privileges needed. Try 'getsystem' first.")
66:	      return
67:	    end
68:	
69:	    unless driver =~ Regexp.new(Regexp.escape(expand_path("%SYSTEMROOT%")), Regexp::IGNORECASE)
70:	      print_error("The driver must be inside %SYSTEMROOT%.")

The driver must be inside %SYSTEMROOT%.


Here is a relevant code snippet related to the "The driver must be inside %SYSTEMROOT%." error message:

65:	      print_error("Administrator or better privileges needed. Try 'getsystem' first.")
66:	      return
67:	    end
68:	
69:	    unless driver =~ Regexp.new(Regexp.escape(expand_path("%SYSTEMROOT%")), Regexp::IGNORECASE)
70:	      print_error("The driver must be inside %SYSTEMROOT%.")
71:	      return
72:	    end
73:	
74:	    unless file_exist?(driver)
75:	      print_error("Driver #{driver} does not exist.")

Driver <DRIVER> does not exist.


Here is a relevant code snippet related to the "Driver <DRIVER> does not exist." error message:

70:	      print_error("The driver must be inside %SYSTEMROOT%.")
71:	      return
72:	    end
73:	
74:	    unless file_exist?(driver)
75:	      print_error("Driver #{driver} does not exist.")
76:	      return
77:	    end
78:	
79:	    inst = install_driver(name, path: driver, starttype: start, error_control: error, service_type: service)
80:	

Service already started.


Here is a relevant code snippet related to the "Service already started." error message:

82:	      ss = service_start(name)
83:	      case ss
84:	      when Windows::Error::SUCCESS
85:	        print_good("Driver loaded successfully.")
86:	      when Windows::Error::SERVICE_ALREADY_RUNNING
87:	        print_error("Service already started.")
88:	      when Windows::Error::SERVICE_DISABLED
89:	        print_error("Service disabled.")
90:	      else
91:	        print_error("There was an error starting the service.")
92:	      end

Service disabled.


Here is a relevant code snippet related to the "Service disabled." error message:

84:	      when Windows::Error::SUCCESS
85:	        print_good("Driver loaded successfully.")
86:	      when Windows::Error::SERVICE_ALREADY_RUNNING
87:	        print_error("Service already started.")
88:	      when Windows::Error::SERVICE_DISABLED
89:	        print_error("Service disabled.")
90:	      else
91:	        print_error("There was an error starting the service.")
92:	      end
93:	    end
94:	  end

There was an error starting the service.


Here is a relevant code snippet related to the "There was an error starting the service." error message:

86:	      when Windows::Error::SERVICE_ALREADY_RUNNING
87:	        print_error("Service already started.")
88:	      when Windows::Error::SERVICE_DISABLED
89:	        print_error("Service disabled.")
90:	      else
91:	        print_error("There was an error starting the service.")
92:	      end
93:	    end
94:	  end
95:	
96:	  def install_driver(name, opts={})

The specified service already exists.


Here is a relevant code snippet related to the "The specified service already exists." error message:

98:	
99:	    if rc == Windows::Error::SUCCESS
100:	      print_status("Service object \"#{name}\" added to the Service Control Manager database.")
101:	      return true
102:	    elsif rc == Windows::Error::SERVICE_EXISTS
103:	      print_error("The specified service already exists.")
104:	      # Show ImagePath just to know if the service corresponds to the desired driver.
105:	      service = service_info(name)
106:	      print_error("Path of driver file in \"#{name}\" service: #{service[:path]}.")
107:	    else
108:	      print_error("There was an error opening the driver handler. GetLastError=#{rc}.")

Path of driver file in "<NAME>" service: <SERVICE:PATH>.


Here is a relevant code snippet related to the "Path of driver file in "<NAME>" service: <SERVICE:PATH>." error message:

101:	      return true
102:	    elsif rc == Windows::Error::SERVICE_EXISTS
103:	      print_error("The specified service already exists.")
104:	      # Show ImagePath just to know if the service corresponds to the desired driver.
105:	      service = service_info(name)
106:	      print_error("Path of driver file in \"#{name}\" service: #{service[:path]}.")
107:	    else
108:	      print_error("There was an error opening the driver handler. GetLastError=#{rc}.")
109:	    end
110:	    return false
111:	  end

There was an error opening the driver handler. GetLastError=<RC>.


Here is a relevant code snippet related to the "There was an error opening the driver handler. GetLastError=<RC>." error message:

102:	    elsif rc == Windows::Error::SERVICE_EXISTS
103:	      print_error("The specified service already exists.")
104:	      # Show ImagePath just to know if the service corresponds to the desired driver.
105:	      service = service_info(name)
106:	      print_error("Path of driver file in \"#{name}\" service: #{service[:path]}.")
107:	    else
108:	      print_error("There was an error opening the driver handler. GetLastError=#{rc}.")
109:	    end
110:	    return false
111:	  end
112:	end

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


Borja Merino <bmerinofe[at]gmail.com>

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.