Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/networking/ubiquiti_config.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'zlib'67class MetasploitModule < Msf::Auxiliary8include Msf::Auxiliary::Ubiquiti9include Msf::Exploit::Deprecated10moved_from 'auxiliary/admin/ubiquiti/ubiquiti_config'1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Ubiquiti Configuration Importer',17'Description' => %q{18This module imports an Ubiquiti device configuration.19The db file within the .unf backup is the data file for20Unifi. This module can take either the db file or .unf.21},22'License' => MSF_LICENSE,23'Author' => ['h00die'],24'Notes' => {25'Stability' => [CRASH_SAFE],26'Reliability' => [],27'SideEffects' => []28}29)30)3132register_options(33[34OptPath.new('CONFIG', [true, 'Path to configuration to import']),35Opt::RHOST(),36Opt::RPORT(22)37]38)39end4041def i_file42datastore['CONFIG'].to_s43end4445def run46unless ::File.exist?(i_file)47fail_with Failure::BadConfig, "Unifi config file #{i_file} does not exist!"48end49# input_file could be a unf (encrypted zip), or the db file contained within.50input_file = ::File.binread(i_file)5152if input_file.nil?53fail_with Failure::BadConfig, "#{i_file} read at 0 bytes. Either file is empty or error reading."54end5556if i_file.end_with? '.unf'57decrypted_data = decrypt_unf(input_file)58if decrypted_data.nil? || decrypted_data.empty?59fail_with Failure::Unknown, 'Unable to decrypt'60end61print_good('File DECRYPTED. Still needs to be repaired')62loot_path = Rex::Quickfile.new('decrypted_zip.zip')63loot_path.write(decrypted_data)64loot_path.close65# ruby zip can't repair, we can try on command line but its not likely to succeed on all platforms66# tested on kali67repaired = repair_zip(loot_path.path)68if repaired.nil?69fail_with Failure::Unknown, "Repair failed on #{loot_path.path}"70end71loot_path = Rex::Quickfile.new('fixed_zip.zip')72loot_path.write(repaired)73loot_path.close74print_good("File DECRYPTED and REPAIRED and saved to #{loot_path.path}.")75config_db = extract_and_process_db(loot_path.path)76if config_db.nil?77fail_with Failure::Unknown, 'Unable to locate db.gz config database file'78end79print_status('Converting BSON to JSON.')80unifi_config_db_json = bson_to_json(config_db)81if unifi_config_db_json == {}82fail_with Failure::Unknown, 'Error in file conversion from BSON to JSON.'83end84unifi_config_eater(datastore['RHOSTS'], datastore['RPORT'], unifi_config_db_json)85print_good('Config import successful')86end87end88end899091