Windows Gather Local Admin Search - Metasploit


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

Module Overview


Name: Windows Gather Local Admin Search
Module: post/windows/gather/local_admin_search_enum
Source code: modules/post/windows/gather/local_admin_search_enum.rb
Disclosure date: -
Last modification time: 2022-01-18 15:08:30 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module will identify systems in a given range that the supplied domain user (should migrate into a user pid) has administrative access to by using the Windows API OpenSCManagerA to establishing a handle to the remote host. Additionally it can enumerate logged in users and group membership via Windows API NetWkstaUserEnum and NetUserGetGroups.

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/gather/local_admin_search_enum

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/gather/local_admin_search_enum
msf post(local_admin_search_enum) > show options
    ... show and set options ...
msf post(local_admin_search_enum) > set SESSION session-id
msf post(local_admin_search_enum) > 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/gather/local_admin_search_enum")
  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.

  • RHOSTS: The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'

Go back to menu.

Msfconsole Usage


Here is how the windows/gather/local_admin_search_enum post exploitation module looks in the msfconsole:

msf6 > use post/windows/gather/local_admin_search_enum

msf6 post(windows/gather/local_admin_search_enum) > show info

       Name: Windows Gather Local Admin Search
     Module: post/windows/gather/local_admin_search_enum
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Brandon McCann "zeknox" <[email protected]>
  Thomas McCarthy "smilingraccoon" <[email protected]>
  Royce Davis "r3dy" <[email protected]>

Compatible session types:
  Meterpreter

Basic options:
  Name               Current Setting  Required  Description
  ----               ---------------  --------  -----------
  DOMAIN                              no        Domain to enumerate user's groups for
  DOMAIN_CONTROLLER                   no        Domain Controller to query groups
  ENUM_GROUPS        true             no        Enumerates groups for identified users.
  ENUM_USERS         true             yes       Enumerates logged on users.
  RHOSTS                              yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  SESSION                             yes       The session to run this module on.
  THREADS            1                yes       The number of concurrent threads (max one per host)

Description:
  This module will identify systems in a given range that the supplied 
  domain user (should migrate into a user pid) has administrative 
  access to by using the Windows API OpenSCManagerA to establishing a 
  handle to the remote host. Additionally it can enumerate logged in 
  users and group membership via Windows API NetWkstaUserEnum and 
  NetUserGetGroups.

Module Options


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

msf6 post(windows/gather/local_admin_search_enum) > show options

Module options (post/windows/gather/local_admin_search_enum):

   Name               Current Setting  Required  Description
   ----               ---------------  --------  -----------
   DOMAIN                              no        Domain to enumerate user's groups for
   DOMAIN_CONTROLLER                   no        Domain Controller to query groups
   ENUM_GROUPS        true             no        Enumerates groups for identified users.
   ENUM_USERS         true             yes       Enumerates logged on users.
   RHOSTS                              yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   SESSION                             yes       The session to run this module on.
   THREADS            1                yes       The number of concurrent threads (max one per host)

Advanced Options


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

msf6 post(windows/gather/local_admin_search_enum) > show advanced

Module advanced options (post/windows/gather/local_admin_search_enum):

   Name                 Current Setting  Required  Description
   ----                 ---------------  --------  -----------
   ShowProgress         true             yes       Display progress messages during a scan
   ShowProgressPercent  10               yes       The interval in percent that progress should be shown
   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/gather/local_admin_search_enum module can do:

msf6 post(windows/gather/local_admin_search_enum) > show actions

Post actions:

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

Evasion Options


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

msf6 post(windows/gather/local_admin_search_enum) > 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.

Running as SYSTEM, module should be run with USER level rights


Here is a relevant code snippet related to the "Running as SYSTEM, module should be run with USER level rights" error message:

48:	    # Saving it here so the modified value remains with this module.
49:	    @domain_controller = datastore['DOMAIN_CONTROLLER']
50:	
51:	    if is_system?
52:	      # running as SYSTEM and will not pass any network credentials
53:	      print_error "Running as SYSTEM, module should be run with USER level rights"
54:	      return
55:	    else
56:	      @adv = client.railgun.advapi32
57:	
58:	      # Get domain and domain controller if options left blank

Could not read RSOP data, will not enumerate users and groups. Manually specify DC.


Here is a relevant code snippet related to the "Could not read RSOP data, will not enumerate users and groups. Manually specify DC." error message:

77:	          dc_applied = /Group Policy was applied from:\s*(.*)\s*/.match(res)
78:	          if dc_applied
79:	            @domain_controller = dc_applied[1].strip
80:	          else
81:	            @dc_error = true
82:	            print_error("Could not read RSOP data, will not enumerate users and groups. Manually specify DC.")
83:	          end
84:	        else
85:	          @dc_error = true
86:	          print_error("User never logged into device, will not enumerate users and groups. Manually specify DC.")
87:	        end

User never logged into device, will not enumerate users and groups. Manually specify DC.


Here is a relevant code snippet related to the "User never logged into device, will not enumerate users and groups. Manually specify DC." error message:

