Windows Gather Database Instance Enumeration - Metasploit


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

Module Overview


Name: Windows Gather Database Instance Enumeration
Module: post/windows/gather/enum_db
Source code: modules/post/windows/gather/enum_db.rb
Disclosure date: -
Last modification time: 2021-10-06 13:43:31 +0000
Supported architecture(s): -
Supported platform(s): Windows
Target service / protocol: -
Target network port(s): -
List of CVEs: -

This module will enumerate a windows system for installed database instances

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/enum_db

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

Go back to menu.

Msfconsole Usage


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

msf6 > use post/windows/gather/enum_db

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

       Name: Windows Gather Database Instance Enumeration
     Module: post/windows/gather/enum_db
   Platform: Windows
       Arch: 
       Rank: Normal

Provided by:
  Barry Shteiman <[email protected]>
  juan vazquez <[email protected]>

Compatible session types:
  Meterpreter

Basic options:
  Name     Current Setting  Required  Description
  ----     ---------------  --------  -----------
  SESSION                   yes       The session to run this module on.

Description:
  This module will enumerate a windows system for installed database 
  instances

Module Options


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

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

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

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   SESSION                   yes       The session to run this module on.

Advanced Options


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

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

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

   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/gather/enum_db module can do:

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

Post actions:

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

Evasion Options


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

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

Done, No Databases were found


Here is a relevant code snippet related to the "Done, No Databases were found" error message:

45:	    if check_sybase
46:	      results += enumerate_sybase
47:	    end
48:	
49:	    if results.empty?
50:	      print_status("Done, No Databases were found")
51:	      return
52:	    end
53:	
54:	    print_status("Done, Databases Found.")
55:	

could not identify information


Here is a relevant code snippet related to the "could not identify information" error message:

161:	        results << ["mssql", "instance:#{registry_getvaldata(key, i)} port:#{tcpport}", "Microsoft SQL Server", tcpport]
162:	      end
163:	    end
164:	    return results
165:	  rescue
166:	    print_error("\t\t! could not identify information")
167:	    return results || []
168:	  end
169:	
170:	  # method to identify oracle instances
171:	  def enumerate_oracle

<VAL_ORACLE_SID> (No Listener Found)


Here is a relevant code snippet related to the "<VAL_ORACLE_SID> (No Listener Found)" error message:

190:	          key = "#{basekey}\\#{i}"
191:	          val_ORACLE_SID = registry_getvaldata(key, "ORACLE_SID")
192:	          val_ORACLE_HOME = registry_getvaldata(key, "ORACLE_HOME")
193:	        end
194:	        if not exist?(val_ORACLE_HOME + "\\NETWORK\\ADMIN\\tnsnames.ora")
195:	          print_error("\t\t! #{val_ORACLE_SID} (No Listener Found)")
196:	          next
197:	        end
198:	
199:	        data_TNSNAMES = read_file(val_ORACLE_HOME + "\\NETWORK\\ADMIN\\tnsnames.ora")
200:	        if data_TNSNAMES =~ /PORT\ \=\ (\d+)/

<VAL_ORACLE_SID> (No Listener Found)


Here is a relevant code snippet related to the "<VAL_ORACLE_SID> (No Listener Found)" error message:

200:	        if data_TNSNAMES =~ /PORT\ \=\ (\d+)/
201:	          port = $1
202:	          print_good("\t\t+ #{val_ORACLE_SID} (Port:#{port})")
203:	          results << [ "oracle", "instance:#{val_ORACLE_SID} port:#{port}", "Oracle Database Server", port ]
204:	        else
205:	          print_error("\t\t! #{val_ORACLE_SID} (No Listener Found)")
206:	        end
207:	      end
208:	    end
209:	    if not found_key
210:	      print_error("\t\t! Oracle instances not found")

Oracle instances not found


Here is a relevant code snippet related to the "Oracle instances not found" error message:

205:	          print_error("\t\t! #{val_ORACLE_SID} (No Listener Found)")
206:	        end
207:	      end
208:	    end
209:	    if not found_key
210:	      print_error("\t\t! Oracle instances not found")
211:	    end
212:	    return results
213:	  rescue
214:	    print_error("\t\t! could not identify information")
215:	    return results || []

could not identify information


Here is a relevant code snippet related to the "could not identify information" error message:

209:	    if not found_key
210:	      print_error("\t\t! Oracle instances not found")
211:	    end
212:	    return results
213:	  rescue
214:	    print_error("\t\t! could not identify information")
215:	    return results || []
216:	  end
217:	
218:	  # method to identify mysql instances
219:	  def enumerate_mysql

could not identify information


