Ubiquiti Configuration Importer - Metasploit


This page contains detailed information about how to use the auxiliary/admin/networking/ubiquiti_config metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: Ubiquiti Configuration Importer
Module: auxiliary/admin/networking/ubiquiti_config
Source code: modules/auxiliary/admin/networking/ubiquiti_config.rb
Disclosure date: -
Last modification time: 2022-03-23 11:32:45 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: -
Target network port(s): 22
List of CVEs: -

This module imports an Ubiquiti device configuration. The db file within the .unf backup is the data file for Unifi. This module can take either the db file or .unf.

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.

Stability:

  • crash-safe: Module should not crash the service.

Basic Usage


msf > use auxiliary/admin/networking/ubiquiti_config
msf auxiliary(ubiquiti_config) > show targets
    ... a list of targets ...
msf auxiliary(ubiquiti_config) > set TARGET target-id
msf auxiliary(ubiquiti_config) > show options
    ... show and set options ...
msf auxiliary(ubiquiti_config) > exploit

Required Options


  • CONFIG: Path to configuration to import

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

Knowledge Base


Vulnerable Application


General Notes

This module imports an Ubiquiti Unifi configuration file into the database. This is similar to post/multi/gather/ubiquiti_unifi_backup only access isn't required, and assumes you already have the file.

This module is able to take a unf file, from the controller and perform the following actions:

  1. Decrypt the file
  2. Fix the zip file if a zip utility is on the system
  3. Extract db.gz
  4. Unzip the db file
  5. Import the db file

Or simply pass the db file for import directly.

Verification Steps


  1. Have a Ubiquiti Unifi configuration file (db or unf)
  2. Start msfconsole
  3. use auxiliary/admin/networking/ubiquiti_config
  4. set RHOST x.x.x.x
  5. set CONFIG /tmp/file.unf
  6. run

Options


RHOST

Needed for setting services and items to. This is relatively arbitrary.

CONFIG

File path to the configuration unf or db file..

Scenarios


Unf File

resource (unifi_config.rb)> use auxiliary/admin/networking/ubiquiti_config
resource (unifi_config.rb)> set rhosts 127.0.0.1
rhosts => 127.0.0.1
resource (unifi_config.rb)> set config /root/.msf4/loot/20190825172544_default_1.1.1.1_ubiquiti.unifi.b_740136.unf
config => /root/.msf4/loot/20190825172544_default_1.1.1.1_ubiquiti.unifi.b_740136.unf
resource (unifi_config.rb)> run
[*] Running module against 127.0.0.1
[+] File DECRYPTED.  Still needs to be repaired
[*] Attempting to repair zip file (this is normal and takes some time)
[+] File DECRYPTED and REPAIRED and saved to /tmp/fixed_zip.zip20190825-6283-1merolj.
[*] extracting db.gz
[*] Converting config BSON to JSON
[+] Admin user unifiadmin with email [email protected] found with password hash $6$R6qnBHgF$CHYrf4t.fXu0pcoloju5a85m3ujrjJLhIO.lN1xZqHZPQoUXXsJB98jgtsvt4Qo2/8t3epzbVLiba7Ls7GCVxcV.
[+] Radius server: 1.1.1.1:1812 with secret ''
[+] Mesh Wifi Network vwire-111117d211c1c1ea password 113b9b872b1114a9111f1a11ae11cdfe
[+] SSH user admin found with password lyxGYOF9UalubyyG and hash $6$37uelU/k$EkJuteQiAIP.CrRaJj4xC9gt61n95FJP3fQuQQmE9TqtFKtmIGsV5XSIJI.muBLOMKMkdlsPl8E3BvjJit.F21
[+] Config import successful
[*] Auxiliary module execution completed

db File

resource (unifi_config.rb)> use auxiliary/admin/networking/ubiquiti_config
resource (unifi_config.rb)> set rhosts 127.0.0.1
rhosts => 127.0.0.1
msf5 auxiliary(admin/networking/ubiquiti_config) > set config /root/.msf4/loot/db
config => /root/.msf4/loot/db
msf5 auxiliary(admin/networking/ubiquiti_config) > run
[*] Running module against 127.0.0.1

[*] Converting config BSON to JSON
[+] Admin user unifiadmin with email [email protected] found with password hash $6$R6qnBHgF$CHYrf4t.fXu0pcoloju5a85m3ujrjJLhIO.lN1xZqHZPQoUXXsJB98jgtsvt4Qo2/8t3epzbVLiba7Ls7GCVxcV.
[+] Radius server: 1.1.1.1:1812 with secret ''
[+] Mesh Wifi Network vwire-111117d211c1c1ea password 113b9b872b1114a9111f1a11ae11cdfe
[+] SSH user admin found with password lyxGYOF9UalubyyG and hash $6$37uelU/k$EkJuteQiAIP.CrRaJj4xC9gt61n95FJP3fQuQQmE9TqtFKtmIGsV5XSIJI.muBLOMKMkdlsPl8E3BvjJit.F21
[+] Config import successful
[*] Auxiliary module execution completed

Go back to menu.

Msfconsole Usage


Here is how the admin/networking/ubiquiti_config auxiliary module looks in the msfconsole:

msf6 > use auxiliary/admin/networking/ubiquiti_config

msf6 auxiliary(admin/networking/ubiquiti_config) > show info

       Name: Ubiquiti Configuration Importer
     Module: auxiliary/admin/networking/ubiquiti_config
    License: Metasploit Framework License (BSD)
       Rank: Normal