81:	            @dc_error = true
82:	            print_error("Could not read RSOP data, will not enumerate users and groups. Manually specify DC.")
83:	          end
84:	        else
85:	          @dc_error = true
86:	          print_error("User never logged into device, will not enumerate users and groups. Manually specify DC.")
87:	        end
88:	      end
89:	    end
90:	  end
91:	

Issue enumerating users on <HOST>


Here is a relevant code snippet related to the "Issue enumerating users on <HOST>" error message:

101:	
102:	    begin
103:	      # Connect to host and enumerate logged in users
104:	      winsessions = client.railgun.netapi32.NetWkstaUserEnum("\\\\#{host}", 1, 4, -1, 4, 4, nil)
105:	    rescue ::Exception => e
106:	      print_error("Issue enumerating users on #{host}")
107:	      return userlist
108:	    end
109:	
110:	    return userlist if winsessions.nil?
111:	

Issue reading memory for <HOST>


Here is a relevant code snippet related to the "Issue reading memory for <HOST>" error message:

115:	    base = 0
116:	    userlist = Array.new
117:	    begin
118:	      mem = client.railgun.memread(startmem, 8 * count)
119:	    rescue ::Exception => e
120:	      print_error("Issue reading memory for #{host}")
121:	      vprint_error(e.to_s)
122:	      return userlist
123:	    end
124:	    # For each entry returned, get domain and name of logged in user
125:	    begin

ENUM_GROUPS


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

134:	        unless temp[:user].empty? or temp[:user][-1, 1] == "$"
135:	
136:	          # Check if enumerated user's domain matches supplied domain, if there was
137:	          # an error, or if option disabled
138:	          data = ""
139:	          if datastore['DOMAIN'].upcase == temp[:domain].upcase and not @dc_error and datastore['ENUM_GROUPS']
140:	            data << " - Groups: #{enum_groups(temp[:user]).chomp(", ")}"
141:	          end
142:	          line = "\tLogged in user:\t#{temp[:domain]}\\#{temp[:user]}#{data}\n"
143:	
144:	          # Write user and groups to notes database

Issue enumerating users on <HOST>


Here is a relevant code snippet related to the "Issue enumerating users on <HOST>" error message:

148:	        end
149:	
150:	        base = base + 8
151:	      }
152:	    rescue ::Exception => e
153:	      print_error("Issue enumerating users on #{host}")
154:	      vprint_error(e.backtrace)
155:	    end
156:	    return userlist
157:	  end
158:	

Issue connecting to DC, try manually setting domain and DC


Here is a relevant code snippet related to the "Issue connecting to DC, try manually setting domain and DC" error message:

164:	    dc = "\\\\#{@domain_controller}"
165:	    begin
166:	      # Connect to DC and enumerate groups of user
167:	      usergroups = client.railgun.netapi32.NetUserGetGroups(dc, user, 0, 4, -1, 4, 4)
168:	    rescue ::Exception => e
169:	      print_error("Issue connecting to DC, try manually setting domain and DC")
170:	      vprint_error(e.to_s)
171:	      return grouplist
172:	    end
173:	
174:	    count = usergroups['totalentries']

Issue reading memory for groups for user <USER>


Here is a relevant code snippet related to the "Issue reading memory for groups for user <USER>" error message:

176:	    base = 0
177:	
178:	    begin
179:	      mem = client.railgun.memread(startmem, 8 * count)
180:	    rescue ::Exception => e
181:	      print_error("Issue reading memory for groups for user #{user}")
182:	      vprint_error(e.to_s)
183:	      return grouplist
184:	    end
185:	
186:	    begin

Issue enumerating groups for user <USER>, check domain


Here is a relevant code snippet related to the "Issue enumerating groups for user <USER>, check domain" error message:

196:	          grouplist << "\n\t-   "
197:	        end
198:	        base = base + 4
199:	      }
200:	    rescue ::Exception => e
201:	      print_error("Issue enumerating groups for user #{user}, check domain")
202:	      vprint_error(e.backtrace)
203:	      return grouplist
204:	    end
205:	
206:	    return grouplist.chomp("\n\t-   ")

<HOST.LJUST-16> <USER> - No Local Admin rights


Here is a relevant code snippet related to the "<HOST.LJUST-16> <USER> - No Local Admin rights" error message:

232:	      # Append data to loot table within database
233:	      print_good(result.chomp("\n")) unless result.nil?
234:	      db_loot(host, user, "localadmin.user")
235:	    else
236:	      # we dont have admin rights
237:	      print_error("#{host.ljust(16)} #{user} - No Local Admin rights")
238:	    end
239:	  end
240:	
241:	  # Write to notes database
242:	  def db_note(host, data, type)

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • Brandon McCann "zeknox" <bmccann[at]accuvant.com>
  • Thomas McCarthy "smilingraccoon" <smilingraccoon[at]gmail.com>
  • Royce Davis "r3dy" <rdavis[at]accuvant.com>

Version


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

Go back to menu.