Here is a relevant code snippet related to the "could not identify information" error message:

233:	      if data and data =~ /port\=(\d+)/
234:	        port = $1
235:	        print_good("\t\t+ MYSQL (Port:#{port})")
236:	        results << ["mysql", "instance:MYSQL port:#{port}", "MySQL Server", port]
237:	      else
238:	        print_error("\t\t! could not identify information")
239:	      end
240:	    end
241:	    return results
242:	  rescue
243:	    print_error("\t\t! could not identify information")

could not identify information


Here is a relevant code snippet related to the "could not identify information" error message:

238:	        print_error("\t\t! could not identify information")
239:	      end
240:	    end
241:	    return results
242:	  rescue
243:	    print_error("\t\t! could not identify information")
244:	    return results || []
245:	  end
246:	
247:	  # method to identify sybase instances
248:	  def enumerate_sybase

could not locate configuration file.


Here is a relevant code snippet related to the "could not locate configuration file." error message:

250:	    instance = registry_getvaldata(basekey, "DSLISTEN")
251:	    location = registry_getvaldata(basekey, "RootDir")
252:	    results = []
253:	
254:	    if not exist?(location + "\\ini\\sql.ini")
255:	      print_error("\t\t! could not locate configuration file.")
256:	      return results
257:	    end
258:	
259:	    data = read_file(location + "\\ini\\sql.ini")
260:	    if data =~ /\[#{instance}\]([^\[]*)/

couldnt locate information.


Here is a relevant code snippet related to the "couldnt locate information." error message:

258:	
259:	    data = read_file(location + "\\ini\\sql.ini")
260:	    if data =~ /\[#{instance}\]([^\[]*)/
261:	      segment = $1
262:	    else
263:	      print_error("\t\t! couldnt locate information.")
264:	      return results
265:	    end
266:	
267:	    if segment =~ /master\=\w+\,[^\,]+\,(\d+)/
268:	      port = $1

couldnt locate information.


Here is a relevant code snippet related to the "couldnt locate information." error message:

265:	    end
266:	
267:	    if segment =~ /master\=\w+\,[^\,]+\,(\d+)/
268:	      port = $1
269:	    else
270:	      print_error("\t\t! couldnt locate information.")
271:	      return results
272:	    end
273:	
274:	    print_good("\t\t+ #{instance} (Port:#{port})")
275:	    results << [ "sybase", "instance:#{instance} port:#{port}", "Sybase SQL Server", port ]

couldnt locate information.


Here is a relevant code snippet related to the "couldnt locate information." error message:

273:	
274:	    print_good("\t\t+ #{instance} (Port:#{port})")
275:	    results << [ "sybase", "instance:#{instance} port:#{port}", "Sybase SQL Server", port ]
276:	    return results
277:	  rescue
278:	    print_error("\t\t! couldnt locate information.")
279:	    return results || []
280:	  end
281:	
282:	  # method to identify db2 instances
283:	  def enumerate_db2

could not identify instances information


Here is a relevant code snippet related to the "could not identify instances information" error message:

285:	    cmd_i = cmd_exec("db2cmd", "-i -w /c db2ilist")
286:	    cmd_p = cmd_exec("db2cmd", "-i -w /c db2 get dbm cfg")
287:	    if cmd_p =~ /\ ?TCP\/IP\ Service\ name[\ ]+\(SVCENAME\)\ =\ (\w+)/
288:	      port = $1
289:	    else
290:	      print_error("\t\t! could not identify instances information")
291:	      return results
292:	    end
293:	
294:	    windir = session.sys.config.getenv('windir')
295:	    getfile = session.fs.file.search(windir + "\\system32\\drivers\\etc\\", "services.*", recurse = true, timeout = -1)

could not identify instances information


Here is a relevant code snippet related to the "could not identify instances information" error message:

303:	    end
304:	
305:	    if data and data =~ /#{port}[\ \t]+(\d+)/
306:	      port_t = $1
307:	    else
308:	      print_error("\t\t! could not identify instances information")
309:	      return results
310:	    end
311:	
312:	    cmd_i.split("\n").compact.each do |line|
313:	      stripped = line.strip

could not identify instances information


Here is a relevant code snippet related to the "could not identify instances information" error message:

315:	      results << [ "db2", "instance:#{stripped} port:#{port_t}", "DB2 Server", port_t ]
316:	    end
317:	
318:	    return results
319:	  rescue
320:	    print_error("\t\t! could not identify instances information")
321:	    return results || []
322:	  end
323:	
324:	  ##### helper methods #####
325:	

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • Barry Shteiman <barry[at]sectorix.com>
  • juan vazquez

Version


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

Go back to menu.