Provided by:
  h00die

Check supported:
  No

Basic options:
  Name    Current Setting  Required  Description
  ----    ---------------  --------  -----------
  CONFIG                   yes       Path to configuration to import
  RHOSTS                   yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  RPORT   22               yes       The target port

Description:
  This module imports an Ubiquiti device configuration. The db file 
  within the .unf backup is the data file for Unifi. This module can 
  take either the db file or .unf.

Module Options


This is a complete list of options available in the admin/networking/ubiquiti_config auxiliary module:

msf6 auxiliary(admin/networking/ubiquiti_config) > show options

Module options (auxiliary/admin/networking/ubiquiti_config):

   Name    Current Setting  Required  Description
   ----    ---------------  --------  -----------
   CONFIG                   yes       Path to configuration to import
   RHOSTS                   yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT   22               yes       The target port

Advanced Options


Here is a complete list of advanced options supported by the admin/networking/ubiquiti_config auxiliary module:

msf6 auxiliary(admin/networking/ubiquiti_config) > show advanced

Module advanced options (auxiliary/admin/networking/ubiquiti_config):

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

Auxiliary Actions


This is a list of all auxiliary actions that the admin/networking/ubiquiti_config module can do:

msf6 auxiliary(admin/networking/ubiquiti_config) > show actions

Auxiliary actions:

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

Evasion Options


Here is the full list of possible evasion options supported by the admin/networking/ubiquiti_config auxiliary module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 auxiliary(admin/networking/ubiquiti_config) > 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.

Unifi config file <I_FILE> does not exist!


Here is a relevant code snippet related to the "Unifi config file <I_FILE> does not exist!" error message:

38:	    datastore['CONFIG'].to_s
39:	  end
40:	
41:	  def run
42:	    unless ::File.exist?(i_file)
43:	      fail_with Failure::BadConfig, "Unifi config file #{i_file} does not exist!"
44:	    end
45:	    # input_file could be a unf (encrypted zip), or the db file contained within.
46:	    input_file = ::File.open(i_file, 'rb')
47:	    f = input_file.read
48:	    input_file.close

<I_FILE> read at 0 bytes. Either file is empty or error reading.


Here is a relevant code snippet related to the "<I_FILE> read at 0 bytes. Either file is empty or error reading." error message:

46:	    input_file = ::File.open(i_file, 'rb')
47:	    f = input_file.read
48:	    input_file.close
49:	
50:	    if f.nil?
51:	      fail_with Failure::BadConfig, "#{i_file} read at 0 bytes.  Either file is empty or error reading."
52:	    end
53:	
54:	    if i_file.end_with? '.unf'
55:	      decrypted_data = decrypt_unf(f)
56:	      if decrypted_data.nil? || decrypted_data.empty?

Unable to decrypt


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

52:	    end
53:	
54:	    if i_file.end_with? '.unf'
55:	      decrypted_data = decrypt_unf(f)
56:	      if decrypted_data.nil? || decrypted_data.empty?
57:	        fail_with Failure::Unknown, 'Unable to decrypt'
58:	      end
59:	      print_good('File DECRYPTED.  Still needs to be repaired')
60:	      loot_path = Rex::Quickfile.new('decrypted_zip.zip')
61:	      loot_path.write(decrypted_data)
62:	      loot_path.close

Repair failed on <LOOT_PATH.PATH>


Here is a relevant code snippet related to the "Repair failed on <LOOT_PATH.PATH>" error message:

62:	      loot_path.close
63:	      # ruby zip can't repair, we can try on command line but its not likely to succeed on all platforms
64:	      # tested on kali
65:	      repaired = repair_zip(loot_path.path)
66:	      if repaired.nil?
67:	        fail_with Failure::Unknown, "Repair failed on #{loot_path.path}"
68:	      end
69:	      loot_path = Rex::Quickfile.new('fixed_zip.zip')
70:	      loot_path.write(repaired)
71:	      loot_path.close
72:	      print_good("File DECRYPTED and REPAIRED and saved to #{loot_path.path}.")

Unable to locate db.gz config database file


Here is a relevant code snippet related to the "Unable to locate db.gz config database file" error message:

70:	      loot_path.write(repaired)
71:	      loot_path.close
72:	      print_good("File DECRYPTED and REPAIRED and saved to #{loot_path.path}.")
73:	      config_db = extract_and_process_db(loot_path.path)
74:	      if config_db.nil?
75:	        fail_with Failure::Unknown, 'Unable to locate db.gz config database file'
76:	      end
77:	      print_status('Converting BSON to JSON.')
78:	      unifi_config_db_json = bson_to_json(config_db)
79:	      if unifi_config_db_json == {}
80:	        fail_with Failure::Unknown, 'Error in file conversion from BSON to JSON.'

Error in file conversion from BSON to JSON.


Here is a relevant code snippet related to the "Error in file conversion from BSON to JSON." error message:

75:	        fail_with Failure::Unknown, 'Unable to locate db.gz config database file'
76:	      end
77:	      print_status('Converting BSON to JSON.')
78:	      unifi_config_db_json = bson_to_json(config_db)
79:	      if unifi_config_db_json == {}
80:	        fail_with Failure::Unknown, 'Error in file conversion from BSON to JSON.'
81:	      end
82:	      unifi_config_eater(datastore['RHOSTS'], datastore['RPORT'], unifi_config_db_json)
83:	      print_good('Config import successful')
84:	    end
85:	  end

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • h00die

Version


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

Go back to menu.